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' ), $wgMessageCache->getExtensionMessagesFor( 'en' ) );
33 ksort( $sortedArray );
36 foreach ( $sortedArray as $key => $value ) {
37 $messages[$key]['enmsg'] = $value;
38 $messages[$key]['statmsg'] = wfMsgReal( $key, array(), false, false, false ); // wfMsgNoDbNoTrans doesn't exist
39 $messages[$key]['msg'] = wfMsgNoTrans( $key );
42 wfProfileOut( __METHOD__
. '-setup' );
44 wfProfileIn( __METHOD__
. '-output' );
45 $wgOut->addScriptFile( 'allmessages.js' );
47 $navText .= wfAllMessagesMakePhp( $messages );
48 $wgOut->addHTML( 'PHP | <a href="' . $wgTitle->escapeLocalUrl( 'ot=html' ) . '">HTML</a> | ' .
49 '<a href="' . $wgTitle->escapeLocalUrl( 'ot=xml' ) . '">XML</a>' .
50 '<pre>' . htmlspecialchars( $navText ) . '</pre>' );
51 } else if ( $ot == 'xml' ) {
53 header( 'Content-type: text/xml' );
54 echo wfAllMessagesMakeXml( $messages );
56 $wgOut->addHTML( '<a href="' . $wgTitle->escapeLocalUrl( 'ot=php' ) . '">PHP</a> | ' .
57 'HTML | <a href="' . $wgTitle->escapeLocalUrl( 'ot=xml' ) . '">XML</a>' );
58 $wgOut->addWikiText( $navText );
59 $wgOut->addHTML( wfAllMessagesMakeHTMLText( $messages ) );
61 wfProfileOut( __METHOD__
. '-output' );
63 wfProfileOut( __METHOD__
);
66 function wfAllMessagesMakeXml( $messages ) {
68 $lang = $wgLang->getCode();
69 $txt = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n";
70 $txt .= "<messages lang=\"$lang\">\n";
71 foreach( $messages as $key => $m ) {
72 $txt .= "\t" . Xml
::element( 'message', array( 'name' => $key ), $m['msg'] ) . "\n";
74 $txt .= "</messages>";
79 * Create the messages array, formatted in PHP to copy to language files.
80 * @param $messages Messages array.
81 * @return The PHP messages array.
82 * @todo Make suitable for language files.
84 function wfAllMessagesMakePhp( $messages ) {
86 $txt = "\n\n\$messages = array(\n";
87 foreach( $messages as $key => $m ) {
88 if( $wgLang->getCode() != 'en' && $m['msg'] == $m['enmsg'] ) {
90 } else if ( wfEmptyMsg( $key, $m['msg'] ) ) {
96 $txt .= "'$key' => '" . preg_replace( '/(?<!\\\\)\'/', "\'", $m['msg']) . "',$comment\n";
103 * 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.
104 * @param $messages Messages array.
105 * @return The HTML list of messages.
107 function wfAllMessagesMakeHTMLText( $messages ) {
108 global $wgLang, $wgContLang, $wgUser;
109 wfProfileIn( __METHOD__
);
111 $sk = $wgUser->getSkin();
112 $talk = wfMsg( 'talkpagelinktext' );
114 $input = Xml
::element( 'input', array(
116 'id' => 'allmessagesinput',
117 'onkeyup' => 'allmessagesfilter()'
119 $checkbox = Xml
::element( 'input', array(
121 'value' => wfMsgHtml( 'allmessagesmodified' ),
122 'id' => 'allmessagescheckbox',
123 'onclick' => 'allmessagesmodified()'
126 $txt = '<span id="allmessagesfilter" style="display: none;">' . wfMsgHtml( 'allmessagesfilter' ) . " {$input}{$checkbox} " . '</span>';
129 <table border="1" cellspacing="0" width="100%" id="allmessagestable">
131 <th rowspan="2">' . wfMsgHtml( 'allmessagesname' ) . '</th>
132 <th>' . wfMsgHtml( 'allmessagesdefault' ) . '</th>
135 <th>' . wfMsgHtml( 'allmessagescurrent' ) . '</th>
138 wfProfileIn( __METHOD__
. "-check" );
140 # This is a nasty hack to avoid doing independent existence checks
141 # without sending the links and table through the slow wiki parser.
143 NS_MEDIAWIKI
=> array(),
144 NS_MEDIAWIKI_TALK
=> array()
146 $dbr = wfGetDB( DB_SLAVE
);
147 $page = $dbr->tableName( 'page' );
148 $sql = "SELECT page_namespace,page_title FROM $page WHERE page_namespace IN (" . NS_MEDIAWIKI
. ", " . NS_MEDIAWIKI_TALK
. ")";
149 $res = $dbr->query( $sql );
150 while( $s = $dbr->fetchObject( $res ) ) {
151 $pageExists[$s->page_namespace
][$s->page_title
] = true;
153 $dbr->freeResult( $res );
154 wfProfileOut( __METHOD__
. "-check" );
156 wfProfileIn( __METHOD__
. "-output" );
160 foreach( $messages as $key => $m ) {
161 $title = $wgLang->ucfirst( $key );
162 if( $wgLang->getCode() != $wgContLang->getCode() ) {
163 $title .= '/' . $wgLang->getCode();
166 $titleObj =& Title
::makeTitle( NS_MEDIAWIKI
, $title );
167 $talkPage =& Title
::makeTitle( NS_MEDIAWIKI_TALK
, $title );
169 $changed = ( $m['statmsg'] != $m['msg'] );
170 $message = htmlspecialchars( $m['statmsg'] );
171 $mw = htmlspecialchars( $m['msg'] );
173 if( isset( $pageExists[NS_MEDIAWIKI
][$title] ) ) {
174 $pageLink = $sk->makeKnownLinkObj( $titleObj, "<span id=\"sp-allmessages-i-$i\">" . htmlspecialchars( $key ) . '</span>' );
176 $pageLink = $sk->makeBrokenLinkObj( $titleObj, "<span id=\"sp-allmessages-i-$i\">" . htmlspecialchars( $key ) . '</span>' );
178 if( isset( $pageExists[NS_MEDIAWIKI_TALK
][$title] ) ) {
179 $talkLink = $sk->makeKnownLinkObj( $talkPage, htmlspecialchars( $talk ) );
181 $talkLink = $sk->makeBrokenLinkObj( $talkPage, htmlspecialchars( $talk ) );
184 $anchor = 'msg_' . htmlspecialchars( strtolower( $title ) );
185 $anchor = "<a id=\"$anchor\" name=\"$anchor\"></a>";
189 <tr class=\"orig\" id=\"sp-allmessages-r1-$i\">
191 $anchor$pageLink<br />$talkLink
195 </tr><tr class=\"new\" id=\"sp-allmessages-r2-$i\">
202 <tr class=\"def\" id=\"sp-allmessages-r1-$i\">
204 $anchor$pageLink<br />$talkLink
213 wfProfileOut( __METHOD__
. '-output' );
215 wfProfileOut( __METHOD__
);