Fix docs for MWNamespace::clearCaches() removal
[lhc/web/wiklou.git] / includes / MWNamespace.php
1 <?php
2 /**
3 * Provide things related to namespaces.
4 *
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.
9 *
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.
14 *
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
19 *
20 * @file
21 */
22 use MediaWiki\MediaWikiServices;
23
24 /**
25 * @deprecated since 1.34, use NamespaceInfo instead
26 */
27 class MWNamespace {
28 /**
29 * Can pages in the given namespace be moved?
30 *
31 * @param int $index Namespace index
32 * @return bool
33 */
34 public static function isMovable( $index ) {
35 return MediaWikiServices::getInstance()->getNamespaceInfo()->isMovable( $index );
36 }
37
38 /**
39 * Is the given namespace is a subject (non-talk) namespace?
40 *
41 * @param int $index Namespace index
42 * @return bool
43 * @since 1.19
44 */
45 public static function isSubject( $index ) {
46 return MediaWikiServices::getInstance()->getNamespaceInfo()->isSubject( $index );
47 }
48
49 /**
50 * Is the given namespace a talk namespace?
51 *
52 * @param int $index Namespace index
53 * @return bool
54 */
55 public static function isTalk( $index ) {
56 return MediaWikiServices::getInstance()->getNamespaceInfo()->isTalk( $index );
57 }
58
59 /**
60 * Get the talk namespace index for a given namespace
61 *
62 * @param int $index Namespace index
63 * @return int
64 */
65 public static function getTalk( $index ) {
66 return MediaWikiServices::getInstance()->getNamespaceInfo()->getTalk( $index );
67 }
68
69 /**
70 * Get the subject namespace index for a given namespace
71 * Special namespaces (NS_MEDIA, NS_SPECIAL) are always the subject.
72 *
73 * @param int $index Namespace index
74 * @return int
75 */
76 public static function getSubject( $index ) {
77 return MediaWikiServices::getInstance()->getNamespaceInfo()->getSubject( $index );
78 }
79
80 /**
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
84 *
85 * @param int $index Namespace index
86 * @return int|null If no associated namespace could be found
87 */
88 public static function getAssociated( $index ) {
89 return MediaWikiServices::getInstance()->getNamespaceInfo()->getAssociated( $index );
90 }
91
92 /**
93 * Returns whether the specified namespace exists
94 *
95 * @param int $index
96 *
97 * @return bool
98 * @since 1.19
99 */
100 public static function exists( $index ) {
101 return MediaWikiServices::getInstance()->getNamespaceInfo()->exists( $index );
102 }
103
104 /**
105 * Returns whether the specified namespaces are the same namespace
106 *
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.
111 *
112 * @param int $ns1 The first namespace index
113 * @param int $ns2 The second namespace index
114 *
115 * @return bool
116 * @since 1.19
117 */
118 public static function equals( $ns1, $ns2 ) {
119 return MediaWikiServices::getInstance()->getNamespaceInfo()->equals( $ns1, $ns2 );
120 }
121
122 /**
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.
126 *
127 * @param int $ns1 The first namespace index
128 * @param int $ns2 The second namespace index
129 *
130 * @return bool
131 * @since 1.19
132 */
133 public static function subjectEquals( $ns1, $ns2 ) {
134 return MediaWikiServices::getInstance()->getNamespaceInfo()->
135 subjectEquals( $ns1, $ns2 );
136 }
137
138 /**
139 * Returns array of all defined namespaces with their canonical
140 * (English) names.
141 *
142 * @return array
143 * @since 1.17
144 */
145 public static function getCanonicalNamespaces() {
146 return MediaWikiServices::getInstance()->getNamespaceInfo()->getCanonicalNamespaces();
147 }
148
149 /**
150 * Returns the canonical (English) name for a given index
151 *
152 * @param int $index Namespace index
153 * @return string|bool If no canonical definition.
154 */
155 public static function getCanonicalName( $index ) {
156 return MediaWikiServices::getInstance()->getNamespaceInfo()->getCanonicalName( $index );
157 }
158
159 /**
160 * Returns the index for a given canonical name, or NULL
161 * The input *must* be converted to lower case first
162 *
163 * @param string $name Namespace name
164 * @return int
165 */
166 public static function getCanonicalIndex( $name ) {
167 return MediaWikiServices::getInstance()->getNamespaceInfo()->getCanonicalIndex( $name );
168 }
169
170 /**
171 * Returns an array of the namespaces (by integer id) that exist on the
172 * wiki. Used primarily by the api in help documentation.
173 * @return array
174 */
175 public static function getValidNamespaces() {
176 return MediaWikiServices::getInstance()->getNamespaceInfo()->getValidNamespaces();
177 }
178
179 /**
180 * Does this namespace ever have a talk namespace?
181 *
182 * @deprecated since 1.30, use hasTalkNamespace() instead.
183 *
184 * @param int $index Namespace index
185 * @return bool True if this namespace either is or has a corresponding talk namespace.
186 */
187 public static function canTalk( $index ) {
188 wfDeprecated( __METHOD__, '1.30' );
189 return self::hasTalkNamespace( $index );
190 }
191
192 /**
193 * Does this namespace ever have a talk namespace?
194 *
195 * @since 1.30
196 *
197 * @param int $index Namespace ID
198 * @return bool True if this namespace either is or has a corresponding talk namespace.
199 */
200 public static function hasTalkNamespace( $index ) {
201 return MediaWikiServices::getInstance()->getNamespaceInfo()->hasTalkNamespace( $index );
202 }
203
204 /**
205 * Does this namespace contain content, for the purposes of calculating
206 * statistics, etc?
207 *
208 * @param int $index Index to check
209 * @return bool
210 */
211 public static function isContent( $index ) {
212 return MediaWikiServices::getInstance()->getNamespaceInfo()->isContent( $index );
213 }
214
215 /**
216 * Might pages in this namespace require the use of the Signature button on
217 * the edit toolbar?
218 *
219 * @param int $index Index to check
220 * @return bool
221 */
222 public static function wantSignatures( $index ) {
223 return MediaWikiServices::getInstance()->getNamespaceInfo()->wantSignatures( $index );
224 }
225
226 /**
227 * Can pages in a namespace be watched?
228 *
229 * @param int $index
230 * @return bool
231 */
232 public static function isWatchable( $index ) {
233 return MediaWikiServices::getInstance()->getNamespaceInfo()->isWatchable( $index );
234 }
235
236 /**
237 * Does the namespace allow subpages?
238 *
239 * @param int $index Index to check
240 * @return bool
241 */
242 public static function hasSubpages( $index ) {
243 return MediaWikiServices::getInstance()->getNamespaceInfo()->hasSubpages( $index );
244 }
245
246 /**
247 * Get a list of all namespace indices which are considered to contain content
248 * @return array Array of namespace indices
249 */
250 public static function getContentNamespaces() {
251 return MediaWikiServices::getInstance()->getNamespaceInfo()->getContentNamespaces();
252 }
253
254 /**
255 * List all namespace indices which are considered subject, aka not a talk
256 * or special namespace. See also MWNamespace::isSubject
257 *
258 * @return array Array of namespace indices
259 */
260 public static function getSubjectNamespaces() {
261 return MediaWikiServices::getInstance()->getNamespaceInfo()->getSubjectNamespaces();
262 }
263
264 /**
265 * List all namespace indices which are considered talks, aka not a subject
266 * or special namespace. See also MWNamespace::isTalk
267 *
268 * @return array Array of namespace indices
269 */
270 public static function getTalkNamespaces() {
271 return MediaWikiServices::getInstance()->getNamespaceInfo()->getTalkNamespaces();
272 }
273
274 /**
275 * Is the namespace first-letter capitalized?
276 *
277 * @param int $index Index to check
278 * @return bool
279 */
280 public static function isCapitalized( $index ) {
281 return MediaWikiServices::getInstance()->getNamespaceInfo()->isCapitalized( $index );
282 }
283
284 /**
285 * Does the namespace (potentially) have different aliases for different
286 * genders. Not all languages make a distinction here.
287 *
288 * @since 1.18
289 * @param int $index Index to check
290 * @return bool
291 */
292 public static function hasGenderDistinction( $index ) {
293 return MediaWikiServices::getInstance()->getNamespaceInfo()->
294 hasGenderDistinction( $index );
295 }
296
297 /**
298 * It is not possible to use pages from this namespace as template?
299 *
300 * @since 1.20
301 * @param int $index Index to check
302 * @return bool
303 */
304 public static function isNonincludable( $index ) {
305 return MediaWikiServices::getInstance()->getNamespaceInfo()->isNonincludable( $index );
306 }
307
308 /**
309 * Get the default content model for a namespace
310 * This does not mean that all pages in that namespace have the model
311 *
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().
314 *
315 * @since 1.21
316 * @param int $index Index to check
317 * @return null|string Default model name for the given namespace, if set
318 */
319 public static function getNamespaceContentModel( $index ) {
320 return MediaWikiServices::getInstance()->getNamespaceInfo()->
321 getNamespaceContentModel( $index );
322 }
323
324 /**
325 * Determine which restriction levels it makes sense to use in a namespace,
326 * optionally filtered by a user's rights.
327 *
328 * @since 1.23
329 * @param int $index Index to check
330 * @param User|null $user User to check
331 * @return array
332 */
333 public static function getRestrictionLevels( $index, User $user = null ) {
334 return MediaWikiServices::getInstance()->getNamespaceInfo()->
335 getRestrictionLevels( $index, $user );
336 }
337
338 /**
339 * Returns the link type to be used for categories.
340 *
341 * This determines which section of a category page titles
342 * in the namespace will appear within.
343 *
344 * @since 1.32
345 * @param int $index Namespace index
346 * @return string One of 'subcat', 'file', 'page'
347 */
348 public static function getCategoryLinkType( $index ) {
349 return MediaWikiServices::getInstance()->getNamespaceInfo()->
350 getCategoryLinkType( $index );
351 }
352 }