(bug 18151) Clean up duplicate code between Special:WantedPages, WantedFiles, WantedT...
authorChad Horohoe <demon@users.mediawiki.org>
Wed, 15 Apr 2009 03:35:59 +0000 (03:35 +0000)
committerChad Horohoe <demon@users.mediawiki.org>
Wed, 15 Apr 2009 03:35:59 +0000 (03:35 +0000)
* New WantedQueryPage class for all of these Wanted*s, moved some identical methods to it
* Removed sortDescending() because it was already defined as returning true @ QueryPage, no need to duplicate

includes/AutoLoader.php
includes/QueryPage.php
includes/specials/SpecialWantedcategories.php
includes/specials/SpecialWantedfiles.php
includes/specials/SpecialWantedpages.php
includes/specials/SpecialWantedtemplates.php

index 8edefe5..12cbdab 100644 (file)
@@ -202,6 +202,7 @@ $wgAutoloadLocalClasses = array(
        'UserArrayFromResult' => 'includes/UserArray.php',
        'UserMailer' => 'includes/UserMailer.php',
        'UserRightsProxy' => 'includes/UserRightsProxy.php',
+       'WantedQueryPage' => 'includes/QueryPage.php',
        'WatchedItem' => 'includes/WatchedItem.php',
        'WatchlistEditor' => 'includes/WatchlistEditor.php',
        'WebRequest' => 'includes/WebRequest.php',
index cb33356..6d26b5f 100644 (file)
@@ -535,3 +535,73 @@ class QueryPage {
                return $title->getFullURL();
        }
 }
+
+/**
+ * Class definition for a wanted query page like
+ * WantedPages, WantedTemplates, etc
+ */
+abstract class WantedQueryPage extends QueryPage {
+
+       function isExpensive() {
+               return true;
+       }
+
+       function isSyndicated() {
+               return false;
+       }
+       
+       /**
+        * Cache page existence for performance
+        */
+       function preprocessResults( $db, $res ) {
+               $batch = new LinkBatch;
+               while ( $row = $db->fetchObject( $res ) )
+                       $batch->add( $row->namespace, $row->title );
+               $batch->execute();
+
+               // Back to start for display
+               if ( $db->numRows( $res ) > 0 )
+                       // If there are no rows we get an error seeking.
+                       $db->dataSeek( $res, 0 );
+       }
+       
+       /**
+        * Format an individual result
+        *
+        * @param $skin Skin to use for UI elements
+        * @param $result Result row
+        * @return string
+        */
+       public function formatResult( $skin, $result ) {
+               $title = Title::makeTitleSafe( $result->namespace, $result->title );
+               if( $title instanceof Title ) {
+                       if( $this->isCached() ) {
+                               $pageLink = $title->exists()
+                                       ? '<s>' . $skin->makeLinkObj( $title ) . '</s>'
+                                       : $skin->makeBrokenLinkObj( $title );
+                       } else {
+                               $pageLink = $skin->makeBrokenLinkObj( $title );
+                       }
+                       return wfSpecialList( $pageLink, $this->makeWlhLink( $title, $skin, $result ) );
+               } else {
+                       $tsafe = htmlspecialchars( $result->title );
+                       return wfMsg( 'wantedpages-badtitle', $tsafe );
+               }
+       }
+       
+       /**
+        * Make a "what links here" link for a given title
+        *
+        * @param Title $title Title to make the link for
+        * @param Skin $skin Skin to use
+        * @param object $result Result row
+        * @return string
+        */
+       private function makeWlhLink( $title, $skin, $result ) {
+               global $wgLang;
+               $wlh = SpecialPage::getTitleFor( 'Whatlinkshere' );
+               $label = wfMsgExt( 'nlinks', array( 'parsemag', 'escape' ),
+               $wgLang->formatNum( $result->value ) );
+               return $skin->link( $wlh, $label, array(), array( 'target' => $title->getPrefixedText() ) );
+       }
+}
index 7497f9b..9a28301 100644 (file)
  * @copyright Copyright © 2005, Ævar Arnfjörð Bjarmason
  * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
  */
-class WantedCategoriesPage extends QueryPage {
+class WantedCategoriesPage extends WantedQueryPage {
 
        function getName() {
                return 'Wantedcategories';
        }
 
-       function isExpensive() {
-               return true;
-       }
-
-       function isSyndicated() {
-               return false;
-       }
-
        function getSQL() {
                $dbr = wfGetDB( DB_SLAVE );
                list( $categorylinks, $page ) = $dbr->tableNamesN( 'categorylinks', 'page' );
@@ -45,23 +37,6 @@ class WantedCategoriesPage extends QueryPage {
                        ";
        }
 
-       function sortDescending() { return true; }
-
-       /**
-        * Fetch user page links and cache their existence
-        */
-       function preprocessResults( $db, $res ) {
-               $batch = new LinkBatch;
-               while ( $row = $db->fetchObject( $res ) )
-                       $batch->add( $row->namespace, $row->title );
-               $batch->execute();
-
-               // Back to start for display
-               if ( $db->numRows( $res ) > 0 )
-                       // If there are no rows we get an error seeking.
-                       $db->dataSeek( $res, 0 );
-       }
-
        function formatResult( $skin, $result ) {
                global $wgLang, $wgContLang;
 
index 4957531..189b9d8 100644 (file)
  * @copyright Copyright © 2008, Soxred93
  * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
  */
-class WantedFilesPage extends QueryPage {
+class WantedFilesPage extends WantedQueryPage {
 
        function getName() {
                return 'Wantedfiles';
        }
 
-       function isExpensive() {
-               return true;
-       }
-
-       function isSyndicated() {
-               return false;
-       }
-
        function getSQL() {
                $dbr = wfGetDB( DB_SLAVE );
                list( $imagelinks, $page ) = $dbr->tableNamesN( 'imagelinks', 'page' );
@@ -44,55 +36,6 @@ class WantedFilesPage extends QueryPage {
                        GROUP BY il_to
                        ";
        }
-
-       function sortDescending() { return true; }
-
-       /**
-        * Fetch user page links and cache their existence
-        */
-       function preprocessResults( $db, $res ) {
-               $batch = new LinkBatch;
-               while ( $row = $db->fetchObject( $res ) )
-                       $batch->add( $row->namespace, $row->title );
-               $batch->execute();
-
-               // Back to start for display
-               if ( $db->numRows( $res ) > 0 )
-                       // If there are no rows we get an error seeking.
-                       $db->dataSeek( $res, 0 );
-       }
-
-       function formatResult( $skin, $result ) {
-               global $wgLang, $wgContLang;
-
-               $nt = Title::makeTitle( $result->namespace, $result->title );
-               $text = $wgContLang->convert( $nt->getText() );
-
-               $plink = $this->isCached() ?
-                       $skin->makeLinkObj( $nt, htmlspecialchars( $text ) ) :
-                       $skin->makeBrokenLinkObj( $nt, htmlspecialchars( $text ) );
-
-               return wfSpecialList(
-                       $plink,
-                       $this->makeWlhLink( $nt, $skin, $result )
-               );
-       }
-
-       /**
-        * Make a "what links here" link for a given title
-        *
-        * @param Title $title Title to make the link for
-        * @param Skin $skin Skin to use
-        * @param object $result Result row
-        * @return string
-        */
-       private function makeWlhLink( $title, $skin, $result ) {
-               global $wgLang;
-               $wlh = SpecialPage::getTitleFor( 'Whatlinkshere' );
-               $label = wfMsgExt( 'nlinks', array( 'parsemag', 'escape' ),
-               $wgLang->formatNum( $result->value ) );
-               return $skin->link( $wlh, $label, array(), array( 'target' => $title->getPrefixedText() ) );
-       }
 }
 
 /**
index 7307b33..b7e82cf 100644 (file)
@@ -8,7 +8,7 @@
  * implements Special:Wantedpages
  * @ingroup SpecialPage
  */
-class WantedPagesPage extends QueryPage {
+class WantedPagesPage extends WantedQueryPage {
        var $nlinks;
 
        function WantedPagesPage( $inc = false, $nlinks = true ) {
@@ -20,11 +20,6 @@ class WantedPagesPage extends QueryPage {
                return 'Wantedpages';
        }
 
-       function isExpensive() {
-               return true;
-       }
-       function isSyndicated() { return false; }
-
        function getSQL() {
                global $wgWantedPagesThreshold;
                $count = $wgWantedPagesThreshold - 1;
@@ -49,66 +44,6 @@ class WantedPagesPage extends QueryPage {
                wfRunHooks( 'WantedPages::getSQL', array( &$this, &$sql ) );
                return $sql;
        }
-
-       /**
-        * Cache page existence for performance
-        */
-       function preprocessResults( $db, $res ) {
-               $batch = new LinkBatch;
-               while ( $row = $db->fetchObject( $res ) )
-                       $batch->add( $row->namespace, $row->title );
-               $batch->execute();
-
-               // Back to start for display
-               if ( $db->numRows( $res ) > 0 )
-                       // If there are no rows we get an error seeking.
-                       $db->dataSeek( $res, 0 );
-       }
-
-       /**
-        * Format an individual result
-        *
-        * @param $skin Skin to use for UI elements
-        * @param $result Result row
-        * @return string
-        */
-       public function formatResult( $skin, $result ) {
-               $title = Title::makeTitleSafe( $result->namespace, $result->title );
-               if( $title instanceof Title ) {
-                       if( $this->isCached() ) {
-                               $pageLink = $title->exists()
-                                       ? '<s>' . $skin->makeLinkObj( $title ) . '</s>'
-                                       : $skin->makeBrokenLinkObj( $title );
-                       } else {
-                               $pageLink = $skin->makeBrokenLinkObj( $title );
-                       }
-                       return wfSpecialList( $pageLink, $this->makeWlhLink( $title, $skin, $result ) );
-               } else {
-                       $tsafe = htmlspecialchars( $result->title );
-                       return wfMsg( 'wantedpages-badtitle', $tsafe );
-               }
-       }
-
-       /**
-        * Make a "what links here" link for a specified result if required
-        *
-        * @param $title Title to make the link for
-        * @param $skin Skin to use
-        * @param $result Result row
-        * @return string
-        */
-       private function makeWlhLink( $title, $skin, $result ) {
-               global $wgLang;
-               if( $this->nlinks ) {
-                       $wlh = SpecialPage::getTitleFor( 'Whatlinkshere' );
-                       $label = wfMsgExt( 'nlinks', array( 'parsemag', 'escape' ),
-                               $wgLang->formatNum( $result->value ) );
-                       return $skin->makeKnownLinkObj( $wlh, $label, 'target=' . $title->getPrefixedUrl() );
-               } else {
-                       return null;
-               }
-       }
-
 }
 
 /**
index 7dd9a26..329d7a3 100644 (file)
  * @copyright Copyright © 2008, Danny B.
  * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
  */
-class WantedTemplatesPage extends QueryPage {
+class WantedTemplatesPage extends WantedQueryPage {
 
        function getName() {
                return 'Wantedtemplates';
        }
 
-       function isExpensive() {
-               return true;
-       }
-
-       function isSyndicated() {
-               return false;
-       }
-
        function getSQL() {
                $dbr = wfGetDB( DB_SLAVE );
                list( $templatelinks, $page ) = $dbr->tableNamesN( 'templatelinks', 'page' );
@@ -45,55 +37,6 @@ class WantedTemplatesPage extends QueryPage {
                        GROUP BY tl_namespace, tl_title
                        ";
        }
-
-       function sortDescending() { return true; }
-
-       /**
-        * Fetch user page links and cache their existence
-        */
-       function preprocessResults( $db, $res ) {
-               $batch = new LinkBatch;
-               while ( $row = $db->fetchObject( $res ) )
-                       $batch->add( $row->namespace, $row->title );
-               $batch->execute();
-
-               // Back to start for display
-               if ( $db->numRows( $res ) > 0 )
-                       // If there are no rows we get an error seeking.
-                       $db->dataSeek( $res, 0 );
-       }
-
-       function formatResult( $skin, $result ) {
-               global $wgLang, $wgContLang;
-
-               $nt = Title::makeTitle( $result->namespace, $result->title );
-               $text = $wgContLang->convert( $nt->getText() );
-
-               $plink = $this->isCached() ?
-                       $skin->makeLinkObj( $nt, htmlspecialchars( $text ) ) :
-                       $skin->makeBrokenLinkObj( $nt, htmlspecialchars( $text ) );
-
-               return wfSpecialList(
-                       $plink,
-                       $this->makeWlhLink( $nt, $skin, $result )
-               );
-       }
-
-       /**
-        * Make a "what links here" link for a given title
-        *
-        * @param Title $title Title to make the link for
-        * @param Skin $skin Skin to use
-        * @param object $result Result row
-        * @return string
-        */
-       private function makeWlhLink( $title, $skin, $result ) {
-               global $wgLang;
-               $wlh = SpecialPage::getTitleFor( 'Whatlinkshere' );
-               $label = wfMsgExt( 'nlinks', array( 'parsemag', 'escape' ),
-               $wgLang->formatNum( $result->value ) );
-               return $skin->link( $wlh, $label, array(), array( 'target' => $title->getPrefixedText() ) );
-       }
 }
 
 /**