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
17 function initialiseMessages( $overwrite = false, $messageArray = false ) {
18 global $wgContLang, $wgContLanguageCode;
19 global $wgContLangClass, $wgAllMessagesEn;
22 $langclass = 'Language'. str_replace( '-', '_', ucfirst( $wgContLanguageCode ) );
23 require_once("$IP/languages/$langclass.php");
25 $variants = $wgContLang->getVariants();
26 if(!in_array($wgContLanguageCode, $variants))
27 $variants[]=$wgContLanguageCode;
29 if ( $messageArray ) {
30 $sortedArray = $messageArray;
32 $sortedArray = $wgAllMessagesEn;
35 ksort( $sortedArray );
38 foreach ($variants as $v) {
39 $langclass = 'Language'. str_replace( '-', '_', ucfirst( $v ) );
40 $lang = new $langclass;
41 if(!is_object($lang)) {
42 die ("class $langclass not defined. perhaps you need to include the file $langclass.php in $wgContLangClass.php?");
44 foreach ($sortedArray as $key => $msg) {
45 $messages[$key."/$v"] = $lang->getMessage($key);
49 initialiseMessagesReal( $overwrite, $messages );
59 function initialiseMessagesReal( $overwrite = false, $messageArray = false ) {
60 global $wgContLang, $wgScript, $wgServer, $wgAllMessagesEn;
61 global $wgOut, $wgArticle, $wgUser;
62 global $wgMessageCache, $wgMemc, $wgDBname, $wgUseMemCached;
64 # Initialise $wgOut and $wgUser for a command line script
68 $wgUser->setLoaded( true ); # Don't load from DB
69 $wgUser->setName( 'MediaWiki default' );
71 # Don't try to draw messages from the database we're initialising
72 $wgMessageCache->disable();
74 $fname = 'initialiseMessages';
76 # cur_user_text responsible for the modifications
77 # Don't change it unless you're prepared to update the DBs accordingly, otherwise the
78 # default messages won't be overwritte
79 $username = 'MediaWiki default';
82 print "Initialising \"MediaWiki\" namespace...\n";
85 $dbr =& wfGetDB( DB_SLAVE );
86 $dbw =& wfGetDB( DB_MASTER );
87 $cur = $dbr->tableName( 'cur' );
89 $timestamp = wfTimestampNow();
90 $invTimestamp = wfInvertTimestamp( $timestamp );
92 $sql = "SELECT cur_title,cur_is_new,cur_user_text FROM $cur WHERE cur_namespace=$ns AND cur_title IN(";
94 # Get keys from $wgAllMessagesEn, which is more complete than the local language
96 if ( $messageArray ) {
97 $sortedArray = $messageArray;
99 $sortedArray = $wgAllMessagesEn;
102 ksort( $sortedArray );
104 # SELECT all existing messages
105 # Can't afford to be locking all rows for update, this script can take quite a long time to complete
106 foreach ( $sortedArray as $key => $enMsg ) {
108 continue; // Skip odd members
115 $titleObj = Title::newFromText( $key );
116 $enctitle = $dbr->strencode($titleObj->getDBkey());
117 $sql .= "'$enctitle'";
120 $res = $dbr->query( $sql );
121 $row = $dbr->fetchObject( $res );
123 # Read the results into an array
124 # Decide whether or not each one needs to be overwritten
125 $existingTitles = array();
127 if ( $row->cur_user_text != $username ) {
128 $existingTitles[$row->cur_title] = 'keep';
130 $existingTitles[$row->cur_title] = 'chuck';
133 $row = $dbr->fetchObject( $res );
136 # Insert queries are done in one multi-row insert
137 # Here's the start of it:
139 $talk = $wgContLang->getNsText( NS_TALK );
140 $mwtalk = $wgContLang->getNsText( NS_MEDIAWIKI_TALK );
142 # Process each message
143 foreach ( $sortedArray as $key => $enMsg ) {
145 continue; // Skip odd members
148 if ( $messageArray ) {
151 $message = wfMsgNoDBForContent( $key );
153 $titleObj = Title::newFromText( $key );
154 $title = $titleObj->getDBkey();
156 # Update messages which already exist
157 if ( array_key_exists( $title, $existingTitles ) ) {
158 if ( $existingTitles[$title] == 'chuck' || $overwrite) {
160 $mwTitleObj = Title::makeTitle( NS_MEDIAWIKI, $title );
161 $article = new Article( $mwTitleObj );
162 $article->quickEdit( $message );
166 array_push( $arr, array(
167 'cur_namespace' => $ns,
168 'cur_title' => $title,
169 'cur_text' => $message,
171 'cur_user_text' => $username,
172 'cur_timestamp' => $dbw->timestamp( $timestamp ),
173 'cur_restrictions' => 'sysop',
175 'inverse_timestamp' => $invTimestamp,
176 'cur_touched' => $dbw->timestamp( $timestamp ) ) );
180 $dbw->insertArray( $cur, $arr, $fname );
182 # Clear the relevant memcached key
183 print 'Clearing message cache...';
184 $wgMessageCache->clear();
188 function loadLanguageFile( $filename )
190 $contents = file_get_contents( $filename );
192 $p = strpos( $contents, "\n" ) + 1;
193 $contents = substr( $contents, $p );
195 return unserialize( $contents );
198 function doUpdates() {
199 global $wgDeferredUpdateList;
200 foreach ( $wgDeferredUpdateList as $up ) { $up->doUpdate(); }