3 * Provide things related to namespaces.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
22 use MediaWiki\MediaWikiServices
;
25 * @deprecated since 1.34, use NamespaceInfo instead
29 * Can pages in the given namespace be moved?
31 * @param int $index Namespace index
34 public static function isMovable( $index ) {
35 return MediaWikiServices
::getInstance()->getNamespaceInfo()->isMovable( $index );
39 * Is the given namespace is a subject (non-talk) namespace?
41 * @param int $index Namespace index
45 public static function isSubject( $index ) {
46 return MediaWikiServices
::getInstance()->getNamespaceInfo()->isSubject( $index );
50 * Is the given namespace a talk namespace?
52 * @param int $index Namespace index
55 public static function isTalk( $index ) {
56 return MediaWikiServices
::getInstance()->getNamespaceInfo()->isTalk( $index );
60 * Get the talk namespace index for a given namespace
62 * @param int $index Namespace index
65 public static function getTalk( $index ) {
66 return MediaWikiServices
::getInstance()->getNamespaceInfo()->getTalk( $index );
70 * Get the subject namespace index for a given namespace
71 * Special namespaces (NS_MEDIA, NS_SPECIAL) are always the subject.
73 * @param int $index Namespace index
76 public static function getSubject( $index ) {
77 return MediaWikiServices
::getInstance()->getNamespaceInfo()->getSubject( $index );
81 * Get the associated namespace.
82 * For talk namespaces, returns the subject (non-talk) namespace
83 * For subject (non-talk) namespaces, returns the talk namespace
85 * @param int $index Namespace index
86 * @return int|null If no associated namespace could be found
88 public static function getAssociated( $index ) {
89 return MediaWikiServices
::getInstance()->getNamespaceInfo()->getAssociated( $index );
93 * Returns whether the specified namespace exists
100 public static function exists( $index ) {
101 return MediaWikiServices
::getInstance()->getNamespaceInfo()->exists( $index );
105 * Returns whether the specified namespaces are the same namespace
107 * @note It's possible that in the future we may start using something
108 * other than just namespace indexes. Under that circumstance making use
109 * of this function rather than directly doing comparison will make
110 * sure that code will not potentially break.
112 * @param int $ns1 The first namespace index
113 * @param int $ns2 The second namespace index
118 public static function equals( $ns1, $ns2 ) {
119 return MediaWikiServices
::getInstance()->getNamespaceInfo()->equals( $ns1, $ns2 );
123 * Returns whether the specified namespaces share the same subject.
124 * eg: NS_USER and NS_USER wil return true, as well
125 * NS_USER and NS_USER_TALK will return true.
127 * @param int $ns1 The first namespace index
128 * @param int $ns2 The second namespace index
133 public static function subjectEquals( $ns1, $ns2 ) {
134 return MediaWikiServices
::getInstance()->getNamespaceInfo()->
135 subjectEquals( $ns1, $ns2 );
139 * Returns array of all defined namespaces with their canonical
145 public static function getCanonicalNamespaces() {
146 return MediaWikiServices
::getInstance()->getNamespaceInfo()->getCanonicalNamespaces();
150 * Returns the canonical (English) name for a given index
152 * @param int $index Namespace index
153 * @return string|bool If no canonical definition.
155 public static function getCanonicalName( $index ) {
156 return MediaWikiServices
::getInstance()->getNamespaceInfo()->getCanonicalName( $index );
160 * Returns the index for a given canonical name, or NULL
161 * The input *must* be converted to lower case first
163 * @param string $name Namespace name
166 public static function getCanonicalIndex( $name ) {
167 return MediaWikiServices
::getInstance()->getNamespaceInfo()->getCanonicalIndex( $name );
171 * Returns an array of the namespaces (by integer id) that exist on the
172 * wiki. Used primarily by the api in help documentation.
175 public static function getValidNamespaces() {
176 return MediaWikiServices
::getInstance()->getNamespaceInfo()->getValidNamespaces();
180 * Does this namespace ever have a talk namespace?
182 * @deprecated since 1.30, use hasTalkNamespace() instead.
184 * @param int $index Namespace index
185 * @return bool True if this namespace either is or has a corresponding talk namespace.
187 public static function canTalk( $index ) {
188 wfDeprecated( __METHOD__
, '1.30' );
189 return self
::hasTalkNamespace( $index );
193 * Does this namespace ever have a talk namespace?
197 * @param int $index Namespace ID
198 * @return bool True if this namespace either is or has a corresponding talk namespace.
200 public static function hasTalkNamespace( $index ) {
201 return MediaWikiServices
::getInstance()->getNamespaceInfo()->hasTalkNamespace( $index );
205 * Does this namespace contain content, for the purposes of calculating
208 * @param int $index Index to check
211 public static function isContent( $index ) {
212 return MediaWikiServices
::getInstance()->getNamespaceInfo()->isContent( $index );
216 * Might pages in this namespace require the use of the Signature button on
219 * @param int $index Index to check
222 public static function wantSignatures( $index ) {
223 return MediaWikiServices
::getInstance()->getNamespaceInfo()->wantSignatures( $index );
227 * Can pages in a namespace be watched?
232 public static function isWatchable( $index ) {
233 return MediaWikiServices
::getInstance()->getNamespaceInfo()->isWatchable( $index );
237 * Does the namespace allow subpages?
239 * @param int $index Index to check
242 public static function hasSubpages( $index ) {
243 return MediaWikiServices
::getInstance()->getNamespaceInfo()->hasSubpages( $index );
247 * Get a list of all namespace indices which are considered to contain content
248 * @return array Array of namespace indices
250 public static function getContentNamespaces() {
251 return MediaWikiServices
::getInstance()->getNamespaceInfo()->getContentNamespaces();
255 * List all namespace indices which are considered subject, aka not a talk
256 * or special namespace. See also MWNamespace::isSubject
258 * @return array Array of namespace indices
260 public static function getSubjectNamespaces() {
261 return MediaWikiServices
::getInstance()->getNamespaceInfo()->getSubjectNamespaces();
265 * List all namespace indices which are considered talks, aka not a subject
266 * or special namespace. See also MWNamespace::isTalk
268 * @return array Array of namespace indices
270 public static function getTalkNamespaces() {
271 return MediaWikiServices
::getInstance()->getNamespaceInfo()->getTalkNamespaces();
275 * Is the namespace first-letter capitalized?
277 * @param int $index Index to check
280 public static function isCapitalized( $index ) {
281 return MediaWikiServices
::getInstance()->getNamespaceInfo()->isCapitalized( $index );
285 * Does the namespace (potentially) have different aliases for different
286 * genders. Not all languages make a distinction here.
289 * @param int $index Index to check
292 public static function hasGenderDistinction( $index ) {
293 return MediaWikiServices
::getInstance()->getNamespaceInfo()->
294 hasGenderDistinction( $index );
298 * It is not possible to use pages from this namespace as template?
301 * @param int $index Index to check
304 public static function isNonincludable( $index ) {
305 return MediaWikiServices
::getInstance()->getNamespaceInfo()->isNonincludable( $index );
309 * Get the default content model for a namespace
310 * This does not mean that all pages in that namespace have the model
312 * @note To determine the default model for a new page's main slot, or any slot in general,
313 * use SlotRoleHandler::getDefaultModel() together with SlotRoleRegistry::getRoleHandler().
316 * @param int $index Index to check
317 * @return null|string Default model name for the given namespace, if set
319 public static function getNamespaceContentModel( $index ) {
320 return MediaWikiServices
::getInstance()->getNamespaceInfo()->
321 getNamespaceContentModel( $index );
325 * Determine which restriction levels it makes sense to use in a namespace,
326 * optionally filtered by a user's rights.
329 * @param int $index Index to check
330 * @param User|null $user User to check
333 public static function getRestrictionLevels( $index, User
$user = null ) {
334 return MediaWikiServices
::getInstance()->getNamespaceInfo()->
335 getRestrictionLevels( $index, $user );
339 * Returns the link type to be used for categories.
341 * This determines which section of a category page titles
342 * in the namespace will appear within.
345 * @param int $index Namespace index
346 * @return string One of 'subcat', 'file', 'page'
348 public static function getCategoryLinkType( $index ) {
349 return MediaWikiServices
::getInstance()->getNamespaceInfo()->
350 getCategoryLinkType( $index );