Moving disambiguations code from specialMaintenance. Fixing the function meantime
[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>".$sk->makeKnownLink( sns().':Disambiguations', wfMsg('disambiguations')) . "</li>\n";
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
111 # Disambiguations, DoubleRedirects and BrokenRedirects are now using the
112 # QueryPage class. Code is in a Special*.php file.
113 function wfSpecialDoubleRedirects() {
114 global $wgOut;
115 $t = Title::makeTitle( NS_SPECIAL, "DoubleRedirects" );
116 $wgOut->redirect ($t->getFullURL());
117 }
118
119 function wfSpecialBrokenRedirects() {
120 global $wgOut;
121 $t = Title::makeTitle( NS_SPECIAL, "BrokenRedirects" );
122 $wgOut->redirect ($t->getFullURL());
123 }
124
125 function wfSpecialDisambiguations() {
126 global $wgOut;
127 $t = Title::makeTitle( NS_SPECIAL, "Disambiguations" );
128 $wgOut->redirect ($t->getFullURL());
129 }
130
131
132 # This doesn't really work anymore, because self-links are now displayed as
133 # unlinked bold text, and are not entered into the link table.
134 function wfSpecialSelfLinks() {
135 global $wgUser, $wgOut, $wgLang, $wgTitle;
136 $fname = 'wfSpecialSelfLinks';
137
138 list( $limit, $offset ) = wfCheckLimits();
139
140 $sql = "SELECT cur_namespace,cur_title FROM cur,links " .
141 "WHERE l_from=l_to AND l_to=cur_id " .
142 "LIMIT {$offset}, {$limit}";
143
144 $res = wfQuery( $sql, DB_SLAVE, $fname );
145
146 $top = getMaintenancePageBacklink( 'selflinks' );
147 $top .= '<p>'.wfMsg('selflinkstext')."</p><br>\n";
148 $top .= wfShowingResults( $offset, $limit );
149 $wgOut->addHTML( "<p>{$top}\n" );
150
151 $sl = wfViewPrevNext( $offset, $limit, 'REPLACETHIS' ) ;
152 $sl = str_replace ( 'REPLACETHIS' , sns().":Maintenance&subfunction=selflinks" , $sl ) ;
153 $wgOut->addHTML( "<br>{$sl}\n" );
154
155 $sk = $wgUser->getSkin();
156 $s = '<ol start=' . ( $offset + 1 ) . '>';
157 while ( $obj = wfFetchObject( $res ) ) {
158 $title = Title::makeTitle( $obj->cur_namespace, $obj->cur_title );
159 $s .= "<li>".$sk->makeKnownLinkObj( $title )."</li>\n" ;
160 }
161 wfFreeResult( $res );
162 $s .= '</ol>';
163 $wgOut->addHTML( $s );
164 $wgOut->addHTML( "<p>{$sl}\n" );
165 }
166
167
168 function wfSpecialMispeelings () {
169 global $wgUser, $wgOut, $wgLang, $wgTitle;
170 $sk = $wgUser->getSkin();
171 $fname = 'wfSpecialMispeelings';
172
173 list( $limit, $offset ) = wfCheckLimits();
174 $dbr =& wfGetDB( DB_SLAVE );
175 extract( $dbr->tableNames( 'cur', 'searchindex' ) );
176
177 # Determine page name
178 $ms = wfMsg ( 'mispeelingspage' ) ;
179 $mss = str_replace ( ' ' , '_' , $ms );
180 $msp = $wgLang->getNsText(4).':'.$ms ;
181 $msl = $sk->makeKnownLink ( $msp ) ;
182
183 # Load list from database
184 $l = $dbr->selectField( 'cur', 'cur_text', array( 'cur_title' => $mss, 'cur_namespace' => 4 ), $fname );
185 $l = explode ( "\n" , $l ) ;
186 $a = array () ;
187 foreach ( $l as $x )
188 if ( substr ( trim ( $x ) , 0 , 1 ) == '*' )
189 $a[] = strtolower ( trim ( substr ( trim ( $x ) , 1 ) ) );
190 asort ( $a ) ;
191
192 $cnt = 0 ;
193 $b = array () ;
194 foreach ( $a AS $x ) {
195 if ( $cnt < $offset+$limit && $x != '' ) {
196 $y = $x ;
197 $x = preg_replace( '/^(\S+).*$/', '$1', $x );
198 $sql = "SELECT DISTINCT cur_title FROM $cur,$searchindex WHERE cur_id=si_page AND ".
199 "cur_namespace=0 AND cur_is_redirect=0 AND " .
200 "(MATCH(si_text) AGAINST ('" . $dbr->strencode( $wgLang->stripForSearch( $x ) ) . "'))" ;
201 $res = $dbr->query( $sql, $fname );
202 while ( $obj = $dbr->fetchObject ( $res ) ) {
203 if ( $cnt >= $offset AND $cnt < $offset+$limit ) {
204 if ( $y != '' ) {
205 if ( count ( $b ) > 0 ) $b[] = "</OL>\n" ;
206 $b[] = "<H3>{$y}</H3>\n<OL start=".($cnt+1).">\n" ;
207 $y = '' ;
208 }
209 $b[] = '<li>'.
210 $sk->makeKnownLink ( $obj->cur_title ).
211 ' ('.
212 $sk->makeBrokenLink ( $obj->cur_title , wfMsg ( "qbedit" ) ).
213 ")</li>\n" ;
214 }
215 $cnt++ ;
216 }
217 }
218 }
219 $top = getMaintenancePageBacklink( 'mispeelings' );
220 $top .= "<p>".wfMsg( 'mispeelingstext', $msl )."</p><br>\n";
221 $top .= wfShowingResults( $offset, $limit );
222 $wgOut->addHTML( "<p>{$top}\n" );
223
224 $sl = wfViewPrevNext( $offset, $limit, 'REPLACETHIS' ) ;
225 $sl = str_replace ( 'REPLACETHIS' , sns().":Maintenance&subfunction=mispeelings" , $sl ) ;
226 $wgOut->addHTML( "<br>{$sl}\n" );
227
228 $s = implode ( '' , $b ) ;
229 if ( count ( $b ) > 0 ) $s .= '</ol>';
230 $wgOut->addHTML( $s );
231 $wgOut->addHTML( "<p>{$sl}\n" );
232 }
233
234
235 function wfSpecialMissingLanguageLinks() {
236 global $wgUser, $wgOut, $wgLang, $wgTitle, $wgRequest;
237
238 $fname = 'wfSpecialMissingLanguageLinks';
239 $thelang = $wgRequest->getText( 'thelang' );
240 if ( $thelang == 'w' ) $thelang = 'en' ; # Fix for international wikis
241
242 list( $limit, $offset ) = wfCheckLimits();
243 $dbr =& wfGetDB( DB_SLAVE );
244 $cur = $dbr->tableName( 'cur' );
245
246 $sql = "SELECT cur_title FROM $cur " .
247 "WHERE cur_namespace=0 AND cur_is_redirect=0 " .
248 "AND cur_title NOT LIKE '%/%' AND cur_text NOT LIKE '%[[{$thelang}:%' " .
249 "LIMIT {$offset}, {$limit}";
250
251 $res = $dbr->query( $sql, $fname );
252
253
254 $mll = wfMsg( 'missinglanguagelinkstext', $wgLang->getLanguageName($thelang) );
255
256 $top = getMaintenancePageBacklink( 'missinglanguagelinks' );
257 $top .= "<p>$mll</p><br>";
258 $top .= wfShowingResults( $offset, $limit );
259 $wgOut->addHTML( "<p>{$top}\n" );
260
261 $sl = wfViewPrevNext( $offset, $limit, 'REPLACETHIS' ) ;
262 $sl = str_replace ( 'REPLACETHIS' , sns().":Maintenance&subfunction=missinglanguagelinks&thelang={$thelang}" , $sl ) ;
263 $wgOut->addHTML( "<br>{$sl}\n" );
264
265 $sk = $wgUser->getSkin();
266 $s = '<ol start=' . ( $offset + 1 ) . '>';
267 while ( $obj = $dbr->fetchObject( $res ) )
268 $s .= "<li>".$sk->makeKnownLink ( $obj->cur_title )."</li>\n" ;
269 $dbr->freeResult( $res );
270 $s .= '</ol>';
271 $wgOut->addHTML( $s );
272 $wgOut->addHTML( "<p>{$sl}\n" );
273 }
274
275 ?>