Showing posts with label computers. Show all posts
Showing posts with label computers. Show all posts

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.

Tuesday, October 21, 2008

The Laptop Lemon and the Hardware Handyman

My current laptop has been something of a lemon at best--if not an outright cursed piece of hardware at worst.  Less than a month after I'd gotten it, it fell out of my laptop bag from a height of only a foot or so, but nonetheless cracked its case such that the stylus pen would no longer stay put (and I subsequently lost two $20 styluses). 

Now, I feel pretty comfortable doing repairs and work on laptops myself, including taking things well apart beyond pulling a drive or replacing the keyboard.  A prior laptop's power connector broke apart, and I replaced it with a metal-reinforced connector (out-of-warranty at the time); another had a fan failure which I later remedied.  But for the cosmetic case damage above, unfortunately, Gateway won't sell end-users the "plastics kit"--replacement plastic case parts--unlike some other manufacturers, so I've just had to live with that physical damage (Gateway wanted $300 to fix it, something I declined.)

But what else leads me to call my laptop a lemon?  At less than two years old, the keyboard began to fail, with several keys no longer responding to anything short of a right hook.  Fortunately, I'd bought the extended warranty, and Gateway shipped me a new keyboard free-of-charge.  Just after the warranty ran out, the internal network card began to fail; it dropped connections regularly (but unpredictably) and also saw weird signal degradation problems where an 11 megabit connection would slowly but unavoidably dwindle away to 1 megabit.  Fortunately, I found a replacement card--an upgrade to 54 megabits, no less--on eBay and swapped it out without much further issue.

Last year, the hard drive died; fortunately, though the death came all at once, it affected only the write heads--so I was able to plug the drive into a USB enclosure, set it to read-only access, and pull off all essential data.  I took that opportunity to upgrade the drive as well to something larger and faster.  At the same time, I maxed out the RAM by replacing one of the 512 MB DIMMs with a 1 GB module, having already done the same to the other DIMM when I replaced the keyboard.

The hinge on the laptop screen has been one of its worst-designed features; within a year, cracks began forming around the hinge's connection to the LCD panel, eventually widening to full-fledged breaks in the plastic.  This put stress on the wires and circuit boards within the screen and hinge, such that moving the screen would cause the tablet buttons to randomly fire (changing the screen orientation, etc.); fine, I disabled the button functionality.

For the past year or so, either the LCD screen backlight or the inverter powering it has been going kaplooey; at first, the screen showed an awful pink cast along the bottom, and more recently, the screen began to flicker.  A couple of days ago, the inverter began overheating to the point that the laptop screen's corners turned black (LCDs respond to heat--running the screen at a lower brightness or directly cooling it allowed the screen to recover).

This morning, the worst happened: the backlight failed altogether, and I haven't been able to resurrect it.  I'm hoping it's the inverter, but I'm following a couple of full screen modules on eBay at the moment, too, just in case the backlight itself has failed.  Worst thing is that I'm on the road for business travel and don't have access to any tools to take the screen apart... but at least I've got my work laptop, and being in Silicon Valley, I am hopeful I can find at least a replacement inverter, if not a whole screen unit, along with the tools I need to fix it (and which hopefully the TSA won't try to confiscate--they're allowed in carry-ons, but since when has the TSA followed their own rules?)

Sigh.  What a pain in the butt.  I'd buy a new laptop if (1) I weren't hoarding cash for our impending home purchase; and (2) installing and setting everything up again wasn't such a huge pain.  I may be a hardware handyman, but sometimes this job gets old.