| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
namespace MediaWiki\Specials; |
| 22 |
|
| 23 |
use MediaWiki\Cache\LinkBatchFactory; |
| 24 |
use MediaWiki\Html\Html; |
| 25 |
use MediaWiki\Linker\Linker; |
| 26 |
use MediaWiki\Linker\LinksMigration; |
| 27 |
use MediaWiki\SpecialPage\QueryPage; |
| 28 |
use MediaWiki\SpecialPage\SpecialPage; |
| 29 |
use MediaWiki\Title\Title; |
| 30 |
use Skin; |
| 31 |
use stdClass; |
| 32 |
use Wikimedia\Rdbms\IConnectionProvider; |
| 33 |
use Wikimedia\Rdbms\IDatabase; |
| 34 |
use Wikimedia\Rdbms\IResultWrapper; |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
class SpecialMostLinkedTemplates extends QueryPage { |
| 44 |
|
| 45 |
private LinksMigration $linksMigration; |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
public function __construct( |
| 53 |
IConnectionProvider $dbProvider, |
| 54 |
LinkBatchFactory $linkBatchFactory, |
| 55 |
LinksMigration $linksMigration |
| 56 |
) { |
| 57 |
parent::__construct( 'Mostlinkedtemplates' ); |
| 58 |
$this->setDatabaseProvider( $dbProvider ); |
| 59 |
$this->setLinkBatchFactory( $linkBatchFactory ); |
| 60 |
$this->linksMigration = $linksMigration; |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
public function isExpensive() { |
| 69 |
return true; |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
public function isSyndicated() { |
| 78 |
return false; |
| 79 |
} |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
public function sortDescending() { |
| 87 |
return true; |
| 88 |
} |
| 89 |
|
| 90 |
public function getQueryInfo() { |
| 91 |
$queryInfo = $this->linksMigration->getQueryInfo( 'templatelinks' ); |
| 92 |
[ $ns, $title ] = $this->linksMigration->getTitleFields( 'templatelinks' ); |
| 93 |
return [ |
| 94 |
'tables' => $queryInfo['tables'], |
| 95 |
'fields' => [ |
| 96 |
'namespace' => $ns, |
| 97 |
'title' => $title, |
| 98 |
'value' => 'COUNT(*)' |
| 99 |
], |
| 100 |
'options' => [ 'GROUP BY' => [ $ns, $title ] ], |
| 101 |
'join_conds' => $queryInfo['joins'] |
| 102 |
]; |
| 103 |
} |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
public function preprocessResults( $db, $res ) { |
| 112 |
$this->executeLBFromResultWrapper( $res ); |
| 113 |
} |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
public function formatResult( $skin, $result ) { |
| 123 |
$title = Title::makeTitleSafe( $result->namespace, $result->title ); |
| 124 |
if ( !$title ) { |
| 125 |
return Html::element( |
| 126 |
'span', |
| 127 |
[ 'class' => 'mw-invalidtitle' ], |
| 128 |
Linker::getInvalidTitleDescription( |
| 129 |
$this->getContext(), |
| 130 |
$result->namespace, |
| 131 |
$result->title |
| 132 |
) |
| 133 |
); |
| 134 |
} |
| 135 |
|
| 136 |
return $this->getLanguage()->specialList( |
| 137 |
$this->getLinkRenderer()->makeLink( $title ), |
| 138 |
$this->makeWlhLink( $title, $result ) |
| 139 |
); |
| 140 |
} |
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
private function makeWlhLink( $title, $result ) { |
| 150 |
$wlh = SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedText() ); |
| 151 |
$label = $this->msg( 'ntransclusions' )->numParams( $result->value )->text(); |
| 152 |
|
| 153 |
return $this->getLinkRenderer()->makeLink( $wlh, $label ); |
| 154 |
} |
| 155 |
|
| 156 |
protected function getGroupName() { |
| 157 |
return 'highuse'; |
| 158 |
} |
| 159 |
} |
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
class_alias( SpecialMostLinkedTemplates::class, 'SpecialMostLinkedTemplates' ); |