Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 51 |
|
0.00% |
0 / 8 |
CRAP | |
0.00% |
0 / 1 |
| SpecialMostCategories | |
0.00% |
0 / 50 |
|
0.00% |
0 / 8 |
110 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 4 |
|
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 | |||
| getQueryInfo | |
0.00% |
0 / 21 |
|
0.00% |
0 / 1 |
2 | |||
| getRecacheDB | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| preprocessResults | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| formatResult | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
12 | |||
| getGroupName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Copyright © 2005 Ævar Arnfjörð Bjarmason |
| 4 | * |
| 5 | * @license GPL-2.0-or-later |
| 6 | * @file |
| 7 | */ |
| 8 | |
| 9 | namespace MediaWiki\Specials; |
| 10 | |
| 11 | use MediaWiki\Deferred\LinksUpdate\CategoryLinksTable; |
| 12 | use MediaWiki\Html\Html; |
| 13 | use MediaWiki\Linker\Linker; |
| 14 | use MediaWiki\Page\LinkBatchFactory; |
| 15 | use MediaWiki\Skin\Skin; |
| 16 | use MediaWiki\SpecialPage\QueryPage; |
| 17 | use MediaWiki\Title\NamespaceInfo; |
| 18 | use MediaWiki\Title\Title; |
| 19 | use stdClass; |
| 20 | use Wikimedia\Rdbms\IConnectionProvider; |
| 21 | use Wikimedia\Rdbms\IReadableDatabase; |
| 22 | use Wikimedia\Rdbms\IResultWrapper; |
| 23 | |
| 24 | /** |
| 25 | * List of pages that have the highest category count. |
| 26 | * |
| 27 | * @ingroup SpecialPage |
| 28 | * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com> |
| 29 | */ |
| 30 | class SpecialMostCategories extends QueryPage { |
| 31 | |
| 32 | private NamespaceInfo $namespaceInfo; |
| 33 | |
| 34 | public function __construct( |
| 35 | NamespaceInfo $namespaceInfo, |
| 36 | IConnectionProvider $dbProvider, |
| 37 | LinkBatchFactory $linkBatchFactory |
| 38 | ) { |
| 39 | parent::__construct( 'Mostcategories' ); |
| 40 | $this->namespaceInfo = $namespaceInfo; |
| 41 | $this->setDatabaseProvider( $dbProvider ); |
| 42 | $this->setLinkBatchFactory( $linkBatchFactory ); |
| 43 | } |
| 44 | |
| 45 | /** @inheritDoc */ |
| 46 | public function isExpensive() { |
| 47 | return true; |
| 48 | } |
| 49 | |
| 50 | /** @inheritDoc */ |
| 51 | public function isSyndicated() { |
| 52 | return false; |
| 53 | } |
| 54 | |
| 55 | /** @inheritDoc */ |
| 56 | public function getQueryInfo() { |
| 57 | return [ |
| 58 | 'tables' => [ 'categorylinks', 'page' ], |
| 59 | 'fields' => [ |
| 60 | 'namespace' => 'page_namespace', |
| 61 | 'title' => 'page_title', |
| 62 | 'value' => 'COUNT(*)' |
| 63 | ], |
| 64 | 'conds' => [ |
| 65 | 'page_namespace' => $this->namespaceInfo->getContentNamespaces() |
| 66 | ], |
| 67 | 'options' => [ |
| 68 | 'HAVING' => 'COUNT(*) > 1', |
| 69 | 'GROUP BY' => [ 'page_namespace', 'page_title' ] |
| 70 | ], |
| 71 | 'join_conds' => [ |
| 72 | 'page' => [ |
| 73 | 'LEFT JOIN', |
| 74 | 'page_id = cl_from' |
| 75 | ] |
| 76 | ] |
| 77 | ]; |
| 78 | } |
| 79 | |
| 80 | /** @inheritDoc */ |
| 81 | protected function getRecacheDB() { |
| 82 | return $this->getDatabaseProvider()->getReplicaDatabase( |
| 83 | CategoryLinksTable::VIRTUAL_DOMAIN, |
| 84 | 'vslow' |
| 85 | ); |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * @param IReadableDatabase $db |
| 90 | * @param IResultWrapper $res |
| 91 | */ |
| 92 | public function preprocessResults( $db, $res ) { |
| 93 | $this->executeLBFromResultWrapper( $res ); |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * @param Skin $skin |
| 98 | * @param stdClass $result Result row |
| 99 | * @return string |
| 100 | */ |
| 101 | public function formatResult( $skin, $result ) { |
| 102 | $title = Title::makeTitleSafe( $result->namespace, $result->title ); |
| 103 | if ( !$title ) { |
| 104 | return Html::element( |
| 105 | 'span', |
| 106 | [ 'class' => 'mw-invalidtitle' ], |
| 107 | Linker::getInvalidTitleDescription( |
| 108 | $this->getContext(), |
| 109 | $result->namespace, |
| 110 | $result->title |
| 111 | ) |
| 112 | ); |
| 113 | } |
| 114 | |
| 115 | $linkRenderer = $this->getLinkRenderer(); |
| 116 | if ( $this->isCached() ) { |
| 117 | $link = $linkRenderer->makeLink( $title ); |
| 118 | } else { |
| 119 | $link = $linkRenderer->makeKnownLink( $title ); |
| 120 | } |
| 121 | |
| 122 | $count = $this->msg( 'ncategories' )->numParams( $result->value )->escaped(); |
| 123 | |
| 124 | return $this->getLanguage()->specialList( $link, $count ); |
| 125 | } |
| 126 | |
| 127 | /** @inheritDoc */ |
| 128 | protected function getGroupName() { |
| 129 | return 'highuse'; |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * Retain the old class name for backwards compatibility. |
| 135 | * @deprecated since 1.41 |
| 136 | */ |
| 137 | class_alias( SpecialMostCategories::class, 'SpecialMostCategories' ); |