rearranging InitialiseMessages code
authorTim Starling <tstarling@users.mediawiki.org>
Sat, 15 Nov 2003 07:53:44 +0000 (07:53 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Sat, 15 Nov 2003 07:53:44 +0000 (07:53 +0000)
maintenance/InitialiseMessages.inc [new file with mode: 0755]
maintenance/rebuildMessages.php [new file with mode: 0755]

diff --git a/maintenance/InitialiseMessages.inc b/maintenance/InitialiseMessages.inc
new file mode 100755 (executable)
index 0000000..0b9a689
--- /dev/null
@@ -0,0 +1,95 @@
+<?
+
+# This script is included from update.php and install.php. Do not run it 
+# by itself.
+
+function initialiseMessages( $overwrite = false) {
+       global $wgLang, $wgScript, $wgServer, $wgAllMessagesEn;
+
+       $fname = "initialiseMessages";
+       $ns = NS_MEDIAWIKI;
+       if ( !$overwrite ) {
+               $sql = "SELECT 1 FROM cur WHERE cur_namespace=$ns LIMIT 1";
+               $res = wfQuery( $sql, DB_READ, $fname );
+               if ( wfNumRows( $res ) ) {
+                       print "MediaWiki: namespace already initialised\n";
+                       return;
+               }
+       }
+
+       $timestamp = wfTimestampNow();
+       $invTimestamp = wfInvertTimestamp( $timestamp );
+       $navText = wfMsgNoDB( "allmessagestext" );
+       $navText .= "
+
+<table border=1 width=100%><tr><td>
+  '''Name'''
+</td><td>
+  '''Default text'''
+</td><td>
+  '''Current text'''
+</td></tr>";
+       
+       print "Initialising \"MediaWiki\" namespace...";
+
+       foreach ( $wgAllMessagesEn as $key => $enMsg ) {
+               $message = wfMsgNoDB( $key );
+               $titleObj = Title::newFromText( $key );
+               $title = $titleObj->getDBkey();
+               $dbencMsg = wfStrencode( $message );
+
+               if ( $overwrite ) {
+                       $sql = "DELETE FROM cur WHERE cur_namespace=$ns AND cur_title='$title'";
+                       wfQuery( $sql, DB_WRITE, $fname );
+               }
+               
+               $sql = "INSERT INTO cur (cur_namespace, cur_title, cur_text,
+                       cur_user_text, cur_timestamp, cur_restrictions,
+                       cur_is_new, inverse_timestamp) VALUES (
+                       $ns,
+                       '$title',
+                       '$dbencMsg',
+                       'MediaWiki default',
+                       '$timestamp',
+                       'sysop',
+                       1,
+                       '$invTimestamp')";
+               wfQuery( $sql, DB_WRITE, $fname );
+               $mwObj =& MagicWord::get( MAG_MSGNW );
+               $mw = $mwObj->getSynonym( 0 );
+               $mw = str_replace( "$1", $key, $mw );
+
+               $message = wfEscapeWikiText( $message );
+               $navText .= 
+"<tr><td>
+  [$wgServer$wgScript?title=MediaWiki:$title&action=edit $key]
+</td><td>
+  $message
+</td><td>
+  $mw
+</td></tr>";
+       }
+       $navText .= "</table>";
+       $navText = wfStrencode( $navText );
+       $title = wfMsgNoDB( "allmessages" );
+
+       if ( $overwrite ) {
+               $sql = "DELETE FROM cur WHERE cur_namespace=$ns AND cur_title='$title'";
+               wfQuery( $sql, DB_WRITE, $fname );
+       }
+
+       $sql = "INSERT INTO cur (cur_namespace, cur_title, cur_text,
+               cur_user_text, cur_timestamp, cur_restrictions,
+               cur_is_new, inverse_timestamp) VALUES (
+               $ns,
+               '$title',
+               '$navText',
+               'MediaWiki default',
+               '$timestamp',
+               'sysop',
+               1,
+               '$invTimestamp')";
+       wfQuery( $sql, DB_WRITE, $fname );
+       print "done \n";
+}
+
diff --git a/maintenance/rebuildMessages.php b/maintenance/rebuildMessages.php
new file mode 100755 (executable)
index 0000000..c0f8aa0
--- /dev/null
@@ -0,0 +1,22 @@
+<?
+
+if ( ! is_readable( "../LocalSettings.php" ) ) {
+       print "A copy of your installation's LocalSettings.php\n" .
+         "must exist in the source directory.\n";
+       exit();
+}
+
+$DP = "../includes";
+include_once( "../LocalSettings.php" );
+include_once( "../AdminSettings.php" );
+
+include_once( "{$IP}/Setup.php" );
+include_once( "./InitialiseMessages.inc" );
+$wgTitle = Title::newFromText( "Rebuild messages script" );
+set_time_limit(0);
+
+initialiseMessages( true );
+
+exit();
+
+?>