3 * Use this special page to get a list of the MediaWiki system messages.
11 function wfSpecialAllmessages() {
12 global $wgOut, $wgRequest, $wgMessageCache;
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' );
50 $title = SpecialPage
::getTitleFor( 'Allmessages' );
52 $navText .= wfAllMessagesMakePhp( $messages );
53 $wgOut->addHTML( $wgLang->pipeList( array(
55 '<a href="' . $title->escapeLocalUrl( array( 'ot' => 'html' ) ) . '">HTML</a>',
56 '<a href="' . $title->escapeLocalUrl( array( 'ot' => 'xml' ) ) . '">XML</a>' .
57 '<pre>' . htmlspecialchars( $navText ) . '</pre>'
59 } else if ( $ot == 'xml' ) {
61 header( 'Content-type: text/xml' );
62 echo wfAllMessagesMakeXml( $messages );
64 $wgOut->addHTML( $wgLang->pipeList( array(
65 '<a href="' . $title->escapeLocalUrl( array( 'ot' => 'php' ) ) . '">PHP</a>',
67 '<a href="' . $title->escapeLocalUrl( array( 'ot' => 'xml' ) ) . '">XML</a>'
69 $wgOut->addWikiText( $navText );
70 $wgOut->addHTML( wfAllMessagesMakeHTMLText( $messages ) );
72 wfProfileOut( __METHOD__
. '-output' );
74 wfProfileOut( __METHOD__
);
77 function wfAllMessagesMakeXml( &$messages ) {
79 $lang = $wgLang->getCode();
80 $txt = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n";
81 $txt .= "<messages lang=\"$lang\">\n";
82 foreach( $messages as $key => $m ) {
83 $txt .= "\t" . Xml
::element( 'message', array( 'name' => $key ), $m['msg'] ) . "\n";
84 $messages[$key] = NULL; // trade bytes
86 $txt .= "</messages>";
91 * Create the messages array, formatted in PHP to copy to language files.
92 * @param $messages Messages array.
93 * @return The PHP messages array.
94 * @todo Make suitable for language files.
96 function wfAllMessagesMakePhp( &$messages ) {
98 $txt = "\n\n\$messages = array(\n";
99 foreach( $messages as $key => $m ) {
100 if( $wgLang->getCode() != 'en' && $m['msg'] == $m['enmsg'] ) {
102 } else if ( wfEmptyMsg( $key, $m['msg'] ) ) {
104 $comment = ' #empty';
108 $txt .= "'$key' => '" . preg_replace( '/(?<!\\\\)\'/', "\'", $m['msg']) . "',$comment\n";
109 $messages[$key] = NULL; // trade bytes
116 * 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.
117 * @param $messages Messages array.
118 * @return The HTML list of messages.
120 function wfAllMessagesMakeHTMLText( &$messages ) {
121 global $wgLang, $wgContLang, $wgUser;
122 wfProfileIn( __METHOD__
);
124 $sk = $wgUser->getSkin();
125 $talk = wfMsg( 'talkpagelinktext' );
127 $input = Xml
::element( 'input', array(
129 'id' => 'allmessagesinput',
130 'onkeyup' => 'allmessagesfilter()'
132 $checkbox = Xml
::element( 'input', array(
134 'value' => wfMsgHtml( 'allmessagesmodified' ),
135 'id' => 'allmessagescheckbox',
136 'onclick' => 'allmessagesmodified()'
139 $txt = '<span id="allmessagesfilter" style="display: none;">' . wfMsgHtml( 'allmessagesfilter' ) .
140 " {$input}{$checkbox} " . '</span>';
143 <table border="1" cellspacing="0" width="100%" id="allmessagestable">
145 <th rowspan="2">' . wfMsgHtml( 'allmessagesname' ) . '</th>
146 <th>' . wfMsgHtml( 'allmessagesdefault' ) . '</th>
149 <th>' . wfMsgHtml( 'allmessagescurrent' ) . '</th>
152 wfProfileIn( __METHOD__
. "-check" );
154 # This is a nasty hack to avoid doing independent existence checks
155 # without sending the links and table through the slow wiki parser.
157 NS_MEDIAWIKI
=> array(),
158 NS_MEDIAWIKI_TALK
=> array()
160 $dbr = wfGetDB( DB_SLAVE
);
161 $res = $dbr->select( 'page',
162 array( 'page_namespace', 'page_title' ),
163 array( 'page_namespace' => array(NS_MEDIAWIKI
,NS_MEDIAWIKI_TALK
) ),
165 array( 'USE INDEX' => 'name_title' )
167 while( $s = $dbr->fetchObject( $res ) ) {
168 $pageExists[$s->page_namespace
][$s->page_title
] = 1;
170 $dbr->freeResult( $res );
171 wfProfileOut( __METHOD__
. "-check" );
173 wfProfileIn( __METHOD__
. "-output" );
177 foreach( $messages as $key => $m ) {
178 $title = $wgLang->ucfirst( $key );
179 if( $wgLang->getCode() != $wgContLang->getCode() ) {
180 $title .= '/' . $wgLang->getCode();
183 $titleObj = Title
::makeTitle( NS_MEDIAWIKI
, $title );
184 $talkPage = Title
::makeTitle( NS_MEDIAWIKI_TALK
, $title );
186 $changed = ( $m['statmsg'] != $m['msg'] );
187 $message = htmlspecialchars( $m['statmsg'] );
188 $mw = htmlspecialchars( $m['msg'] );
190 if( array_key_exists( $title, $pageExists[NS_MEDIAWIKI
] ) ) {
191 // FIXME: the span should be taken care of in $customAttribs, shouldn't it?
192 $pageLink = $sk->linkKnown(
194 "<span id=\"sp-allmessages-i-$i\">" . htmlspecialchars( $key ) . '</span>'
197 $pageLink = $sk->makeBrokenLinkObj( $titleObj, "<span id=\"sp-allmessages-i-$i\">" .
198 htmlspecialchars( $key ) . '</span>' );
200 if( array_key_exists( $title, $pageExists[NS_MEDIAWIKI_TALK
] ) ) {
201 $talkLink = $sk->linkKnown( $talkPage, htmlspecialchars( $talk ) );
203 $talkLink = $sk->makeBrokenLinkObj( $talkPage, htmlspecialchars( $talk ) );
206 $anchor = 'msg_' . htmlspecialchars( strtolower( $title ) );
207 $anchor = "<a id=\"$anchor\" name=\"$anchor\"></a>";
211 <tr class=\"orig\" id=\"sp-allmessages-r1-$i\">
213 $anchor$pageLink<br />$talkLink
217 </tr><tr class=\"new\" id=\"sp-allmessages-r2-$i\">
224 <tr class=\"def\" id=\"sp-allmessages-r1-$i\">
226 $anchor$pageLink<br />$talkLink
232 $messages[$key] = NULL; // trade bytes
236 wfProfileOut( __METHOD__
. '-output' );
238 wfProfileOut( __METHOD__
);