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, $wgLang;
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( $wgLang->pipeList( array(
54 '<a href="' . $wgTitle->escapeLocalUrl( 'ot=html' ) . '">HTML</a>',
55 '<a href="' . $wgTitle->escapeLocalUrl( 'ot=xml' ) . '">XML</a>' .
56 '<pre>' . htmlspecialchars( $navText ) . '</pre>'
58 } else if ( $ot == 'xml' ) {
60 header( 'Content-type: text/xml' );
61 echo wfAllMessagesMakeXml( $messages );
63 $wgOut->addHTML( $wgLang->pipeList( array(
64 '<a href="' . $wgTitle->escapeLocalUrl( 'ot=php' ) . '">PHP</a>',
66 '<a href="' . $wgTitle->escapeLocalUrl( 'ot=xml' ) . '">XML</a>'
68 $wgOut->addWikiText( $navText );
69 $wgOut->addHTML( wfAllMessagesMakeHTMLText( $messages ) );
71 wfProfileOut( __METHOD__
. '-output' );
73 wfProfileOut( __METHOD__
);
76 function wfAllMessagesMakeXml( &$messages ) {
78 $lang = $wgLang->getCode();
79 $txt = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n";
80 $txt .= "<messages lang=\"$lang\">\n";
81 foreach( $messages as $key => $m ) {
82 $txt .= "\t" . Xml
::element( 'message', array( 'name' => $key ), $m['msg'] ) . "\n";
83 $messages[$key] = NULL; // trade bytes
85 $txt .= "</messages>";
90 * Create the messages array, formatted in PHP to copy to language files.
91 * @param $messages Messages array.
92 * @return The PHP messages array.
93 * @todo Make suitable for language files.
95 function wfAllMessagesMakePhp( &$messages ) {
97 $txt = "\n\n\$messages = array(\n";
98 foreach( $messages as $key => $m ) {
99 if( $wgLang->getCode() != 'en' && $m['msg'] == $m['enmsg'] ) {
101 } else if ( wfEmptyMsg( $key, $m['msg'] ) ) {
103 $comment = ' #empty';
107 $txt .= "'$key' => '" . preg_replace( '/(?<!\\\\)\'/', "\'", $m['msg']) . "',$comment\n";
108 $messages[$key] = NULL; // trade bytes
115 * 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.
116 * @param $messages Messages array.
117 * @return The HTML list of messages.
119 function wfAllMessagesMakeHTMLText( &$messages ) {
120 global $wgLang, $wgContLang, $wgUser;
121 wfProfileIn( __METHOD__
);
123 $sk = $wgUser->getSkin();
124 $talk = wfMsg( 'talkpagelinktext' );
126 $input = Xml
::element( 'input', array(
128 'id' => 'allmessagesinput',
129 'onkeyup' => 'allmessagesfilter()'
131 $checkbox = Xml
::element( 'input', array(
133 'value' => wfMsgHtml( 'allmessagesmodified' ),
134 'id' => 'allmessagescheckbox',
135 'onclick' => 'allmessagesmodified()'
138 $txt = '<span id="allmessagesfilter" style="display: none;">' . wfMsgHtml( 'allmessagesfilter' ) .
139 " {$input}{$checkbox} " . '</span>';
142 <table border="1" cellspacing="0" width="100%" id="allmessagestable">
144 <th rowspan="2">' . wfMsgHtml( 'allmessagesname' ) . '</th>
145 <th>' . wfMsgHtml( 'allmessagesdefault' ) . '</th>
148 <th>' . wfMsgHtml( 'allmessagescurrent' ) . '</th>
151 wfProfileIn( __METHOD__
. "-check" );
153 # This is a nasty hack to avoid doing independent existence checks
154 # without sending the links and table through the slow wiki parser.
156 NS_MEDIAWIKI
=> array(),
157 NS_MEDIAWIKI_TALK
=> array()
159 $dbr = wfGetDB( DB_SLAVE
);
160 $res = $dbr->select( 'page',
161 array( 'page_namespace', 'page_title' ),
162 array( 'page_namespace' => array(NS_MEDIAWIKI
,NS_MEDIAWIKI_TALK
) ),
164 array( 'USE INDEX' => 'name_title' )
166 while( $s = $dbr->fetchObject( $res ) ) {
167 $pageExists[$s->page_namespace
][$s->page_title
] = 1;
169 $dbr->freeResult( $res );
170 wfProfileOut( __METHOD__
. "-check" );
172 wfProfileIn( __METHOD__
. "-output" );
176 foreach( $messages as $key => $m ) {
177 $title = $wgLang->ucfirst( $key );
178 if( $wgLang->getCode() != $wgContLang->getCode() ) {
179 $title .= '/' . $wgLang->getCode();
182 $titleObj = Title
::makeTitle( NS_MEDIAWIKI
, $title );
183 $talkPage = Title
::makeTitle( NS_MEDIAWIKI_TALK
, $title );
185 $changed = ( $m['statmsg'] != $m['msg'] );
186 $message = htmlspecialchars( $m['statmsg'] );
187 $mw = htmlspecialchars( $m['msg'] );
189 if( array_key_exists( $title, $pageExists[NS_MEDIAWIKI
] ) ) {
190 $pageLink = $sk->makeKnownLinkObj( $titleObj, "<span id=\"sp-allmessages-i-$i\">" .
191 htmlspecialchars( $key ) . '</span>' );
193 $pageLink = $sk->makeBrokenLinkObj( $titleObj, "<span id=\"sp-allmessages-i-$i\">" .
194 htmlspecialchars( $key ) . '</span>' );
196 if( array_key_exists( $title, $pageExists[NS_MEDIAWIKI_TALK
] ) ) {
197 $talkLink = $sk->makeKnownLinkObj( $talkPage, htmlspecialchars( $talk ) );
199 $talkLink = $sk->makeBrokenLinkObj( $talkPage, htmlspecialchars( $talk ) );
202 $anchor = 'msg_' . htmlspecialchars( strtolower( $title ) );
203 $anchor = "<a id=\"$anchor\" name=\"$anchor\"></a>";
207 <tr class=\"orig\" id=\"sp-allmessages-r1-$i\">
209 $anchor$pageLink<br />$talkLink
213 </tr><tr class=\"new\" id=\"sp-allmessages-r2-$i\">
220 <tr class=\"def\" id=\"sp-allmessages-r1-$i\">
222 $anchor$pageLink<br />$talkLink
228 $messages[$key] = NULL; // trade bytes
232 wfProfileOut( __METHOD__
. '-output' );
234 wfProfileOut( __METHOD__
);