]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - includes/specials/SpecialMostlinkedtemplates.php
MediaWiki 1.15.4-scripts
[autoinstallsdev/mediawiki.git] / includes / specials / SpecialMostlinkedtemplates.php
1 <?php
2 /**
3  * @file
4  * @ingroup SpecialPage
5  */
6  
7 /**
8  * Special page lists templates with a large number of
9  * transclusion links, i.e. "most used" templates
10  *
11  * @ingroup SpecialPage
12  * @author Rob Church <robchur@gmail.com>
13  */
14 class SpecialMostlinkedtemplates extends QueryPage {
15
16         /**
17          * Name of the report
18          *
19          * @return string
20          */
21         public function getName() {
22                 return 'Mostlinkedtemplates';
23         }
24
25         /**
26          * Is this report expensive, i.e should it be cached?
27          *
28          * @return bool
29          */
30         public function isExpensive() {
31                 return true;
32         }
33
34         /**
35          * Is there a feed available?
36          *
37          * @return bool
38          */
39         public function isSyndicated() {
40                 return false;
41         }
42
43         /**
44          * Sort the results in descending order?
45          *
46          * @return bool
47          */
48         public function sortDescending() {
49                 return true;
50         }
51
52         /**
53          * Generate SQL for the report
54          *
55          * @return string
56          */
57         public function getSql() {
58                 $dbr = wfGetDB( DB_SLAVE );
59                 $templatelinks = $dbr->tableName( 'templatelinks' );
60                 $name = $dbr->addQuotes( $this->getName() );
61                 return "SELECT {$name} AS type,
62                         " . NS_TEMPLATE . " AS namespace,
63                         tl_title AS title,
64                         COUNT(*) AS value
65                         FROM {$templatelinks}
66                         WHERE tl_namespace = " . NS_TEMPLATE . "
67                         GROUP BY tl_title";
68         }
69
70         /**
71          * Pre-cache page existence to speed up link generation
72          *
73          * @param Database $dbr Database connection
74          * @param int $res Result pointer
75          */
76         public function preprocessResults( $db, $res ) {
77                 $batch = new LinkBatch();
78                 while( $row = $db->fetchObject( $res ) ) {
79                         $batch->add( $row->namespace, $row->title );
80                 }
81                 $batch->execute();
82                 if( $db->numRows( $res ) > 0 )
83                         $db->dataSeek( $res, 0 );
84         }
85
86         /**
87          * Format a result row
88          *
89          * @param Skin $skin Skin to use for UI elements
90          * @param object $result Result row
91          * @return string
92          */
93         public function formatResult( $skin, $result ) {
94                 $title = Title::makeTitleSafe( $result->namespace, $result->title );
95
96                 $skin->link( $title );
97                 return wfSpecialList(
98                         $skin->makeLinkObj( $title ),
99                         $this->makeWlhLink( $title, $skin, $result )
100                 );
101         }
102
103         /**
104          * Make a "what links here" link for a given title
105          *
106          * @param Title $title Title to make the link for
107          * @param Skin $skin Skin to use
108          * @param object $result Result row
109          * @return string
110          */
111         private function makeWlhLink( $title, $skin, $result ) {
112                 global $wgLang;
113                 $wlh = SpecialPage::getTitleFor( 'Whatlinkshere' );
114                 $label = wfMsgExt( 'nlinks', array( 'parsemag', 'escape' ),
115                 $wgLang->formatNum( $result->value ) );
116                 return $skin->link( $wlh, $label, array(), array( 'target' => $title->getPrefixedText() ) );
117         }
118 }
119
120 /**
121  * Execution function
122  *
123  * @param mixed $par Parameters passed to the page
124  */
125 function wfSpecialMostlinkedtemplates( $par = false ) {
126         list( $limit, $offset ) = wfCheckLimits();
127         $mlt = new SpecialMostlinkedtemplates();
128         $mlt->doQuery( $offset, $limit );
129 }