Add missing functions for language variants
[mediawiki.git] / maintenance / InitialiseMessages.inc
blobb5822881061a6e3a2c2579b95bbba50e8add118d
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  */
15 /** */
16 function initialiseMessages( $overwrite = false, $messageArray = false ) {
17         global $wgLang, $wgScript, $wgServer, $wgAllMessagesEn;
18         global $wgOut, $wgArticle, $wgUser;
19         global $wgMessageCache, $wgMemc, $wgDBname, $wgUseMemCached;
21         # Initialise $wgOut and $wgUser for a command line script
22         $wgOut->disable();
24         $wgUser = new User;
25         $wgUser->setLoaded( true ); # Don't load from DB
26         $wgUser->setName( 'MediaWiki default' );
27         
28         # Don't try to draw messages from the database we're initialising
29         $wgMessageCache->disable();
31         $fname = 'initialiseMessages';
32         $ns = NS_MEDIAWIKI;
33         # cur_user_text responsible for the modifications
34         # Don't change it unless you're prepared to update the DBs accordingly, otherwise the 
35         # default messages won't be overwritte
36         $username = 'MediaWiki default';
38         
39         print "Initialising \"MediaWiki\" namespace...\n";
41         
42         $dbr =& wfGetDB( DB_SLAVE );
43         $dbw =& wfGetDB( DB_MASTER );
44         $cur = $dbr->tableName( 'cur' );
46         $timestamp = wfTimestampNow();
47         $invTimestamp = wfInvertTimestamp( $timestamp );
49         $sql = "SELECT cur_title,cur_is_new,cur_user_text FROM $cur WHERE cur_namespace=$ns AND cur_title IN(";
51         # Get keys from $wgAllMessagesEn, which is more complete than the local language
52         $first = true;
53         if ( $messageArray ) {
54                 $sortedArray = $messageArray;
55         } else {
56                 $sortedArray = $wgAllMessagesEn;
57         }
58         
59         ksort( $sortedArray );
61         # SELECT all existing messages
62         # Can't afford to be locking all rows for update, this script can take quite a long time to complete
63         foreach ( $sortedArray as $key => $enMsg ) {
64                 if ( $key == '' ) {
65                         continue; // Skip odd members
66                 }
67                 if ( $first ) {
68                         $first = false;
69                 } else {
70                         $sql .= ',';
71                 }
72                 $titleObj = Title::newFromText( $key );
73                 $enctitle = $dbr->strencode($titleObj->getDBkey());
74                 $sql .= "'$enctitle'";
75         }
76         $sql .= ')';
77         $res = $dbr->query( $sql );
78         $row = $dbr->fetchObject( $res );
80         # Read the results into an array
81         # Decide whether or not each one needs to be overwritten
82         $existingTitles = array();
83         while ( $row ) {
84                 if ( $row->cur_user_text != $username ) {
85                         $existingTitles[$row->cur_title] = 'keep';
86                 } else {
87                         $existingTitles[$row->cur_title] = 'chuck';
88                 }
90                 $row = $dbr->fetchObject( $res );
91         }
93         # Insert queries are done in one multi-row insert
94         # Here's the start of it:
95         $arr = array();
96         $talk = $wgLang->getNsText( NS_TALK );
97         $mwtalk = $wgLang->getNsText( NS_MEDIAWIKI_TALK );
98         
99         # Process each message
100         foreach ( $sortedArray as $key => $enMsg ) {
101                 if ( $key == '' ) {
102                         continue; // Skip odd members
103                 }
104                 # Get message text
105                 if ( $messageArray ) {
106                         $message = $enMsg;
107                 } else {
108                         $message = wfMsgNoDB( $key );
109                 }
110                 $titleObj = Title::newFromText( $key );
111                 $title = $titleObj->getDBkey();
113                 # Update messages which already exist
114                 if ( array_key_exists( $title, $existingTitles ) ) {
115                         if ( $existingTitles[$title] == 'chuck' || $overwrite) {
116                                 # print "$title\n";
117                                 $mwTitleObj = Title::makeTitle( NS_MEDIAWIKI, $title );
118                                 $article = new Article( $mwTitleObj );
119                                 $article->quickEdit( $message );
120                         }
121                         $doInsert = false;
122                 } else {
123                         array_push( $arr, array(
124                                 'cur_namespace' => $ns,
125                                 'cur_title' => $title,
126                                 'cur_text' => $message,
127                                 'cur_user' => 0,
128                                 'cur_user_text' => $username,
129                                 'cur_timestamp' => $dbw->timestamp( $timestamp ),
130                                 'cur_restrictions' => 'sysop',
131                                 'cur_is_new' => 1,
132                                 'inverse_timestamp' => $invTimestamp,
133                                 'cur_touched' => $dbw->timestamp( $timestamp ) ) );
134                 }
135         }
137         $dbw->insertArray( $cur, $arr, $fname );
139         # Clear the relevant memcached key
140         print 'Clearing message cache...';
141         $wgMessageCache->clear();
142         print "Done.\n";
145 function loadLanguageFile( $filename )
147         $contents = file_get_contents( $filename );
148         # Remove header line
149         $p = strpos( $contents, "\n" ) + 1;
150         $contents = substr( $contents, $p );
151         # Unserialize
152         return unserialize( $contents );
155 function doUpdates() {
156         global $wgDeferredUpdateList;
157         foreach ( $wgDeferredUpdateList as $up ) { $up->doUpdate(); }