Add previous/next links to old revision pages
[mediawiki.git] / maintenance / InitialiseMessages.inc
blobced6d9c1e26f7688043fcaf51018f5075b88b278
1 <?php
2 /**
3  * Script to initialise the MediaWiki namespace
4  *
5  * $Id$
6  *
7  * This script is included from update.php and install.php. Do not run it 
8  * by itself.
9  *
10  * @deprecated
11  * @package MediaWiki
12  * @subpackage Maintenance
13  */
17 function initialiseMessages( $overwrite = false, $messageArray = false ) {
18         global $wgContLang, $wgContLanguageCode;
19         global $wgContLangClass, $wgAllMessagesEn;
20         global $IP;
21         
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;
31         } else {
32                 $sortedArray = $wgAllMessagesEn;
33         }
34         
35         ksort( $sortedArray );
36         
37         $messages=array();
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?");
43                 }
44                 foreach ($sortedArray as $key => $msg) {
45                         $messages[$key."/$v"] = $lang->getMessage($key);
46                 }
47         }       
49         initialiseMessagesReal( $overwrite, $messages );
58 /** */
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
65         $wgOut->disable();
67         $wgUser = new User;
68         $wgUser->setLoaded( true ); # Don't load from DB
69         $wgUser->setName( 'MediaWiki default' );
70         
71         # Don't try to draw messages from the database we're initialising
72         $wgMessageCache->disable();
74         $fname = 'initialiseMessages';
75         $ns = NS_MEDIAWIKI;
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';
81         
82         print "Initialising \"MediaWiki\" namespace...\n";
84         
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
95         $first = true;
96         if ( $messageArray ) {
97                 $sortedArray = $messageArray;
98         } else {
99                 $sortedArray = $wgAllMessagesEn;
100         }
101         
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 ) {
107                 if ( $key == '' ) {
108                         continue; // Skip odd members
109                 }
110                 if ( $first ) {
111                         $first = false;
112                 } else {
113                         $sql .= ',';
114                 }
115                 $titleObj = Title::newFromText( $key );
116                 $enctitle = $dbr->strencode($titleObj->getDBkey());
117                 $sql .= "'$enctitle'";
118         }
119         $sql .= ')';
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();
126         while ( $row ) {
127                 if ( $row->cur_user_text != $username ) {
128                         $existingTitles[$row->cur_title] = 'keep';
129                 } else {
130                         $existingTitles[$row->cur_title] = 'chuck';
131                 }
133                 $row = $dbr->fetchObject( $res );
134         }
136         # Insert queries are done in one multi-row insert
137         # Here's the start of it:
138         $arr = array();
139         $talk = $wgContLang->getNsText( NS_TALK );
140         $mwtalk = $wgContLang->getNsText( NS_MEDIAWIKI_TALK );
141         
142         # Process each message
143         foreach ( $sortedArray as $key => $enMsg ) {
144                 if ( $key == '' ) {
145                         continue; // Skip odd members
146                 }
147                 # Get message text
148                 if ( $messageArray ) {
149                         $message = $enMsg;
150                 } else {
151                         $message = wfMsgNoDBForContent( $key );
152                 }
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) {
159                                 # print "$title\n";
160                                 $mwTitleObj = Title::makeTitle( NS_MEDIAWIKI, $title );
161                                 $article = new Article( $mwTitleObj );
162                                 $article->quickEdit( $message );
163                         }
164                         $doInsert = false;
165                 } else {
166                         array_push( $arr, array(
167                                 'cur_namespace' => $ns,
168                                 'cur_title' => $title,
169                                 'cur_text' => $message,
170                                 'cur_user' => 0,
171                                 'cur_user_text' => $username,
172                                 'cur_timestamp' => $dbw->timestamp( $timestamp ),
173                                 'cur_restrictions' => 'sysop',
174                                 'cur_is_new' => 1,
175                                 'inverse_timestamp' => $invTimestamp,
176                                 'cur_touched' => $dbw->timestamp( $timestamp ) ) );
177                 }
178         }
180         $dbw->insertArray( $cur, $arr, $fname );
182         # Clear the relevant memcached key
183         print 'Clearing message cache...';
184         $wgMessageCache->clear();
185         print "Done.\n";
188 function loadLanguageFile( $filename )
190         $contents = file_get_contents( $filename );
191         # Remove header line
192         $p = strpos( $contents, "\n" ) + 1;
193         $contents = substr( $contents, $p );
194         # Unserialize
195         return unserialize( $contents );
198 function doUpdates() {
199         global $wgDeferredUpdateList;
200         foreach ( $wgDeferredUpdateList as $up ) { $up->doUpdate(); }