MediaWiki  master
SpecialUncategorizedCategories.php
Go to the documentation of this file.
1 <?php
24 namespace MediaWiki\Specials;
25 
30 use Skin;
31 use stdClass;
33 
45  private $exceptionList = null;
46 
53  public function __construct(
54  NamespaceInfo $namespaceInfo,
55  IConnectionProvider $dbProvider,
56  LinkBatchFactory $linkBatchFactory,
57  LanguageConverterFactory $languageConverterFactory
58  ) {
59  parent::__construct(
60  $namespaceInfo,
61  $dbProvider,
62  $linkBatchFactory,
63  $languageConverterFactory
64  );
65  $this->mName = 'Uncategorizedcategories';
66  $this->requestedNamespace = NS_CATEGORY;
67  }
68 
75  private function getExceptionList() {
76  if ( $this->exceptionList === null ) {
77  $this->exceptionList = [];
78  $exList = $this->msg( 'uncategorized-categories-exceptionlist' )
79  ->inContentLanguage()->plain();
80  $proposedTitles = explode( "\n", $exList );
81  foreach ( $proposedTitles as $titleStr ) {
82  if ( !str_starts_with( $titleStr, '*' ) ) {
83  continue;
84  }
85  $titleStr = preg_replace( "/^\\*\\s*/", '', $titleStr );
86  $title = Title::newFromText( $titleStr, NS_CATEGORY );
87  if ( $title && $title->getNamespace() !== NS_CATEGORY ) {
88  $title = Title::makeTitleSafe( NS_CATEGORY, $titleStr );
89  }
90  if ( $title ) {
91  $this->exceptionList[] = $title->getDBkey();
92  }
93  }
94  }
95  return $this->exceptionList;
96  }
97 
98  public function getQueryInfo() {
99  $query = parent::getQueryInfo();
100  $exceptionList = $this->getExceptionList();
101  if ( $exceptionList ) {
102  $dbr = $this->getDatabaseProvider()->getReplicaDatabase();
103  $query['conds'][] = 'page_title not in ( ' . $dbr->makeList( $exceptionList ) . ' )';
104  }
105 
106  return $query;
107  }
108 
115  public function formatResult( $skin, $result ) {
116  $title = Title::makeTitle( NS_CATEGORY, $result->title );
117  $text = $title->getText();
118 
119  return $this->getLinkRenderer()->makeKnownLink( $title, $text );
120  }
121 }
122 
127 class_alias( SpecialUncategorizedCategories::class, 'SpecialUncategorizedCategories' );
const NS_CATEGORY
Definition: Defines.php:78
An interface for creating language converters.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
A special page that lists uncategorized categories.
__construct(NamespaceInfo $namespaceInfo, IConnectionProvider $dbProvider, LinkBatchFactory $linkBatchFactory, LanguageConverterFactory $languageConverterFactory)
getQueryInfo()
Subclasses return an SQL query here, formatted as an array with the following keys: tables => Table(s...
A special page looking for page without any category.
This is a utility class for dealing with namespaces that encodes all the "magic" behaviors of them ba...
Represents a title within MediaWiki.
Definition: Title.php:76
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:400
static makeTitleSafe( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:650
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:624
The base class for all skins.
Definition: Skin.php:60
Provide primary and replica IDatabase connections.