Remove self-links and display their text in bold instead.
[mediawiki.git] / maintenance / InitialiseMessages.inc
blob4f59afd0b00d6eddf69158d4f49a028a4b4d6cca
1 <?
3 # This script is included from update.php and install.php. Do not run it 
4 # by itself.
6 function initialiseMessages( $overwrite = false) {
7         global $wgLang, $wgScript, $wgServer, $wgAllMessagesEn;
8         global $wgOut, $wgArticle, $wgUser;
10         $fname = "initialiseMessages";
11         $ns = NS_MEDIAWIKI;
13         $timestamp = wfTimestampNow();
14         $invTimestamp = wfInvertTimestamp( $timestamp );
15         $navText = wfMsgNoDB( "allmessagestext" );
16         $navText .= "
18 <table border=1 width=100%><tr><td>
19   '''Name'''
20 </td><td>
21   '''Default text'''
22 </td><td>
23   '''Current text'''
24 </td></tr>";
25         
26         print "Initialising \"MediaWiki\" namespace...\n";
27         $sql = "SELECT cur_title FROM cur WHERE cur_namespace=$ns AND cur_title IN(";
29         $first = true;
30         $sortedArray = ksort( $wgAllMessagesEn );
32         foreach ( $sortedArray as $key => $enMsg ) {
33                 if ( $first ) {
34                         $first = false;
35                 } else {
36                         $sql .= ",";
37                 }
39                 $message = wfMsgNoDB( $key );
40                 $titleObj = Title::newFromText( $key );
41                 $enctitle = wfStrencode($titleObj->getDBkey());
42                 $sql .= "'$enctitle'";
43         }
44         $sql .= ")";
45         print "Reading...";
46         $res = wfQuery( $sql, DB_READ );
47         print ".";
48         $row = wfFetchObject( $res );
49         print "done\n";
51         print "Setting up...";
52         $exists = array();
53         while ( $row ) {
54                 $exists[$row->cur_title] = 1;
55                 $row = wfFetchObject( $res );
56         }
57         print ".";
58         $sql = "INSERT INTO cur (cur_namespace, cur_title, cur_text,
59                 cur_user_text, cur_timestamp, cur_restrictions,
60                 cur_is_new, inverse_timestamp, cur_touched) VALUES      ";
61         $first = true;
62         $mwObj =& MagicWord::get( MAG_MSGNW );
63         $msgnw = $mwObj->getSynonym( 0 );
64         print "Done\n";
65         
66         print "Processing...";
67         
68         foreach ( $sortedArray as $key => $enMsg ) {
69                 $message = wfMsgNoDB( $key );
70                 $titleObj = Title::newFromText( $key );
71                 $title = $titleObj->getDBkey();
72                 $dbencMsg = wfStrencode( $message );
74                 $doInsert = true;
75                 if ( $overwrite ) {
76                         $sql = "DELETE FROM cur WHERE cur_namespace=$ns AND cur_title='$title'";
77                         wfQuery( $sql, DB_WRITE, $fname );
78                 } else {        
79                         if (array_key_exists($title, $exists)) {
80                                 $doInsert = false;
81                         }
82                 }
83                 if ( $doInsert ) {
84                         if ( $first ) {
85                                 $first = false;
86                         } else {
87                                 $sql .= ",";
88                         }
89                         $sql .=
90                                 "($ns,
91                                 '$title',
92                                 '$dbencMsg',
93                                 'MediaWiki default',
94                                 '$timestamp',
95                                 'sysop',
96                                 1,
97                                 '$invTimestamp',
98                                 '$timestamp')";
99                 }
100                 $mw = str_replace( "$1", $key, $msgnw );
102                 $message = wfEscapeWikiText( $message );
103                 $navText .= 
104 "<tr><td>
105   [$wgServer$wgScript?title=MediaWiki:$title&action=edit $key]
106 </td><td>
107   $message
108 </td><td>
109   $mw
110 </td></tr>";
111         }
112         print "Done\n";
113         print "Writing...";
114         wfQuery( $sql, DB_WRITE, $fname );
115         print "Done\n";
117         $navText .= "</table>";
119         $title = wfMsgNoDB( "allmessages" );
120         $titleObj = Title::makeTitle( NS_MEDIAWIKI, $title );
121         $wgArticle = new Article( $titleObj );
122         $wgOut->disable();
123         $wgUser = User::newFromName( 'MediaWiki default' );
124         print "Writing to " . $titleObj->getPrefixedDBkey() . "\n";
125         if ( $titleObj->getArticleID() ) {
126                 $wgArticle->updateArticle( $navText, '', 0, 0 );
127         } else {
128                 $wgArticle->insertNewArticle( $navText, '', 0, 0 );
129         }
130         print "Finished\n";