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