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