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 ) {
56 $titleObj = Title::newFromText( $key );
57 $enctitle = wfStrencode($titleObj->getDBkey());
58 $sql .= "'$enctitle'";
61 $res = wfQuery( $sql, DB_READ );
62 $row = wfFetchObject( $res );
64 # Read the results into an array
65 # Decide whether or not each one needs to be overwritten
66 $existingTitles = array();
68 if ( !$row->cur_is_new || $row->cur_user_text != $username ) {
69 $existingTitles[$row->cur_title] = "keep";
71 $existingTitles[$row->cur_title] = "chuck";
74 $row = wfFetchObject( $res );
77 # Insert queries are done in one multi-row insert
78 # Here's the start of it:
79 $sql = "INSERT INTO cur (cur_namespace, cur_title, cur_text,
80 cur_user_text, cur_timestamp, cur_restrictions,
81 cur_is_new, inverse_timestamp, cur_touched) VALUES ";
83 $mwObj =& MagicWord::get( MAG_MSGNW );
84 $msgnw = $mwObj->getSynonym( 0 );
85 $talk = $wgLang->getNsText( NS_TALK );
86 $mwtalk = $wgLang->getNsText( NS_MEDIAWIKI_TALK );
88 # Process each message
89 foreach ( $sortedArray as $key => $enMsg ) {
91 if ( $messageArray ) {
94 $message = wfMsgNoDB( $key );
96 $titleObj = Title::newFromText( $key );
97 $title = $titleObj->getDBkey();
98 $dbencMsg = wfStrencode( $message );
100 # Update messages which already exist
101 # Note: UPDATE is now used instead of DELETE/INSERT to avoid wiping cur_restrictions
102 if ( array_key_exists( $title, $existingTitles ) ) {
103 if ( $existingTitles[$title] == "chuck" || $overwrite) {
106 cur_text='$dbencMsg',
108 cur_user_text='$username',
109 cur_timestamp='$timestamp',
110 cur_touched='$timestamp',
111 inverse_timestamp='$invTimestamp'
112 WHERE cur_namespace=8 and cur_title='$title'", DB_WRITE
117 # Queue for insertion
135 # Make table row for navigation page
136 $mw = str_replace( "$1", $key, $msgnw );
138 $message = wfEscapeWikiText( $message );
141 [$wgServer$wgScript?title=MediaWiki:$title&action=edit $key]<br>
142 [[$mwtalk:$title|$talk]]
150 # Perform the insert query
152 wfQuery( $sql, DB_WRITE, $fname );
155 # Write the navigation page
157 $navText .= "</table>";
158 $title = wfMsgNoDB( "allmessages" );
159 $titleObj = Title::makeTitle( NS_MEDIAWIKI, $title );
160 $wgArticle = new Article( $titleObj );
162 $wgUser = User::newFromName( 'MediaWiki default' );
163 if ( $titleObj->getArticleID() ) {
164 $wgArticle->updateArticle( $navText, '', 0, 0 );
166 $wgArticle->insertNewArticle( $navText, '', 0, 0 );
169 # Clear the relevant memcached key
170 if( $wgUseMemCached ) {
171 print "Clearing message cache...";
172 $wgMemc->delete( "$wgDBname:messages" );
177 function loadArrayFromFile( $filename )
179 $contents = file_get_contents( $filename );
180 return unserialize( $contents );