
s part of my political agenda, in a recent post I walked through the steps of configuring Word 2007's blogging features to work with Subtext. At the end of that article, I promised to review the code changes required to make Subtext accept pictures from Word 2007. The fix I detail here consists of relatively minor code changes, limited to two c# files in the Subtext.Framework project:
- MetaWeblog.cs
- MetaWeblogAPI.cs
If you regularly compile the Subtext source code, you'll find making these changes a snap. If not, you might find it easier to skip the rest of this article, navigate to your site's bin directory, rename the Subtext.Framework.dll file and drop this one in its place.
Before moving forward, I should note that the changes described are against the Subtext 1.9.5b code base and future versions of the code base probably have this incompatibility addressed, so a bit of advice: make sure which version of Subtext you are using before you begin digging into the internals.
MetaWeblogAPI.cs
If you crack open the MetaWeblogAPI.cs file (under Subtext.Framework.XmlRpc) and search for the newMediaObject method, you'll find the following under the IMetaWeblog interface:
[XmlRpcMethod("metaWeblog.newMediaObject",
Description = "Uploads an image, movie, song, or other media "
+ "using the metaWeblog API. Returns the metaObject struct.")]
mediaObjectInfo newMediaObject(object blogid, string username,
string password, mediaObject mediaobject);
Note the blogid parameter is of type object, unlike every other method in the interface, which all support blogid parameters of type string. The easiest fix in this module is to change the change the parameter type to string, and I suspect that this alone might solve the issue, but a more thorough approach, one that leaves compatibility for other applications that may actually use the object-based blogid, is to add a more specific declaration or two. I chose this path of overkill, rather than that of minimalism by adding support for both string and int types; while not strictly necessary, it was quite easy to do. The full definition of the newMediaObject declaration appears below, with the additions surrounded with a dotted border:
[XmlRpcMethod("metaWeblog.newMediaObject", Description = "Uploads an image, movie, song, or other media " + "using the metaWeblog API. Returns the metaObject struct.")] mediaObjectInfo newMediaObject(string blogid, string username, string password, mediaObject mediaobject);
[XmlRpcMethod("metaWeblog.newMediaObject", Description = "Uploads an image, movie, song, or other media " + "using the metaWeblog API. Returns the metaObject struct.")] mediaObjectInfo newMediaObject(int blogid, string username, string password, mediaObject mediaobject); |
[XmlRpcMethod("metaWeblog.newMediaObject", Description = "Uploads an image, movie, song, or other media " + "using the metaWeblog API. Returns the metaObject struct.")] mediaObjectInfo newMediaObject(object blogid, string username, string password, mediaObject mediaobject);
|
These are, of course, only slight variations on the original declaration.
MetaWeblog.cs
Having declared the additional forms of newMediaObject that Subtext will support, we are half way complete. The final changes that are to be made are contained in the MetaWeblog class. Search for the implementation of newMediaObject and you'll find the original signature:
public
mediaObjectInfo newMediaObject(object blogid, string username,
string password, mediaObject mediaobject)
Note the blogid parameter with the type object. I found it best to not change the existing code. Instead, we need only to implement the two additions defined for the interface supporting the two alternate parameter types. Implementing pass-through methods for this is the least painful of approaches:
public
mediaObjectInfo newMediaObject(int blogid, string username, string password, mediaObject mediaobject) { return newMediaObject(blogid.ToString(), username, password, mediaobject); } public
mediaObjectInfo newMediaObject(string blogid, string username, string password, mediaObject mediaobject) { return newMediaObject((object)blogid, username, password, mediaobject); } |
And that's pretty much it for changes to Subtext. After we compile this and deploy the resulting modified Subtext.Framework assembly, Subtext should support images from Word 2007.