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