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