remove inverse_timestamp wherever it is found and disable wfInvertTimestamp()
[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 $invTimestamp = wfInvertTimestamp( $timestamp );
110
111 #$sql = "SELECT cur_title,cur_is_new,cur_user_text FROM $cur WHERE cur_namespace=$ns AND cur_title IN(";
112 $sql = "SELECT page_title,page_is_new,rev_user_text FROM $page, $revision WHERE
113 page_namespace=$ns AND rev_page=page_id AND page_title IN(";
114
115 # Get keys from $wgAllMessagesEn, which is more complete than the local language
116 $first = true;
117 if ( $messageArray ) {
118 $sortedArray = $messageArray;
119 } else {
120 $sortedArray = $wgAllMessagesEn;
121 }
122
123 ksort( $sortedArray );
124
125 # SELECT all existing messages
126 # Can't afford to be locking all rows for update, this script can take quite a long time to complete
127 foreach ( $sortedArray as $key => $enMsg ) {
128 if ( $key == '' ) {
129 continue; // Skip odd members
130 }
131 if ( $first ) {
132 $first = false;
133 } else {
134 $sql .= ',';
135 }
136 $titleObj = Title::newFromText( $wgContLang->ucfirst( $key ) );
137 $enctitle = $dbr->strencode($titleObj->getDBkey());
138 $sql .= "'$enctitle'";
139 }
140 $sql .= ')';
141 $res = $dbr->query( $sql );
142 $row = $dbr->fetchObject( $res );
143
144 # Read the results into an array
145 # Decide whether or not each one needs to be overwritten
146 $existingTitles = array();
147 while ( $row ) {
148 if ( $row->rev_user_text != $username ) {
149 $existingTitles[$row->page_title] = 'keep';
150 } else {
151 $existingTitles[$row->page_title] = 'chuck';
152 }
153
154 $row = $dbr->fetchObject( $res );
155 }
156
157 # Insert queries are done in one multi-row insert
158 # Here's the start of it:
159 $arr = array();
160 $talk = $wgContLang->getNsText( NS_TALK );
161 $mwtalk = $wgContLang->getNsText( NS_MEDIAWIKI_TALK );
162
163 # Process each message
164 foreach ( $sortedArray as $key => $enMsg ) {
165 if ( $key == '' ) {
166 continue; // Skip odd members
167 }
168 # Get message text
169 if ( $messageArray ) {
170 $message = $enMsg;
171 } else {
172 $message = wfMsgNoDBForContent( $key );
173 }
174 $titleObj = Title::newFromText( $wgContLang->ucfirst( $key ) );
175 $title = $titleObj->getDBkey();
176
177 # Update messages which already exist
178 if ( array_key_exists( $title, $existingTitles ) ) {
179 if ( $existingTitles[$title] == 'chuck' || $overwrite) {
180 # print "$title\n";
181 $mwTitleObj = Title::makeTitle( NS_MEDIAWIKI, $title );
182 $article = new Article( $mwTitleObj );
183 $article->quickEdit( $message );
184 }
185 } else {
186 extract( $dbw->tableNames( 'text', 'page', 'revision' ) );
187 $sql = "INSERT INTO $text (old_text, old_flags) VALUES ('" .
188 wfStrencode( $message ) .
189 "', '')";
190 $dbw->query( $sql, $fname );
191 $text_id = $dbw->insertID();
192
193 $sql = "INSERT INTO $page (page_namespace, page_title, page_restrictions, page_counter, page_is_redirect,
194 page_is_new, page_random, page_touched, page_latest) VALUES (
195 {$ns}, '{$title}', 'sysop', 0, 0, 1, 0.5, '{$timestamp}', {$text_id} )";
196 $dbw->query( $sql, $fname );
197 $page_id = $dbw->insertID();
198
199 $sql = "INSERT INTO $revision (rev_id, rev_page, rev_comment, rev_user, rev_user_text,
200 rev_timestamp, rev_minor_edit)
201 VALUES ({$text_id}, {$page_id}, '', 0, '{$username}', '{$timestamp}', 0)";
202 $dbw->query( $sql, $fname );
203
204 }
205 }
206
207 # Clear the relevant memcached key
208 print 'Clearing message cache...';
209 $wgMessageCache->clear();
210 print "Done.\n";
211 }
212
213 /** */
214 function loadLanguageFile( $filename ) {
215 $contents = file_get_contents( $filename );
216 # Remove header line
217 $p = strpos( $contents, "\n" ) + 1;
218 $contents = substr( $contents, $p );
219 # Unserialize
220 return unserialize( $contents );
221 }
222
223 /** */
224 function doUpdates() {
225 global $wgDeferredUpdateList;
226 foreach ( $wgDeferredUpdateList as $up ) { $up->doUpdate(); }
227 }
228 ?>