Initial revision
[lhc/web/wiklou.git] / includes / SpecialWantedpages.php
1 <?
2 global $IP;
3 include_once ( "$IP/LogPage.php" ) ;
4
5 function wfSpecialWantedpages()
6 {
7 global $wgUser, $wgOut, $wgLang, $wgTitle;
8 global $limit, $offset; # From query string
9 $fname = "wfSpecialWantedpages";
10
11 # Cache
12 $vsp = $wgLang->getValidSpecialPages() ;
13 $mw = $vsp["Wantedpages"] ;
14 $mw = str_replace ( " " , "_" , $mw ) ; # DBKEY
15 $log = new LogPage ( $mw ) ;
16 $log->mUpdateRecentChanges = false ;
17
18 $wgOut->setRobotpolicy( "noindex,nofollow" );
19 global $wgMiserMode;
20 if ( $wgMiserMode ) {
21 $s = "=== " . wfMsg( "perfdisabled" ) . " ===\n" ;
22 $s .= $log->getContent() ;
23 $wgOut->addWikiText ( $s ) ;
24 return;
25 }
26
27 if ( ! $limit ) {
28 $limit = $wgUser->getOption( "rclimit" );
29 if ( ! $limit ) { $limit = 50; }
30 }
31 if ( ! $offset ) { $offset = 0; }
32
33 $cache = "" ; # To be saved, eventually
34
35 $sql = "SELECT bl_to, COUNT( DISTINCT bl_from ) as nlinks " .
36 "FROM brokenlinks GROUP BY bl_to HAVING nlinks > 1 " .
37 "ORDER BY nlinks DESC LIMIT {$offset}, {$limit}";
38 $res = wfQuery( $sql, $fname );
39
40 $sk = $wgUser->getSkin();
41
42 $top = wfShowingResults( $offset, $limit );
43 $wgOut->addHTML( "<p>{$top}\n" );
44
45 $sl = wfViewPrevNext( $offset, $limit,
46 $wgLang->specialpage( "Wantedpages" ) );
47 $wgOut->addHTML( "<br>{$sl}\n" );
48
49 $s = "<ol start=" . ( $offset + 1 ) . ">";
50 while ( $obj = wfFetchObject( $res ) ) {
51 $nt = Title::newFromDBkey( $obj->bl_to );
52
53 $plink = $sk->makeBrokenLink( $nt->getPrefixedText(), "" );
54 $nl = str_replace( "$1", $obj->nlinks, wfMsg( "nlinks" ) );
55 $nlink = $sk->makeKnownLink( $wgLang->specialPage(
56 "Whatlinkshere" ), $nl, "target=" . $nt->getPrefixedURL() );
57
58 $cache .= "* [[".$nt->getPrefixedText()."]] ({$nl})\n" ;
59
60 $s .= "<li>{$plink} ({$nlink})</li>\n";
61 }
62 wfFreeResult( $res );
63 $s .= "</ol>";
64 $wgOut->addHTML( $s );
65 $wgOut->addHTML( "<p>{$sl}\n" );
66
67 # Saving cache
68 if ( $offset > 0 OR $limit < 50 ) return ; #Not suitable
69 $log->mContent = $cache ;
70 $log->mContentLoaded = true ;
71 $log->saveContent() ;
72 }
73
74 ?>