Tuesday, May 5, 2009

Hacking MediaWiki to Hide Prior Deletion Warning & Logs

Recently, I've been living in "demo world" (some might say "demo hell," mind you), rehearsing, rehashing, and delivering software demonstrations to interested parties.  This project has been all about quickly integrating different applications via standardized mechanisms like Web Services and the careful use of Service-Oriented Architecture (SOA), and a big part of it has been to deliver meaningful content from the individual applications into a Wiki (we're using MediaWiki, like Wikipedia and the US intelligence community's "Intellipedia").

Living in demo world, though, usually means resetting after each rehearsal, dry run, and actual demo to get ready for the next one, and with MediaWiki, that meant deleting articles so that they could later be recreated (for various reasons, we didn't want to just do new edits to the same articles; we needed to recreate them each time).  There's a problem, though: MediaWiki maintains a "deletion log," showing each time the page was deleted (and allowing for undeletion), and by default that log appears--with an additional warning--when a user tries to recreate the article.  Amplify this log's size by several dozen deletion & recreation cycles, and it's suddenly a big problem; we don't want our demo to look like a demo, mind you.

I dug around in the MediaWiki documentation and on Google a fair amount looking for a solution, and though there are several MediaWiki extensions which allow for deleting the actual prior instances (to remove illegal content, for example) and processes, none really fit the bill.  First, they'd have to be repeated between demos, adding an additional piece of "staging," and any additional complexity in the demo script is bad, bad, bad.  Second, several either didn't work (erasing the revisions but not the actual log entry showing they'd existed at some point, for example), or even came with the caveat that they could potentially corrupt the MediaWiki database--argh!

So I next looked for the warning message shown by MediaWiki when recreating a deleted article; it's a system message, and thus appears in the "Special:Allmessages" page (the particular entry is titled "recreate-deleted-warn" it turns out).  Changing or blanking that message isn't going to work; the deletion log will still show, and it's more objectionable in demo world than the actual warning.  But, with the name of the message in hand, I could then search the MediaWiki source code to see where it was displayed...

... which turns out to be a function in (as expected) EditPage.php, one of the core includes which contains the code used to edit a page.  The function in question is showDeletionLog(), and as its comments explain, it displays any deletion log entries along with "a nice little note for the user" if editing a previously-deleted page.

The fix?

A simple "return" at the top of the function, preventing it from doing anything.  I could have added logic to show it on some occasions and not on others, but in the end, simply returning without doing anything for all calls to that function did the trick.  And the deletion log is still available via its own special page, along with the ability to restore deleted edits, etc.; it simply is no longer shown to the user when editing the deleted page.

One future enhancement: the HTML "DIV" tag containing the deletion log & warning message could easily be set to be hidden by default, but be shown via a click on a message (for example, a cliched "click here to view this page's previous deletions" link with a JavaScript to toggle the div's visibility would work fine).  In fact, one could avoid hacking the core MediaWiki code entirely by simply putting in a plug-in extension which hides that div (handily bearing the ID of "mw-recreate-deleted-warn") during page load.  But that's beyond the scope of my demo world needs.

No comments: