Google Gears hack: MediaWiki offline functionality in less than one hour

Wikis are popular intranet tools in which teams collaboratively develop a shared knowledge base. So far, however, there has often been the problem that wikis were not available (even read-only) offline, e.g., when traveling.

Google Gears is an interesting new technology to solve the problem of offline web applications in a surprisingly easy way. In order to try out the potential of it, I have recently tried to apply it to the MediaWiki system (actually a Semantic MediaWiki installation).

What do you have to do?

  • Create a folder gears in your MediaWiki installation directory
  • Download the gears_init.js from the Google Gears web site and place it in the newly created folder
  • Download the gears_offline.js from the Google Gears tutorial
  • Modify the manifest file name in this file to a php script, e.g. manifest.php
  • Create the manifest.php that creates the file list on the fly (based on access to the database):

{
“betaManifestVersion”: 1,
<?php
$l = mysql_connect(‘localhost’,’user‘,’pass‘);
mysql_selectdb(‘mediawikidbname‘);
  $q = “SELECT max(rc_timestamp) from recentchanges”
$r = mysql_query($q);
$t = mysql_fetch_row($r);
  echo ‘”version”: “‘ . $t[0] . ‘”,’;
?>

“entries”:
[

<?php
$q = “SELECT page_title from page”
$r = mysql_query($q);
 while ($t = mysql_fetch_row($r))
{
echo ‘{ “url”: “
/index.php/’ . $t[0] . ‘” },’;
}
  echo ‘{ “url”: “/index.php/Main” }’;
?>
]

}

  • Modify the MonoBook.php skin file (or any other skin you are using):
    • Include the two javascript files in the header section
    • add “init()” to body onload
    • add a link somewhere on the page (e.g., footer) invoking the javascript function createStore()
    • add a placeholder <span id=’textOut’></span> somewhere for status messages, e.g. in the footer

Of course, the approach is quite a hack and does not scale for large wikis because there is always a complete replication of online content as soon as some change occurred (this could be made smarter by not leaving everything to Gears, but implementing your own update strategy). Likewise, offline search, editing, and other cool features are not available (this would require much more effort towards AJAXifying MediaWiki). So this simple solution just provides the possibility of offline reading – and this transparently to the user (and within less than one hour :).

Technorati tags: ,

3 thoughts on “Google Gears hack: MediaWiki offline functionality in less than one hour”

Comments are closed.