* Fix nohistory message on empty page history
[lhc/web/wiklou.git] / includes / SpecialWantedpages.php
index 7f125f8..2f16efb 100644 (file)
@@ -1,68 +1,72 @@
-<?
-
-include_once ( "LogPage.php" ) ;
-
-function wfSpecialWantedpages()
-{
-       global $wgUser, $wgOut, $wgLang, $wgTitle;
-       global $limit, $offset; # From query string
-       $fname = "wfSpecialWantedpages";
-
-       # Cache
-       $vsp = $wgLang->getValidSpecialPages() ;
-       $log = new LogPage( $vsp["Wantedpages"] );
-       $log->mUpdateRecentChanges = false;
-
-       $wgOut->setRobotpolicy( "noindex,nofollow" );
-       global $wgMiserMode;
-       if ( $wgMiserMode ) {
-               $log->showAsDisabledPage();
-               return;
+<?php
+/**
+ *
+ * @package MediaWiki
+ * @subpackage SpecialPage
+ */
+
+/**
+ *
+ */
+require_once ( 'QueryPage.php' ) ;
+
+/**
+ *
+ * @package MediaWiki
+ * @subpackage SpecialPage
+ */
+class WantedPagesPage extends QueryPage {
+
+       function getName() {
+               return 'Wantedpages';
        }
 
-       if ( ! $limit ) {
-               $limit = $wgUser->getOption( "rclimit" );
-               if ( ! $limit ) { $limit = 50; }
+       function isExpensive() {
+               return true;
+       }
+       function isSyndicated() { return false; }
+
+       function getSQL() {
+               $dbr =& wfGetDB( DB_SLAVE );
+               $pagelinks = $dbr->tableName( 'pagelinks' );
+               $page      = $dbr->tableName( 'page' );
+               return
+                       "SELECT 'Wantedpages' AS type,
+                               pl_namespace AS namespace,
+                               pl_title AS title,
+                               COUNT(*) AS value
+                        FROM $pagelinks
+                        LEFT JOIN $page
+                        ON pl_namespace=page_namespace AND pl_title=page_title
+                        WHERE page_namespace IS NULL
+                        GROUP BY pl_namespace,pl_title
+                        HAVING COUNT(*) > 1";
        }
-       if ( ! $offset ) { $offset = 0; }
-
-       $cache = "" ; # To be saved, eventually
-
-       $sql = "SELECT bl_to, COUNT( DISTINCT bl_from ) as nlinks " .
-         "FROM brokenlinks GROUP BY bl_to HAVING nlinks > 1 " .
-         "ORDER BY nlinks DESC LIMIT {$offset}, {$limit}";
-       $res = wfQuery( $sql, $fname );
-
-       $sk = $wgUser->getSkin();
-
-       $top = wfShowingResults( $offset, $limit );
-       $wgOut->addHTML( "<p>{$top}\n" );
 
-       $sl = wfViewPrevNext( $offset, $limit,
-         $wgLang->specialpage( "Wantedpages" ) );
-       $wgOut->addHTML( "<br>{$sl}\n" );
+       function formatResult( $skin, $result ) {
+               global $wgContLang;
 
-       $s = "<ol start=" . ( $offset + 1 ) . ">";
-       while ( $obj = wfFetchObject( $res ) ) {
-               $nt = Title::newFromDBkey( $obj->bl_to );
+               $nt = Title::makeTitle( $result->namespace, $result->title );
+               $text = $wgContLang->convert( $nt->getPrefixedText() );
+               $plink = $skin->makeBrokenLink( $nt->getPrefixedText(), $text );
+               
+               $nl = wfMsg( "nlinks", $result->value );
+               $nlink = $skin->makeKnownLink( $wgContLang->specialPage( "Whatlinkshere" ), $nl,
+                 "target=" . $nt->getPrefixedURL() );
 
-               $plink = $sk->makeBrokenLink( $nt->getPrefixedText(), "" );
-               $nl = str_replace( "$1", $obj->nlinks, wfMsg( "nlinks" ) );
-               $nlink = $sk->makeKnownLink( $wgLang->specialPage(
-                 "Whatlinkshere" ), $nl, "target=" . $nt->getPrefixedURL() );
+               return "{$plink} ({$nlink})";
+       }
+}
 
-               $cache .= "* [[".$nt->getPrefixedText()."]] ({$nl})\n" ;
+/**
+ * constructor
+ */
+function wfSpecialWantedpages() {
+       list( $limit, $offset ) = wfCheckLimits();
 
-               $s .= "<li>{$plink} ({$nlink})</li>\n";
-       }
-       wfFreeResult( $res );
-       $s .= "</ol>";
-       $wgOut->addHTML( $s );
-       $wgOut->addHTML( "<p>{$sl}\n" );
+       $wpp = new WantedPagesPage();
 
-       # Saving cache
-       if ( $offset > 0 OR $limit < 50 ) return ; #Not suitable
-       $log->replaceContent( $s );
+       $wpp->doQuery( $offset, $limit );
 }
 
 ?>