Re-enable message transformations when we're done building the message list.
[lhc/web/wiklou.git] / includes / SpecialAllmessages.php
1 <?php
2 /**
3 * Provide functions to generate a special page
4 * @package MediaWiki
5 * @subpackage SpecialPage
6 */
7
8 /**
9 *
10 */
11 function wfSpecialAllmessages() {
12 global $wgOut, $wgAllMessagesEn, $wgRequest, $wgMessageCache, $wgTitle;
13
14 $fname = "wfSpecialAllMessages";
15 wfProfileIn( $fname );
16
17 wfProfileIn( "$fname-setup");
18 $ot = $wgRequest->getText( 'ot' );
19 $mwMsg =& MagicWord::get( MAG_MSG );
20
21 $navText = wfMsg( 'allmessagestext', $mwMsg->getSynonym( 0 ) );
22 $first = true;
23 $sortedArray = $wgAllMessagesEn;
24 ksort( $sortedArray );
25 $messages = array();
26 $wgMessageCache->disableTransform();
27 foreach ( $sortedArray as $key => $enMsg ) {
28 $messages[$key]['enmsg'] = $enMsg;
29 $messages[$key]['statmsg'] = wfMsgNoDb( $key );
30 $messages[$key]['msg'] = wfMsg ( $key );
31 }
32 $wgMessageCache->enableTransform();
33 wfProfileOut( "$fname-setup" );
34
35 wfProfileIn( "$fname-output" );
36 if ($ot == 'php') {
37 $navText .= makePhp($messages);
38 $wgOut->addHTML('PHP | <a href="'.$wgTitle->escapeLocalUrl('ot=html').'">HTML</a><pre>'.htmlspecialchars($navText).'</pre>');
39 } else {
40 $wgOut->addHTML( '<a href="'.$wgTitle->escapeLocalUrl('ot=php').'">PHP</a> | HTML' );
41 $wgOut->addWikiText( $navText );
42 $wgOut->addHTML( makeHTMLText( $messages ) );
43 }
44 wfProfileOut( "$fname-output" );
45
46 wfProfileOut( $fname );
47 }
48
49 /**
50 *
51 */
52 function makePhp($messages) {
53 global $wgLanguageCode;
54 $txt = "\n\n".'$wgAllMessages'.ucfirst($wgLanguageCode).' = array('."\n";
55 foreach( $messages as $key => $m ) {
56 if(strtolower($wgLanguageCode) != 'en' and $m['msg'] == $m['enmsg'] ) {
57 if (strstr($m['msg'],"\n")) {
58 $txt.='/* ';
59 $comment=' */';
60 } else {
61 $txt .= '#';
62 $comment = '';
63 }
64 } elseif ($m['msg'] == '&lt;'.$key.'&gt;'){
65 $m['msg'] = '';
66 $comment = ' #empty';
67 } else {
68 $comment = '';
69 }
70 $txt .= "'".$key."' => \"".str_replace('"','\"',$m['msg'])."\",$comment\n";
71 }
72 $txt .= ');';
73 return $txt;
74 }
75
76 /**
77 *
78 */
79 function makeHTMLText( $messages ) {
80 global $wgLang, $wgUser;
81 $fname = "makeHTMLText";
82 wfProfileIn( $fname );
83
84 $sk =& $wgUser->getSkin();
85 $talk = $wgLang->getNsText( NS_TALK );
86 $mwnspace = $wgLang->getNsText( NS_MEDIAWIKI );
87 $mwtalk = $wgLang->getNsText( NS_MEDIAWIKI_TALK );
88 $txt = "
89
90 <table border='1' cellspacing='0' width='100%'>
91 <tr bgcolor='#b2b2ff'>
92 <th>Name</th>
93 <th>Default text</th>
94 <th>Current text</th>
95 </tr>";
96
97 wfProfileIn( "$fname-check" );
98 # This is a nasty hack to avoid doing independent existence checks
99 # without sending the links and table through the slow wiki parser.
100 $pageExists = array(
101 NS_MEDIAWIKI => array(),
102 NS_MEDIAWIKI_TALK => array()
103 );
104 $sql = "SELECT cur_namespace,cur_title FROM cur WHERE cur_namespace IN (" . NS_MEDIAWIKI . ", " . NS_MEDIAWIKI_TALK . ")";
105 $dbr =& wfGetDB( DB_SLAVE );
106 $res = $dbr->query( $sql );
107 while( $s = $dbr->fetchObject( $res ) ) {
108 $pageExists[$s->cur_namespace][$s->cur_title] = true;
109 }
110 $dbr->freeResult( $res );
111 wfProfileOut( "$fname-check" );
112
113 wfProfileIn( "$fname-output" );
114 foreach( $messages as $key => $m ) {
115 $title = $wgLang->ucfirst( $key );
116 $titleObj =& Title::makeTitle( NS_MEDIAWIKI, $title );
117 $talkPage =& Title::makeTitle( NS_MEDIAWIKI_TALK, $title );
118
119 $colorIt = ($m['statmsg'] == $m['msg']) ? " bgcolor=\"#f0f0ff\"" : " bgcolor=\"#ffe2e2\"";
120 $message = htmlspecialchars( $m['statmsg'] );
121 $mw = htmlspecialchars( $m['msg'] );
122
123 #$pageLink = $sk->makeLinkObj( $titleObj, htmlspecialchars( $key ) );
124 #$talkLink = $sk->makeLinkObj( $talkPage, htmlspecialchars( $talk ) );
125 if( isset( $pageExists[NS_MEDIAWIKI][$title] ) ) {
126 $pageLink = $sk->makeKnownLinkObj( $titleObj, htmlspecialchars( $key ) );
127 } else {
128 $pageLink = $sk->makeBrokenLinkObj( $titleObj, htmlspecialchars( $key ) );
129 }
130 if( isset( $pageExists[NS_MEDIAWIKI_TALK][$title] ) ) {
131 $talkLink = $sk->makeKnownLinkObj( $talkPage, htmlspecialchars( $talk ) );
132 } else {
133 $talkLink = $sk->makeBrokenLinkObj( $talkPage, htmlspecialchars( $talk ) );
134 }
135
136 $txt .=
137 "<tr$colorIt><td>
138 $pageLink<br />
139 $talkLink
140 </td><td>
141 $message
142 </td><td>
143 $mw
144 </td></tr>";
145 }
146 $txt .= "</table>";
147 wfProfileOut( "$fname-output" );
148
149 wfProfileOut( $fname );
150 return $txt;
151 }
152
153 ?>