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