* Don't show hist link if hidden
[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->addWikiMsg( '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
29 $wgMessageCache->loadAllMessages();
30
31 $sortedArray = array_merge( Language::getMessagesFor( 'en' ), $wgMessageCache->getExtensionMessagesFor( 'en' ) );
32 ksort( $sortedArray );
33 $messages = array();
34
35 foreach ( $sortedArray as $key => $value ) {
36 $messages[$key]['enmsg'] = $value;
37 $messages[$key]['statmsg'] = wfMsgReal( $key, array(), false, false, false ); // wfMsgNoDbNoTrans doesn't exist
38 $messages[$key]['msg'] = wfMsgNoTrans( $key );
39 }
40
41 wfProfileOut( __METHOD__ . '-setup' );
42
43 wfProfileIn( __METHOD__ . '-output' );
44 if ( $ot == 'php' ) {
45 $navText .= wfAllMessagesMakePhp( $messages );
46 $wgOut->addHTML( 'PHP | <a href="' . $wgTitle->escapeLocalUrl( 'ot=html' ) . '">HTML</a> | ' .
47 '<a href="' . $wgTitle->escapeLocalUrl( 'ot=xml' ) . '">XML</a>' .
48 '<pre>' . htmlspecialchars( $navText ) . '</pre>' );
49 } else if ( $ot == 'xml' ) {
50 $wgOut->disable();
51 header( 'Content-type: text/xml' );
52 echo wfAllMessagesMakeXml( $messages );
53 } else {
54 $wgOut->addHTML( '<a href="' . $wgTitle->escapeLocalUrl( 'ot=php' ) . '">PHP</a> | ' .
55 'HTML | <a href="' . $wgTitle->escapeLocalUrl( 'ot=xml' ) . '">XML</a>' );
56 $wgOut->addWikiText( $navText );
57 $wgOut->addHTML( wfAllMessagesMakeHTMLText( $messages ) );
58 }
59 wfProfileOut( __METHOD__ . '-output' );
60
61 wfProfileOut( __METHOD__ );
62 }
63
64 function wfAllMessagesMakeXml( $messages ) {
65 global $wgLang;
66 $lang = $wgLang->getCode();
67 $txt = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n";
68 $txt .= "<messages lang=\"$lang\">\n";
69 foreach( $messages as $key => $m ) {
70 $txt .= "\t" . Xml::element( 'message', array( 'name' => $key ), $m['msg'] ) . "\n";
71 }
72 $txt .= "</messages>";
73 return $txt;
74 }
75
76 /**
77 * Create the messages array, formatted in PHP to copy to language files.
78 * @param $messages Messages array.
79 * @return The PHP messages array.
80 * @todo Make suitable for language files.
81 */
82 function wfAllMessagesMakePhp( $messages ) {
83 global $wgLang;
84 $txt = "\n\n\$messages = array(\n";
85 foreach( $messages as $key => $m ) {
86 if( $wgLang->getCode() != 'en' && $m['msg'] == $m['enmsg'] ) {
87 continue;
88 } else if ( wfEmptyMsg( $key, $m['msg'] ) ) {
89 $m['msg'] = '';
90 $comment = ' #empty';
91 } else {
92 $comment = '';
93 }
94 $txt .= "'$key' => '" . preg_replace( '/(?<!\\\\)\'/', "\'", $m['msg']) . "',$comment\n";
95 }
96 $txt .= ');';
97 return $txt;
98 }
99
100 /**
101 * 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.
102 * @param $messages Messages array.
103 * @return The HTML list of messages.
104 */
105 function wfAllMessagesMakeHTMLText( $messages ) {
106 global $wgLang, $wgContLang, $wgUser;
107 wfProfileIn( __METHOD__ );
108
109 $sk = $wgUser->getSkin();
110 $talk = wfMsg( 'talkpagelinktext' );
111
112 $input = Xml::element( 'input', array(
113 'type' => 'text',
114 'id' => 'allmessagesinput',
115 'onkeyup' => 'allmessagesfilter()'
116 ), '' );
117 $checkbox = Xml::element( 'input', array(
118 'type' => 'button',
119 'value' => wfMsgHtml( 'allmessagesmodified' ),
120 'id' => 'allmessagescheckbox',
121 'onclick' => 'allmessagesmodified()'
122 ), '' );
123
124 $txt = '<span id="allmessagesfilter" style="display: none;">' . wfMsgHtml( 'allmessagesfilter' ) . " {$input}{$checkbox} " . '</span>';
125
126 $txt .= '
127 <table border="1" cellspacing="0" width="100%" id="allmessagestable">
128 <tr>
129 <th rowspan="2">' . wfMsgHtml( 'allmessagesname' ) . '</th>
130 <th>' . wfMsgHtml( 'allmessagesdefault' ) . '</th>
131 </tr>
132 <tr>
133 <th>' . wfMsgHtml( 'allmessagescurrent' ) . '</th>
134 </tr>';
135
136 wfProfileIn( __METHOD__ . "-check" );
137
138 # This is a nasty hack to avoid doing independent existence checks
139 # without sending the links and table through the slow wiki parser.
140 $pageExists = array(
141 NS_MEDIAWIKI => array(),
142 NS_MEDIAWIKI_TALK => array()
143 );
144 $dbr = wfGetDB( DB_SLAVE );
145 $page = $dbr->tableName( 'page' );
146 $sql = "SELECT page_namespace,page_title FROM $page WHERE page_namespace IN (" . NS_MEDIAWIKI . ", " . NS_MEDIAWIKI_TALK . ")";
147 $res = $dbr->query( $sql );
148 while( $s = $dbr->fetchObject( $res ) ) {
149 $pageExists[$s->page_namespace][$s->page_title] = true;
150 }
151 $dbr->freeResult( $res );
152 wfProfileOut( __METHOD__ . "-check" );
153
154 wfProfileIn( __METHOD__ . "-output" );
155
156 $i = 0;
157
158 foreach( $messages as $key => $m ) {
159 $title = $wgLang->ucfirst( $key );
160 if( $wgLang->getCode() != $wgContLang->getCode() ) {
161 $title .= '/' . $wgLang->getCode();
162 }
163
164 $titleObj =& Title::makeTitle( NS_MEDIAWIKI, $title );
165 $talkPage =& Title::makeTitle( NS_MEDIAWIKI_TALK, $title );
166
167 $changed = ( $m['statmsg'] != $m['msg'] );
168 $message = htmlspecialchars( $m['statmsg'] );
169 $mw = htmlspecialchars( $m['msg'] );
170
171 if( isset( $pageExists[NS_MEDIAWIKI][$title] ) ) {
172 $pageLink = $sk->makeKnownLinkObj( $titleObj, "<span id=\"sp-allmessages-i-$i\">" . htmlspecialchars( $key ) . '</span>' );
173 } else {
174 $pageLink = $sk->makeBrokenLinkObj( $titleObj, "<span id=\"sp-allmessages-i-$i\">" . htmlspecialchars( $key ) . '</span>' );
175 }
176 if( isset( $pageExists[NS_MEDIAWIKI_TALK][$title] ) ) {
177 $talkLink = $sk->makeKnownLinkObj( $talkPage, htmlspecialchars( $talk ) );
178 } else {
179 $talkLink = $sk->makeBrokenLinkObj( $talkPage, htmlspecialchars( $talk ) );
180 }
181
182 $anchor = 'msg_' . htmlspecialchars( strtolower( $title ) );
183 $anchor = "<a id=\"$anchor\" name=\"$anchor\"></a>";
184
185 if( $changed ) {
186 $txt .= "
187 <tr class=\"orig\" id=\"sp-allmessages-r1-$i\">
188 <td rowspan=\"2\">
189 $anchor$pageLink<br />$talkLink
190 </td><td>
191 $message
192 </td>
193 </tr><tr class=\"new\" id=\"sp-allmessages-r2-$i\">
194 <td>
195 $mw
196 </td>
197 </tr>";
198 } else {
199 $txt .= "
200 <tr class=\"def\" id=\"sp-allmessages-r1-$i\">
201 <td>
202 $anchor$pageLink<br />$talkLink
203 </td><td>
204 $mw
205 </td>
206 </tr>";
207 }
208 $i++;
209 }
210 $txt .= '</table>';
211 wfProfileOut( __METHOD__ . '-output' );
212
213 wfProfileOut( __METHOD__ );
214 return $txt;
215 }
216
217