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
15 function initialiseMessages( $overwrite = false, $messageArray = false ) {
16 global $wgContLang, $wgContLanguageCode;
17 global $wgContLangClass, $wgAllMessagesEn;
18 global $wgDisableLangConversion;
21 # overwrite language conversion option so that all variants
22 # of the messages are initialised
23 $wgDisableLangConversion = false;
25 if ( $messageArray ) {
26 $sortedArray = $messageArray;
28 $sortedArray = $wgAllMessagesEn;
31 ksort( $sortedArray );
34 $variants = $wgContLang->getVariants();
35 if(!in_array($wgContLanguageCode, $variants))
36 $variants[]=$wgContLanguageCode;
38 foreach ($variants as $v) {
39 $langclass = 'Language'. str_replace( '-', '_', ucfirst( $v ) );
40 if( !class_exists($langclass) ) {
41 die ("class $langclass not defined. perhaps you need to include the file $langclass.php in $wgContLangClass.php?");
43 $lang = new $langclass;
45 if($v==$wgContLanguageCode)
49 foreach ($sortedArray as $key => $msg) {
50 $messages[$key.$suffix] = $lang->getMessage($key);
54 initialiseMessagesReal( $overwrite, $messages );
64 function initialiseMessagesReal( $overwrite = false, $messageArray = false ) {
65 global $wgContLang, $wgScript, $wgServer, $wgAllMessagesEn;
66 global $wgOut, $wgArticle, $wgUser;
67 global $wgMessageCache, $wgMemc, $wgDBname, $wgUseMemCached;
69 # Initialise $wgOut and $wgUser for a command line script
73 $wgUser->setLoaded( true ); # Don't load from DB
74 $wgUser->setName( 'MediaWiki default' );
76 # Don't try to draw messages from the database we're initialising
77 $wgMessageCache->disable();
78 $wgMessageCache->disableTransform();
80 $fname = 'initialiseMessages';
82 # cur_user_text responsible for the modifications
83 # Don't change it unless you're prepared to update the DBs accordingly, otherwise the
84 # default messages won't be overwritte
85 $username = 'MediaWiki default';
88 print "Initialising \"MediaWiki\" namespace...\n";
91 $dbr =& wfGetDB( DB_SLAVE );
92 $dbw =& wfGetDB( DB_MASTER );
93 $cur = $dbr->tableName( 'cur' );
95 $timestamp = wfTimestampNow();
96 $invTimestamp = wfInvertTimestamp( $timestamp );
98 $sql = "SELECT cur_title,cur_is_new,cur_user_text FROM $cur WHERE cur_namespace=$ns AND cur_title IN(";
100 # Get keys from $wgAllMessagesEn, which is more complete than the local language
102 if ( $messageArray ) {
103 $sortedArray = $messageArray;
105 $sortedArray = $wgAllMessagesEn;
108 ksort( $sortedArray );
110 # SELECT all existing messages
111 # Can't afford to be locking all rows for update, this script can take quite a long time to complete
112 foreach ( $sortedArray as $key => $enMsg ) {
114 continue; // Skip odd members
121 $titleObj = Title::newFromText( $key );
122 $enctitle = $dbr->strencode($titleObj->getDBkey());
123 $sql .= "'$enctitle'";
126 $res = $dbr->query( $sql );
127 $row = $dbr->fetchObject( $res );
129 # Read the results into an array
130 # Decide whether or not each one needs to be overwritten
131 $existingTitles = array();
133 if ( $row->cur_user_text != $username ) {
134 $existingTitles[$row->cur_title] = 'keep';
136 $existingTitles[$row->cur_title] = 'chuck';
139 $row = $dbr->fetchObject( $res );
142 # Insert queries are done in one multi-row insert
143 # Here's the start of it:
145 $talk = $wgContLang->getNsText( NS_TALK );
146 $mwtalk = $wgContLang->getNsText( NS_MEDIAWIKI_TALK );
148 # Process each message
149 foreach ( $sortedArray as $key => $enMsg ) {
151 continue; // Skip odd members
154 if ( $messageArray ) {
157 $message = wfMsgNoDBForContent( $key );
159 $titleObj = Title::newFromText( $key );
160 $title = $titleObj->getDBkey();
162 # Update messages which already exist
163 if ( array_key_exists( $title, $existingTitles ) ) {
164 if ( $existingTitles[$title] == 'chuck' || $overwrite) {
166 $mwTitleObj = Title::makeTitle( NS_MEDIAWIKI, $title );
167 $article = new Article( $mwTitleObj );
168 $article->quickEdit( $message );
172 array_push( $arr, array(
173 'cur_namespace' => $ns,
174 'cur_title' => $title,
175 'cur_text' => $message,
177 'cur_user_text' => $username,
178 'cur_timestamp' => $dbw->timestamp( $timestamp ),
179 'cur_restrictions' => 'sysop',
181 'inverse_timestamp' => $invTimestamp,
182 'cur_touched' => $dbw->timestamp( $timestamp ) ) );
186 $dbw->insert( 'cur', $arr, $fname );
188 # Clear the relevant memcached key
189 print 'Clearing message cache...';
190 $wgMessageCache->clear();
194 function loadLanguageFile( $filename )
196 $contents = file_get_contents( $filename );
198 $p = strpos( $contents, "\n" ) + 1;
199 $contents = substr( $contents, $p );
201 return unserialize( $contents );
204 function doUpdates() {
205 global $wgDeferredUpdateList;
206 foreach ( $wgDeferredUpdateList as $up ) { $up->doUpdate(); }