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