Fix #153 path by <stehan dot walter at epfl dot ch>
[lhc/web/wiklou.git] / includes / SpecialMaintenance.php
1 <?php
2 /**
3 *
4 * @package MediaWiki
5 * @subpackage SpecialPage
6 */
7
8 /**
9 * shortcut to get the current language "special" namespace name
10 */
11 function sns() {
12 global $wgContLang;
13 return $wgContLang->getNsText(NS_SPECIAL);
14 }
15
16
17 /**
18 * Entry point
19 */
20 function wfSpecialMaintenance( $par=NULL ) {
21 global $wgUser, $wgOut, $wgContLang, $wgTitle, $wgRequest, $wgContLanguageCode;
22 global $wgMiserMode;
23
24 # This pages is expensive ressource wise
25 if ( $wgMiserMode ) {
26 $wgOut->addWikiText( wfMsg( 'perfdisabled' ) );
27 return;
28 }
29
30 # Get parameters from the URL
31 $submitmll = $wgRequest->getVal( 'submitmll' );
32
33 if( $par ) {
34 $subfunction = $par;
35 } else {
36 $subfunction = $wgRequest->getText( 'subfunction' );
37 }
38
39 # Call the subfunction requested by the user
40 switch( $subfunction ) {
41 case 'disambiguations': return wfSpecialDisambiguations() ; break;
42
43 # doubleredirects & brokenredirects are old maintenance subpages.
44 case 'doubleredirects': return wfSpecialDoubleRedirects() ; break;
45 case 'brokenredirects': return wfSpecialBrokenRedirects() ; break;
46
47 case 'selflinks': return wfSpecialSelfLinks() ; break;
48 case 'mispeelings': return wfSpecialMispeelings() ; break;
49 case 'missinglanguagelinks': return wfSpecialMissingLanguageLinks() ; break;
50 }
51
52 if ( !is_null( $submitmll ) ) return wfSpecialMissingLanguageLinks() ;
53
54 $sk = $wgUser->getSkin();
55
56 # Generate page output
57
58 $r = wfMsg('maintnancepagetext') ;
59
60 # Links to subfunctions
61 $r .= "<ul>\n" ;
62 $r .= "<li>".$sk->makeKnownLink( sns().':Disambiguations', wfMsg('disambiguations')) . "</li>\n";
63 $r .= '<li>'.$sk->makeKnownLink( sns().':DoubleRedirects', wfMsg('doubleredirects')) . "</li>\n";
64 $r .= '<li>'.$sk->makeKnownLink( sns().':BrokenRedirects', wfMsg('brokenredirects')) . "</li>\n";
65 #$r .= "<li>".getMPL("selflinks")."</li>\n" ; # Doesn't work
66 $r .= '<li>'.getMPL("mispeelings")."</li>\n" ;
67
68 # Interface for the missing language links
69 $r .= '<li>';
70 $l = getMPL('missinglanguagelinks');
71 $l = str_replace ( '</a>' , '' , $l ) ;
72 $l = str_replace ( '<a ' , '<form method="post" ' , $l ) ;
73 $l = str_replace ( ' href=' , ' action=' , $l ) ;
74 $l = explode ( '>' , $l ) ;
75 $l = $l[0] ;
76 $r .= $l.">\n" ;
77 $r .= '<input type="submit" name="submitmll" value="' ;
78 $r .= htmlspecialchars(wfMsg('missinglanguagelinksbutton'), ENT_QUOTES);
79 $r .= "\" />\n" ;
80 $r .= "<select name=\"thelang\">\n" ;
81
82 $a = $wgContLang->getLanguageNames();
83 $ak = array_keys ( $a ) ;
84 foreach ( $ak AS $k ) {
85 if ( $k != $wgContLanguageCode )
86 $r .= "<option value='{$k}'>{$a[$k]}</option>\n" ;
87 }
88 $r .= "</select>\n" ;
89 $r .= "</form>\n</li>" ;
90
91 $r .= "</ul>\n" ;
92 $wgOut->addHTML ( $r ) ;
93 }
94
95 /**
96 * Generate a maintenance page link
97 */
98 function getMPL ( $x ) {
99 global $wgUser , $wgLang;
100 $sk = $wgUser->getSkin() ;
101 return $sk->makeKnownLink( sns().":Maintenance" , wfMsg($x), 'subfunction='.$x ) ;
102 }
103
104
105 function getMaintenancePageBacklink( $subfunction ) {
106 global $wgUser, $wgContLang;
107 $sk = $wgUser->getSkin();
108 $r = $sk->makeKnownLink (
109 $wgContLang->getNsText( NS_SPECIAL ) . ':Maintenance',
110 wfMsg( 'maintenancebacklink' ) ) ;
111 $t = wfMsg ( $subfunction ) ;
112
113 $s = '<table width="100%" border="0"><tr><td>';
114 $s .= '<h2>'.$t.'</h2></td><td align="right">';
115 $s .= "{$r}</td></tr></table>\n" ;
116 return $s ;
117 }
118
119
120 /**#@+
121 * Disambiguations, DoubleRedirects and BrokenRedirects are now using the
122 * QueryPage class. Code is in a Special*.php file.
123 *
124 * @deprecated
125 */
126 function wfSpecialDoubleRedirects() {
127 global $wgOut;
128 $t = Title::makeTitle( NS_SPECIAL, "DoubleRedirects" );
129 $wgOut->redirect ($t->getFullURL());
130 }
131
132 function wfSpecialBrokenRedirects() {
133 global $wgOut;
134 $t = Title::makeTitle( NS_SPECIAL, "BrokenRedirects" );
135 $wgOut->redirect ($t->getFullURL());
136 }
137
138 function wfSpecialDisambiguations() {
139 global $wgOut;
140 $t = Title::makeTitle( NS_SPECIAL, "Disambiguations" );
141 $wgOut->redirect ($t->getFullURL());
142 }
143 /**#@-*/
144
145
146 /**
147 * This doesn't really work anymore, because self-links are now displayed as
148 * unlinked bold text, and are not entered into the link table.
149 *
150 * @deprecated
151 */
152 function wfSpecialSelfLinks() {
153 global $wgUser, $wgOut, $wgLang, $wgTitle;
154 $fname = 'wfSpecialSelfLinks';
155
156 list( $limit, $offset ) = wfCheckLimits();
157
158 $sql = "SELECT page_namespace,page_title FROM page,links " .
159 "WHERE l_from=l_to AND l_to=page_id " .
160 "LIMIT {$offset}, {$limit}";
161
162 $res = wfQuery( $sql, DB_SLAVE, $fname );
163
164 $top = getMaintenancePageBacklink( 'selflinks' );
165 $top .= '<p>'.wfMsg('selflinkstext')."</p><br />\n";
166 $top .= wfShowingResults( $offset, $limit );
167 $wgOut->addHTML( "<p>{$top}\n" );
168
169 $sl = wfViewPrevNext( $offset, $limit, 'REPLACETHIS' ) ;
170 $sl = str_replace ( 'REPLACETHIS' , sns().":Maintenance&subfunction=selflinks" , $sl ) ;
171 $wgOut->addHTML( "<br />{$sl}\n" );
172
173 $sk = $wgUser->getSkin();
174 $s = '<ol start=' . ( $offset + 1 ) . '>';
175 while ( $obj = wfFetchObject( $res ) ) {
176 $title = Title::makeTitle( $obj->page_namespace, $obj->page_title );
177 $s .= "<li>".$sk->makeKnownLinkObj( $title )."</li>\n" ;
178 }
179 wfFreeResult( $res );
180 $s .= '</ol>';
181 $wgOut->addHTML( $s );
182 $wgOut->addHTML( "<p>{$sl}\n" );
183 }
184
185 /**
186 *
187 */
188 function wfSpecialMispeelings () {
189 global $wgUser, $wgOut, $wgContLang, $wgTitle;
190 $sk = $wgUser->getSkin();
191 $fname = 'wfSpecialMispeelings';
192
193 list( $limit, $offset ) = wfCheckLimits();
194 $dbr =& wfGetDB( DB_SLAVE );
195 extract( $dbr->tableNames( 'cur', 'searchindex' ) );
196
197 # Determine page name
198 $ms = wfMsg ( 'mispeelingspage' ) ;
199 $mss = str_replace ( ' ' , '_' , $ms );
200 $msp = $wgContLang->getNsText(4).':'.$ms ;
201 $msl = $sk->makeKnownLink ( $msp ) ;
202
203 # Load list from database
204 $l = $dbr->selectField( 'cur', 'cur_text', array( 'cur_title' => $mss, 'cur_namespace' => 4 ), $fname );
205 $l = explode ( "\n" , $l ) ;
206 $a = array () ;
207 foreach ( $l as $x )
208 if ( substr ( trim ( $x ) , 0 , 1 ) == '*' )
209 $a[] = strtolower ( trim ( substr ( trim ( $x ) , 1 ) ) );
210 asort ( $a ) ;
211
212 $cnt = 0 ;
213 $b = array () ;
214 foreach ( $a AS $x ) {
215 if ( $cnt < $offset+$limit && $x != '' ) {
216 $y = $x ;
217 $x = preg_replace( '/^(\S+).*$/', '$1', $x );
218 $sql = "SELECT DISTINCT cur_title FROM $cur,$searchindex WHERE cur_id=si_page AND ".
219 "cur_namespace=".NS_MAIN." AND cur_is_redirect=0 AND " .
220 "(MATCH(si_text) AGAINST ('" . $dbr->strencode( $wgContLang->stripForSearch( $x ) ) . "'))" ;
221 $res = $dbr->query( $sql, $fname );
222 while ( $obj = $dbr->fetchObject ( $res ) ) {
223 if ( $cnt >= $offset AND $cnt < $offset+$limit ) {
224 if ( $y != '' ) {
225 if ( count ( $b ) > 0 ) $b[] = "</OL>\n" ;
226 $b[] = "<H3>{$y}</H3>\n<OL start=".($cnt+1).">\n" ;
227 $y = '' ;
228 }
229 $b[] = '<li>'.
230 $sk->makeKnownLink ( $obj->cur_title ).
231 ' ('.
232 $sk->makeBrokenLink ( $obj->cur_title , wfMsg ( "qbedit" ) ).
233 ")</li>\n" ;
234 }
235 $cnt++ ;
236 }
237 }
238 }
239 $top = getMaintenancePageBacklink( 'mispeelings' );
240 $top .= "<p>".wfMsg( 'mispeelingstext', $msl )."</p><br />\n";
241 $top .= wfShowingResults( $offset, $limit );
242 $wgOut->addHTML( "<p>{$top}\n" );
243
244 $sl = wfViewPrevNext( $offset, $limit, 'REPLACETHIS' ) ;
245 $sl = str_replace ( 'REPLACETHIS' , sns().":Maintenance&subfunction=mispeelings" , $sl ) ;
246 $wgOut->addHTML( "<br />{$sl}\n" );
247
248 $s = implode ( '' , $b ) ;
249 if ( count ( $b ) > 0 ) $s .= '</ol>';
250 $wgOut->addHTML( $s );
251 $wgOut->addHTML( "<p>{$sl}\n" );
252 }
253
254 /**
255 *
256 */
257 function wfSpecialMissingLanguageLinks() {
258 global $wgUser, $wgOut, $wgContLang, $wgTitle, $wgRequest;
259
260 $fname = 'wfSpecialMissingLanguageLinks';
261 $thelang = $wgRequest->getText( 'thelang' );
262 if ( $thelang == 'w' ) $thelang = 'en' ; # Fix for international wikis
263
264 list( $limit, $offset ) = wfCheckLimits();
265 $dbr =& wfGetDB( DB_SLAVE );
266 $cur = $dbr->tableName( 'cur' );
267
268 $sql = "SELECT cur_title FROM $cur " .
269 "WHERE cur_namespace=".NS_MAIN." AND cur_is_redirect=0 " .
270 "AND cur_title NOT LIKE '%/%' AND cur_text NOT LIKE '%[[" . wfStrencode( $thelang ) . ":%' " .
271 "LIMIT {$offset}, {$limit}";
272
273 $res = $dbr->query( $sql, $fname );
274
275
276 $mll = wfMsg( 'missinglanguagelinkstext', $wgContLang->getLanguageName($thelang) );
277
278 $top = getMaintenancePageBacklink( 'missinglanguagelinks' );
279 $top .= "<p>$mll</p><br />";
280 $top .= wfShowingResults( $offset, $limit );
281 $wgOut->addHTML( "<p>{$top}\n" );
282
283 $sl = wfViewPrevNext( $offset, $limit, 'REPLACETHIS' ) ;
284 $sl = str_replace ( 'REPLACETHIS' , sns().":Maintenance&subfunction=missinglanguagelinks&thelang=".
285 htmlspecialchars($thelang), $sl ) ;
286 $wgOut->addHTML( "<br />{$sl}\n" );
287
288 $sk = $wgUser->getSkin();
289 $s = '<ol start=' . ( $offset + 1 ) . '>';
290 while ( $obj = $dbr->fetchObject( $res ) )
291 $s .= "<li>".$sk->makeKnownLink ( $obj->cur_title )."</li>\n" ;
292 $dbr->freeResult( $res );
293 $s .= '</ol>';
294 $wgOut->addHTML( $s );
295 $wgOut->addHTML( "<p>{$sl}\n" );
296 }
297
298 ?>