Bug 1980 - Port 443 added to https / SSL URLs
[lhc/web/wiklou.git] / includes / SpecialWantedpages.php
index 3dab5de..e345703 100644 (file)
@@ -1,63 +1,73 @@
-<?
+<?php
+/**
+ *
+ * @package MediaWiki
+ * @subpackage SpecialPage
+ */
+
+/**
+ *
+ */
+require_once ( 'QueryPage.php' ) ;
+
+/**
+ *
+ * @package MediaWiki
+ * @subpackage SpecialPage
+ */
+class WantedPagesPage extends QueryPage {
+
+       function getName() {
+               return 'Wantedpages';
+       }
 
-include_once ( "LogPage.php" ) ;
+       function isExpensive() {
+               return true;
+       }
+       function isSyndicated() { return false; }
+
+       function getSQL() {
+               $dbr =& wfGetDB( DB_SLAVE );
+               $brokenlinks = $dbr->tableName( 'brokenlinks' );
+
+               # We cheat and return the full-text from bl_to in the title.
+               # In the future, a pre-parsed name will be available.
+               $agrvalue=$dbr->aggregateValue('COUNT(DISTINCT bl_from)');
+               return
+                       "SELECT 'Wantedpages' as type,
+                               0 as namespace,
+                               bl_to as title,
+                               COUNT(DISTINCT bl_from) as value
+                       FROM $brokenlinks
+                       GROUP BY bl_to
+                       HAVING $agrvalue > 1";
+       }
 
-function wfSpecialWantedpages()
-{
-       global $wgUser, $wgOut, $wgLang, $wgTitle;
-       $fname = "wfSpecialWantedpages";
+       function formatResult( $skin, $result ) {
+               global $wgContLang;
 
-       # Cache
-       $vsp = $wgLang->getValidSpecialPages() ;
-       $log = new LogPage( $vsp["Wantedpages"] );
-       $log->mUpdateRecentChanges = false;
+               $nt = Title::newFromDBkey( $result->title );
+               if( is_null( $nt ) ) {
+                       return "<!-- Bad title '" . htmlspecialchars( $result->title ) . "' -->";
+               }
+               $plink = $skin->makeBrokenLink( $nt->getPrefixedText(), "" );
+               $nl = wfMsg( "nlinks", $result->value );
+               $nlink = $skin->makeKnownLink( $wgContLang->specialPage( "Whatlinkshere" ), $nl,
+                 "target=" . $nt->getPrefixedURL() );
 
-       $wgOut->setRobotpolicy( "noindex,nofollow" );
-       global $wgMiserMode;
-       if ( $wgMiserMode ) {
-               $log->showAsDisabledPage();
-               return;
+               return "{$plink} ({$nlink})";
        }
+}
 
+/**
+ * constructor
+ */
+function wfSpecialWantedpages() {
        list( $limit, $offset ) = wfCheckLimits();
 
-       $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();
+       $wpp = new WantedPagesPage();
 
-       $top = wfShowingResults( $offset, $limit );
-       $wgOut->addHTML( "<p>{$top}\n" );
-
-       $sl = wfViewPrevNext( $offset, $limit,
-         $wgLang->specialpage( "Wantedpages" ) );
-       $wgOut->addHTML( "<br>{$sl}\n" );
-
-       $s = "<ol start=" . ( $offset + 1 ) . ">";
-       while ( $obj = wfFetchObject( $res ) ) {
-               $nt = Title::newFromDBkey( $obj->bl_to );
-
-               $plink = $sk->makeBrokenLink( $nt->getPrefixedText(), "" );
-               $nl = str_replace( "$1", $obj->nlinks, wfMsg( "nlinks" ) );
-               $nlink = $sk->makeKnownLink( $wgLang->specialPage(
-                 "Whatlinkshere" ), $nl, "target=" . $nt->getPrefixedURL() );
-
-               $cache .= "* [[".$nt->getPrefixedText()."]] ({$nl})\n" ;
-
-               $s .= "<li>{$plink} ({$nlink})</li>\n";
-       }
-       wfFreeResult( $res );
-       $s .= "</ol>";
-       $wgOut->addHTML( $s );
-       $wgOut->addHTML( "<p>{$sl}\n" );
-
-       # Saving cache
-       if ( $offset > 0 OR $limit < 50 ) return ; #Not suitable
-       $log->replaceContent( $s );
+       $wpp->doQuery( $offset, $limit );
 }
 
 ?>