3 * Script to initialise the MediaWiki namespace
7 * This script is included from update.php and install.php. Do not run it
12 * @subpackage Maintenance
16 function initialiseMessages( $overwrite = false, $messageArray = false ) {
17 global $wgLang, $wgScript, $wgServer, $wgAllMessagesEn;
18 global $wgOut, $wgArticle, $wgUser;
19 global $wgMessageCache, $wgMemc, $wgDBname, $wgUseMemCached;
21 # Initialise $wgOut and $wgUser for a command line script
25 $wgUser->setLoaded( true ); # Don't load from DB
26 $wgUser->setName( 'MediaWiki default' );
28 # Don't try to draw messages from the database we're initialising
29 $wgMessageCache->disable();
31 $fname = 'initialiseMessages';
33 # cur_user_text responsible for the modifications
34 # Don't change it unless you're prepared to update the DBs accordingly, otherwise the
35 # default messages won't be overwritte
36 $username = 'MediaWiki default';
39 print "Initialising \"MediaWiki\" namespace...\n";
42 $dbr =& wfGetDB( DB_SLAVE );
43 $dbw =& wfGetDB( DB_MASTER );
44 $cur = $dbr->tableName( 'cur' );
46 $timestamp = wfTimestampNow();
47 $invTimestamp = wfInvertTimestamp( $timestamp );
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:
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();
113 # Update messages which already exist
114 if ( array_key_exists( $title, $existingTitles ) ) {
115 if ( $existingTitles[$title] == 'chuck' || $overwrite) {
117 $mwTitleObj = Title::makeTitle( NS_MEDIAWIKI, $title );
118 $article = new Article( $mwTitleObj );
119 $article->quickEdit( $message );
123 array_push( $arr, array(
124 'cur_namespace' => $ns,
125 'cur_title' => $title,
126 'cur_text' => $message,
128 'cur_user_text' => $username,
129 'cur_timestamp' => $dbw->timestamp( $timestamp ),
130 'cur_restrictions' => 'sysop',
132 'inverse_timestamp' => $invTimestamp,
133 'cur_touched' => $dbw->timestamp( $timestamp ) ) );
137 $dbw->insertArray( $cur, $arr, $fname );
139 # Clear the relevant memcached key
140 print 'Clearing message cache...';
141 $wgMessageCache->clear();
145 function loadLanguageFile( $filename )
147 $contents = file_get_contents( $filename );
149 $p = strpos( $contents, "\n" ) + 1;
150 $contents = substr( $contents, $p );
152 return unserialize( $contents );
155 function doUpdates() {
156 global $wgDeferredUpdateList;
157 foreach ( $wgDeferredUpdateList as $up ) { $up->doUpdate(); }