* (bug 20494) OutputPage::getArticleBodyOnly() no longer requires an useless argument
[lhc/web/wiklou.git] / includes / specials / SpecialMostlinked.php
1 <?php
2 /**
3 * @file
4 * @ingroup SpecialPage
5 */
6
7 /**
8 * A special page to show pages ordered by the number of pages linking to them.
9 * Implements Special:Mostlinked
10 *
11 * @ingroup SpecialPage
12 *
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
18 */
19 class MostlinkedPage extends QueryPage {
20
21 function getName() { return 'Mostlinked'; }
22 function isExpensive() { return true; }
23 function isSyndicated() { return false; }
24
25 /**
26 * Note: Getting page_namespace only works if $this->isCached() is false
27 */
28 function getSQL() {
29 $dbr = wfGetDB( DB_SLAVE );
30 list( $pagelinks, $page ) = $dbr->tableNamesN( 'pagelinks', 'page' );
31 return
32 "SELECT 'Mostlinked' AS type,
33 pl_namespace AS namespace,
34 pl_title AS title,
35 COUNT(*) AS value,
36 page_namespace
37 FROM $pagelinks
38 LEFT JOIN $page ON pl_namespace=page_namespace AND pl_title=page_title
39 GROUP BY pl_namespace, pl_title, page_namespace
40 HAVING COUNT(*) > 1";
41 }
42
43 /**
44 * Pre-fill the link cache
45 */
46 function preprocessResults( $db, $res ) {
47 if( $db->numRows( $res ) > 0 ) {
48 $linkBatch = new LinkBatch();
49 while( $row = $db->fetchObject( $res ) )
50 $linkBatch->add( $row->namespace, $row->title );
51 $db->dataSeek( $res, 0 );
52 $linkBatch->execute();
53 }
54 }
55
56 /**
57 * Make a link to "what links here" for the specified title
58 *
59 * @param $title Title being queried
60 * @param $skin Skin to use
61 * @return string
62 */
63 function makeWlhLink( &$title, $caption, &$skin ) {
64 $wlh = SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedDBkey() );
65 return $skin->linkKnown( $wlh, $caption );
66 }
67
68 /**
69 * Make links to the page corresponding to the item, and the "what links here" page for it
70 *
71 * @param $skin Skin to be used
72 * @param $result Result row
73 * @return string
74 */
75 function formatResult( $skin, $result ) {
76 global $wgLang;
77 $title = Title::makeTitleSafe( $result->namespace, $result->title );
78 if ( !$title ) {
79 return '<!-- ' . htmlspecialchars( "Invalid title: [[$title]]" ) . ' -->';
80 }
81 $link = $skin->link( $title );
82 $wlh = $this->makeWlhLink( $title,
83 wfMsgExt( 'nlinks', array( 'parsemag', 'escape'),
84 $wgLang->formatNum( $result->value ) ), $skin );
85 return wfSpecialList( $link, $wlh );
86 }
87 }
88
89 /**
90 * constructor
91 */
92 function wfSpecialMostlinked() {
93 list( $limit, $offset ) = wfCheckLimits();
94
95 $wpp = new MostlinkedPage();
96
97 $wpp->doQuery( $offset, $limit );
98 }