2 # Script to initialise the MediaWiki namespace
4 # This script is included from update.php and install.php. Do not run it
7 function initialiseMessages( $overwrite = false, $messageArray = false ) {
8 global $wgLang, $wgScript, $wgServer, $wgAllMessagesEn;
9 global $wgOut, $wgArticle, $wgUser;
10 global $wgMessageCache, $wgMemc, $wgDBname, $wgUseMemCached;
12 # Don't try to draw messages from the database we're initialising
13 $wgMessageCache->disable();
15 $fname = "initialiseMessages";
17 # cur_user_text responsible for the modifications
18 # Don't change it unless you're prepared to update the DBs accordingly, otherwise the
19 # default messages won't be overwritte
20 $username = "MediaWiki default";
22 $timestamp = wfTimestampNow();
23 $invTimestamp = wfInvertTimestamp( $timestamp );
24 $mwMsg =& MagicWord::get( MAG_MSG );
25 $navText = str_replace( "$1", "allmessagestext", $mwMsg->getSynonym( 0 ) );
28 <table border=1 width=100%><tr><td>
36 print "Initialising \"MediaWiki\" namespace...\n";
37 $sql = "SELECT cur_title,cur_is_new,cur_user_text FROM cur WHERE cur_namespace=$ns AND cur_title IN(";
39 # Get keys from $wgAllMessagesEn, which is more complete than the local language
41 if ( $messageArray ) {
42 $sortedArray = $wgAllMessagesEn;
44 $sortedArray = $wgAllMessagesEn;
47 ksort( $sortedArray );
49 # SELECT all existing messages
50 foreach ( $sortedArray as $key => $enMsg ) {
52 continue; // Skip odd members
59 $titleObj = Title::newFromText( $key );
60 $enctitle = wfStrencode($titleObj->getDBkey());
61 $sql .= "'$enctitle'";
64 $res = wfQuery( $sql, DB_READ );
65 $row = wfFetchObject( $res );
67 # Read the results into an array
68 # Decide whether or not each one needs to be overwritten
69 $existingTitles = array();
71 if ( !$row->cur_is_new || $row->cur_user_text != $username ) {
72 $existingTitles[$row->cur_title] = "keep";
74 $existingTitles[$row->cur_title] = "chuck";
77 $row = wfFetchObject( $res );
80 # Insert queries are done in one multi-row insert
81 # Here's the start of it:
82 $sql = "INSERT INTO cur (cur_namespace, cur_title, cur_text,
83 cur_user_text, cur_timestamp, cur_restrictions,
84 cur_is_new, inverse_timestamp, cur_touched) VALUES ";
86 $mwObj =& MagicWord::get( MAG_MSGNW );
87 $msgnw = $mwObj->getSynonym( 0 );
88 $talk = $wgLang->getNsText( NS_TALK );
89 $mwtalk = $wgLang->getNsText( NS_MEDIAWIKI_TALK );
91 # Process each message
92 foreach ( $sortedArray as $key => $enMsg ) {
94 continue; // Skip odd members
97 if ( $messageArray ) {
100 $message = wfMsgNoDB( $key );
102 $titleObj = Title::newFromText( $key );
103 $title = $titleObj->getDBkey();
104 $dbencMsg = wfStrencode( $message );
106 # Update messages which already exist
107 # Note: UPDATE is now used instead of DELETE/INSERT to avoid wiping cur_restrictions
108 if ( array_key_exists( $title, $existingTitles ) ) {
109 if ( $existingTitles[$title] == "chuck" || $overwrite) {
112 cur_text='$dbencMsg',
114 cur_user_text='$username',
115 cur_timestamp='$timestamp',
116 cur_touched='$timestamp',
117 inverse_timestamp='$invTimestamp'
118 WHERE cur_namespace=8 and cur_title='$title'", DB_WRITE
123 # Queue for insertion
141 # Make table row for navigation page
142 $mw = str_replace( "$1", $key, $msgnw );
144 $message = wfEscapeWikiText( $message );
147 [$wgServer$wgScript?title=MediaWiki:$title&action=edit $key]<br>
148 [[$mwtalk:$title|$talk]]
156 # Perform the insert query
158 wfQuery( $sql, DB_WRITE, $fname );
161 # Write the navigation page
163 $navText .= "</table>";
164 $title = wfMsgNoDB( "allmessages" );
165 $titleObj = Title::makeTitle( NS_MEDIAWIKI, $title );
166 $wgArticle = new Article( $titleObj );
168 $wgUser = User::newFromName( 'MediaWiki default' );
169 if ( $titleObj->getArticleID() ) {
170 $wgArticle->updateArticle( $navText, '', 0, 0 );
172 $wgArticle->insertNewArticle( $navText, '', 0, 0 );
175 # Clear the relevant memcached key
176 if( $wgUseMemCached ) {
177 print "Clearing message cache...";
178 $wgMemc->delete( "$wgDBname:messages" );
183 function loadArrayFromFile( $filename )
185 $contents = file_get_contents( $filename );
186 return unserialize( $contents );