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';
37 print "Initialising \"MediaWiki\" namespace...\n";
40 $dbr =& wfGetDB( DB_SLAVE );
41 $dbw =& wfGetDB( DB_MASTER );
42 $cur = $dbr->tableName( 'cur' );
44 $timestamp = wfTimestampNow();
45 $invTimestamp = wfInvertTimestamp( $timestamp );
47 $sql = "SELECT cur_title,cur_is_new,cur_user_text FROM $cur WHERE cur_namespace=$ns AND cur_title IN(";
49 # Get keys from $wgAllMessagesEn, which is more complete than the local language
51 if ( $messageArray ) {
52 $sortedArray = $messageArray;
54 $sortedArray = $wgAllMessagesEn;
57 ksort( $sortedArray );
59 # SELECT all existing messages
60 # Can't afford to be locking all rows for update, this script can take quite a long time to complete
61 foreach ( $sortedArray as $key => $enMsg ) {
63 continue; // Skip odd members
70 $titleObj = Title::newFromText( $key );
71 $enctitle = $dbr->strencode($titleObj->getDBkey());
72 $sql .= "'$enctitle'";
75 $res = $dbr->query( $sql );
76 $row = $dbr->fetchObject( $res );
78 # Read the results into an array
79 # Decide whether or not each one needs to be overwritten
80 $existingTitles = array();
82 if ( $row->cur_user_text != $username ) {
83 $existingTitles[$row->cur_title] = 'keep';
85 $existingTitles[$row->cur_title] = 'chuck';
88 $row = $dbr->fetchObject( $res );
91 # Insert queries are done in one multi-row insert
92 # Here's the start of it:
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 = $dbw->strencode( $message );
112 # Update messages which already exist
113 if ( array_key_exists( $title, $existingTitles ) ) {
114 if ( $existingTitles[$title] == 'chuck' || $overwrite) {
116 $mwTitleObj = Title::makeTitle( NS_MEDIAWIKI, $title );
117 $article = new Article( $mwTitleObj );
118 $article->quickEdit( $message );
122 array_push($arr,array(
126 cur_user_text=>$username,
127 cur_timestamp=>$dbw->timestamp($timestamp),
128 cur_restrictions=>'sysop',
130 inverse_timestamp=>$invTimestamp,
131 cur_touched=>$dbw->timestamp($timestamp)));
135 $dbw->insertArray( $cur, $arr, $fname );
137 # Clear the relevant memcached key
138 print 'Clearing message cache...';
139 $wgMessageCache->clear();
143 function loadLanguageFile( $filename )
145 $contents = file_get_contents( $filename );
147 $p = strpos( $contents, "\n" ) + 1;
148 $contents = substr( $contents, $p );
150 return unserialize( $contents );
153 function doUpdates() {
154 global $wgDeferredUpdateList;
155 foreach ( $wgDeferredUpdateList as $up ) { $up->doUpdate(); }