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 = Language
::getMessagesFor( '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 );
39 $messages[$key]['msg'] = wfMsgNoTrans( $key );
40 $sortedArray[$key] = NULL; // trade bytes from $sortedArray to this
43 unset($sortedArray); // trade bytes from $sortedArray to this
45 wfProfileOut( __METHOD__
. '-setup' );
47 wfProfileIn( __METHOD__
. '-output' );
48 $wgOut->addScriptFile( 'allmessages.js' );
49 $title = SpecialPage
::getTitleFor( 'Allmessages' );
51 $navText .= wfAllMessagesMakePhp( $messages );
52 $wgOut->addHTML( $wgLang->pipeList( array(
54 '<a href="' . $title->escapeLocalUrl( array( 'ot' => 'html' ) ) . '">HTML</a>',
55 '<a href="' . $title->escapeLocalUrl( array( '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="' . $title->escapeLocalUrl( array( 'ot' => 'php' ) ) . '">PHP</a>',
66 '<a href="' . $title->escapeLocalUrl( array( '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 $linkText = "<span id=\"sp-allmessages-i-$i\">" . htmlspecialchars( $key ) . '</span>';
191 if( array_key_exists( $title, $pageExists[NS_MEDIAWIKI
] ) ) {
192 // FIXME: the span should be taken care of in $customAttribs, shouldn't it?
193 $pageLink = $sk->linkKnown(
198 $pageLink = $sk->link(
206 if( array_key_exists( $title, $pageExists[NS_MEDIAWIKI_TALK
] ) ) {
207 $talkLink = $sk->linkKnown( $talkPage, htmlspecialchars( $talk ) );
209 $talkLink = $sk->link(
211 htmlspecialchars( $talk ),
218 $anchor = 'msg_' . htmlspecialchars( strtolower( $title ) );
219 $anchor = "<a id=\"$anchor\" name=\"$anchor\"></a>";
223 <tr class=\"orig\" id=\"sp-allmessages-r1-$i\">
225 $anchor$pageLink<br />$talkLink
229 </tr><tr class=\"new\" id=\"sp-allmessages-r2-$i\">
236 <tr class=\"def\" id=\"sp-allmessages-r1-$i\">
238 $anchor$pageLink<br />$talkLink
244 $messages[$key] = NULL; // trade bytes
248 wfProfileOut( __METHOD__
. '-output' );
250 wfProfileOut( __METHOD__
);