New feature (special page): Ancient pages: list oldest articles first
[lhc/web/wiklou.git] / includes / SpecialWantedpages.php
1 <?
2
3 include_once ( "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 $log = new LogPage( $vsp["Wantedpages"] );
14 $log->mUpdateRecentChanges = false;
15
16 $wgOut->setRobotpolicy( "noindex,nofollow" );
17 global $wgMiserMode;
18 if ( $wgMiserMode ) {
19 $log->showAsDisabledPage();
20 return;
21 }
22
23 if ( ! $limit ) {
24 $limit = $wgUser->getOption( "rclimit" );
25 if ( ! $limit ) { $limit = 50; }
26 }
27 if ( ! $offset ) { $offset = 0; }
28
29 $cache = "" ; # To be saved, eventually
30
31 $sql = "SELECT bl_to, COUNT( DISTINCT bl_from ) as nlinks " .
32 "FROM brokenlinks GROUP BY bl_to HAVING nlinks > 1 " .
33 "ORDER BY nlinks DESC LIMIT {$offset}, {$limit}";
34 $res = wfQuery( $sql, $fname );
35
36 $sk = $wgUser->getSkin();
37
38 $top = wfShowingResults( $offset, $limit );
39 $wgOut->addHTML( "<p>{$top}\n" );
40
41 $sl = wfViewPrevNext( $offset, $limit,
42 $wgLang->specialpage( "Wantedpages" ) );
43 $wgOut->addHTML( "<br>{$sl}\n" );
44
45 $s = "<ol start=" . ( $offset + 1 ) . ">";
46 while ( $obj = wfFetchObject( $res ) ) {
47 $nt = Title::newFromDBkey( $obj->bl_to );
48
49 $plink = $sk->makeBrokenLink( $nt->getPrefixedText(), "" );
50 $nl = str_replace( "$1", $obj->nlinks, wfMsg( "nlinks" ) );
51 $nlink = $sk->makeKnownLink( $wgLang->specialPage(
52 "Whatlinkshere" ), $nl, "target=" . $nt->getPrefixedURL() );
53
54 $cache .= "* [[".$nt->getPrefixedText()."]] ({$nl})\n" ;
55
56 $s .= "<li>{$plink} ({$nlink})</li>\n";
57 }
58 wfFreeResult( $res );
59 $s .= "</ol>";
60 $wgOut->addHTML( $s );
61 $wgOut->addHTML( "<p>{$sl}\n" );
62
63 # Saving cache
64 if ( $offset > 0 OR $limit < 50 ) return ; #Not suitable
65 $log->replaceContent( $s );
66 }
67
68 ?>