Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 51 |
|
0.00% |
0 / 11 |
CRAP | |
0.00% |
0 / 1 |
| SpecialUnusedTemplates | |
0.00% |
0 / 50 |
|
0.00% |
0 / 11 |
156 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| isExpensive | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| isSyndicated | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| sortDescending | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getOrderFields | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getQueryInfo | |
0.00% |
0 / 28 |
|
0.00% |
0 / 1 |
6 | |||
| preprocessResults | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| formatResult | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 | |||
| getPageHeader | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getGroupName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getRecacheDB | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Copyright © 2006 Rob Church |
| 4 | * |
| 5 | * @license GPL-2.0-or-later |
| 6 | * @file |
| 7 | */ |
| 8 | |
| 9 | namespace MediaWiki\Specials; |
| 10 | |
| 11 | use MediaWiki\Deferred\LinksUpdate\TemplateLinksTable; |
| 12 | use MediaWiki\Linker\LinksMigration; |
| 13 | use MediaWiki\Skin\Skin; |
| 14 | use MediaWiki\SpecialPage\QueryPage; |
| 15 | use MediaWiki\SpecialPage\SpecialPage; |
| 16 | use MediaWiki\Title\Title; |
| 17 | use stdClass; |
| 18 | use Wikimedia\Rdbms\IConnectionProvider; |
| 19 | |
| 20 | /** |
| 21 | * Lists of unused templates |
| 22 | * |
| 23 | * @see SpecialMostLinkedTemplates |
| 24 | * @ingroup SpecialPage |
| 25 | * @author Rob Church <robchur@gmail.com> |
| 26 | */ |
| 27 | class SpecialUnusedTemplates extends QueryPage { |
| 28 | |
| 29 | private LinksMigration $linksMigration; |
| 30 | |
| 31 | public function __construct( |
| 32 | IConnectionProvider $dbProvider, |
| 33 | LinksMigration $linksMigration |
| 34 | ) { |
| 35 | parent::__construct( 'Unusedtemplates' ); |
| 36 | $this->setDatabaseProvider( $dbProvider ); |
| 37 | $this->linksMigration = $linksMigration; |
| 38 | } |
| 39 | |
| 40 | /** @inheritDoc */ |
| 41 | public function isExpensive() { |
| 42 | return true; |
| 43 | } |
| 44 | |
| 45 | /** @inheritDoc */ |
| 46 | public function isSyndicated() { |
| 47 | return false; |
| 48 | } |
| 49 | |
| 50 | /** @inheritDoc */ |
| 51 | protected function sortDescending() { |
| 52 | return false; |
| 53 | } |
| 54 | |
| 55 | /** @inheritDoc */ |
| 56 | protected function getOrderFields() { |
| 57 | return [ 'title' ]; |
| 58 | } |
| 59 | |
| 60 | /** @inheritDoc */ |
| 61 | public function getQueryInfo() { |
| 62 | $queryInfo = $this->linksMigration->getQueryInfo( |
| 63 | 'templatelinks', |
| 64 | 'templatelinks', |
| 65 | 'LEFT JOIN' |
| 66 | ); |
| 67 | [ $ns, $title ] = $this->linksMigration->getTitleFields( 'templatelinks' ); |
| 68 | $joinConds = []; |
| 69 | $templatelinksJoin = [ |
| 70 | 'LEFT JOIN', [ "$title = page_title", |
| 71 | "$ns = page_namespace" ] ]; |
| 72 | if ( in_array( 'linktarget', $queryInfo['tables'] ) ) { |
| 73 | $joinConds['linktarget'] = $templatelinksJoin; |
| 74 | } else { |
| 75 | $joinConds['templatelinks'] = $templatelinksJoin; |
| 76 | } |
| 77 | $joinConds['page_props'] = [ 'LEFT JOIN', [ 'page_id = pp_page', 'pp_propname' => 'expectunusedtemplate' ] ]; |
| 78 | return [ |
| 79 | 'tables' => array_merge( $queryInfo['tables'], [ 'page' ], [ 'page_props' ] ), |
| 80 | 'fields' => [ |
| 81 | 'namespace' => 'page_namespace', |
| 82 | 'title' => 'page_title', |
| 83 | ], |
| 84 | 'conds' => [ |
| 85 | 'page_namespace' => NS_TEMPLATE, |
| 86 | 'tl_from' => null, |
| 87 | 'page_is_redirect' => 0, |
| 88 | 'pp_page' => null |
| 89 | ], |
| 90 | 'join_conds' => array_merge( $joinConds, $queryInfo['joins'] ) |
| 91 | ]; |
| 92 | } |
| 93 | |
| 94 | /** @inheritDoc */ |
| 95 | public function preprocessResults( $db, $res ) { |
| 96 | $this->executeLBFromResultWrapper( $res ); |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * @param Skin $skin |
| 101 | * @param stdClass $result Result row |
| 102 | * @return string |
| 103 | */ |
| 104 | public function formatResult( $skin, $result ) { |
| 105 | $linkRenderer = $this->getLinkRenderer(); |
| 106 | $title = Title::makeTitle( NS_TEMPLATE, $result->title ); |
| 107 | $pageLink = $linkRenderer->makeKnownLink( $title ); |
| 108 | $wlhLink = $linkRenderer->makeKnownLink( |
| 109 | SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedText() ), |
| 110 | $this->msg( 'unusedtemplateswlh' )->text() |
| 111 | ); |
| 112 | |
| 113 | return $this->getLanguage()->specialList( $pageLink, $wlhLink ); |
| 114 | } |
| 115 | |
| 116 | /** @inheritDoc */ |
| 117 | protected function getPageHeader() { |
| 118 | return $this->msg( 'unusedtemplatestext' )->parseAsBlock(); |
| 119 | } |
| 120 | |
| 121 | /** @inheritDoc */ |
| 122 | protected function getGroupName() { |
| 123 | return 'maintenance'; |
| 124 | } |
| 125 | |
| 126 | /** @inheritDoc */ |
| 127 | protected function getRecacheDB() { |
| 128 | return $this->getDatabaseProvider()->getReplicaDatabase( |
| 129 | TemplateLinksTable::VIRTUAL_DOMAIN, |
| 130 | 'vslow' |
| 131 | ); |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | /** |
| 136 | * Retain the old class name for backwards compatibility. |
| 137 | * @deprecated since 1.41 |
| 138 | */ |
| 139 | class_alias( SpecialUnusedTemplates::class, 'SpecialUnusedTemplates' ); |