wiki.techinc.nl/includes/specials/SpecialMostlinked.php

105 lines
3.1 KiB
PHP
Raw Normal View History

2005-08-15 02:57:19 +00:00
<?php
2010-06-21 12:59:04 +00:00
/**
* Implements Special:Mostlinked
*
* Copyright © 2005 Ævar Arnfjörð Bjarmason, 2006 Rob Church
2010-06-21 12:59:04 +00:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2010-06-21 12:59:04 +00:00
* http://www.gnu.org/copyleft/gpl.html
*
* @file
* @ingroup SpecialPage
* @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
* @author Rob Church <robchur@gmail.com>
*/
2005-08-15 02:57:19 +00:00
/**
* A special page to show pages ordered by the number of pages linking to them.
2005-08-15 02:57:19 +00:00
*
* @ingroup SpecialPage
2005-08-15 02:57:19 +00:00
*/
class MostlinkedPage extends QueryPage {
function __construct( $name = 'Mostlinked' ) {
parent::__construct( $name );
}
2005-09-13 17:33:33 +00:00
function isExpensive() { return true; }
2005-08-15 02:57:19 +00:00
function isSyndicated() { return false; }
function getQueryInfo() {
return array (
'tables' => array ( 'pagelinks', 'page' ),
'fields' => array ( 'pl_namespace AS namespace',
'pl_title AS title',
'COUNT(*) AS value',
'page_namespace' ),
'options' => array ( 'HAVING' => 'COUNT(*) > 1',
'GROUP BY' => 'pl_namespace, pl_title, '.
'page_namespace' ),
'join_conds' => array ( 'page' => array ( 'LEFT JOIN',
array ( 'page_namespace = pl_namespace',
'page_title = pl_title' ) ) )
);
2005-08-15 02:57:19 +00:00
}
/**
* Pre-fill the link cache
*/
function preprocessResults( $db, $res ) {
2006-12-16 21:53:34 +00:00
if( $db->numRows( $res ) > 0 ) {
$linkBatch = new LinkBatch();
foreach ( $res as $row ) {
2008-03-15 10:46:28 +00:00
$linkBatch->add( $row->namespace, $row->title );
}
2006-12-16 21:53:34 +00:00
$db->dataSeek( $res, 0 );
$linkBatch->execute();
}
}
2006-01-07 13:31:29 +00:00
/**
* Make a link to "what links here" for the specified title
*
* @param $title Title being queried
2010-02-08 20:41:05 +00:00
* @param $caption String: text to display on the link
* @param $skin Skin to use
2010-02-08 20:41:05 +00:00
* @return String
*/
function makeWlhLink( &$title, $caption, &$skin ) {
$wlh = SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedDBkey() );
return $skin->linkKnown( $wlh, $caption );
}
2005-08-15 02:57:19 +00:00
/**
* 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 ) {
2006-05-08 18:17:55 +00:00
global $wgLang;
$title = Title::makeTitleSafe( $result->namespace, $result->title );
if ( !$title ) {
return '<!-- ' . htmlspecialchars( "Invalid title: [[$title]]" ) . ' -->';
}
$link = $skin->link( $title );
2006-05-14 17:44:15 +00:00
$wlh = $this->makeWlhLink( $title,
wfMsgExt( 'nlinks', array( 'parsemag', 'escape'),
$wgLang->formatNum( $result->value ) ), $skin );
return wfSpecialList( $link, $wlh );
2005-08-15 02:57:19 +00:00
}
}