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