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