4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 * http://www.gnu.org/copyleft/gpl.html
22 * @ingroup SpecialPage
26 * Special page lists templates with a large number of
27 * transclusion links, i.e. "most used" templates
29 * @ingroup SpecialPage
30 * @author Rob Church <robchur@gmail.com>
32 class SpecialMostlinkedtemplates
extends QueryPage
{
39 public function getName() {
40 return 'Mostlinkedtemplates';
44 * Is this report expensive, i.e should it be cached?
48 public function isExpensive() {
53 * Is there a feed available?
57 public function isSyndicated() {
62 * Sort the results in descending order?
66 public function sortDescending() {
71 * Generate SQL for the report
75 public function getSql() {
76 $dbr = wfGetDB( DB_SLAVE
);
77 $templatelinks = $dbr->tableName( 'templatelinks' );
78 $name = $dbr->addQuotes( $this->getName() );
79 return "SELECT {$name} AS type,
80 " . NS_TEMPLATE
. " AS namespace,
84 WHERE tl_namespace = " . NS_TEMPLATE
. "
89 * Pre-cache page existence to speed up link generation
91 * @param $db Database connection
92 * @param $res ResultWrapper
94 public function preprocessResults( $db, $res ) {
95 $batch = new LinkBatch();
96 while( $row = $db->fetchObject( $res ) ) {
97 $batch->add( $row->namespace, $row->title
);
100 if( $db->numRows( $res ) > 0 )
101 $db->dataSeek( $res, 0 );
105 * Format a result row
107 * @param $skin Skin to use for UI elements
108 * @param $result Result row
111 public function formatResult( $skin, $result ) {
112 $title = Title
::makeTitleSafe( $result->namespace, $result->title
);
114 return wfSpecialList(
115 $skin->link( $title ),
116 $this->makeWlhLink( $title, $skin, $result )
121 * Make a "what links here" link for a given title
123 * @param $title Title to make the link for
124 * @param $skin Skin to use
125 * @param $result Result row
128 private function makeWlhLink( $title, $skin, $result ) {
130 $wlh = SpecialPage
::getTitleFor( 'Whatlinkshere' );
131 $label = wfMsgExt( 'nlinks', array( 'parsemag', 'escape' ),
132 $wgLang->formatNum( $result->value
) );
133 return $skin->link( $wlh, $label, array(), array( 'target' => $title->getPrefixedText() ) );
140 * @param $par Mixed: parameters passed to the page
142 function wfSpecialMostlinkedtemplates( $par = false ) {
143 list( $limit, $offset ) = wfCheckLimits();
144 $mlt = new SpecialMostlinkedtemplates();
145 $mlt->doQuery( $offset, $limit );