[ Index ] |
PHP Cross Reference of MediaWiki-1.24.0 |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Implements Special:Mostlinkedtemplates 4 * 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. 9 * 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. 14 * 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 19 * 20 * @file 21 * @ingroup SpecialPage 22 * @author Rob Church <[email protected]> 23 */ 24 25 /** 26 * Special page lists templates with a large number of 27 * transclusion links, i.e. "most used" templates 28 * 29 * @ingroup SpecialPage 30 */ 31 class MostlinkedTemplatesPage extends QueryPage { 32 function __construct( $name = 'Mostlinkedtemplates' ) { 33 parent::__construct( $name ); 34 } 35 36 /** 37 * Is this report expensive, i.e should it be cached? 38 * 39 * @return bool 40 */ 41 public function isExpensive() { 42 return true; 43 } 44 45 /** 46 * Is there a feed available? 47 * 48 * @return bool 49 */ 50 public function isSyndicated() { 51 return false; 52 } 53 54 /** 55 * Sort the results in descending order? 56 * 57 * @return bool 58 */ 59 public function sortDescending() { 60 return true; 61 } 62 63 public function getQueryInfo() { 64 return array( 65 'tables' => array( 'templatelinks' ), 66 'fields' => array( 67 'namespace' => 'tl_namespace', 68 'title' => 'tl_title', 69 'value' => 'COUNT(*)' 70 ), 71 'options' => array( 'GROUP BY' => array( 'tl_namespace', 'tl_title' ) ) 72 ); 73 } 74 75 /** 76 * Pre-cache page existence to speed up link generation 77 * 78 * @param DatabaseBase $db 79 * @param ResultWrapper $res 80 */ 81 public function preprocessResults( $db, $res ) { 82 if ( !$res->numRows() ) { 83 return; 84 } 85 86 $batch = new LinkBatch(); 87 foreach ( $res as $row ) { 88 $batch->add( $row->namespace, $row->title ); 89 } 90 $batch->execute(); 91 92 $res->seek( 0 ); 93 } 94 95 /** 96 * Format a result row 97 * 98 * @param Skin $skin 99 * @param object $result Result row 100 * @return string 101 */ 102 public function formatResult( $skin, $result ) { 103 $title = Title::makeTitleSafe( $result->namespace, $result->title ); 104 if ( !$title ) { 105 return Html::element( 106 'span', 107 array( 'class' => 'mw-invalidtitle' ), 108 Linker::getInvalidTitleDescription( 109 $this->getContext(), 110 $result->namespace, 111 $result->title 112 ) 113 ); 114 } 115 116 return $this->getLanguage()->specialList( 117 Linker::link( $title ), 118 $this->makeWlhLink( $title, $result ) 119 ); 120 } 121 122 /** 123 * Make a "what links here" link for a given title 124 * 125 * @param Title $title Title to make the link for 126 * @param object $result Result row 127 * @return string 128 */ 129 private function makeWlhLink( $title, $result ) { 130 $wlh = SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedText() ); 131 $label = $this->msg( 'ntransclusions' )->numParams( $result->value )->escaped(); 132 133 return Linker::link( $wlh, $label ); 134 } 135 136 protected function getGroupName() { 137 return 'highuse'; 138 } 139 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 14:03:12 2014 | Cross-referenced by PHPXref 0.7.1 |