Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
18.18% |
6 / 33 |
|
25.00% |
1 / 4 |
CRAP | |
0.00% |
0 / 1 |
| SpecialUncategorizedCategories | |
18.75% |
6 / 32 |
|
25.00% |
1 / 4 |
75.90 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 | |||
| getExceptionList | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
56 | |||
| getQueryInfo | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
2 | |||
| formatResult | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * @license GPL-2.0-or-later |
| 4 | * @file |
| 5 | */ |
| 6 | |
| 7 | namespace MediaWiki\Specials; |
| 8 | |
| 9 | use MediaWiki\Languages\LanguageConverterFactory; |
| 10 | use MediaWiki\Page\LinkBatchFactory; |
| 11 | use MediaWiki\Skin\Skin; |
| 12 | use MediaWiki\Title\NamespaceInfo; |
| 13 | use MediaWiki\Title\Title; |
| 14 | use stdClass; |
| 15 | use Wikimedia\Rdbms\IConnectionProvider; |
| 16 | |
| 17 | /** |
| 18 | * List of uncategorized category pages. |
| 19 | * |
| 20 | * @ingroup SpecialPage |
| 21 | */ |
| 22 | class SpecialUncategorizedCategories extends SpecialUncategorizedPages { |
| 23 | /** |
| 24 | * Holds a list of categories, which shouldn't be listed on this special page, |
| 25 | * even if it is uncategorized. |
| 26 | * @var array |
| 27 | */ |
| 28 | private $exceptionList = null; |
| 29 | |
| 30 | public function __construct( |
| 31 | NamespaceInfo $namespaceInfo, |
| 32 | IConnectionProvider $dbProvider, |
| 33 | LinkBatchFactory $linkBatchFactory, |
| 34 | LanguageConverterFactory $languageConverterFactory |
| 35 | ) { |
| 36 | parent::__construct( |
| 37 | $namespaceInfo, |
| 38 | $dbProvider, |
| 39 | $linkBatchFactory, |
| 40 | $languageConverterFactory |
| 41 | ); |
| 42 | $this->mName = 'Uncategorizedcategories'; |
| 43 | $this->requestedNamespace = NS_CATEGORY; |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Returns an array of category titles (usually without the namespace), which |
| 48 | * shouldn't be listed on this page, even if they're uncategorized. |
| 49 | * |
| 50 | * @return array |
| 51 | */ |
| 52 | private function getExceptionList() { |
| 53 | if ( $this->exceptionList === null ) { |
| 54 | $this->exceptionList = []; |
| 55 | $exList = $this->msg( 'uncategorized-categories-exceptionlist' ) |
| 56 | ->inContentLanguage()->plain(); |
| 57 | $proposedTitles = explode( "\n", $exList ); |
| 58 | foreach ( $proposedTitles as $titleStr ) { |
| 59 | if ( !str_starts_with( $titleStr, '*' ) ) { |
| 60 | continue; |
| 61 | } |
| 62 | $titleStr = preg_replace( "/^\\*\\s*/", '', $titleStr ); |
| 63 | $title = Title::newFromText( $titleStr, NS_CATEGORY ); |
| 64 | if ( $title && $title->getNamespace() !== NS_CATEGORY ) { |
| 65 | $title = Title::makeTitleSafe( NS_CATEGORY, $titleStr ); |
| 66 | } |
| 67 | if ( $title ) { |
| 68 | $this->exceptionList[] = $title->getDBkey(); |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | return $this->exceptionList; |
| 73 | } |
| 74 | |
| 75 | /** @inheritDoc */ |
| 76 | public function getQueryInfo() { |
| 77 | $query = parent::getQueryInfo(); |
| 78 | $exceptionList = $this->getExceptionList(); |
| 79 | if ( $exceptionList ) { |
| 80 | $dbr = $this->getDatabaseProvider()->getReplicaDatabase(); |
| 81 | $query['conds'][] = $dbr->expr( 'page_title', '!=', $exceptionList ); |
| 82 | } |
| 83 | |
| 84 | return $query; |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Formats the result |
| 89 | * @param Skin $skin The current skin |
| 90 | * @param stdClass $result The query result |
| 91 | * @return string The category link |
| 92 | */ |
| 93 | public function formatResult( $skin, $result ) { |
| 94 | $title = Title::makeTitle( NS_CATEGORY, $result->title ); |
| 95 | $text = $title->getText(); |
| 96 | |
| 97 | return $this->getLinkRenderer()->makeKnownLink( $title, $text ); |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Retain the old class name for backwards compatibility. |
| 103 | * @deprecated since 1.41 |
| 104 | */ |
| 105 | class_alias( SpecialUncategorizedCategories::class, 'SpecialUncategorizedCategories' ); |