Page MenuHomePhabricator

Mostlinkedredirects.patch

Authored By
bzimport
Nov 21 2014, 9:51 PM
Size
7 KB
Referenced Files
None
Subscribers
None

Mostlinkedredirects.patch

Index: maintenance/language/messages.inc
===================================================================
--- maintenance/language/messages.inc (revision 31239)
+++ maintenance/language/messages.inc (working copy)
@@ -1070,6 +1070,8 @@
'mostlinked-summary',
'mostlinkedcategories',
'mostlinkedcategories-summary',
+ 'mostlinkedredirects',
+ 'mostlinkedredirects-summary',
'mostlinkedtemplates',
'mostlinkedtemplates-summary',
'mostcategories',
Index: maintenance/language/messageTypes.inc
===================================================================
--- maintenance/language/messageTypes.inc (revision 31239)
+++ maintenance/language/messageTypes.inc (working copy)
@@ -139,6 +139,7 @@
'wantedpages-summary',
'mostlinked-summary',
'mostlinkedcategories-summary',
+ 'mostlinkedredirects-summary',
'mostlinkedtemplates-summary',
'mostcategories-summary',
'mostimages-summary',
Index: includes/SpecialMostlinkedredirects.php
===================================================================
--- includes/SpecialMostlinkedredirects.php (revision 0)
+++ includes/SpecialMostlinkedredirects.php (revision 0)
@@ -0,0 +1,92 @@
+<?php
+
+/**
+ * A special page to show redirects ordered by the number of pages linking to them.
+ * Implements Special:Mostlinked
+ *
+ * @addtogroup SpecialPage
+ *
+ * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
+ * @author Rob Church <robchur@gmail.com>
+ * @author Oldak Quill <oldakquill@gmail.com>
+ * @copyright Copyright © 2005, Ævar Arnfjörð Bjarmason
+ * @copyright © 2006 Rob Church
+ * @copyright © 2008 Oldak Quill
+ * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
+ */
+class MostlinkedRedirectsPage extends QueryPage {
+
+ function getName() { return 'Mostlinkedredirects'; }
+ function isExpensive() { return true; }
+ function isSyndicated() { return false; }
+
+ /**
+ * Note: Getting redirect_namespace only works if $this->isCached() is false
+ */
+ function getSQL() {
+ $dbr = wfGetDB( DB_SLAVE );
+ list( $pagelinks, $redirect ) = $dbr->tableNamesN( 'pagelinks', 'redirect' );
+ return
+ "SELECT 'Mostlinkedredirects' AS type,
+ pl_namespace AS namespace,
+ pl_title AS title,
+ COUNT(*) AS value
+ FROM $pagelinks
+ LEFT JOIN $redirect ON pl_namespace=rd_namespace AND pl_title=rd_title
+ GROUP BY 1,2,3
+ HAVING COUNT(*) > 1";
+ }
+
+ /**
+ * Pre-fill the link cache
+ */
+ function preprocessResults( &$db, &$res ) {
+ if( $db->numRows( $res ) > 0 ) {
+ $linkBatch = new LinkBatch();
+ while( $row = $db->fetchObject( $res ) )
+ $linkBatch->addObj( Title::makeTitleSafe( $row->namespace, $row->title ) );
+ $db->dataSeek( $res, 0 );
+ $linkBatch->execute();
+ }
+ }
+
+ /**
+ * Make a link to "what links here" for the specified title
+ *
+ * @param $title Title being queried
+ * @param $skin Skin to use
+ * @return string
+ */
+ function makeWlhLink( &$title, $caption, &$skin ) {
+ $wlh = SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedDBkey() );
+ return $skin->makeKnownLinkObj( $wlh, $caption );
+ }
+
+ /**
+ * Make links to the page corresponding to the item, and the "what links here" page for it
+ *
+ * @param $skin Skin to be used
+ * @param $result Result row
+ * @return string
+ */
+ function formatResult( $skin, $result ) {
+ global $wgLang;
+ $title = Title::makeTitleSafe( $result->namespace, $result->title );
+ $link = $skin->makeLinkObj( $title );
+ $wlh = $this->makeWlhLink( $title,
+ wfMsgExt( 'nlinks', array( 'parsemag', 'escape'),
+ $wgLang->formatNum( $result->value ) ), $skin );
+ return wfSpecialList( $link, $wlh );
+ }
+}
+
+/**
+ * constructor
+ */
+function wfSpecialMostlinkedredirects() {
+ list( $limit, $offset ) = wfCheckLimits();
+
+ $wpp = new MostlinkedRedirectsPage();
+
+ $wpp->doQuery( $offset, $limit );
+}
Index: includes/AutoLoader.php
===================================================================
--- includes/AutoLoader.php (revision 31239)
+++ includes/AutoLoader.php (working copy)
@@ -211,6 +211,7 @@
'MostimagesPage' => 'includes/SpecialMostimages.php',
'MostlinkedPage' => 'includes/SpecialMostlinked.php',
'MostlinkedCategoriesPage' => 'includes/SpecialMostlinkedcategories.php',
+ 'MostlinkedRedirectsPage' => 'includes/SpecialMostlinkedredirects.php',
'SpecialMostlinkedtemplates' => 'includes/SpecialMostlinkedtemplates.php',
'MostrevisionsPage' => 'includes/SpecialMostrevisions.php',
'FewestrevisionsPage' => 'includes/SpecialFewestrevisions.php',
Index: includes/QueryPage.php
===================================================================
--- includes/QueryPage.php (revision 31239)
+++ includes/QueryPage.php (working copy)
@@ -25,6 +25,7 @@
array( 'MostcategoriesPage', 'Mostcategories' ),
array( 'MostimagesPage', 'Mostimages' ),
array( 'MostlinkedCategoriesPage', 'Mostlinkedcategories' ),
+ array( 'MostlinkedRedirectsPage', 'Mostlinkedredirects' ),
array( 'SpecialMostlinkedtemplates', 'Mostlinkedtemplates' ),
array( 'MostlinkedPage', 'Mostlinked' ),
array( 'MostrevisionsPage', 'Mostrevisions' ),
Index: includes/SpecialPage.php
===================================================================
--- includes/SpecialPage.php (revision 31239)
+++ includes/SpecialPage.php (working copy)
@@ -103,6 +103,7 @@
'Mostlinked' => array( 'SpecialPage', 'Mostlinked' ),
'Mostlinkedcategories' => array( 'SpecialPage', 'Mostlinkedcategories' ),
'Mostlinkedtemplates' => array( 'SpecialPage', 'Mostlinkedtemplates' ),
+ 'Mostlinkedredirects' => array( 'SpecialPage', 'Mostlinkedredirects' ),
'Mostcategories' => array( 'SpecialPage', 'Mostcategories' ),
'Mostimages' => array( 'SpecialPage', 'Mostimages' ),
'Mostrevisions' => array( 'SpecialPage', 'Mostrevisions' ),
Index: languages/messages/MessagesEn.php
===================================================================
--- languages/messages/MessagesEn.php (revision 31239)
+++ languages/messages/MessagesEn.php (working copy)
@@ -375,6 +375,7 @@
'Wantedcategories' => array( 'Wantedcategories' ),
'Mostlinked' => array( 'Mostlinked' ),
'Mostlinkedcategories' => array( 'Mostlinkedcategories' ),
+ 'Mostlinkedredirects' => array( 'Mostlinkedredirects' ),
'Mostlinkedtemplates' => array( 'Mostlinkedtemplates' ),
'Mostcategories' => array( 'Mostcategories' ),
'Mostimages' => array( 'Mostimages' ),
@@ -1661,6 +1662,8 @@
'mostlinked-summary' => '', # only translate this message to other languages if you have to change it
'mostlinkedcategories' => 'Most linked to categories',
'mostlinkedcategories-summary' => '', # only translate this message to other languages if you have to change it
+'mostlinkedredirects' => 'Most linked to redirects',
+'mostlinkedredirects-summary' => '', # only translate this message to other languages if you have to change it
'mostlinkedtemplates' => 'Most linked-to templates',
'mostlinkedtemplates-summary' => '', # only translate this message to other languages if you have to change it
'mostcategories' => 'Pages with the most categories',

File Metadata

Mime Type
text/x-diff
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3669
Default Alt Text
Mostlinkedredirects.patch (7 KB)

Event Timeline