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
13 require_once('languages/Names.php');
15 function initialiseMessages( $overwrite = false, $messageArray = false ) {
16 global $wgContLang, $wgContLanguageCode;
17 global $wgContLangClass, $wgAllMessagesEn;
18 global $wgDisableLangConversion;
19 global $wgForceUIMsgAsContentMsg;
20 global $wgLanguageNames;
23 # overwrite language conversion option so that all variants
24 # of the messages are initialised
25 $wgDisableLangConversion = false;
27 if ( $messageArray ) {
28 $sortedArray = $messageArray;
30 $sortedArray = $wgAllMessagesEn;
33 ksort( $sortedArray );
36 $variants = $wgContLang->getVariants();
37 if(!in_array($wgContLanguageCode, $variants))
38 $variants[]=$wgContLanguageCode;
40 foreach ($variants as $v) {
41 $langclass = 'Language'. str_replace( '-', '_', ucfirst( $v ) );
42 if( !class_exists($langclass) ) {
43 die ("class $langclass not defined. perhaps you need to include the file $langclass.php in $wgContLangClass.php?");
45 $lang = new $langclass;
47 if($v==$wgContLanguageCode)
51 foreach ($sortedArray as $key => $msg) {
52 $messages[$key.$suffix] = $lang->getMessage($key);
57 initialize all messages in $wgForceUIMsgAsContentMsg for all
58 languages in Names.php
60 if( is_array( $wgForceUIMsgAsContentMsg ) ) {
61 foreach( $wgForceUIMsgAsContentMsg as $uikey ) {
62 foreach( $wgLanguageNames as $code => $name) {
63 if( $code == $wgContLanguageCode )
65 $msg = $wgContLang->getMessage( $uikey );
67 $messages[$uikey. '/' . $code] = $msg;
72 initialiseMessagesReal( $overwrite, $messages );
82 function initialiseMessagesReal( $overwrite = false, $messageArray = false ) {
83 global $wgContLang, $wgScript, $wgServer, $wgAllMessagesEn;
84 global $wgOut, $wgArticle, $wgUser;
85 global $wgMessageCache, $wgMemc, $wgDBname, $wgUseMemCached;
87 # Initialise $wgOut and $wgUser for a command line script
91 $wgUser->setLoaded( true ); # Don't load from DB
92 $wgUser->setName( 'MediaWiki default' );
94 # Don't try to draw messages from the database we're initialising
95 $wgMessageCache->disable();
96 $wgMessageCache->disableTransform();
98 $fname = 'initialiseMessages';
100 # cur_user_text responsible for the modifications
101 # Don't change it unless you're prepared to update the DBs accordingly, otherwise the
102 # default messages won't be overwritte
103 $username = 'MediaWiki default';
106 print "Initialising \"MediaWiki\" namespace...\n";
109 $dbr =& wfGetDB( DB_SLAVE );
110 $dbw =& wfGetDB( DB_MASTER );
111 $cur = $dbr->tableName( 'cur' );
113 $timestamp = wfTimestampNow();
114 $invTimestamp = wfInvertTimestamp( $timestamp );
116 $sql = "SELECT cur_title,cur_is_new,cur_user_text FROM $cur WHERE cur_namespace=$ns AND cur_title IN(";
118 # Get keys from $wgAllMessagesEn, which is more complete than the local language
120 if ( $messageArray ) {
121 $sortedArray = $messageArray;
123 $sortedArray = $wgAllMessagesEn;
126 ksort( $sortedArray );
128 # SELECT all existing messages
129 # Can't afford to be locking all rows for update, this script can take quite a long time to complete
130 foreach ( $sortedArray as $key => $enMsg ) {
132 continue; // Skip odd members
139 $titleObj = Title::newFromText( $key );
140 $enctitle = $dbr->strencode($titleObj->getDBkey());
141 $sql .= "'$enctitle'";
144 $res = $dbr->query( $sql );
145 $row = $dbr->fetchObject( $res );
147 # Read the results into an array
148 # Decide whether or not each one needs to be overwritten
149 $existingTitles = array();
151 if ( $row->cur_user_text != $username ) {
152 $existingTitles[$row->cur_title] = 'keep';
154 $existingTitles[$row->cur_title] = 'chuck';
157 $row = $dbr->fetchObject( $res );
160 # Insert queries are done in one multi-row insert
161 # Here's the start of it:
163 $talk = $wgContLang->getNsText( NS_TALK );
164 $mwtalk = $wgContLang->getNsText( NS_MEDIAWIKI_TALK );
166 # Process each message
167 foreach ( $sortedArray as $key => $enMsg ) {
169 continue; // Skip odd members
172 if ( $messageArray ) {
175 $message = wfMsgNoDBForContent( $key );
177 $titleObj = Title::newFromText( $key );
178 $title = $titleObj->getDBkey();
180 # Update messages which already exist
181 if ( array_key_exists( $title, $existingTitles ) ) {
182 if ( $existingTitles[$title] == 'chuck' || $overwrite) {
184 $mwTitleObj = Title::makeTitle( NS_MEDIAWIKI, $title );
185 $article = new Article( $mwTitleObj );
186 $article->quickEdit( $message );
190 array_push( $arr, array(
191 'cur_namespace' => $ns,
192 'cur_title' => $title,
193 'cur_text' => $message,
195 'cur_user_text' => $username,
196 'cur_timestamp' => $dbw->timestamp( $timestamp ),
197 'cur_restrictions' => 'sysop',
199 'inverse_timestamp' => $invTimestamp,
200 'cur_touched' => $dbw->timestamp( $timestamp ) ) );
204 $dbw->insert( 'cur', $arr, $fname );
206 # Clear the relevant memcached key
207 print 'Clearing message cache...';
208 $wgMessageCache->clear();
212 function loadLanguageFile( $filename )
214 $contents = file_get_contents( $filename );
216 $p = strpos( $contents, "\n" ) + 1;
217 $contents = substr( $contents, $p );
219 return unserialize( $contents );
222 function doUpdates() {
223 global $wgDeferredUpdateList;
224 foreach ( $wgDeferredUpdateList as $up ) { $up->doUpdate(); }