Merge capitallinks message fixes from REL1_4
[lhc/web/wiklou.git] / maintenance / InitialiseMessages.inc
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 */
12
13
14 function initialiseMessages( $overwrite = false, $messageArray = false ) {
15 global $wgContLang, $wgContLanguageCode;
16 global $wgContLangClass, $wgAllMessagesEn;
17 global $wgDisableLangConversion;
18 global $wgForceUIMsgAsContentMsg;
19 global $wgLanguageNames;
20 global $IP;
21
22 # overwrite language conversion option so that all variants
23 # of the messages are initialised
24 $wgDisableLangConversion = false;
25
26 if ( $messageArray ) {
27 $sortedArray = $messageArray;
28 } else {
29 $sortedArray = $wgAllMessagesEn;
30 }
31
32 ksort( $sortedArray );
33 $messages=array();
34
35 $variants = $wgContLang->getVariants();
36 if(!in_array($wgContLanguageCode, $variants))
37 $variants[]=$wgContLanguageCode;
38
39 foreach ($variants as $v) {
40 $langclass = 'Language'. str_replace( '-', '_', ucfirst( $v ) );
41 if( !class_exists($langclass) ) {
42 die ("class $langclass not defined. perhaps you need to include the file $langclass.php in $wgContLangClass.php?");
43 }
44 $lang = new $langclass;
45
46 if($v==$wgContLanguageCode)
47 $suffix='';
48 else
49 $suffix="/$v";
50 foreach ($sortedArray as $key => $msg) {
51 $messages[$key.$suffix] = $lang->getMessage($key);
52 }
53 }
54
55 require_once('languages/Names.php');
56
57 /*
58 initialize all messages in $wgForceUIMsgAsContentMsg for all
59 languages in Names.php
60 */
61 if( is_array( $wgForceUIMsgAsContentMsg ) ) {
62 foreach( $wgForceUIMsgAsContentMsg as $uikey ) {
63 foreach( $wgLanguageNames as $code => $name) {
64 if( $code == $wgContLanguageCode )
65 continue;
66 $msg = $wgContLang->getMessage( $uikey );
67 if( $msg )
68 $messages[$uikey. '/' . $code] = $msg;
69 }
70 }
71 }
72
73 initialiseMessagesReal( $overwrite, $messages );
74 }
75
76
77
78
79
80
81
82 /** */
83 function initialiseMessagesReal( $overwrite = false, $messageArray = false ) {
84 global $wgContLang, $wgScript, $wgServer, $wgAllMessagesEn;
85 global $wgOut, $wgArticle, $wgUser;
86 global $wgMessageCache, $wgMemc, $wgDBname, $wgUseMemCached;
87
88 # Initialise $wgOut and $wgUser for a command line script
89 $wgOut->disable();
90
91 $wgUser = new User;
92 $wgUser->setLoaded( true ); # Don't load from DB
93 $wgUser->setName( 'MediaWiki default' );
94
95 # Don't try to draw messages from the database we're initialising
96 $wgMessageCache->disable();
97 $wgMessageCache->disableTransform();
98
99 $fname = 'initialiseMessages';
100 $ns = NS_MEDIAWIKI;
101 # cur_user_text responsible for the modifications
102 # Don't change it unless you're prepared to update the DBs accordingly, otherwise the
103 # default messages won't be overwritte
104 $username = 'MediaWiki default';
105
106
107 print "Initialising \"MediaWiki\" namespace...\n";
108
109
110 $dbr =& wfGetDB( DB_SLAVE );
111 $dbw =& wfGetDB( DB_MASTER );
112 $page = $dbr->tableName( 'page' );
113 $revision = $dbr->tableName( 'revision' );
114
115 $timestamp = wfTimestampNow();
116 $invTimestamp = wfInvertTimestamp( $timestamp );
117
118 #$sql = "SELECT cur_title,cur_is_new,cur_user_text FROM $cur WHERE cur_namespace=$ns AND cur_title IN(";
119 $sql = "SELECT page_title,page_is_new,rev_user_text FROM $page, $revision WHERE
120 page_namespace=$ns AND rev_page=page_id AND page_title IN(";
121
122 # Get keys from $wgAllMessagesEn, which is more complete than the local language
123 $first = true;
124 if ( $messageArray ) {
125 $sortedArray = $messageArray;
126 } else {
127 $sortedArray = $wgAllMessagesEn;
128 }
129
130 ksort( $sortedArray );
131
132 # SELECT all existing messages
133 # Can't afford to be locking all rows for update, this script can take quite a long time to complete
134 foreach ( $sortedArray as $key => $enMsg ) {
135 if ( $key == '' ) {
136 continue; // Skip odd members
137 }
138 if ( $first ) {
139 $first = false;
140 } else {
141 $sql .= ',';
142 }
143 $titleObj = Title::newFromText( $wgContLang->ucfirst( $key ) );
144 $enctitle = $dbr->strencode($titleObj->getDBkey());
145 $sql .= "'$enctitle'";
146 }
147 $sql .= ')';
148 $res = $dbr->query( $sql );
149 $row = $dbr->fetchObject( $res );
150
151 # Read the results into an array
152 # Decide whether or not each one needs to be overwritten
153 $existingTitles = array();
154 while ( $row ) {
155 if ( $row->rev_user_text != $username ) {
156 $existingTitles[$row->page_title] = 'keep';
157 } else {
158 $existingTitles[$row->page_title] = 'chuck';
159 }
160
161 $row = $dbr->fetchObject( $res );
162 }
163
164 # Insert queries are done in one multi-row insert
165 # Here's the start of it:
166 $arr = array();
167 $talk = $wgContLang->getNsText( NS_TALK );
168 $mwtalk = $wgContLang->getNsText( NS_MEDIAWIKI_TALK );
169
170 # Process each message
171 foreach ( $sortedArray as $key => $enMsg ) {
172 if ( $key == '' ) {
173 continue; // Skip odd members
174 }
175 # Get message text
176 if ( $messageArray ) {
177 $message = $enMsg;
178 } else {
179 $message = wfMsgNoDBForContent( $key );
180 }
181 $titleObj = Title::newFromText( $wgContLang->ucfirst( $key ) );
182 $title = $titleObj->getDBkey();
183
184 # Update messages which already exist
185 if ( array_key_exists( $title, $existingTitles ) ) {
186 if ( $existingTitles[$title] == 'chuck' || $overwrite) {
187 # print "$title\n";
188 $mwTitleObj = Title::makeTitle( NS_MEDIAWIKI, $title );
189 $article = new Article( $mwTitleObj );
190 $article->quickEdit( $message );
191 }
192 } else {
193 extract( $dbw->tableNames( 'text', 'page', 'revision' ) );
194 $sql = "INSERT INTO $text (old_text, old_flags) VALUES ('" .
195 wfStrencode( $message ) .
196 "', '')";
197 $dbw->query( $sql, $fname );
198 $text_id = $dbw->insertID();
199
200 $sql = "INSERT INTO $page (page_namespace, page_title, page_restrictions, page_counter, page_is_redirect,
201 page_is_new, page_random, page_touched, page_latest) VALUES (
202 {$ns}, '{$title}', 'sysop', 0, 0, 1, 0.5, '{$timestamp}', {$text_id} )";
203 $dbw->query( $sql, $fname );
204 $page_id = $dbw->insertID();
205
206 $sql = "INSERT INTO $revision (rev_id, rev_page, rev_comment, rev_user, rev_user_text,
207 rev_timestamp, inverse_timestamp, rev_minor_edit)
208 VALUES ({$text_id}, {$page_id}, '', 0, '{$username}', '{$timestamp}', '{$invTimestamp}', 0)";
209 $dbw->query( $sql, $fname );
210
211 }
212 }
213
214 # Clear the relevant memcached key
215 print 'Clearing message cache...';
216 $wgMessageCache->clear();
217 print "Done.\n";
218 }
219
220 function loadLanguageFile( $filename )
221 {
222 $contents = file_get_contents( $filename );
223 # Remove header line
224 $p = strpos( $contents, "\n" ) + 1;
225 $contents = substr( $contents, $p );
226 # Unserialize
227 return unserialize( $contents );
228 }
229
230 function doUpdates() {
231 global $wgDeferredUpdateList;
232 foreach ( $wgDeferredUpdateList as $up ) { $up->doUpdate(); }
233 }
234
235 ?>