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' );
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' ) {
51 header( 'Content-type: text/xml' );
52 echo wfAllMessagesMakeXml( $messages );
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 ) );
59 wfProfileOut( __METHOD__
. '-output' );
61 wfProfileOut( __METHOD__
);
64 function wfAllMessagesMakeXml( $messages ) {
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";
72 $txt .= "</messages>";
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.
82 function wfAllMessagesMakePhp( $messages ) {
84 $txt = "\n\n\$messages = array(\n";
85 foreach( $messages as $key => $m ) {
86 if( $wgLang->getCode() != 'en' && $m['msg'] == $m['enmsg'] ) {
88 } else if ( wfEmptyMsg( $key, $m['msg'] ) ) {
94 $txt .= "'$key' => '" . preg_replace( '/(?<!\\\\)\'/', "\'", $m['msg']) . "',$comment\n";
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.
105 function wfAllMessagesMakeHTMLText( $messages ) {
106 global $wgLang, $wgContLang, $wgUser;
107 wfProfileIn( __METHOD__
);
109 $sk = $wgUser->getSkin();
110 $talk = wfMsg( 'talkpagelinktext' );
112 $input = Xml
::element( 'input', array(
114 'id' => 'allmessagesinput',
115 'onkeyup' => 'allmessagesfilter()'
117 $checkbox = Xml
::element( 'input', array(
119 'value' => wfMsgHtml( 'allmessagesmodified' ),
120 'id' => 'allmessagescheckbox',
121 'onclick' => 'allmessagesmodified()'
124 $txt = '<span id="allmessagesfilter" style="display: none;">' . wfMsgHtml( 'allmessagesfilter' ) . " {$input}{$checkbox} " . '</span>';
127 <table border="1" cellspacing="0" width="100%" id="allmessagestable">
129 <th rowspan="2">' . wfMsgHtml( 'allmessagesname' ) . '</th>
130 <th>' . wfMsgHtml( 'allmessagesdefault' ) . '</th>
133 <th>' . wfMsgHtml( 'allmessagescurrent' ) . '</th>
136 wfProfileIn( __METHOD__
. "-check" );
138 # This is a nasty hack to avoid doing independent existence checks
139 # without sending the links and table through the slow wiki parser.
141 NS_MEDIAWIKI
=> array(),
142 NS_MEDIAWIKI_TALK
=> array()
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;
151 $dbr->freeResult( $res );
152 wfProfileOut( __METHOD__
. "-check" );
154 wfProfileIn( __METHOD__
. "-output" );
158 foreach( $messages as $key => $m ) {
159 $title = $wgLang->ucfirst( $key );
160 if( $wgLang->getCode() != $wgContLang->getCode() ) {
161 $title .= '/' . $wgLang->getCode();
164 $titleObj =& Title
::makeTitle( NS_MEDIAWIKI
, $title );
165 $talkPage =& Title
::makeTitle( NS_MEDIAWIKI_TALK
, $title );
167 $changed = ( $m['statmsg'] != $m['msg'] );
168 $message = htmlspecialchars( $m['statmsg'] );
169 $mw = htmlspecialchars( $m['msg'] );
171 if( isset( $pageExists[NS_MEDIAWIKI
][$title] ) ) {
172 $pageLink = $sk->makeKnownLinkObj( $titleObj, "<span id=\"sp-allmessages-i-$i\">" . htmlspecialchars( $key ) . '</span>' );
174 $pageLink = $sk->makeBrokenLinkObj( $titleObj, "<span id=\"sp-allmessages-i-$i\">" . htmlspecialchars( $key ) . '</span>' );
176 if( isset( $pageExists[NS_MEDIAWIKI_TALK
][$title] ) ) {
177 $talkLink = $sk->makeKnownLinkObj( $talkPage, htmlspecialchars( $talk ) );
179 $talkLink = $sk->makeBrokenLinkObj( $talkPage, htmlspecialchars( $talk ) );
182 $anchor = 'msg_' . htmlspecialchars( strtolower( $title ) );
183 $anchor = "<a id=\"$anchor\" name=\"$anchor\"></a>";
187 <tr class=\"orig\" id=\"sp-allmessages-r1-$i\">
189 $anchor$pageLink<br />$talkLink
193 </tr><tr class=\"new\" id=\"sp-allmessages-r2-$i\">
200 <tr class=\"def\" id=\"sp-allmessages-r1-$i\">
202 $anchor$pageLink<br />$talkLink
211 wfProfileOut( __METHOD__
. '-output' );
213 wfProfileOut( __METHOD__
);