2 # Script to initialise the MediaWiki namespace
4 # This script is included from update.php and install.php. Do not run it
7 function initialiseMessages( $overwrite = false, $messageArray = false ) {
8 global $wgLang, $wgScript, $wgServer, $wgAllMessagesEn;
9 global $wgOut, $wgArticle, $wgUser;
10 global $wgMessageCache, $wgMemc, $wgDBname, $wgUseMemCached;
12 # Initialise $wgOut and $wgUser for a command line script
16 $wgUser->setLoaded( true ); # Don't load from DB
17 $wgUser->setName( 'MediaWiki default' );
19 # Don't try to draw messages from the database we're initialising
20 $wgMessageCache->disable();
22 $fname = 'initialiseMessages';
24 # cur_user_text responsible for the modifications
25 # Don't change it unless you're prepared to update the DBs accordingly, otherwise the
26 # default messages won't be overwritte
27 $username = 'MediaWiki default';
29 $timestamp = wfTimestampNow();
30 $invTimestamp = wfInvertTimestamp( $timestamp );
31 $navText = '{{int:allmessagestext}}';
34 <table border=1 width=100%><tr><td>
42 print "Initialising \"MediaWiki\" namespace...\n";
43 $sql = "SELECT cur_title,cur_is_new,cur_user_text FROM cur WHERE cur_namespace=$ns AND cur_title IN(";
45 # Get keys from $wgAllMessagesEn, which is more complete than the local language
47 if ( $messageArray ) {
48 $sortedArray = $messageArray;
50 $sortedArray = $wgAllMessagesEn;
53 ksort( $sortedArray );
55 # SELECT all existing messages
56 foreach ( $sortedArray as $key => $enMsg ) {
58 continue; // Skip odd members
65 $titleObj = Title::newFromText( $key );
66 $enctitle = wfStrencode($titleObj->getDBkey());
67 $sql .= "'$enctitle'";
70 $res = wfQuery( $sql, DB_READ );
71 $row = wfFetchObject( $res );
73 # Read the results into an array
74 # Decide whether or not each one needs to be overwritten
75 $existingTitles = array();
77 if ( $row->cur_user_text != $username ) {
78 $existingTitles[$row->cur_title] = 'keep';
80 $existingTitles[$row->cur_title] = 'chuck';
83 $row = wfFetchObject( $res );
86 # Insert queries are done in one multi-row insert
87 # Here's the start of it:
88 $sql = "INSERT INTO cur (cur_namespace, cur_title, cur_text,
89 cur_user_text, cur_timestamp, cur_restrictions,
90 cur_is_new, inverse_timestamp, cur_touched) VALUES ";
92 $talk = $wgLang->getNsText( NS_TALK );
93 $mwtalk = $wgLang->getNsText( NS_MEDIAWIKI_TALK );
95 # Process each message
96 foreach ( $sortedArray as $key => $enMsg ) {
98 continue; // Skip odd members
101 if ( $messageArray ) {
104 $message = wfMsgNoDB( $key );
106 $titleObj = Title::newFromText( $key );
107 $title = $titleObj->getDBkey();
108 $dbencMsg = wfStrencode( $message );
110 # Update messages which already exist
111 if ( array_key_exists( $title, $existingTitles ) ) {
112 if ( $existingTitles[$title] == 'chuck' || $overwrite) {
114 $mwTitleObj = Title::makeTitle( NS_MEDIAWIKI, $title );
115 $article = new Article( $mwTitleObj );
116 $article->quickEdit( $message );
120 # Queue for insertion
138 # Make table row for navigation page
139 $message = wfEscapeWikiText( $message );
142 [$wgServer$wgScript?title=MediaWiki:$title&action=edit $key]<br>
143 [[$mwtalk:$title|$talk]]
151 # Perform the insert query
153 wfQuery( $sql, DB_WRITE, $fname );
156 # Write the navigation page
158 $navText .= '</table>';
159 $title = wfMsgNoDB( 'allmessages' );
160 $titleObj = Title::makeTitle( NS_WIKIPEDIA, $title );
161 $wgArticle = new Article( $titleObj );
163 $wgUser = User::newFromName( 'MediaWiki default' );
164 if ( $titleObj->getArticleID() ) {
165 $wgArticle->updateArticle( $navText, '', 0, 0 );
167 $wgArticle->insertNewArticle( $navText, '', 0, 0 );
170 # Clear the relevant memcached key
171 if( $wgUseMemCached ) {
172 print 'Clearing message cache...';
173 $wgMemc->delete( $wgDBname.':messages' );
178 function loadLanguageFile( $filename )
180 $contents = file_get_contents( $filename );
182 $p = strpos( $contents, "\n" ) + 1;
183 $contents = substr( $contents, $p );
185 return unserialize( $contents );
188 function doUpdates() {
189 global $wgDeferredUpdateList;
190 foreach ( $wgDeferredUpdateList as $up ) { $up->doUpdate(); }