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