462c326e3e7a8ac38d214301f7b02f85ef83da88
3 * Use this special page to get a list of the MediaWiki system messages.
4 * @addtogroup SpecialPage
10 function wfSpecialAllmessages() {
11 global $wgOut, $wgRequest, $wgMessageCache, $wgTitle;
12 global $wgUseDatabaseMessages;
14 # The page isn't much use if the MediaWiki namespace is not being used
15 if( !$wgUseDatabaseMessages ) {
16 $wgOut->addWikiMsg( 'allmessagesnotsupportedDB' );
20 wfProfileIn( __METHOD__
);
22 wfProfileIn( __METHOD__
. '-setup' );
23 $ot = $wgRequest->getText( 'ot' );
25 $navText = wfMsg( 'allmessagestext' );
27 # Make sure all extension messages are available
29 $wgMessageCache->loadAllMessages();
31 $sortedArray = array_merge( Language
::getMessagesFor( 'en' ), $wgMessageCache->getExtensionMessagesFor( 'en' ) );
32 ksort( $sortedArray );
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 );
41 wfProfileOut( __METHOD__
. '-setup' );
43 wfProfileIn( __METHOD__
. '-output' );
44 $wgOut->addScriptFile( 'allmessages.js' );
46 $navText .= wfAllMessagesMakePhp( $messages );
47 $wgOut->addHTML( 'PHP | <a href="' . $wgTitle->escapeLocalUrl( 'ot=html' ) . '">HTML</a> | ' .
48 '<a href="' . $wgTitle->escapeLocalUrl( 'ot=xml' ) . '">XML</a>' .
49 '<pre>' . htmlspecialchars( $navText ) . '</pre>' );
50 } else if ( $ot == 'xml' ) {
52 header( 'Content-type: text/xml' );
53 echo wfAllMessagesMakeXml( $messages );
55 $wgOut->addHTML( '<a href="' . $wgTitle->escapeLocalUrl( 'ot=php' ) . '">PHP</a> | ' .
56 'HTML | <a href="' . $wgTitle->escapeLocalUrl( 'ot=xml' ) . '">XML</a>' );
57 $wgOut->addWikiText( $navText );
58 $wgOut->addHTML( wfAllMessagesMakeHTMLText( $messages ) );
60 wfProfileOut( __METHOD__
. '-output' );
62 wfProfileOut( __METHOD__
);
65 function wfAllMessagesMakeXml( $messages ) {
67 $lang = $wgLang->getCode();
68 $txt = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n";
69 $txt .= "<messages lang=\"$lang\">\n";
70 foreach( $messages as $key => $m ) {
71 $txt .= "\t" . Xml
::element( 'message', array( 'name' => $key ), $m['msg'] ) . "\n";
73 $txt .= "</messages>";
78 * Create the messages array, formatted in PHP to copy to language files.
79 * @param $messages Messages array.
80 * @return The PHP messages array.
81 * @todo Make suitable for language files.
83 function wfAllMessagesMakePhp( $messages ) {
85 $txt = "\n\n\$messages = array(\n";
86 foreach( $messages as $key => $m ) {
87 if( $wgLang->getCode() != 'en' && $m['msg'] == $m['enmsg'] ) {
89 } else if ( wfEmptyMsg( $key, $m['msg'] ) ) {
95 $txt .= "'$key' => '" . preg_replace( '/(?<!\\\\)\'/', "\'", $m['msg']) . "',$comment\n";
102 * 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.
103 * @param $messages Messages array.
104 * @return The HTML list of messages.
106 function wfAllMessagesMakeHTMLText( $messages ) {
107 global $wgLang, $wgContLang, $wgUser;
108 wfProfileIn( __METHOD__
);
110 $sk = $wgUser->getSkin();
111 $talk = wfMsg( 'talkpagelinktext' );
113 $input = Xml
::element( 'input', array(
115 'id' => 'allmessagesinput',
116 'onkeyup' => 'allmessagesfilter()'
118 $checkbox = Xml
::element( 'input', array(
120 'value' => wfMsgHtml( 'allmessagesmodified' ),
121 'id' => 'allmessagescheckbox',
122 'onclick' => 'allmessagesmodified()'
125 $txt = '<span id="allmessagesfilter" style="display: none;">' . wfMsgHtml( 'allmessagesfilter' ) . " {$input}{$checkbox} " . '</span>';
128 <table border="1" cellspacing="0" width="100%" id="allmessagestable">
130 <th rowspan="2">' . wfMsgHtml( 'allmessagesname' ) . '</th>
131 <th>' . wfMsgHtml( 'allmessagesdefault' ) . '</th>
134 <th>' . wfMsgHtml( 'allmessagescurrent' ) . '</th>
137 wfProfileIn( __METHOD__
. "-check" );
139 # This is a nasty hack to avoid doing independent existence checks
140 # without sending the links and table through the slow wiki parser.
142 NS_MEDIAWIKI
=> array(),
143 NS_MEDIAWIKI_TALK
=> array()
145 $dbr = wfGetDB( DB_SLAVE
);
146 $page = $dbr->tableName( 'page' );
147 $sql = "SELECT page_namespace,page_title FROM $page WHERE page_namespace IN (" . NS_MEDIAWIKI
. ", " . NS_MEDIAWIKI_TALK
. ")";
148 $res = $dbr->query( $sql );
149 while( $s = $dbr->fetchObject( $res ) ) {
150 $pageExists[$s->page_namespace
][$s->page_title
] = true;
152 $dbr->freeResult( $res );
153 wfProfileOut( __METHOD__
. "-check" );
155 wfProfileIn( __METHOD__
. "-output" );
159 foreach( $messages as $key => $m ) {
160 $title = $wgLang->ucfirst( $key );
161 if( $wgLang->getCode() != $wgContLang->getCode() ) {
162 $title .= '/' . $wgLang->getCode();
165 $titleObj =& Title
::makeTitle( NS_MEDIAWIKI
, $title );
166 $talkPage =& Title
::makeTitle( NS_MEDIAWIKI_TALK
, $title );
168 $changed = ( $m['statmsg'] != $m['msg'] );
169 $message = htmlspecialchars( $m['statmsg'] );
170 $mw = htmlspecialchars( $m['msg'] );
172 if( isset( $pageExists[NS_MEDIAWIKI
][$title] ) ) {
173 $pageLink = $sk->makeKnownLinkObj( $titleObj, "<span id=\"sp-allmessages-i-$i\">" . htmlspecialchars( $key ) . '</span>' );
175 $pageLink = $sk->makeBrokenLinkObj( $titleObj, "<span id=\"sp-allmessages-i-$i\">" . htmlspecialchars( $key ) . '</span>' );
177 if( isset( $pageExists[NS_MEDIAWIKI_TALK
][$title] ) ) {
178 $talkLink = $sk->makeKnownLinkObj( $talkPage, htmlspecialchars( $talk ) );
180 $talkLink = $sk->makeBrokenLinkObj( $talkPage, htmlspecialchars( $talk ) );
183 $anchor = 'msg_' . htmlspecialchars( strtolower( $title ) );
184 $anchor = "<a id=\"$anchor\" name=\"$anchor\"></a>";
188 <tr class=\"orig\" id=\"sp-allmessages-r1-$i\">
190 $anchor$pageLink<br />$talkLink
194 </tr><tr class=\"new\" id=\"sp-allmessages-r2-$i\">
201 <tr class=\"def\" id=\"sp-allmessages-r1-$i\">
203 $anchor$pageLink<br />$talkLink
212 wfProfileOut( __METHOD__
. '-output' );
214 wfProfileOut( __METHOD__
);