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( 'MediaWiki default' );
19 # Don't try to draw messages from the database we're initialising
20 $wgMessageCache->disable();
22 $fname = 'initialiseMessages';
24 # cur_user_text responsible for the modifications
25 # Don't change it unless you're prepared to update the DBs accordingly, otherwise the
26 # default messages won't be overwritte
27 $username = 'MediaWiki default';
29 $timestamp = wfTimestampNow();
30 $invTimestamp = wfInvertTimestamp( $timestamp );
31 $navText = '{{int:allmessagestext}}';
34 <table border=1 width=100%><tr><td>
42 print "Initialising \"MediaWiki\" namespace...\n";
45 $dbr =& wfGetDB( DB_SLAVE );
46 $dbw =& wfGetDB( DB_MASTER );
47 $cur = $dbr->tableName( 'cur' );
49 $sql = "SELECT cur_title,cur_is_new,cur_user_text FROM $cur WHERE cur_namespace=$ns AND cur_title IN(";
51 # Get keys from $wgAllMessagesEn, which is more complete than the local language
53 if ( $messageArray ) {
54 $sortedArray = $messageArray;
56 $sortedArray = $wgAllMessagesEn;
59 ksort( $sortedArray );
61 # SELECT all existing messages
62 # Can't afford to be locking all rows for update, this script can take quite a long time to complete
63 foreach ( $sortedArray as $key => $enMsg ) {
65 continue; // Skip odd members
72 $titleObj = Title::newFromText( $key );
73 $enctitle = $dbr->strencode($titleObj->getDBkey());
74 $sql .= "'$enctitle'";
77 $res = $dbr->query( $sql );
78 $row = $dbr->fetchObject( $res );
80 # Read the results into an array
81 # Decide whether or not each one needs to be overwritten
82 $existingTitles = array();
84 if ( $row->cur_user_text != $username ) {
85 $existingTitles[$row->cur_title] = 'keep';
87 $existingTitles[$row->cur_title] = 'chuck';
90 $row = $dbr->fetchObject( $res );
93 # Insert queries are done in one multi-row insert
94 # Here's the start of it:
95 $sql = "INSERT INTO $cur (cur_namespace, cur_title, cur_text,
96 cur_user_text, cur_timestamp, cur_restrictions,
97 cur_is_new, inverse_timestamp, cur_touched) VALUES ";
99 $talk = $wgLang->getNsText( NS_TALK );
100 $mwtalk = $wgLang->getNsText( NS_MEDIAWIKI_TALK );
102 # Process each message
103 foreach ( $sortedArray as $key => $enMsg ) {
105 continue; // Skip odd members
108 if ( $messageArray ) {
111 $message = wfMsgNoDB( $key );
113 $titleObj = Title::newFromText( $key );
114 $title = $titleObj->getDBkey();
115 $dbencMsg = $dbw->strencode( $message );
117 # Update messages which already exist
118 if ( array_key_exists( $title, $existingTitles ) ) {
119 if ( $existingTitles[$title] == 'chuck' || $overwrite) {
121 $mwTitleObj = Title::makeTitle( NS_MEDIAWIKI, $title );
122 $article = new Article( $mwTitleObj );
123 $article->quickEdit( $message );
127 # Queue for insertion
145 # Make table row for navigation page
146 $message = wfEscapeWikiText( $message );
149 [$wgServer$wgScript?title=MediaWiki:$title&action=edit $key]<br>
150 [[$mwtalk:$title|$talk]]
158 # Perform the insert query
160 $dbw->query( $sql, $fname );
163 # Write the navigation page
165 $navText .= '</table>';
166 $title = wfMsgNoDB( 'allmessages' );
167 $titleObj = Title::makeTitle( NS_WIKIPEDIA, $title );
168 $wgArticle = new Article( $titleObj );
170 $wgUser = User::newFromName( 'MediaWiki default' );
171 if ( $titleObj->getArticleID() ) {
172 $wgArticle->updateArticle( $navText, '', 0, 0 );
174 $wgArticle->insertNewArticle( $navText, '', 0, 0 );
177 # Clear the relevant memcached key
178 print 'Clearing message cache...';
179 $wgMessageCache->clear();
183 function loadLanguageFile( $filename )
185 $contents = file_get_contents( $filename );
187 $p = strpos( $contents, "\n" ) + 1;
188 $contents = substr( $contents, $p );
190 return unserialize( $contents );
193 function doUpdates() {
194 global $wgDeferredUpdateList;
195 foreach ( $wgDeferredUpdateList as $up ) { $up->doUpdate(); }