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 );
32 print "Initialising \"MediaWiki\" namespace...\n";
35 $dbr =& wfGetDB( DB_SLAVE );
36 $dbw =& wfGetDB( DB_MASTER );
37 $cur = $dbr->tableName( 'cur' );
39 $sql = "SELECT cur_title,cur_is_new,cur_user_text FROM $cur WHERE cur_namespace=$ns AND cur_title IN(";
41 # Get keys from $wgAllMessagesEn, which is more complete than the local language
43 if ( $messageArray ) {
44 $sortedArray = $messageArray;
46 $sortedArray = $wgAllMessagesEn;
49 ksort( $sortedArray );
51 # SELECT all existing messages
52 # Can't afford to be locking all rows for update, this script can take quite a long time to complete
53 foreach ( $sortedArray as $key => $enMsg ) {
55 continue; // Skip odd members
62 $titleObj = Title::newFromText( $key );
63 $enctitle = $dbr->strencode($titleObj->getDBkey());
64 $sql .= "'$enctitle'";
67 $res = $dbr->query( $sql );
68 $row = $dbr->fetchObject( $res );
70 # Read the results into an array
71 # Decide whether or not each one needs to be overwritten
72 $existingTitles = array();
74 if ( $row->cur_user_text != $username ) {
75 $existingTitles[$row->cur_title] = 'keep';
77 $existingTitles[$row->cur_title] = 'chuck';
80 $row = $dbr->fetchObject( $res );
83 # Insert queries are done in one multi-row insert
84 # Here's the start of it:
85 $sql = "INSERT INTO $cur (cur_namespace, cur_title, cur_text,
86 cur_user_text, cur_timestamp, cur_restrictions,
87 cur_is_new, inverse_timestamp, cur_touched) VALUES ";
89 $talk = $wgLang->getNsText( NS_TALK );
90 $mwtalk = $wgLang->getNsText( NS_MEDIAWIKI_TALK );
92 # Process each message
93 foreach ( $sortedArray as $key => $enMsg ) {
95 continue; // Skip odd members
98 if ( $messageArray ) {
101 $message = wfMsgNoDB( $key );
103 $titleObj = Title::newFromText( $key );
104 $title = $titleObj->getDBkey();
105 $dbencMsg = $dbw->strencode( $message );
107 # Update messages which already exist
108 if ( array_key_exists( $title, $existingTitles ) ) {
109 if ( $existingTitles[$title] == 'chuck' || $overwrite) {
111 $mwTitleObj = Title::makeTitle( NS_MEDIAWIKI, $title );
112 $article = new Article( $mwTitleObj );
113 $article->quickEdit( $message );
117 # Queue for insertion
136 # Perform the insert query
138 $dbw->query( $sql, $fname );
141 # Clear the relevant memcached key
142 print 'Clearing message cache...';
143 $wgMessageCache->clear();
147 function loadLanguageFile( $filename )
149 $contents = file_get_contents( $filename );
151 $p = strpos( $contents, "\n" ) + 1;
152 $contents = substr( $contents, $p );
154 return unserialize( $contents );
157 function doUpdates() {
158 global $wgDeferredUpdateList;
159 foreach ( $wgDeferredUpdateList as $up ) { $up->doUpdate(); }