$wgLanguageCode no longer indicates the user language, for that use $wgLang->getCode...
[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, $wgRequest, $wgMessageCache, $wgTitle;
13 global $wgUseDatabaseMessages;
14
15 # The page isn't much use if the MediaWiki namespace is not being used
16 if( !$wgUseDatabaseMessages ) {
17 $wgOut->addWikiText( wfMsg( 'allmessagesnotsupportedDB' ) );
18 return;
19 }
20
21 $fname = "wfSpecialAllMessages";
22 wfProfileIn( $fname );
23
24 wfProfileIn( "$fname-setup");
25 $ot = $wgRequest->getText( 'ot' );
26
27 $navText = wfMsg( 'allmessagestext' );
28
29 # Make sure all extension messages are available
30 wfLoadAllExtensions();
31
32 $first = true;
33 $sortedArray = array_merge( Language::getMessagesFor( 'en' ), $wgMessageCache->mExtensionMessages );
34 ksort( $sortedArray );
35 $messages = array();
36 $wgMessageCache->disableTransform();
37
38 foreach ( $sortedArray as $key => $value ) {
39 $messages[$key]['enmsg'] = is_array( $value ) ? $value['en'] : $value;
40 $messages[$key]['statmsg'] = wfMsgNoDb( $key );
41 $messages[$key]['msg'] = wfMsg ( $key );
42 }
43
44 $wgMessageCache->enableTransform();
45 wfProfileOut( "$fname-setup" );
46
47 wfProfileIn( "$fname-output" );
48 if ($ot == 'php') {
49 $navText .= makePhp($messages);
50 $wgOut->addHTML('PHP | <a href="'.$wgTitle->escapeLocalUrl('ot=html').'">HTML</a><pre>'.htmlspecialchars($navText).'</pre>');
51 } else {
52 $wgOut->addHTML( '<a href="'.$wgTitle->escapeLocalUrl('ot=php').'">PHP</a> | HTML' );
53 $wgOut->addWikiText( $navText );
54 $wgOut->addHTML( makeHTMLText( $messages ) );
55 }
56 wfProfileOut( "$fname-output" );
57
58 wfProfileOut( $fname );
59 }
60
61 /**
62 *
63 */
64 function makePhp($messages) {
65 global $wgLang;
66 $txt = "\n\n\$messages = array(\n";
67 foreach( $messages as $key => $m ) {
68 if($wgLang->getCode() != 'en' and $m['msg'] == $m['enmsg'] ) {
69 //if (strstr($m['msg'],"\n")) {
70 // $txt.='/* ';
71 // $comment=' */';
72 //} else {
73 // $txt .= '#';
74 // $comment = '';
75 //}
76 continue;
77 } elseif ($m['msg'] == '&lt;'.$key.'&gt;'){
78 $m['msg'] = '';
79 $comment = ' #empty';
80 } else {
81 $comment = '';
82 }
83 $txt .= "'$key' => '" . preg_replace( "/(?<!\\\\)'/", "\'", $m['msg']) . "',$comment\n";
84 }
85 $txt .= ');';
86 return $txt;
87 }
88
89 /**
90 *
91 */
92 function makeHTMLText( $messages ) {
93 global $wgLang, $wgContLang, $wgUser;
94 $fname = "makeHTMLText";
95 wfProfileIn( $fname );
96
97 $sk =& $wgUser->getSkin();
98 $talk = $wgLang->getNsText( NS_TALK );
99 $mwnspace = $wgLang->getNsText( NS_MEDIAWIKI );
100 $mwtalk = $wgLang->getNsText( NS_MEDIAWIKI_TALK );
101
102 $input = wfElement( 'input', array(
103 'type' => 'text',
104 'id' => 'allmessagesinput',
105 'onkeyup' => 'allmessagesfilter()',),
106 '');
107 $checkbox = wfElement( 'input', array(
108 'type' => 'button',
109 'value' => wfMsgHtml( 'allmessagesmodified' ),
110 'id' => 'allmessagescheckbox',
111 'onclick' => 'allmessagesmodified()',),
112 '');
113
114 $txt = '<span id="allmessagesfilter" style="display:none;">' .
115 wfMsgHtml('allmessagesfilter') . " {$input}{$checkbox} " . '</span>';
116
117 $txt .= "
118 <table border='1' cellspacing='0' width='100%' id='allmessagestable'>
119 <tr>
120 <th rowspan='2'>" . wfMsgHtml('allmessagesname') . "</th>
121 <th>" . wfMsgHtml('allmessagesdefault') . "</th>
122 </tr>
123 <tr>
124 <th>" . wfMsgHtml('allmessagescurrent') . "</th>
125 </tr>";
126
127 wfProfileIn( "$fname-check" );
128 # This is a nasty hack to avoid doing independent existence checks
129 # without sending the links and table through the slow wiki parser.
130 $pageExists = array(
131 NS_MEDIAWIKI => array(),
132 NS_MEDIAWIKI_TALK => array()
133 );
134 $dbr =& wfGetDB( DB_SLAVE );
135 $page = $dbr->tableName( 'page' );
136 $sql = "SELECT page_namespace,page_title FROM $page WHERE page_namespace IN (" . NS_MEDIAWIKI . ", " . NS_MEDIAWIKI_TALK . ")";
137 $res = $dbr->query( $sql );
138 while( $s = $dbr->fetchObject( $res ) ) {
139 $pageExists[$s->page_namespace][$s->page_title] = true;
140 }
141 $dbr->freeResult( $res );
142 wfProfileOut( "$fname-check" );
143
144 wfProfileIn( "$fname-output" );
145
146 $i = 0;
147
148 foreach( $messages as $key => $m ) {
149
150 $title = $wgLang->ucfirst( $key );
151 if($wgLang->getCode() != $wgContLang->getCode())
152 $title.= '/' . $wgLang->getCode();
153
154 $titleObj =& Title::makeTitle( NS_MEDIAWIKI, $title );
155 $talkPage =& Title::makeTitle( NS_MEDIAWIKI_TALK, $title );
156
157 $changed = ($m['statmsg'] != $m['msg']);
158 $message = htmlspecialchars( $m['statmsg'] );
159 $mw = htmlspecialchars( $m['msg'] );
160
161 #$pageLink = $sk->makeLinkObj( $titleObj, htmlspecialchars( $key ) );
162 #$talkLink = $sk->makeLinkObj( $talkPage, htmlspecialchars( $talk ) );
163 if( isset( $pageExists[NS_MEDIAWIKI][$title] ) ) {
164 $pageLink = $sk->makeKnownLinkObj( $titleObj, "<span id='sp-allmessages-i-$i'>" . htmlspecialchars( $key ) . "</span>" );
165 } else {
166 $pageLink = $sk->makeBrokenLinkObj( $titleObj, "<span id='sp-allmessages-i-$i'>" . htmlspecialchars( $key ) . "</span>" );
167 }
168 if( isset( $pageExists[NS_MEDIAWIKI_TALK][$title] ) ) {
169 $talkLink = $sk->makeKnownLinkObj( $talkPage, htmlspecialchars( $talk ) );
170 } else {
171 $talkLink = $sk->makeBrokenLinkObj( $talkPage, htmlspecialchars( $talk ) );
172 }
173
174 $anchor = 'msg_' . htmlspecialchars( strtolower( $title ) );
175 $anchor = "<a id=\"$anchor\" name=\"$anchor\"></a>";
176
177 if($changed) {
178
179 $txt .= "
180 <tr class='orig' id='sp-allmessages-r1-$i'>
181 <td rowspan='2'>
182 $anchor$pageLink<br />$talkLink
183 </td><td>
184 $message
185 </td>
186 </tr><tr class='new' id='sp-allmessages-r2-$i'>
187 <td>
188 $mw
189 </td>
190 </tr>";
191 } else {
192
193 $txt .= "
194 <tr class='def' id='sp-allmessages-r1-$i'>
195 <td>
196 $anchor$pageLink<br />$talkLink
197 </td><td>
198 $mw
199 </td>
200 </tr>";
201
202 }
203 $i++;
204 }
205 $txt .= "</table>";
206 wfProfileOut( "$fname-output" );
207
208 wfProfileOut( $fname );
209 return $txt;
210 }
211
212 ?>