Add welsh file, updated from meta
[mediawiki.git] / maintenance / InitialiseMessages.inc
blob67c24c136c137276733f433cebb92979e06e029b
1 <?php
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         $mwMsg =& MagicWord::get( MAG_MSG );
16         $navText = str_replace( "$1", "allmessagestext", $mwMsg->getSynonym( 0 ) );
17         $navText .= "
19 <table border=1 width=100%><tr><td>
20   '''Name'''
21 </td><td>
22   '''Default text'''
23 </td><td>
24   '''Current text'''
25 </td></tr>";
26         
27         print "Initialising \"MediaWiki\" namespace...\n";
28         $sql = "SELECT cur_title FROM cur WHERE cur_namespace=$ns AND cur_title IN(";
30         $first = true;
31         $sortedArray = $wgAllMessagesEn;
32         ksort( $sortedArray );
33         
34         foreach ( $sortedArray as $key => $enMsg ) {
35                 if ( $first ) {
36                         $first = false;
37                 } else {
38                         $sql .= ",";
39                 }
41                 $message = wfMsgNoDB( $key );
42                 $titleObj = Title::newFromText( $key );
43                 $enctitle = wfStrencode($titleObj->getDBkey());
44                 $sql .= "'$enctitle'";
45         }
46         $sql .= ")";
47         $res = wfQuery( $sql, DB_READ );
48         $row = wfFetchObject( $res );
50         $exists = array();
51         while ( $row ) {
52                 $exists[$row->cur_title] = 1;
53                 $row = wfFetchObject( $res );
54         }
55         $sql = "INSERT INTO cur (cur_namespace, cur_title, cur_text,
56                 cur_user_text, cur_timestamp, cur_restrictions,
57                 cur_is_new, inverse_timestamp, cur_touched) VALUES      ";
58         $first = true;
59         $mwObj =& MagicWord::get( MAG_MSGNW );
60         $msgnw = $mwObj->getSynonym( 0 );
61         $talk = $wgLang->getNsText( NS_TALK );
62         $mwtalk = $wgLang->getNsText( NS_MEDIAWIKI_TALK );
63         
64         foreach ( $sortedArray as $key => $enMsg ) {
65                 $message = wfMsgNoDB( $key );
66                 $titleObj = Title::newFromText( $key );
67                 $title = $titleObj->getDBkey();
68                 $dbencMsg = wfStrencode( $message );
70                 $doInsert = true;
71                 if ( $overwrite ) {
72                         wfQuery( "DELETE FROM cur WHERE cur_namespace=$ns AND cur_title='$title'", DB_WRITE, $fname );
73                 } else {        
74                         if (array_key_exists($title, $exists)) {
75                                 $doInsert = false;
76                         }
77                 }
78                 if ( $doInsert ) {
79                         if ( $first ) {
80                                 $first = false;
81                         } else {
82                                 $sql .= ",";
83                         }
84                         $sql .=
85                                 "($ns,
86                                 '$title',
87                                 '$dbencMsg',
88                                 'MediaWiki default',
89                                 '$timestamp',
90                                 'sysop',
91                                 1,
92                                 '$invTimestamp',
93                                 '$timestamp')";
94                 }
95                 $mw = str_replace( "$1", $key, $msgnw );
97                 $message = wfEscapeWikiText( $message );
98                 $navText .= 
99 "<tr><td>
100   [$wgServer$wgScript?title=MediaWiki:$title&action=edit $key]<br>
101   [[$mwtalk:$title|$talk]]
102 </td><td>
103   $message
104 </td><td>
105   $mw
106 </td></tr>";
107         }
109         if ( !$first ) {
110                 wfQuery( $sql, DB_WRITE, $fname );
111         }
114         $navText .= "</table>";
116         $title = wfMsgNoDB( "allmessages" );
117         $titleObj = Title::makeTitle( NS_MEDIAWIKI, $title );
118         $wgArticle = new Article( $titleObj );
119         $wgOut->disable();
120         $wgUser = User::newFromName( 'MediaWiki default' );
121         if ( $titleObj->getArticleID() ) {
122                 $wgArticle->updateArticle( $navText, '', 0, 0 );
123         } else {
124                 $wgArticle->insertNewArticle( $navText, '', 0, 0 );
125         }