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