3 * Use this special page to get a list of the MediaWiki system messages.
11 function wfSpecialAllmessages() {
12 global $wgOut, $wgRequest, $wgMessageCache, $wgTitle;
13 global $wgUseDatabaseMessages;
15 # The page isn't much use if the MediaWiki namespace is not being used
16 if( !$wgUseDatabaseMessages ) {
17 $wgOut->addWikiMsg( 'allmessagesnotsupportedDB' );
21 wfProfileIn( __METHOD__
);
23 wfProfileIn( __METHOD__
. '-setup' );
24 $ot = $wgRequest->getText( 'ot' );
26 $navText = wfMsg( 'allmessagestext' );
28 # Make sure all extension messages are available
30 $wgMessageCache->loadAllMessages();
32 $sortedArray = array_merge( Language
::getMessagesFor( 'en' ),
33 $wgMessageCache->getExtensionMessagesFor( 'en' ) );
34 ksort( $sortedArray );
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
44 unset($sortedArray); // trade bytes from $sortedArray to this
46 wfProfileOut( __METHOD__
. '-setup' );
48 wfProfileIn( __METHOD__
. '-output' );
49 $wgOut->addScriptFile( 'allmessages.js' );
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' ) {
57 header( 'Content-type: text/xml' );
58 echo wfAllMessagesMakeXml( $messages );
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 ) );
65 wfProfileOut( __METHOD__
. '-output' );
67 wfProfileOut( __METHOD__
);
70 function wfAllMessagesMakeXml( &$messages ) {
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
79 $txt .= "</messages>";
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.
89 function wfAllMessagesMakePhp( &$messages ) {
91 $txt = "\n\n\$messages = array(\n";
92 foreach( $messages as $key => $m ) {
93 if( $wgLang->getCode() != 'en' && $m['msg'] == $m['enmsg'] ) {
95 } else if ( wfEmptyMsg( $key, $m['msg'] ) ) {
101 $txt .= "'$key' => '" . preg_replace( '/(?<!\\\\)\'/', "\'", $m['msg']) . "',$comment\n";
102 $messages[$key] = NULL; // trade bytes
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.
113 function wfAllMessagesMakeHTMLText( &$messages ) {
114 global $wgLang, $wgContLang, $wgUser;
115 wfProfileIn( __METHOD__
);
117 $sk = $wgUser->getSkin();
118 $talk = wfMsg( 'talkpagelinktext' );
120 $input = Xml
::element( 'input', array(
122 'id' => 'allmessagesinput',
123 'onkeyup' => 'allmessagesfilter()'
125 $checkbox = Xml
::element( 'input', array(
127 'value' => wfMsgHtml( 'allmessagesmodified' ),
128 'id' => 'allmessagescheckbox',
129 'onclick' => 'allmessagesmodified()'
132 $txt = '<span id="allmessagesfilter" style="display: none;">' . wfMsgHtml( 'allmessagesfilter' ) .
133 " {$input}{$checkbox} " . '</span>';
136 <table border="1" cellspacing="0" width="100%" id="allmessagestable">
138 <th rowspan="2">' . wfMsgHtml( 'allmessagesname' ) . '</th>
139 <th>' . wfMsgHtml( 'allmessagesdefault' ) . '</th>
142 <th>' . wfMsgHtml( 'allmessagescurrent' ) . '</th>
145 wfProfileIn( __METHOD__
. "-check" );
147 # This is a nasty hack to avoid doing independent existence checks
148 # without sending the links and table through the slow wiki parser.
150 NS_MEDIAWIKI
=> array(),
151 NS_MEDIAWIKI_TALK
=> array()
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
) ),
158 array( 'USE INDEX' => 'name_title' )
160 while( $s = $dbr->fetchObject( $res ) ) {
161 $pageExists[$s->page_namespace
][$s->page_title
] = 1;
163 $dbr->freeResult( $res );
164 wfProfileOut( __METHOD__
. "-check" );
166 wfProfileIn( __METHOD__
. "-output" );
170 foreach( $messages as $key => $m ) {
171 $title = $wgLang->ucfirst( $key );
172 if( $wgLang->getCode() != $wgContLang->getCode() ) {
173 $title .= '/' . $wgLang->getCode();
176 $titleObj = Title
::makeTitle( NS_MEDIAWIKI
, $title );
177 $talkPage = Title
::makeTitle( NS_MEDIAWIKI_TALK
, $title );
179 $changed = ( $m['statmsg'] != $m['msg'] );
180 $message = htmlspecialchars( $m['statmsg'] );
181 $mw = htmlspecialchars( $m['msg'] );
183 if( array_key_exists( $title, $pageExists[NS_MEDIAWIKI
] ) ) {
184 $pageLink = $sk->makeKnownLinkObj( $titleObj, "<span id=\"sp-allmessages-i-$i\">" .
185 htmlspecialchars( $key ) . '</span>' );
187 $pageLink = $sk->makeBrokenLinkObj( $titleObj, "<span id=\"sp-allmessages-i-$i\">" .
188 htmlspecialchars( $key ) . '</span>' );
190 if( array_key_exists( $title, $pageExists[NS_MEDIAWIKI_TALK
] ) ) {
191 $talkLink = $sk->makeKnownLinkObj( $talkPage, htmlspecialchars( $talk ) );
193 $talkLink = $sk->makeBrokenLinkObj( $talkPage, htmlspecialchars( $talk ) );
196 $anchor = 'msg_' . htmlspecialchars( strtolower( $title ) );
197 $anchor = "<a id=\"$anchor\" name=\"$anchor\"></a>";
201 <tr class=\"orig\" id=\"sp-allmessages-r1-$i\">
203 $anchor$pageLink<br />$talkLink
207 </tr><tr class=\"new\" id=\"sp-allmessages-r2-$i\">
214 <tr class=\"def\" id=\"sp-allmessages-r1-$i\">
216 $anchor$pageLink<br />$talkLink
222 $messages[$key] = NULL; // trade bytes
226 wfProfileOut( __METHOD__
. '-output' );
228 wfProfileOut( __METHOD__
);