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