3 * Provide functions to generate a special page
5 * @subpackage SpecialPage
11 function wfSpecialAllmessages() {
12 global $wgOut, $wgRequest, $wgMessageCache, $wgTitle;
13 global $wgUseDatabaseMessages, $wgLang, $wgContLang;
15 # The page isn't much use if the MediaWiki namespace is not being used
16 if( !$wgUseDatabaseMessages ) {
17 $wgOut->addWikiText( wfMsg( 'allmessagesnotsupportedDB' ) );
21 $fname = "wfSpecialAllMessages";
22 wfProfileIn( $fname );
24 wfProfileIn( "$fname-setup");
25 $ot = $wgRequest->getText( 'ot' );
27 $navText = wfMsg( 'allmessagestext' );
29 # Make sure all extension messages are available
30 MessageCache
::loadAllMessages();
33 $sortedArray = array_merge( Language
::getMessagesFor( 'en' ), $wgMessageCache->getExtensionMessagesFor( 'en' ) );
34 ksort( $sortedArray );
35 $contentCode = $wgContLang->getCode();
36 $fallback = Language
::getFallbackFor( $wgLang->getCode() );
38 $wgMessageCache->disableTransform();
40 foreach ( array_keys( $sortedArray ) as $key ) {
41 if ( $contentCode == $fallback ) {
42 $messages[$key]['fallbackmsg'] = wfMsgNoDbForContent( $key );
44 $messages[$key]['fallbackmsg'] = wfMsgNoDb( "$key/$fallback" );
46 $messages[$key]['statmsg'] = wfMsgNoDb( $key );
47 $messages[$key]['msg'] = wfMsg ( $key );
50 $wgMessageCache->enableTransform();
51 wfProfileOut( "$fname-setup" );
53 wfProfileIn( "$fname-output" );
55 $navText .= makePhp($messages);
56 $wgOut->addHTML('PHP | <a href="'.$wgTitle->escapeLocalUrl('ot=html').'">HTML</a><pre>'.htmlspecialchars($navText).'</pre>');
58 $wgOut->addHTML( '<a href="'.$wgTitle->escapeLocalUrl('ot=php').'">PHP</a> | HTML' );
59 $wgOut->addWikiText( $navText );
60 $wgOut->addHTML( makeHTMLText( $messages ) );
62 wfProfileOut( "$fname-output" );
64 wfProfileOut( $fname );
70 function makePhp($messages) {
72 $txt = "\n\n\$messages = array(\n";
73 foreach( $messages as $key => $m ) {
74 if($wgLang->getCode() != 'en' and $m['msg'] == $m['fallbackmsg'] ) {
75 //if (strstr($m['msg'],"\n")) {
83 } elseif ( wfEmptyMsg( $key, $m['msg'] ) ) {
89 $txt .= "'$key' => '" . preg_replace( "/(?<!\\\\)'/", "\'", $m['msg']) . "',$comment\n";
98 function makeHTMLText( $messages ) {
99 global $wgLang, $wgContLang, $wgUser;
100 $fname = "makeHTMLText";
101 wfProfileIn( $fname );
103 $sk =& $wgUser->getSkin();
104 $talk = $wgLang->getNsText( NS_TALK
);
105 $mwnspace = $wgLang->getNsText( NS_MEDIAWIKI
);
106 $mwtalk = $wgLang->getNsText( NS_MEDIAWIKI_TALK
);
108 $input = wfElement( 'input', array(
110 'id' => 'allmessagesinput',
111 'onkeyup' => 'allmessagesfilter()',),
113 $checkbox = wfElement( 'input', array(
115 'value' => wfMsgHtml( 'allmessagesmodified' ),
116 'id' => 'allmessagescheckbox',
117 'onclick' => 'allmessagesmodified()',),
120 $txt = '<span id="allmessagesfilter" style="display:none;">' .
121 wfMsgHtml('allmessagesfilter') . " {$input}{$checkbox} " . '</span>';
124 <table border='1' cellspacing='0' width='100%' id='allmessagestable'>
126 <th rowspan='2'>" . wfMsgHtml('allmessagesname') . "</th>
127 <th>" . wfMsgHtml('allmessagesdefault') . "</th>
130 <th>" . wfMsgHtml('allmessagescurrent') . "</th>
133 wfProfileIn( "$fname-check" );
134 # This is a nasty hack to avoid doing independent existence checks
135 # without sending the links and table through the slow wiki parser.
137 NS_MEDIAWIKI
=> array(),
138 NS_MEDIAWIKI_TALK
=> array()
140 $dbr =& wfGetDB( DB_SLAVE
);
141 $page = $dbr->tableName( 'page' );
142 $sql = "SELECT page_namespace,page_title FROM $page WHERE page_namespace IN (" . NS_MEDIAWIKI
. ", " . NS_MEDIAWIKI_TALK
. ")";
143 $res = $dbr->query( $sql );
144 while( $s = $dbr->fetchObject( $res ) ) {
145 $pageExists[$s->page_namespace
][$s->page_title
] = true;
147 $dbr->freeResult( $res );
148 wfProfileOut( "$fname-check" );
150 wfProfileIn( "$fname-output" );
154 foreach( $messages as $key => $m ) {
156 $title = $wgLang->ucfirst( $key );
157 if($wgLang->getCode() != $wgContLang->getCode())
158 $title.= '/' . $wgLang->getCode();
160 $titleObj =& Title
::makeTitle( NS_MEDIAWIKI
, $title );
161 $talkPage =& Title
::makeTitle( NS_MEDIAWIKI_TALK
, $title );
163 $changed = ($m['statmsg'] != $m['msg']);
164 $message = htmlspecialchars( $m['statmsg'] );
165 $mw = htmlspecialchars( $m['msg'] );
167 #$pageLink = $sk->makeLinkObj( $titleObj, htmlspecialchars( $key ) );
168 #$talkLink = $sk->makeLinkObj( $talkPage, htmlspecialchars( $talk ) );
169 if( isset( $pageExists[NS_MEDIAWIKI
][$title] ) ) {
170 $pageLink = $sk->makeKnownLinkObj( $titleObj, "<span id='sp-allmessages-i-$i'>" . htmlspecialchars( $key ) . "</span>" );
172 $pageLink = $sk->makeBrokenLinkObj( $titleObj, "<span id='sp-allmessages-i-$i'>" . htmlspecialchars( $key ) . "</span>" );
174 if( isset( $pageExists[NS_MEDIAWIKI_TALK
][$title] ) ) {
175 $talkLink = $sk->makeKnownLinkObj( $talkPage, htmlspecialchars( $talk ) );
177 $talkLink = $sk->makeBrokenLinkObj( $talkPage, htmlspecialchars( $talk ) );
180 $anchor = 'msg_' . htmlspecialchars( strtolower( $title ) );
181 $anchor = "<a id=\"$anchor\" name=\"$anchor\"></a>";
186 <tr class='orig' id='sp-allmessages-r1-$i'>
188 $anchor$pageLink<br />$talkLink
192 </tr><tr class='new' id='sp-allmessages-r2-$i'>
200 <tr class='def' id='sp-allmessages-r1-$i'>
202 $anchor$pageLink<br />$talkLink
212 wfProfileOut( "$fname-output" );
214 wfProfileOut( $fname );