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
28 MessageCache
::loadAllMessages();
30 $sortedArray = array_merge( Language
::getMessagesFor( 'en' ), $wgMessageCache->getExtensionMessagesFor( 'en' ) );
31 ksort( $sortedArray );
33 $wgMessageCache->disableTransform();
35 foreach ( $sortedArray as $key => $value ) {
36 $messages[$key]['enmsg'] = $value;
37 $messages[$key]['statmsg'] = wfMsgNoDb( $key );
38 $messages[$key]['msg'] = wfMsg ( $key );
41 $wgMessageCache->enableTransform();
42 wfProfileOut( __METHOD__
. '-setup' );
44 wfProfileIn( __METHOD__
. '-output' );
46 $navText .= makePhp( $messages );
47 $wgOut->addHTML( 'PHP | <a href="' . $wgTitle->escapeLocalUrl( 'ot=html' ) . '">HTML</a><pre>' . htmlspecialchars( $navText ) . '</pre>' );
49 $wgOut->addHTML( '<a href="' . $wgTitle->escapeLocalUrl( 'ot=php' ) . '">PHP</a> | HTML' );
50 $wgOut->addWikiText( $navText );
51 $wgOut->addHTML( makeHTMLText( $messages ) );
53 wfProfileOut( __METHOD__
. '-output' );
55 wfProfileOut( __METHOD__
);
59 * Create the messages array, formatted in PHP to copy to language files.
60 * @param $messages Messages array.
61 * @return The PHP messages array.
62 * @todo Make suitable for language files.
64 function makePhp( $messages ) {
66 $txt = "\n\n\$messages = array(\n";
67 foreach( $messages as $key => $m ) {
68 if( $wgLang->getCode() != 'en' && $m['msg'] == $m['enmsg'] ) {
70 } else if ( wfEmptyMsg( $key, $m['msg'] ) ) {
76 $txt .= "'$key' => '" . preg_replace( '/(?<!\\\\)\'/', "\'", $m['msg']) . "',$comment\n";
83 * 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.
84 * @param $messages Messages array.
85 * @return The HTML list of messages.
87 function makeHTMLText( $messages ) {
88 global $wgLang, $wgContLang, $wgUser;
89 wfProfileIn( __METHOD__
);
91 $sk = $wgUser->getSkin();
92 $talk = wfMsg( 'talkpagelinktext' );
94 $input = wfElement( 'input', array(
96 'id' => 'allmessagesinput',
97 'onkeyup' => 'allmessagesfilter()'
99 $checkbox = wfElement( 'input', array(
101 'value' => wfMsgHtml( 'allmessagesmodified' ),
102 'id' => 'allmessagescheckbox',
103 'onclick' => 'allmessagesmodified()'
106 $txt = '<span id="allmessagesfilter" style="display: none;">' . wfMsgHtml( 'allmessagesfilter' ) . " {$input}{$checkbox} " . '</span>';
109 <table border="1" cellspacing="0" width="100%" id="allmessagestable">
111 <th rowspan="2">' . wfMsgHtml( 'allmessagesname' ) . '</th>
112 <th>' . wfMsgHtml( 'allmessagesdefault' ) . '</th>
115 <th>' . wfMsgHtml( 'allmessagescurrent' ) . '</th>
118 wfProfileIn( __METHOD__
. "-check" );
120 # This is a nasty hack to avoid doing independent existence checks
121 # without sending the links and table through the slow wiki parser.
123 NS_MEDIAWIKI
=> array(),
124 NS_MEDIAWIKI_TALK
=> array()
126 $dbr = wfGetDB( DB_SLAVE
);
127 $page = $dbr->tableName( 'page' );
128 $sql = "SELECT page_namespace,page_title FROM $page WHERE page_namespace IN (" . NS_MEDIAWIKI
. ", " . NS_MEDIAWIKI_TALK
. ")";
129 $res = $dbr->query( $sql );
130 while( $s = $dbr->fetchObject( $res ) ) {
131 $pageExists[$s->page_namespace
][$s->page_title
] = true;
133 $dbr->freeResult( $res );
134 wfProfileOut( __METHOD__
. "-check" );
136 wfProfileIn( __METHOD__
. "-output" );
140 foreach( $messages as $key => $m ) {
141 $title = $wgLang->ucfirst( $key );
142 if( $wgLang->getCode() != $wgContLang->getCode() ) {
143 $title .= '/' . $wgLang->getCode();
146 $titleObj =& Title
::makeTitle( NS_MEDIAWIKI
, $title );
147 $talkPage =& Title
::makeTitle( NS_MEDIAWIKI_TALK
, $title );
149 $changed = ( $m['statmsg'] != $m['msg'] );
150 $message = htmlspecialchars( $m['statmsg'] );
151 $mw = htmlspecialchars( $m['msg'] );
153 if( isset( $pageExists[NS_MEDIAWIKI
][$title] ) ) {
154 $pageLink = $sk->makeKnownLinkObj( $titleObj, "<span id=\"sp-allmessages-i-$i\">" . htmlspecialchars( $key ) . '</span>' );
156 $pageLink = $sk->makeBrokenLinkObj( $titleObj, "<span id=\"sp-allmessages-i-$i\">" . htmlspecialchars( $key ) . '</span>' );
158 if( isset( $pageExists[NS_MEDIAWIKI_TALK
][$title] ) ) {
159 $talkLink = $sk->makeKnownLinkObj( $talkPage, htmlspecialchars( $talk ) );
161 $talkLink = $sk->makeBrokenLinkObj( $talkPage, htmlspecialchars( $talk ) );
164 $anchor = 'msg_' . htmlspecialchars( strtolower( $title ) );
165 $anchor = "<a id=\"$anchor\" name=\"$anchor\"></a>";
169 <tr class=\"orig\" id=\"sp-allmessages-r1-$i\">
171 $anchor$pageLink<br />$talkLink
175 </tr><tr class=\"new\" id=\"sp-allmessages-r2-$i\">
182 <tr class=\"def\" id=\"sp-allmessages-r1-$i\">
184 $anchor$pageLink<br />$talkLink
193 wfProfileOut( __METHOD__
. '-output' );
195 wfProfileOut( __METHOD__
);