more specific error message, using WikiError, if user trys to create account with...
[mediawiki.git] / includes / specials / SpecialMostlinked.php
blobe8d1bcddd8c777ba0021c656d47d80ca18ac3bd9
1 <?php
2 /**
3 * @file
4 * @ingroup SpecialPage
5 */
7 /**
8 * A special page to show pages ordered by the number of pages linking to them.
9 * Implements Special:Mostlinked
11 * @ingroup SpecialPage
13 * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
14 * @author Rob Church <robchur@gmail.com>
15 * @copyright Copyright © 2005, Ævar Arnfjörð Bjarmason
16 * @copyright © 2006 Rob Church
17 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
19 class MostlinkedPage extends QueryPage {
21 function getName() { return 'Mostlinked'; }
22 function isExpensive() { return true; }
23 function isSyndicated() { return false; }
25 function getSQL() {
26 $dbr = wfGetDB( DB_SLAVE );
27 list( $pagelinks, $page ) = $dbr->tableNamesN( 'pagelinks', 'page' );
28 return
29 "SELECT 'Mostlinked' AS type,
30 pl_namespace AS namespace,
31 pl_title AS title,
32 COUNT(*) AS value
33 FROM $pagelinks
34 LEFT JOIN $page ON pl_namespace=page_namespace AND pl_title=page_title
35 GROUP BY pl_namespace, pl_title
36 HAVING COUNT(*) > 1";
39 /**
40 * Pre-fill the link cache
42 function preprocessResults( $db, $res ) {
43 if( $db->numRows( $res ) > 0 ) {
44 $linkBatch = new LinkBatch();
45 while( $row = $db->fetchObject( $res ) )
46 $linkBatch->add( $row->namespace, $row->title );
47 $db->dataSeek( $res, 0 );
48 $linkBatch->execute();
52 /**
53 * Make a link to "what links here" for the specified title
55 * @param $title Title being queried
56 * @param $skin Skin to use
57 * @return string
59 function makeWlhLink( &$title, $caption, &$skin ) {
60 $wlh = SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedDBkey() );
61 return $skin->linkKnown( $wlh, $caption );
64 /**
65 * Make links to the page corresponding to the item, and the "what links here" page for it
67 * @param $skin Skin to be used
68 * @param $result Result row
69 * @return string
71 function formatResult( $skin, $result ) {
72 global $wgLang;
73 $title = Title::makeTitleSafe( $result->namespace, $result->title );
74 if ( !$title ) {
75 return '<!-- ' . htmlspecialchars( "Invalid title: [[$title]]" ) . ' -->';
77 $link = $skin->link( $title );
78 $wlh = $this->makeWlhLink( $title,
79 wfMsgExt( 'nlinks', array( 'parsemag', 'escape'),
80 $wgLang->formatNum( $result->value ) ), $skin );
81 return wfSpecialList( $link, $wlh );
85 /**
86 * constructor
88 function wfSpecialMostlinked() {
89 list( $limit, $offset ) = wfCheckLimits();
91 $wpp = new MostlinkedPage();
93 $wpp->doQuery( $offset, $limit );