typo, use variable '$name', not a constant 'name'.
[lhc/web/wiklou.git] / includes / SpecialMostlinked.php
1 <?php
2
3 /**
4 * A special page to show pages ordered by the number of pages linking to them.
5 * Implements Special:Mostlinked
6 *
7 * @addtogroup SpecialPage
8 *
9 * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
10 * @author Rob Church <robchur@gmail.com>
11 * @copyright Copyright © 2005, Ævar Arnfjörð Bjarmason
12 * @copyright © 2006 Rob Church
13 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
14 */
15 class MostlinkedPage extends QueryPage {
16
17 function getName() { return 'Mostlinked'; }
18 function isExpensive() { return true; }
19 function isSyndicated() { return false; }
20
21 /**
22 * Note: Getting page_namespace only works if $this->isCached() is false
23 */
24 function getSQL() {
25 $dbr = wfGetDB( DB_SLAVE );
26 list( $pagelinks, $page ) = $dbr->tableNamesN( 'pagelinks', 'page' );
27 return
28 "SELECT 'Mostlinked' AS type,
29 pl_namespace AS namespace,
30 pl_title AS title,
31 COUNT(*) AS value,
32 page_namespace
33 FROM $pagelinks
34 LEFT JOIN $page ON pl_namespace=page_namespace AND pl_title=page_title
35 GROUP BY 1,2,3,5
36 HAVING COUNT(*) > 1";
37 }
38
39 /**
40 * Pre-fill the link cache
41 */
42 function preprocessResults( &$db, &$res ) {
43 if( $db->numRows( $res ) > 0 ) {
44 $linkBatch = new LinkBatch();
45 while( $row = $db->fetchObject( $res ) )
46 $linkBatch->addObj( Title::makeTitleSafe( $row->namespace, $row->title ) );
47 $db->dataSeek( $res, 0 );
48 $linkBatch->execute();
49 }
50 }
51
52 /**
53 * Make a link to "what links here" for the specified title
54 *
55 * @param $title Title being queried
56 * @param $skin Skin to use
57 * @return string
58 */
59 function makeWlhLink( &$title, $caption, &$skin ) {
60 $wlh = SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedDBkey() );
61 return $skin->makeKnownLinkObj( $wlh, $caption );
62 }
63
64 /**
65 * Make links to the page corresponding to the item, and the "what links here" page for it
66 *
67 * @param $skin Skin to be used
68 * @param $result Result row
69 * @return string
70 */
71 function formatResult( $skin, $result ) {
72 global $wgLang;
73 $title = Title::makeTitleSafe( $result->namespace, $result->title );
74 $link = $skin->makeLinkObj( $title );
75 $wlh = $this->makeWlhLink( $title,
76 wfMsgExt( 'nlinks', array( 'parsemag', 'escape'),
77 $wgLang->formatNum( $result->value ) ), $skin );
78 return wfSpecialList( $link, $wlh );
79 }
80 }
81
82 /**
83 * constructor
84 */
85 function wfSpecialMostlinked() {
86 list( $limit, $offset ) = wfCheckLimits();
87
88 $wpp = new MostlinkedPage();
89
90 $wpp->doQuery( $offset, $limit );
91 }
92
93