no need for position:absolute
[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 initialiseMessagesReal( $overwrite, $messages );
73 }
74
75 /** */
76 function initialiseMessagesReal( $overwrite = false, $messageArray = false ) {
77 global $wgContLang, $wgScript, $wgServer, $wgAllMessagesEn;
78 global $wgOut, $wgArticle, $wgUser;
79 global $wgMessageCache, $wgMemc, $wgDBname, $wgUseMemCached;
80
81 # Initialise $wgOut and $wgUser for a command line script
82 $wgOut->disable();
83
84 $wgUser = new User;
85 $wgUser->setLoaded( true ); # Don't load from DB
86 $wgUser->setName( 'MediaWiki default' );
87
88 # Don't try to draw messages from the database we're initialising
89 $wgMessageCache->disable();
90 $wgMessageCache->disableTransform();
91
92 $fname = 'initialiseMessages';
93 $ns = NS_MEDIAWIKI;
94 # cur_user_text responsible for the modifications
95 # Don't change it unless you're prepared to update the DBs accordingly, otherwise the
96 # default messages won't be overwritte
97 $username = 'MediaWiki default';
98
99
100 print "Initialising \"MediaWiki\" namespace...\n";
101
102
103 $dbr =& wfGetDB( DB_SLAVE );
104 $dbw =& wfGetDB( DB_MASTER );
105 $page = $dbr->tableName( 'page' );
106 $revision = $dbr->tableName( 'revision' );
107
108 $timestamp = wfTimestampNow();
109
110 #$sql = "SELECT cur_title,cur_is_new,cur_user_text FROM $cur WHERE cur_namespace=$ns AND cur_title IN(";
111 $sql = "SELECT page_title,page_is_new,rev_user_text FROM $page, $revision WHERE
112 page_namespace=$ns AND rev_page=page_id AND page_title IN(";
113
114 # Get keys from $wgAllMessagesEn, which is more complete than the local language
115 $first = true;
116 if ( $messageArray ) {
117 $sortedArray = $messageArray;
118 } else {
119 $sortedArray = $wgAllMessagesEn;
120 }
121
122 ksort( $sortedArray );
123
124 # SELECT all existing messages
125 # Can't afford to be locking all rows for update, this script can take quite a long time to complete
126 foreach ( $sortedArray as $key => $enMsg ) {
127 if ( $key == '' ) {
128 continue; // Skip odd members
129 }
130 if ( $first ) {
131 $first = false;
132 } else {
133 $sql .= ',';
134 }
135 $titleObj = Title::newFromText( $wgContLang->ucfirst( $key ) );
136 $enctitle = $dbr->strencode($titleObj->getDBkey());
137 $sql .= "'$enctitle'";
138 }
139 $sql .= ')';
140 $res = $dbr->query( $sql );
141 $row = $dbr->fetchObject( $res );
142
143 # Read the results into an array
144 # Decide whether or not each one needs to be overwritten
145 $existingTitles = array();
146 while ( $row ) {
147 if ( $row->rev_user_text != $username && $row->rev_user_text != 'Template namespace initialisation script' ) {
148 $existingTitles[$row->page_title] = 'keep';
149 } else {
150 $existingTitles[$row->page_title] = 'chuck';
151 }
152
153 $row = $dbr->fetchObject( $res );
154 }
155
156 # Insert queries are done in one multi-row insert
157 # Here's the start of it:
158 $arr = array();
159 $talk = $wgContLang->getNsText( NS_TALK );
160 $mwtalk = $wgContLang->getNsText( NS_MEDIAWIKI_TALK );
161
162 # Process each message
163 foreach ( $sortedArray as $key => $enMsg ) {
164 if ( $key == '' ) {
165 continue; // Skip odd members
166 }
167 # Get message text
168 if ( $messageArray ) {
169 $message = $enMsg;
170 } else {
171 $message = wfMsgNoDBForContent( $key );
172 }
173 $titleObj = Title::newFromText( $wgContLang->ucfirst( $key ), NS_MEDIAWIKI );
174 $title = $titleObj->getDBkey();
175
176 # Update messages which already exist
177 if ( array_key_exists( $title, $existingTitles ) ) {
178 if ( $existingTitles[$title] == 'chuck' || $overwrite) {
179 # Don't bother writing a new revision if we're the same
180 # as the current text!
181 $revision = Revision::newFromTitle( $titleObj );
182 if( is_null( $revision ) || $revision->getText() != $message ) {
183 $article = new Article( $titleObj );
184 $article->quickEdit( $message );
185 }
186 }
187 } else {
188 $article = new Article( $titleObj );
189 $newid = $article->insertOn( $dbw, 'sysop' );
190 # FIXME: set restrictions
191 $revision = new Revision( array(
192 'page' => $newid,
193 'text' => $message,
194 'user' => 0,
195 'user_text' => $username,
196 'comment' => '',
197 ) );
198 $revid = $revision->insertOn( $dbw );
199 $article->updateRevisionOn( $dbw, $revision );
200 }
201 }
202
203 # Clear the relevant memcached key
204 print 'Clearing message cache...';
205 $wgMessageCache->clear();
206 print "Done.\n";
207 }
208
209 /** */
210 function loadLanguageFile( $filename ) {
211 $contents = file_get_contents( $filename );
212 # Remove header line
213 $p = strpos( $contents, "\n" ) + 1;
214 $contents = substr( $contents, $p );
215 # Unserialize
216 return unserialize( $contents );
217 }
218
219 /** */
220 function doUpdates() {
221 global $wgDeferredUpdateList;
222 foreach ( $wgDeferredUpdateList as $up ) { $up->doUpdate(); }
223 }
224 ?>