allow NULL html/mathml entries in math table
[mediawiki.git] / maintenance / InitialiseMessages.inc
blob9f8da0d1cc42c22e9cb0f43d4160c354c27ba59a
1 <?php
2 /**
3  * Script to initialise the MediaWiki namespace
4  *
5  * This script is included from update.php and install.php. Do not run it 
6  * by itself.
7  *
8  * @deprecated
9  * @package MediaWiki
10  * @subpackage Maintenance
11  */
13 /** */
14 function initialiseMessages( $overwrite = false, $messageArray = false ) {
15         global $wgLang, $wgScript, $wgServer, $wgAllMessagesEn;
16         global $wgOut, $wgArticle, $wgUser;
17         global $wgMessageCache, $wgMemc, $wgDBname, $wgUseMemCached;
19         # Initialise $wgOut and $wgUser for a command line script
20         $wgOut->disable();
22         $wgUser = new User;
23         $wgUser->setLoaded( true ); # Don't load from DB
24         $wgUser->setName( 'MediaWiki default' );
25         
26         # Don't try to draw messages from the database we're initialising
27         $wgMessageCache->disable();
29         $fname = 'initialiseMessages';
30         $ns = NS_MEDIAWIKI;
31         # cur_user_text responsible for the modifications
32         # Don't change it unless you're prepared to update the DBs accordingly, otherwise the 
33         # default messages won't be overwritte
34         $username = 'MediaWiki default';
36         $timestamp = wfTimestampNow();
37         $invTimestamp = wfInvertTimestamp( $timestamp );
38         
39         print "Initialising \"MediaWiki\" namespace...\n";
41         
42         $dbr =& wfGetDB( DB_SLAVE );
43         $dbw =& wfGetDB( DB_MASTER );
44         $cur = $dbr->tableName( 'cur' );
46         $sql = "SELECT cur_title,cur_is_new,cur_user_text FROM $cur WHERE cur_namespace=$ns AND cur_title IN(";
48         # Get keys from $wgAllMessagesEn, which is more complete than the local language
49         $first = true;
50         if ( $messageArray ) {
51                 $sortedArray = $messageArray;
52         } else {
53                 $sortedArray = $wgAllMessagesEn;
54         }
55         
56         ksort( $sortedArray );
58         # SELECT all existing messages
59         # Can't afford to be locking all rows for update, this script can take quite a long time to complete
60         foreach ( $sortedArray as $key => $enMsg ) {
61                 if ( $key == '' ) {
62                         continue; // Skip odd members
63                 }
64                 if ( $first ) {
65                         $first = false;
66                 } else {
67                         $sql .= ',';
68                 }
69                 $titleObj = Title::newFromText( $key );
70                 $enctitle = $dbr->strencode($titleObj->getDBkey());
71                 $sql .= "'$enctitle'";
72         }
73         $sql .= ')';
74         $res = $dbr->query( $sql );
75         $row = $dbr->fetchObject( $res );
77         # Read the results into an array
78         # Decide whether or not each one needs to be overwritten
79         $existingTitles = array();
80         while ( $row ) {
81                 if ( $row->cur_user_text != $username ) {
82                         $existingTitles[$row->cur_title] = 'keep';
83                 } else {
84                         $existingTitles[$row->cur_title] = 'chuck';
85                 }
87                 $row = $dbr->fetchObject( $res );
88         }
90         # Insert queries are done in one multi-row insert
91         # Here's the start of it:
92         $sql = "INSERT INTO $cur (cur_namespace, cur_title, cur_text,
93                 cur_user_text, cur_timestamp, cur_restrictions,
94                 cur_is_new, inverse_timestamp, cur_touched) VALUES      ";
95         $first = true;
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();
112                 $dbencMsg = $dbw->strencode( $message );
114                 # Update messages which already exist
115                 if ( array_key_exists( $title, $existingTitles ) ) {
116                         if ( $existingTitles[$title] == 'chuck' || $overwrite) {
117                                 # print "$title\n";
118                                 $mwTitleObj = Title::makeTitle( NS_MEDIAWIKI, $title );
119                                 $article = new Article( $mwTitleObj );
120                                 $article->quickEdit( $message );
121                         }
122                         $doInsert = false;
123                 } else {
124                         # Queue for insertion
125                         if ( $first ) {
126                                 $first = false;
127                         } else {
128                                 $sql .= ',';
129                         }
130                         $sql .=
131                           "($ns,
132                           '$title',
133                           '$dbencMsg',
134                           '$username',
135                           '$timestamp',
136                           'sysop',
137                           1,
138                           '$invTimestamp',
139                           '$timestamp')";
140                 }
141         }
143         # Perform the insert query
144         if ( !$first ) {
145                 $dbw->query( $sql, $fname );
146         }
148         # Clear the relevant memcached key
149         print 'Clearing message cache...';
150         $wgMessageCache->clear();
151         print "Done.\n";
154 function loadLanguageFile( $filename )
156         $contents = file_get_contents( $filename );
157         # Remove header line
158         $p = strpos( $contents, "\n" ) + 1;
159         $contents = substr( $contents, $p );
160         # Unserialize
161         return unserialize( $contents );
164 function doUpdates() {
165         global $wgDeferredUpdateList;
166         foreach ( $wgDeferredUpdateList as $up ) { $up->doUpdate(); }