3 * Script to initialise the MediaWiki namespace
5 * This script is included from update.php and install.php. Do not run it
10 * @subpackage Maintenance
14 function initialiseMessages( $overwrite = false, $messageArray = false ) {
15 global $wgLang, $wgScript, $wgServer, $wgAllMessagesEn;
16 global $wgOut, $wgArticle, $wgUser;
17 global $wgMessageCache, $wgMemc, $wgDBname, $wgUseMemCached;
19 # Initialise $wgOut and $wgUser for a command line script
23 $wgUser->setLoaded( true ); # Don't load from DB
24 $wgUser->setName( 'MediaWiki default' );
26 # Don't try to draw messages from the database we're initialising
27 $wgMessageCache->disable();
29 $fname = 'initialiseMessages';
31 # cur_user_text responsible for the modifications
32 # Don't change it unless you're prepared to update the DBs accordingly, otherwise the
33 # default messages won't be overwritte
34 $username = 'MediaWiki default';
36 $timestamp = wfTimestampNow();
37 $invTimestamp = wfInvertTimestamp( $timestamp );
39 print "Initialising \"MediaWiki\" namespace...\n";
42 $dbr =& wfGetDB( DB_SLAVE );
43 $dbw =& wfGetDB( DB_MASTER );
44 $cur = $dbr->tableName( 'cur' );
46 $sql = "SELECT cur_title,cur_is_new,cur_user_text FROM $cur WHERE cur_namespace=$ns AND cur_title IN(";
48 # Get keys from $wgAllMessagesEn, which is more complete than the local language
50 if ( $messageArray ) {
51 $sortedArray = $messageArray;
53 $sortedArray = $wgAllMessagesEn;
56 ksort( $sortedArray );
58 # SELECT all existing messages
59 # Can't afford to be locking all rows for update, this script can take quite a long time to complete
60 foreach ( $sortedArray as $key => $enMsg ) {
62 continue; // Skip odd members
69 $titleObj = Title::newFromText( $key );
70 $enctitle = $dbr->strencode($titleObj->getDBkey());
71 $sql .= "'$enctitle'";
74 $res = $dbr->query( $sql );
75 $row = $dbr->fetchObject( $res );
77 # Read the results into an array
78 # Decide whether or not each one needs to be overwritten
79 $existingTitles = array();
81 if ( $row->cur_user_text != $username ) {
82 $existingTitles[$row->cur_title] = 'keep';
84 $existingTitles[$row->cur_title] = 'chuck';
87 $row = $dbr->fetchObject( $res );
90 # Insert queries are done in one multi-row insert
91 # Here's the start of it:
92 $sql = "INSERT INTO $cur (cur_namespace, cur_title, cur_text,
93 cur_user_text, cur_timestamp, cur_restrictions,
94 cur_is_new, inverse_timestamp, cur_touched) VALUES ";
96 $talk = $wgLang->getNsText( NS_TALK );
97 $mwtalk = $wgLang->getNsText( NS_MEDIAWIKI_TALK );
99 # Process each message
100 foreach ( $sortedArray as $key => $enMsg ) {
102 continue; // Skip odd members
105 if ( $messageArray ) {
108 $message = wfMsgNoDB( $key );
110 $titleObj = Title::newFromText( $key );
111 $title = $titleObj->getDBkey();
112 $dbencMsg = $dbw->strencode( $message );
114 # Update messages which already exist
115 if ( array_key_exists( $title, $existingTitles ) ) {
116 if ( $existingTitles[$title] == 'chuck' || $overwrite) {
118 $mwTitleObj = Title::makeTitle( NS_MEDIAWIKI, $title );
119 $article = new Article( $mwTitleObj );
120 $article->quickEdit( $message );
124 # Queue for insertion
143 # Perform the insert query
145 $dbw->query( $sql, $fname );
148 # Clear the relevant memcached key
149 print 'Clearing message cache...';
150 $wgMessageCache->clear();
154 function loadLanguageFile( $filename )
156 $contents = file_get_contents( $filename );
158 $p = strpos( $contents, "\n" ) + 1;
159 $contents = substr( $contents, $p );
161 return unserialize( $contents );
164 function doUpdates() {
165 global $wgDeferredUpdateList;
166 foreach ( $wgDeferredUpdateList as $up ) { $up->doUpdate(); }