Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
45.45% |
20 / 44 |
|
36.36% |
4 / 11 |
CRAP | |
0.00% |
0 / 1 |
| SpecialMostLinkedTemplates | |
45.45% |
20 / 44 |
|
36.36% |
4 / 11 |
35.37 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| isExpensive | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| isSyndicated | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| sortDescending | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getQueryInfo | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
1 | |||
| preprocessResults | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| formatResult | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
6 | |||
| makeWlhLink | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| execute | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| getGroupName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getRecacheDB | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * @license GPL-2.0-or-later |
| 4 | * @file |
| 5 | */ |
| 6 | |
| 7 | namespace MediaWiki\Specials; |
| 8 | |
| 9 | use MediaWiki\Deferred\LinksUpdate\TemplateLinksTable; |
| 10 | use MediaWiki\Html\Html; |
| 11 | use MediaWiki\Linker\Linker; |
| 12 | use MediaWiki\Linker\LinksMigration; |
| 13 | use MediaWiki\Page\LinkBatchFactory; |
| 14 | use MediaWiki\Skin\Skin; |
| 15 | use MediaWiki\SpecialPage\QueryPage; |
| 16 | use MediaWiki\SpecialPage\SpecialPage; |
| 17 | use MediaWiki\Title\Title; |
| 18 | use stdClass; |
| 19 | use Wikimedia\Rdbms\IConnectionProvider; |
| 20 | use Wikimedia\Rdbms\IReadableDatabase; |
| 21 | use Wikimedia\Rdbms\IResultWrapper; |
| 22 | |
| 23 | /** |
| 24 | * List of templates with a large number of transclusion links, |
| 25 | * i.e. "most used" templates |
| 26 | * |
| 27 | * @ingroup SpecialPage |
| 28 | * @author Rob Church <robchur@gmail.com> |
| 29 | */ |
| 30 | class SpecialMostLinkedTemplates extends QueryPage { |
| 31 | |
| 32 | public function __construct( |
| 33 | IConnectionProvider $dbProvider, |
| 34 | LinkBatchFactory $linkBatchFactory, |
| 35 | private readonly LinksMigration $linksMigration, |
| 36 | ) { |
| 37 | parent::__construct( 'Mostlinkedtemplates' ); |
| 38 | $this->setDatabaseProvider( $dbProvider ); |
| 39 | $this->setLinkBatchFactory( $linkBatchFactory ); |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Is this report expensive, i.e should it be cached? |
| 44 | * |
| 45 | * @return bool |
| 46 | */ |
| 47 | public function isExpensive() { |
| 48 | return true; |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Is there a feed available? |
| 53 | * |
| 54 | * @return bool |
| 55 | */ |
| 56 | public function isSyndicated() { |
| 57 | return false; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Sort the results in descending order? |
| 62 | * |
| 63 | * @return bool |
| 64 | */ |
| 65 | public function sortDescending() { |
| 66 | return true; |
| 67 | } |
| 68 | |
| 69 | /** @inheritDoc */ |
| 70 | public function getQueryInfo() { |
| 71 | $queryInfo = $this->linksMigration->getQueryInfo( 'templatelinks' ); |
| 72 | [ $ns, $title ] = $this->linksMigration->getTitleFields( 'templatelinks' ); |
| 73 | return [ |
| 74 | 'tables' => $queryInfo['tables'], |
| 75 | 'fields' => [ |
| 76 | 'namespace' => $ns, |
| 77 | 'title' => $title, |
| 78 | 'value' => 'COUNT(*)' |
| 79 | ], |
| 80 | 'options' => [ 'GROUP BY' => [ $ns, $title ] ], |
| 81 | 'join_conds' => $queryInfo['joins'] |
| 82 | ]; |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Pre-cache page existence to speed up link generation |
| 87 | * |
| 88 | * @param IReadableDatabase $db |
| 89 | * @param IResultWrapper $res |
| 90 | */ |
| 91 | public function preprocessResults( $db, $res ) { |
| 92 | $this->executeLBFromResultWrapper( $res ); |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Format a result row |
| 97 | * |
| 98 | * @param Skin $skin |
| 99 | * @param stdClass $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 | [ '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 | $this->getLinkRenderer()->makeLink( $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 stdClass $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 )->text(); |
| 132 | |
| 133 | return $this->getLinkRenderer()->makeLink( $wlh, $label ); |
| 134 | } |
| 135 | |
| 136 | /** @inheritDoc */ |
| 137 | public function execute( $par ) { |
| 138 | $this->getOutput()->addModuleStyles( 'mediawiki.special' ); |
| 139 | parent::execute( $par ); |
| 140 | } |
| 141 | |
| 142 | /** @inheritDoc */ |
| 143 | protected function getGroupName() { |
| 144 | return 'highuse'; |
| 145 | } |
| 146 | |
| 147 | /** @inheritDoc */ |
| 148 | protected function getRecacheDB() { |
| 149 | return $this->getDatabaseProvider()->getReplicaDatabase( |
| 150 | TemplateLinksTable::VIRTUAL_DOMAIN, |
| 151 | 'vslow' |
| 152 | ); |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | // @codeCoverageIgnoreStart |
| 157 | /** |
| 158 | * Retain the old class name for backwards compatibility. |
| 159 | * @deprecated since 1.41 |
| 160 | */ |
| 161 | class_alias( SpecialMostLinkedTemplates::class, 'SpecialMostLinkedTemplates' ); |
| 162 | // @codeCoverageIgnoreEnd |