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 $langclass = 'Language'. str_replace( '-', '_', ucfirst( $wgContLanguageCode ) );
26 require_once("$IP/languages/$langclass.php");
28 $variants = $wgContLang->getVariants();
29 if(!in_array($wgContLanguageCode, $variants))
30 $variants[]=$wgContLanguageCode;
32 if ( $messageArray ) {
33 $sortedArray = $messageArray;
35 $sortedArray = $wgAllMessagesEn;
38 ksort( $sortedArray );
41 foreach ($variants as $v) {
42 $langclass = 'Language'. str_replace( '-', '_', ucfirst( $v ) );
43 $lang = new $langclass;
44 if(!is_object($lang)) {
45 die ("class $langclass not defined. perhaps you need to include the file $langclass.php in $wgContLangClass.php?");
47 if($v==$wgContLanguageCode)
51 foreach ($sortedArray as $key => $msg) {
52 $messages[$key.$suffix] = $lang->getMessage($key);
56 initialiseMessagesReal( $overwrite, $messages );
66 function initialiseMessagesReal( $overwrite = false, $messageArray = false ) {
67 global $wgContLang, $wgScript, $wgServer, $wgAllMessagesEn;
68 global $wgOut, $wgArticle, $wgUser;
69 global $wgMessageCache, $wgMemc, $wgDBname, $wgUseMemCached;
71 # Initialise $wgOut and $wgUser for a command line script
75 $wgUser->setLoaded( true ); # Don't load from DB
76 $wgUser->setName( 'MediaWiki default' );
78 # Don't try to draw messages from the database we're initialising
79 $wgMessageCache->disable();
80 $wgMessageCache->disableTransform();
82 $fname = 'initialiseMessages';
84 # cur_user_text responsible for the modifications
85 # Don't change it unless you're prepared to update the DBs accordingly, otherwise the
86 # default messages won't be overwritte
87 $username = 'MediaWiki default';
90 print "Initialising \"MediaWiki\" namespace...\n";
93 $dbr =& wfGetDB( DB_SLAVE );
94 $dbw =& wfGetDB( DB_MASTER );
95 $cur = $dbr->tableName( 'cur' );
97 $timestamp = wfTimestampNow();
98 $invTimestamp = wfInvertTimestamp( $timestamp );
100 $sql = "SELECT cur_title,cur_is_new,cur_user_text FROM $cur WHERE cur_namespace=$ns AND cur_title IN(";
102 # Get keys from $wgAllMessagesEn, which is more complete than the local language
104 if ( $messageArray ) {
105 $sortedArray = $messageArray;
107 $sortedArray = $wgAllMessagesEn;
110 ksort( $sortedArray );
112 # SELECT all existing messages
113 # Can't afford to be locking all rows for update, this script can take quite a long time to complete
114 foreach ( $sortedArray as $key => $enMsg ) {
116 continue; // Skip odd members
123 $titleObj = Title::newFromText( $key );
124 $enctitle = $dbr->strencode($titleObj->getDBkey());
125 $sql .= "'$enctitle'";
128 $res = $dbr->query( $sql );
129 $row = $dbr->fetchObject( $res );
131 # Read the results into an array
132 # Decide whether or not each one needs to be overwritten
133 $existingTitles = array();
135 if ( $row->cur_user_text != $username ) {
136 $existingTitles[$row->cur_title] = 'keep';
138 $existingTitles[$row->cur_title] = 'chuck';
141 $row = $dbr->fetchObject( $res );
144 # Insert queries are done in one multi-row insert
145 # Here's the start of it:
147 $talk = $wgContLang->getNsText( NS_TALK );
148 $mwtalk = $wgContLang->getNsText( NS_MEDIAWIKI_TALK );
150 # Process each message
151 foreach ( $sortedArray as $key => $enMsg ) {
153 continue; // Skip odd members
156 if ( $messageArray ) {
159 $message = wfMsgNoDBForContent( $key );
161 $titleObj = Title::newFromText( $key );
162 $title = $titleObj->getDBkey();
164 # Update messages which already exist
165 if ( array_key_exists( $title, $existingTitles ) ) {
166 if ( $existingTitles[$title] == 'chuck' || $overwrite) {
168 $mwTitleObj = Title::makeTitle( NS_MEDIAWIKI, $title );
169 $article = new Article( $mwTitleObj );
170 $article->quickEdit( $message );
174 array_push( $arr, array(
175 'cur_namespace' => $ns,
176 'cur_title' => $title,
177 'cur_text' => $message,
179 'cur_user_text' => $username,
180 'cur_timestamp' => $dbw->timestamp( $timestamp ),
181 'cur_restrictions' => 'sysop',
183 'inverse_timestamp' => $invTimestamp,
184 'cur_touched' => $dbw->timestamp( $timestamp ) ) );
188 $dbw->insert( 'cur', $arr, $fname );
190 # Clear the relevant memcached key
191 print 'Clearing message cache...';
192 $wgMessageCache->clear();
196 function loadLanguageFile( $filename )
198 $contents = file_get_contents( $filename );
200 $p = strpos( $contents, "\n" ) + 1;
201 $contents = substr( $contents, $p );
203 return unserialize( $contents );
206 function doUpdates() {
207 global $wgDeferredUpdateList;
208 foreach ( $wgDeferredUpdateList as $up ) { $up->doUpdate(); }