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