* Added a test for a link with multiple pipes
[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 $ns = $wgContLang->getNamespaces() ;
14 return $ns[NS_SPECIAL] ;
15 }
16
17
18 /**
19 * Entry point
20 */
21 function wfSpecialMaintenance( $par=NULL ) {
22 global $wgUser, $wgOut, $wgContLang, $wgTitle, $wgRequest, $wgContLanguageCode;
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 = $wgContLang->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 = str_replace ( ' href=' , ' action=' , $l ) ;
76 $l = explode ( '>' , $l ) ;
77 $l = $l[0] ;
78 $r .= $l.">\n" ;
79 $r .= '<input type="submit" name="submitmll" value="' ;
80 $r .= htmlspecialchars(wfMsg('missinglanguagelinksbutton'), ENT_QUOTES);
81 $r .= "\" />\n" ;
82 $r .= "<select name=\"thelang\">\n" ;
83
84 $a = $wgContLang->getLanguageNames();
85 $ak = array_keys ( $a ) ;
86 foreach ( $ak AS $k ) {
87 if ( $k != $wgContLanguageCode )
88 $r .= "<option value='{$k}'>{$a[$k]}</option>\n" ;
89 }
90 $r .= "</select>\n" ;
91 $r .= "</form>\n</li>" ;
92
93 $r .= "</ul>\n" ;
94 $wgOut->addHTML ( $r ) ;
95 }
96
97 /**
98 * Generate a maintenance page link
99 */
100 function getMPL ( $x ) {
101 global $wgUser , $wgLang;
102 $sk = $wgUser->getSkin() ;
103 return $sk->makeKnownLink( sns().":Maintenance" , wfMsg($x), 'subfunction='.$x ) ;
104 }
105
106
107 function getMaintenancePageBacklink( $subfunction ) {
108 global $wgUser , $wgContLang;
109 $sk = $wgUser->getSkin() ;
110 $ns = $wgContLang->getNamespaces() ;
111 $r = $sk->makeKnownLink (
112 $ns[-1].':Maintenance',
113 wfMsg( 'maintenancebacklink' ) ) ;
114 $t = wfMsg ( $subfunction ) ;
115
116 $s = '<table width="100%" border="0"><tr><td>';
117 $s .= '<h2>'.$t.'</h2></td><td align="right">';
118 $s .= "{$r}</td></tr></table>\n" ;
119 return $s ;
120 }
121
122
123 /**#@+
124 * Disambiguations, DoubleRedirects and BrokenRedirects are now using the
125 * QueryPage class. Code is in a Special*.php file.
126 *
127 * @deprecated
128 */
129 function wfSpecialDoubleRedirects() {
130 global $wgOut;
131 $t = Title::makeTitle( NS_SPECIAL, "DoubleRedirects" );
132 $wgOut->redirect ($t->getFullURL());
133 }
134
135 function wfSpecialBrokenRedirects() {
136 global $wgOut;
137 $t = Title::makeTitle( NS_SPECIAL, "BrokenRedirects" );
138 $wgOut->redirect ($t->getFullURL());
139 }
140
141 function wfSpecialDisambiguations() {
142 global $wgOut;
143 $t = Title::makeTitle( NS_SPECIAL, "Disambiguations" );
144 $wgOut->redirect ($t->getFullURL());
145 }
146 /**#@-*/
147
148
149 /**
150 * This doesn't really work anymore, because self-links are now displayed as
151 * unlinked bold text, and are not entered into the link table.
152 *
153 * @deprecated
154 */
155 function wfSpecialSelfLinks() {
156 global $wgUser, $wgOut, $wgLang, $wgTitle;
157 $fname = 'wfSpecialSelfLinks';
158
159 list( $limit, $offset ) = wfCheckLimits();
160
161 $sql = "SELECT page_namespace,page_title FROM page,links " .
162 "WHERE l_from=l_to AND l_to=page_id " .
163 "LIMIT {$offset}, {$limit}";
164
165 $res = wfQuery( $sql, DB_SLAVE, $fname );
166
167 $top = getMaintenancePageBacklink( 'selflinks' );
168 $top .= '<p>'.wfMsg('selflinkstext')."</p><br />\n";
169 $top .= wfShowingResults( $offset, $limit );
170 $wgOut->addHTML( "<p>{$top}\n" );
171
172 $sl = wfViewPrevNext( $offset, $limit, 'REPLACETHIS' ) ;
173 $sl = str_replace ( 'REPLACETHIS' , sns().":Maintenance&subfunction=selflinks" , $sl ) ;
174 $wgOut->addHTML( "<br />{$sl}\n" );
175
176 $sk = $wgUser->getSkin();
177 $s = '<ol start=' . ( $offset + 1 ) . '>';
178 while ( $obj = wfFetchObject( $res ) ) {
179 $title = Title::makeTitle( $obj->page_namespace, $obj->page_title );
180 $s .= "<li>".$sk->makeKnownLinkObj( $title )."</li>\n" ;
181 }
182 wfFreeResult( $res );
183 $s .= '</ol>';
184 $wgOut->addHTML( $s );
185 $wgOut->addHTML( "<p>{$sl}\n" );
186 }
187
188 /**
189 *
190 */
191 function wfSpecialMispeelings () {
192 global $wgUser, $wgOut, $wgContLang, $wgTitle;
193 $sk = $wgUser->getSkin();
194 $fname = 'wfSpecialMispeelings';
195
196 list( $limit, $offset ) = wfCheckLimits();
197 $dbr =& wfGetDB( DB_SLAVE );
198 extract( $dbr->tableNames( 'cur', 'searchindex' ) );
199
200 # Determine page name
201 $ms = wfMsg ( 'mispeelingspage' ) ;
202 $mss = str_replace ( ' ' , '_' , $ms );
203 $msp = $wgContLang->getNsText(4).':'.$ms ;
204 $msl = $sk->makeKnownLink ( $msp ) ;
205
206 # Load list from database
207 $l = $dbr->selectField( 'cur', 'cur_text', array( 'cur_title' => $mss, 'cur_namespace' => 4 ), $fname );
208 $l = explode ( "\n" , $l ) ;
209 $a = array () ;
210 foreach ( $l as $x )
211 if ( substr ( trim ( $x ) , 0 , 1 ) == '*' )
212 $a[] = strtolower ( trim ( substr ( trim ( $x ) , 1 ) ) );
213 asort ( $a ) ;
214
215 $cnt = 0 ;
216 $b = array () ;
217 foreach ( $a AS $x ) {
218 if ( $cnt < $offset+$limit && $x != '' ) {
219 $y = $x ;
220 $x = preg_replace( '/^(\S+).*$/', '$1', $x );
221 $sql = "SELECT DISTINCT cur_title FROM $cur,$searchindex WHERE cur_id=si_page AND ".
222 "cur_namespace=".NS_MAIN." AND cur_is_redirect=0 AND " .
223 "(MATCH(si_text) AGAINST ('" . $dbr->strencode( $wgContLang->stripForSearch( $x ) ) . "'))" ;
224 $res = $dbr->query( $sql, $fname );
225 while ( $obj = $dbr->fetchObject ( $res ) ) {
226 if ( $cnt >= $offset AND $cnt < $offset+$limit ) {
227 if ( $y != '' ) {
228 if ( count ( $b ) > 0 ) $b[] = "</OL>\n" ;
229 $b[] = "<H3>{$y}</H3>\n<OL start=".($cnt+1).">\n" ;
230 $y = '' ;
231 }
232 $b[] = '<li>'.
233 $sk->makeKnownLink ( $obj->cur_title ).
234 ' ('.
235 $sk->makeBrokenLink ( $obj->cur_title , wfMsg ( "qbedit" ) ).
236 ")</li>\n" ;
237 }
238 $cnt++ ;
239 }
240 }
241 }
242 $top = getMaintenancePageBacklink( 'mispeelings' );
243 $top .= "<p>".wfMsg( 'mispeelingstext', $msl )."</p><br />\n";
244 $top .= wfShowingResults( $offset, $limit );
245 $wgOut->addHTML( "<p>{$top}\n" );
246
247 $sl = wfViewPrevNext( $offset, $limit, 'REPLACETHIS' ) ;
248 $sl = str_replace ( 'REPLACETHIS' , sns().":Maintenance&subfunction=mispeelings" , $sl ) ;
249 $wgOut->addHTML( "<br />{$sl}\n" );
250
251 $s = implode ( '' , $b ) ;
252 if ( count ( $b ) > 0 ) $s .= '</ol>';
253 $wgOut->addHTML( $s );
254 $wgOut->addHTML( "<p>{$sl}\n" );
255 }
256
257 /**
258 *
259 */
260 function wfSpecialMissingLanguageLinks() {
261 global $wgUser, $wgOut, $wgContLang, $wgTitle, $wgRequest;
262
263 $fname = 'wfSpecialMissingLanguageLinks';
264 $thelang = $wgRequest->getText( 'thelang' );
265 if ( $thelang == 'w' ) $thelang = 'en' ; # Fix for international wikis
266
267 list( $limit, $offset ) = wfCheckLimits();
268 $dbr =& wfGetDB( DB_SLAVE );
269 $cur = $dbr->tableName( 'cur' );
270
271 $sql = "SELECT cur_title FROM $cur " .
272 "WHERE cur_namespace=".NS_MAIN." AND cur_is_redirect=0 " .
273 "AND cur_title NOT LIKE '%/%' AND cur_text NOT LIKE '%[[" . wfStrencode( $thelang ) . ":%' " .
274 "LIMIT {$offset}, {$limit}";
275
276 $res = $dbr->query( $sql, $fname );
277
278
279 $mll = wfMsg( 'missinglanguagelinkstext', $wgContLang->getLanguageName($thelang) );
280
281 $top = getMaintenancePageBacklink( 'missinglanguagelinks' );
282 $top .= "<p>$mll</p><br />";
283 $top .= wfShowingResults( $offset, $limit );
284 $wgOut->addHTML( "<p>{$top}\n" );
285
286 $sl = wfViewPrevNext( $offset, $limit, 'REPLACETHIS' ) ;
287 $sl = str_replace ( 'REPLACETHIS' , sns().":Maintenance&subfunction=missinglanguagelinks&thelang=".
288 htmlspecialchars($thelang), $sl ) ;
289 $wgOut->addHTML( "<br />{$sl}\n" );
290
291 $sk = $wgUser->getSkin();
292 $s = '<ol start=' . ( $offset + 1 ) . '>';
293 while ( $obj = $dbr->fetchObject( $res ) )
294 $s .= "<li>".$sk->makeKnownLink ( $obj->cur_title )."</li>\n" ;
295 $dbr->freeResult( $res );
296 $s .= '</ol>';
297 $wgOut->addHTML( $s );
298 $wgOut->addHTML( "<p>{$sl}\n" );
299 }
300
301 ?>