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->addWikiText( wfMsg( '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 );
34 $wgMessageCache->disableTransform();
36 foreach ( $sortedArray as $key => $value ) {
37 $messages[$key]['enmsg'] = $value;
38 $messages[$key]['statmsg'] = wfMsgNoDb( $key );
39 $messages[$key]['msg'] = wfMsg ( $key );
42 $wgMessageCache->enableTransform();
43 wfProfileOut( __METHOD__
. '-setup' );
45 wfProfileIn( __METHOD__
. '-output' );
47 $navText .= makePhp( $messages );
48 $wgOut->addHTML( 'PHP | <a href="' . $wgTitle->escapeLocalUrl( 'ot=html' ) . '">HTML</a> | <a href="' . $wgTitle->escapeLocalUrl( 'ot=xml' ) . '">XML</a><pre>' . htmlspecialchars( $navText ) . '</pre>' );
49 } else if ( $ot == 'xml' ) {
51 header( 'Content-type: text/xml' );
52 echo makeXml( $messages );
54 $wgOut->addHTML( '<a href="' . $wgTitle->escapeLocalUrl( 'ot=php' ) . '">PHP</a> | HTML | <a href="' . $wgTitle->escapeLocalUrl( 'ot=xml' ) . '">XML</a>' );
55 $wgOut->addWikiText( $navText );
56 $wgOut->addHTML( makeHTMLText( $messages ) );
58 wfProfileOut( __METHOD__
. '-output' );
60 wfProfileOut( __METHOD__
);
63 function makeXml( $messages ) {
65 $lang = $wgLang->getCode();
66 $txt = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n";
67 $txt .= "<messages lang=\"$lang\">\n";
68 foreach( $messages as $key => $m ) {
69 $txt .= "\t" . Xml
::element( 'message', array( 'name' => $key ), $m['msg'] ) . "\n";
71 $txt .= "</messages>";
76 * Create the messages array, formatted in PHP to copy to language files.
77 * @param $messages Messages array.
78 * @return The PHP messages array.
79 * @todo Make suitable for language files.
81 function makePhp( $messages ) {
83 $txt = "\n\n\$messages = array(\n";
84 foreach( $messages as $key => $m ) {
85 if( $wgLang->getCode() != 'en' && $m['msg'] == $m['enmsg'] ) {
87 } else if ( wfEmptyMsg( $key, $m['msg'] ) ) {
93 $txt .= "'$key' => '" . preg_replace( '/(?<!\\\\)\'/', "\'", $m['msg']) . "',$comment\n";
100 * 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.
101 * @param $messages Messages array.
102 * @return The HTML list of messages.
104 function makeHTMLText( $messages ) {
105 global $wgLang, $wgContLang, $wgUser;
106 wfProfileIn( __METHOD__
);
108 $sk = $wgUser->getSkin();
109 $talk = wfMsg( 'talkpagelinktext' );
111 $input = wfElement( 'input', array(
113 'id' => 'allmessagesinput',
114 'onkeyup' => 'allmessagesfilter()'
116 $checkbox = wfElement( 'input', array(
118 'value' => wfMsgHtml( 'allmessagesmodified' ),
119 'id' => 'allmessagescheckbox',
120 'onclick' => 'allmessagesmodified()'
123 $txt = '<span id="allmessagesfilter" style="display: none;">' . wfMsgHtml( 'allmessagesfilter' ) . " {$input}{$checkbox} " . '</span>';
126 <table border="1" cellspacing="0" width="100%" id="allmessagestable">
128 <th rowspan="2">' . wfMsgHtml( 'allmessagesname' ) . '</th>
129 <th>' . wfMsgHtml( 'allmessagesdefault' ) . '</th>
132 <th>' . wfMsgHtml( 'allmessagescurrent' ) . '</th>
135 wfProfileIn( __METHOD__
. "-check" );
137 # This is a nasty hack to avoid doing independent existence checks
138 # without sending the links and table through the slow wiki parser.
140 NS_MEDIAWIKI
=> array(),
141 NS_MEDIAWIKI_TALK
=> array()
143 $dbr = wfGetDB( DB_SLAVE
);
144 $page = $dbr->tableName( 'page' );
145 $sql = "SELECT page_namespace,page_title FROM $page WHERE page_namespace IN (" . NS_MEDIAWIKI
. ", " . NS_MEDIAWIKI_TALK
. ")";
146 $res = $dbr->query( $sql );
147 while( $s = $dbr->fetchObject( $res ) ) {
148 $pageExists[$s->page_namespace
][$s->page_title
] = true;
150 $dbr->freeResult( $res );
151 wfProfileOut( __METHOD__
. "-check" );
153 wfProfileIn( __METHOD__
. "-output" );
157 foreach( $messages as $key => $m ) {
158 $title = $wgLang->ucfirst( $key );
159 if( $wgLang->getCode() != $wgContLang->getCode() ) {
160 $title .= '/' . $wgLang->getCode();
163 $titleObj =& Title
::makeTitle( NS_MEDIAWIKI
, $title );
164 $talkPage =& Title
::makeTitle( NS_MEDIAWIKI_TALK
, $title );
166 $changed = ( $m['statmsg'] != $m['msg'] );
167 $message = htmlspecialchars( $m['statmsg'] );
168 $mw = htmlspecialchars( $m['msg'] );
170 if( isset( $pageExists[NS_MEDIAWIKI
][$title] ) ) {
171 $pageLink = $sk->makeKnownLinkObj( $titleObj, "<span id=\"sp-allmessages-i-$i\">" . htmlspecialchars( $key ) . '</span>' );
173 $pageLink = $sk->makeBrokenLinkObj( $titleObj, "<span id=\"sp-allmessages-i-$i\">" . htmlspecialchars( $key ) . '</span>' );
175 if( isset( $pageExists[NS_MEDIAWIKI_TALK
][$title] ) ) {
176 $talkLink = $sk->makeKnownLinkObj( $talkPage, htmlspecialchars( $talk ) );
178 $talkLink = $sk->makeBrokenLinkObj( $talkPage, htmlspecialchars( $talk ) );
181 $anchor = 'msg_' . htmlspecialchars( strtolower( $title ) );
182 $anchor = "<a id=\"$anchor\" name=\"$anchor\"></a>";
186 <tr class=\"orig\" id=\"sp-allmessages-r1-$i\">
188 $anchor$pageLink<br />$talkLink
192 </tr><tr class=\"new\" id=\"sp-allmessages-r2-$i\">
199 <tr class=\"def\" id=\"sp-allmessages-r1-$i\">
201 $anchor$pageLink<br />$talkLink
210 wfProfileOut( __METHOD__
. '-output' );
212 wfProfileOut( __METHOD__
);