varchar instead of char for interwiki table
[lhc/web/wiklou.git] / includes / SpecialAllmessages.php
1 <?php
2 /**
3 * Use this special page to get a list of the MediaWiki system messages.
4 * @addtogroup SpecialPage
5 */
6
7 /**
8 * Constructor.
9 */
10 function wfSpecialAllmessages() {
11 global $wgOut, $wgRequest, $wgMessageCache, $wgTitle;
12 global $wgUseDatabaseMessages;
13
14 # The page isn't much use if the MediaWiki namespace is not being used
15 if( !$wgUseDatabaseMessages ) {
16 $wgOut->addWikiText( wfMsg( 'allmessagesnotsupportedDB' ) );
17 return;
18 }
19
20 wfProfileIn( __METHOD__ );
21
22 wfProfileIn( __METHOD__ . '-setup' );
23 $ot = $wgRequest->getText( 'ot' );
24
25 $navText = wfMsg( 'allmessagestext' );
26
27 # Make sure all extension messages are available
28 MessageCache::loadAllMessages();
29
30 $sortedArray = array_merge( Language::getMessagesFor( 'en' ), $wgMessageCache->getExtensionMessagesFor( 'en' ) );
31 ksort( $sortedArray );
32 $messages = array();
33 $wgMessageCache->disableTransform();
34
35 foreach ( $sortedArray as $key => $value ) {
36 $messages[$key]['enmsg'] = $value;
37 $messages[$key]['statmsg'] = wfMsgNoDb( $key );
38 $messages[$key]['msg'] = wfMsg ( $key );
39 }
40
41 $wgMessageCache->enableTransform();
42 wfProfileOut( __METHOD__ . '-setup' );
43
44 wfProfileIn( __METHOD__ . '-output' );
45 if ( $ot == 'php' ) {
46 $navText .= makePhp( $messages );
47 $wgOut->addHTML( 'PHP | <a href="' . $wgTitle->escapeLocalUrl( 'ot=html' ) . '">HTML</a><pre>' . htmlspecialchars( $navText ) . '</pre>' );
48 } else {
49 $wgOut->addHTML( '<a href="' . $wgTitle->escapeLocalUrl( 'ot=php' ) . '">PHP</a> | HTML' );
50 $wgOut->addWikiText( $navText );
51 $wgOut->addHTML( makeHTMLText( $messages ) );
52 }
53 wfProfileOut( __METHOD__ . '-output' );
54
55 wfProfileOut( __METHOD__ );
56 }
57
58 /**
59 * Create the messages array, formatted in PHP to copy to language files.
60 * @param $messages Messages array.
61 * @return The PHP messages array.
62 * @todo Make suitable for language files.
63 */
64 function makePhp( $messages ) {
65 global $wgLang;
66 $txt = "\n\n\$messages = array(\n";
67 foreach( $messages as $key => $m ) {
68 if( $wgLang->getCode() != 'en' && $m['msg'] == $m['enmsg'] ) {
69 continue;
70 } else if ( wfEmptyMsg( $key, $m['msg'] ) ) {
71 $m['msg'] = '';
72 $comment = ' #empty';
73 } else {
74 $comment = '';
75 }
76 $txt .= "'$key' => '" . preg_replace( '/(?<!\\\\)\'/', "\'", $m['msg']) . "',$comment\n";
77 }
78 $txt .= ');';
79 return $txt;
80 }
81
82 /**
83 * Create a list of messages, formatted in HTML as a list of messages and values and showing differences between the default language file message and the message in MediaWiki: namespace.
84 * @param $messages Messages array.
85 * @return The HTML list of messages.
86 */
87 function makeHTMLText( $messages ) {
88 global $wgLang, $wgContLang, $wgUser;
89 wfProfileIn( __METHOD__ );
90
91 $sk = $wgUser->getSkin();
92 $talk = $wgLang->getNsText( NS_TALK );
93
94 $input = wfElement( 'input', array(
95 'type' => 'text',
96 'id' => 'allmessagesinput',
97 'onkeyup' => 'allmessagesfilter()'
98 ), '' );
99 $checkbox = wfElement( 'input', array(
100 'type' => 'button',
101 'value' => wfMsgHtml( 'allmessagesmodified' ),
102 'id' => 'allmessagescheckbox',
103 'onclick' => 'allmessagesmodified()'
104 ), '' );
105
106 $txt = '<span id="allmessagesfilter" style="display: none;">' . wfMsgHtml( 'allmessagesfilter' ) . " {$input}{$checkbox} " . '</span>';
107
108 $txt .= '
109 <table border="1" cellspacing="0" width="100%" id="allmessagestable">
110 <tr>
111 <th rowspan="2">' . wfMsgHtml( 'allmessagesname' ) . '</th>
112 <th>' . wfMsgHtml( 'allmessagesdefault' ) . '</th>
113 </tr>
114 <tr>
115 <th>' . wfMsgHtml( 'allmessagescurrent' ) . '</th>
116 </tr>';
117
118 wfProfileIn( __METHOD__ . "-check" );
119
120 # This is a nasty hack to avoid doing independent existence checks
121 # without sending the links and table through the slow wiki parser.
122 $pageExists = array(
123 NS_MEDIAWIKI => array(),
124 NS_MEDIAWIKI_TALK => array()
125 );
126 $dbr = wfGetDB( DB_SLAVE );
127 $page = $dbr->tableName( 'page' );
128 $sql = "SELECT page_namespace,page_title FROM $page WHERE page_namespace IN (" . NS_MEDIAWIKI . ", " . NS_MEDIAWIKI_TALK . ")";
129 $res = $dbr->query( $sql );
130 while( $s = $dbr->fetchObject( $res ) ) {
131 $pageExists[$s->page_namespace][$s->page_title] = true;
132 }
133 $dbr->freeResult( $res );
134 wfProfileOut( __METHOD__ . "-check" );
135
136 wfProfileIn( __METHOD__ . "-output" );
137
138 $i = 0;
139
140 foreach( $messages as $key => $m ) {
141 $title = $wgLang->ucfirst( $key );
142 if( $wgLang->getCode() != $wgContLang->getCode() ) {
143 $title .= '/' . $wgLang->getCode();
144 }
145
146 $titleObj =& Title::makeTitle( NS_MEDIAWIKI, $title );
147 $talkPage =& Title::makeTitle( NS_MEDIAWIKI_TALK, $title );
148
149 $changed = ( $m['statmsg'] != $m['msg'] );
150 $message = htmlspecialchars( $m['statmsg'] );
151 $mw = htmlspecialchars( $m['msg'] );
152
153 if( isset( $pageExists[NS_MEDIAWIKI][$title] ) ) {
154 $pageLink = $sk->makeKnownLinkObj( $titleObj, "<span id=\"sp-allmessages-i-$i\">" . htmlspecialchars( $key ) . '</span>' );
155 } else {
156 $pageLink = $sk->makeBrokenLinkObj( $titleObj, "<span id=\"sp-allmessages-i-$i\">" . htmlspecialchars( $key ) . '</span>' );
157 }
158 if( isset( $pageExists[NS_MEDIAWIKI_TALK][$title] ) ) {
159 $talkLink = $sk->makeKnownLinkObj( $talkPage, htmlspecialchars( $talk ) );
160 } else {
161 $talkLink = $sk->makeBrokenLinkObj( $talkPage, htmlspecialchars( $talk ) );
162 }
163
164 $anchor = 'msg_' . htmlspecialchars( strtolower( $title ) );
165 $anchor = "<a id=\"$anchor\" name=\"$anchor\"></a>";
166
167 if( $changed ) {
168 $txt .= "
169 <tr class=\"orig\" id=\"sp-allmessages-r1-$i\">
170 <td rowspan=\"2\">
171 $anchor$pageLink<br />$talkLink
172 </td><td>
173 $message
174 </td>
175 </tr><tr class=\"new\" id=\"sp-allmessages-r2-$i\">
176 <td>
177 $mw
178 </td>
179 </tr>";
180 } else {
181 $txt .= "
182 <tr class=\"def\" id=\"sp-allmessages-r1-$i\">
183 <td>
184 $anchor$pageLink<br />$talkLink
185 </td><td>
186 $mw
187 </td>
188 </tr>";
189 }
190 $i++;
191 }
192 $txt .= '</table>';
193 wfProfileOut( __METHOD__ . '-output' );
194
195 wfProfileOut( __METHOD__ );
196 return $txt;
197 }
198
199 ?>