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 # Initialise $wgOut and $wgUser for a command line script
16 $wgUser->setLoaded( true ); # Don't load from DB
17 $wgUser->setName( "Template namespace initialisation script" );
18 $wgUser->addRight( "bot" );
19 $wgUser = User::newFromName( 'MediaWiki default' );
21 # Don't try to draw messages from the database we're initialising
22 $wgMessageCache->disable();
24 $fname = "initialiseMessages";
26 # cur_user_text responsible for the modifications
27 # Don't change it unless you're prepared to update the DBs accordingly, otherwise the
28 # default messages won't be overwritte
29 $username = "MediaWiki default";
31 $timestamp = wfTimestampNow();
32 $invTimestamp = wfInvertTimestamp( $timestamp );
33 $navText = '{{int:allmessagestext}}';
36 <table border=1 width=100%><tr><td>
44 print "Initialising \"MediaWiki\" namespace...\n";
45 $sql = "SELECT cur_title,cur_is_new,cur_user_text FROM cur WHERE cur_namespace=$ns AND cur_title IN(";
47 # Get keys from $wgAllMessagesEn, which is more complete than the local language
49 if ( $messageArray ) {
50 $sortedArray = $wgAllMessagesEn;
52 $sortedArray = $wgAllMessagesEn;
55 ksort( $sortedArray );
57 # SELECT all existing messages
58 foreach ( $sortedArray as $key => $enMsg ) {
60 continue; // Skip odd members
67 $titleObj = Title::newFromText( $key );
68 $enctitle = wfStrencode($titleObj->getDBkey());
69 $sql .= "'$enctitle'";
72 $res = wfQuery( $sql, DB_READ );
73 $row = wfFetchObject( $res );
75 # Read the results into an array
76 # Decide whether or not each one needs to be overwritten
77 $existingTitles = array();
79 if ( $row->cur_user_text != $username ) {
80 $existingTitles[$row->cur_title] = "keep";
82 $existingTitles[$row->cur_title] = "chuck";
85 $row = wfFetchObject( $res );
88 # Insert queries are done in one multi-row insert
89 # Here's the start of it:
90 $sql = "INSERT INTO cur (cur_namespace, cur_title, cur_text,
91 cur_user_text, cur_timestamp, cur_restrictions,
92 cur_is_new, inverse_timestamp, cur_touched) VALUES ";
94 $talk = $wgLang->getNsText( NS_TALK );
95 $mwtalk = $wgLang->getNsText( NS_MEDIAWIKI_TALK );
97 # Process each message
98 foreach ( $sortedArray as $key => $enMsg ) {
100 continue; // Skip odd members
103 if ( $messageArray ) {
106 $message = wfMsgNoDB( $key );
108 $titleObj = Title::newFromText( $key );
109 $title = $titleObj->getDBkey();
110 $dbencMsg = wfStrencode( $message );
112 # Update messages which already exist
113 if ( array_key_exists( $title, $existingTitles ) ) {
114 if ( $existingTitles[$title] == "chuck" || $overwrite) {
116 # Save old current version
117 $sql = "insert into old (old_namespace,old_title,old_text,old_comment,old_user,old_user_text,old_timestamp)
118 select cur_namespace,cur_title,cur_text,cur_comment,cur_user,cur_user_text,cur_timestamp
119 from cur where cur_namespace=8 and cur_title='$title'";
120 wfQuery( $sql, DB_WRITE );
122 $sql = "update cur set cur_text='$dbencMsg',cur_timestamp='$timestamp',cur_user=0,
123 cur_user_text='$username', inverse_timestamp=$invTimestamp, cur_comment='',
124 cur_is_new=0,cur_is_redirect=0,cur_minor_edit=0, cur_touched='$timestamp'
125 WHERE cur_namespace=8 and cur_title='$title'";
126 wfQuery( $sql, DB_WRITE );
130 # Queue for insertion
148 # Make table row for navigation page
149 $message = wfEscapeWikiText( $message );
152 [$wgServer$wgScript?title=MediaWiki:$title&action=edit $key]<br>
153 [[$mwtalk:$title|$talk]]
161 # Perform the insert query
163 wfQuery( $sql, DB_WRITE, $fname );
166 # Write the navigation page
168 $navText .= "</table>";
169 $title = wfMsgNoDB( "allmessages" );
170 $titleObj = Title::makeTitle( NS_MEDIAWIKI, $title );
171 $wgArticle = new Article( $titleObj );
173 $wgUser = User::newFromName( 'MediaWiki default' );
174 if ( $titleObj->getArticleID() ) {
175 $wgArticle->updateArticle( $navText, '', 0, 0 );
177 $wgArticle->insertNewArticle( $navText, '', 0, 0 );
180 # Clear the relevant memcached key
181 if( $wgUseMemCached ) {
182 print "Clearing message cache...";
183 $wgMemc->delete( "$wgDBname:messages" );
188 function loadArrayFromFile( $filename )
190 $contents = file_get_contents( $filename );
191 return unserialize( $contents );
194 function doUpdates() {
195 global $wgDeferredUpdateList;
196 foreach ( $wgDeferredUpdateList as $up ) { $up->doUpdate(); }