4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 * http://www.gnu.org/copyleft/gpl.html
22 * @ingroup SpecialPage
26 * A special page to show pages ordered by the number of pages linking to them.
27 * Implements Special:Mostlinked
29 * @ingroup SpecialPage
31 * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
32 * @author Rob Church <robchur@gmail.com>
33 * @copyright Copyright © 2005, Ævar Arnfjörð Bjarmason
34 * @copyright © 2006 Rob Church
35 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
37 class MostlinkedPage
extends QueryPage
{
39 function getName() { return 'Mostlinked'; }
40 function isExpensive() { return true; }
41 function isSyndicated() { return false; }
46 $dbr = wfGetDB( DB_SLAVE
);
48 # In miser mode, reduce the query cost by adding a threshold for large wikis
50 $numPages = SiteStats
::pages();
51 if ( $numPages > 10000 ) {
53 } elseif ( $numPages > 100 ) {
54 $cutoff = intval( sqrt( $numPages ) );
62 list( $pagelinks, $page ) = $dbr->tableNamesN( 'pagelinks', 'page' );
64 "SELECT 'Mostlinked' AS type,
65 pl_namespace AS namespace,
69 LEFT JOIN $page ON pl_namespace=page_namespace AND pl_title=page_title
70 GROUP BY pl_namespace, pl_title
71 HAVING COUNT(*) > $cutoff";
75 * Pre-fill the link cache
77 function preprocessResults( $db, $res ) {
78 if( $db->numRows( $res ) > 0 ) {
79 $linkBatch = new LinkBatch();
80 while( $row = $db->fetchObject( $res ) )
81 $linkBatch->add( $row->namespace, $row->title
);
82 $db->dataSeek( $res, 0 );
83 $linkBatch->execute();
88 * Make a link to "what links here" for the specified title
90 * @param $title Title being queried
91 * @param $caption String: text to display on the link
92 * @param $skin Skin to use
95 function makeWlhLink( &$title, $caption, &$skin ) {
96 $wlh = SpecialPage
::getTitleFor( 'Whatlinkshere', $title->getPrefixedDBkey() );
97 return $skin->linkKnown( $wlh, $caption );
101 * Make links to the page corresponding to the item, and the "what links here" page for it
103 * @param $skin Skin to be used
104 * @param $result Result row
107 function formatResult( $skin, $result ) {
109 $title = Title
::makeTitleSafe( $result->namespace, $result->title
);
111 return '<!-- ' . htmlspecialchars( "Invalid title: [[$title]]" ) . ' -->';
113 $link = $skin->link( $title );
114 $wlh = $this->makeWlhLink( $title,
115 wfMsgExt( 'nlinks', array( 'parsemag', 'escape'),
116 $wgLang->formatNum( $result->value
) ), $skin );
117 return wfSpecialList( $link, $wlh );
124 function wfSpecialMostlinked() {
125 list( $limit, $offset ) = wfCheckLimits();
127 $wpp = new MostlinkedPage();
129 $wpp->doQuery( $offset, $limit );