| 1 |
<?php |
| 2 |
|
| 3 |
h |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
namespace MediaWiki\Specials; |
| 24 |
|
| 25 |
use MediaWiki\Linker\LinksMigration; |
| 26 |
use MediaWiki\SpecialPage\QueryPage; |
| 27 |
use MediaWiki\SpecialPage\SpecialPage; |
| 28 |
use MediaWiki\Title\Title; |
| 29 |
use Skin; |
| 30 |
use stdClass; |
| 31 |
use Wikimedia\Rdbms\IConnectionProvider; |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
class SpecialUnusedTemplates extends QueryPage { |
| 41 |
|
| 42 |
private LinksMigration $linksMigration; |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
public function __construct( |
| 49 |
IConnectionProvider $dbProvider, |
| 50 |
LinksMigration $linksMigration |
| 51 |
) { |
| 52 |
parent::__construct( 'Unusedtemplates' ); |
| 53 |
$this->setDatabaseProvider( $dbProvider ); |
| 54 |
$this->linksMigration = $linksMigration; |
| 55 |
} |
| 56 |
|
| 57 |
public function isExpensive() { |
| 58 |
return true; |
| 59 |
} |
| 60 |
|
| 61 |
public function isSyndicated() { |
| 62 |
return false; |
| 63 |
} |
| 64 |
|
| 65 |
protected function sortDescending() { |
| 66 |
return false; |
| 67 |
} |
| 68 |
|
| 69 |
protected function getOrderFields() { |
| 70 |
return [ 'title' ]; |
| 71 |
} |
| 72 |
|
| 73 |
public function getQueryInfo() { |
| 74 |
$queryInfo = $this->linksMigration->getQueryInfo( |
| 75 |
'templatelinks', |
| 76 |
'templatelinks', |
| 77 |
'LEFT JOIN' |
| 78 |
); |
| 79 |
[ $ns, $title ] = $this->linksMigration->getTitleFields( 'templatelinks' ); |
| 80 |
$joinConds = []; |
| 81 |
$templatelinksJoin = [ |
| 82 |
'LEFT JOIN', [ "$title = page_title", |
| 83 |
"$ns = page_namespace" ] ]; |
| 84 |
if ( in_array( 'linktarget', $queryInfo['tables'] ) ) { |
| 85 |
$joinConds['linktarget'] = $templatelinksJoin; |
| 86 |
} else { |
| 87 |
$joinConds['templatelinks'] = $templatelinksJoin; |
| 88 |
} |
| 89 |
$joinConds['page_props'] = [ 'LEFT JOIN', [ 'page_id = pp_page', 'pp_propname' => 'expectunusedtemplate' ] ]; |
| 90 |
return [ |
| 91 |
'tables' => array_merge( $queryInfo['tables'], [ 'page' ], [ 'page_props' ] ), |
| 92 |
'fields' => [ |
| 93 |
'namespace' => 'page_namespace', |
| 94 |
'title' => 'page_title', |
| 95 |
], |
| 96 |
'conds' => [ |
| 97 |
'page_namespace' => NS_TEMPLATE, |
| 98 |
'tl_from' => null, |
| 99 |
'page_is_redirect' => 0, |
| 100 |
'pp_page' => null |
| 101 |
], |
| 102 |
'join_conds' => array_merge( $joinConds, $queryInfo['joins'] ) |
| 103 |
]; |
| 104 |
} |
| 105 |
|
| 106 |
public function preprocessResults( $db, $res ) { |
| 107 |
$this->executeLBFromResultWrapper( $res ); |
| 108 |
} |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
public function formatResult( $skin, $result ) { |
| 116 |
$linkRenderer = $this->getLinkRenderer(); |
| 117 |
$title = Title::makeTitle( NS_TEMPLATE, $result->title ); |
| 118 |
$pageLink = $linkRenderer->makeKnownLink( $title ); |
| 119 |
$wlhLink = $linkRenderer->makeKnownLink( |
| 120 |
SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedText() ), |
| 121 |
$this->msg( 'unusedtemplateswlh' )->text() |
| 122 |
); |
| 123 |
|
| 124 |
return $this->getLanguage()->specialList( $pageLink, $wlhLink ); |
| 125 |
} |
| 126 |
|
| 127 |
protected function getPageHeader() { |
| 128 |
return $this->msg( 'unusedtemplatestext' )->parseAsBlock(); |
| 129 |
} |
| 130 |
|
| 131 |
protected function getGroupName() { |
| 132 |
return 'maintenance'; |
| 133 |
} |
| 134 |
} |
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
class_alias( SpecialUnusedTemplates::class, 'SpecialUnusedTemplates' ); |