Merge "Services: Convert DefaultPreferencesFactory's static to a const now HHVM is...
[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 * @since 1.30
183 *
184 * @param int $index Namespace ID
185 * @return bool True if this namespace either is or has a corresponding talk namespace.
186 */
187 public static function hasTalkNamespace( $index ) {
188 return MediaWikiServices::getInstance()->getNamespaceInfo()->hasTalkNamespace( $index );
189 }
190
191 /**
192 * Does this namespace contain content, for the purposes of calculating
193 * statistics, etc?
194 *
195 * @param int $index Index to check
196 * @return bool
197 */
198 public static function isContent( $index ) {
199 return MediaWikiServices::getInstance()->getNamespaceInfo()->isContent( $index );
200 }
201
202 /**
203 * Might pages in this namespace require the use of the Signature button on
204 * the edit toolbar?
205 *
206 * @param int $index Index to check
207 * @return bool
208 */
209 public static function wantSignatures( $index ) {
210 return MediaWikiServices::getInstance()->getNamespaceInfo()->wantSignatures( $index );
211 }
212
213 /**
214 * Can pages in a namespace be watched?
215 *
216 * @param int $index
217 * @return bool
218 */
219 public static function isWatchable( $index ) {
220 return MediaWikiServices::getInstance()->getNamespaceInfo()->isWatchable( $index );
221 }
222
223 /**
224 * Does the namespace allow subpages?
225 *
226 * @param int $index Index to check
227 * @return bool
228 */
229 public static function hasSubpages( $index ) {
230 return MediaWikiServices::getInstance()->getNamespaceInfo()->hasSubpages( $index );
231 }
232
233 /**
234 * Get a list of all namespace indices which are considered to contain content
235 * @return array Array of namespace indices
236 */
237 public static function getContentNamespaces() {
238 return MediaWikiServices::getInstance()->getNamespaceInfo()->getContentNamespaces();
239 }
240
241 /**
242 * List all namespace indices which are considered subject, aka not a talk
243 * or special namespace. See also MWNamespace::isSubject
244 *
245 * @return array Array of namespace indices
246 */
247 public static function getSubjectNamespaces() {
248 return MediaWikiServices::getInstance()->getNamespaceInfo()->getSubjectNamespaces();
249 }
250
251 /**
252 * List all namespace indices which are considered talks, aka not a subject
253 * or special namespace. See also MWNamespace::isTalk
254 *
255 * @return array Array of namespace indices
256 */
257 public static function getTalkNamespaces() {
258 return MediaWikiServices::getInstance()->getNamespaceInfo()->getTalkNamespaces();
259 }
260
261 /**
262 * Is the namespace first-letter capitalized?
263 *
264 * @param int $index Index to check
265 * @return bool
266 */
267 public static function isCapitalized( $index ) {
268 return MediaWikiServices::getInstance()->getNamespaceInfo()->isCapitalized( $index );
269 }
270
271 /**
272 * Does the namespace (potentially) have different aliases for different
273 * genders. Not all languages make a distinction here.
274 *
275 * @since 1.18
276 * @param int $index Index to check
277 * @return bool
278 */
279 public static function hasGenderDistinction( $index ) {
280 return MediaWikiServices::getInstance()->getNamespaceInfo()->
281 hasGenderDistinction( $index );
282 }
283
284 /**
285 * It is not possible to use pages from this namespace as template?
286 *
287 * @since 1.20
288 * @param int $index Index to check
289 * @return bool
290 */
291 public static function isNonincludable( $index ) {
292 return MediaWikiServices::getInstance()->getNamespaceInfo()->isNonincludable( $index );
293 }
294
295 /**
296 * Get the default content model for a namespace
297 * This does not mean that all pages in that namespace have the model
298 *
299 * @note To determine the default model for a new page's main slot, or any slot in general,
300 * use SlotRoleHandler::getDefaultModel() together with SlotRoleRegistry::getRoleHandler().
301 *
302 * @since 1.21
303 * @param int $index Index to check
304 * @return null|string Default model name for the given namespace, if set
305 */
306 public static function getNamespaceContentModel( $index ) {
307 return MediaWikiServices::getInstance()->getNamespaceInfo()->
308 getNamespaceContentModel( $index );
309 }
310
311 /**
312 * Determine which restriction levels it makes sense to use in a namespace,
313 * optionally filtered by a user's rights.
314 *
315 * @since 1.23
316 * @param int $index Index to check
317 * @param User|null $user User to check
318 * @return array
319 */
320 public static function getRestrictionLevels( $index, User $user = null ) {
321 return MediaWikiServices::getInstance()
322 ->getPermissionManager()
323 ->getNamespaceRestrictionLevels( $index, $user );
324 }
325
326 /**
327 * Returns the link type to be used for categories.
328 *
329 * This determines which section of a category page titles
330 * in the namespace will appear within.
331 *
332 * @since 1.32
333 * @param int $index Namespace index
334 * @return string One of 'subcat', 'file', 'page'
335 */
336 public static function getCategoryLinkType( $index ) {
337 return MediaWikiServices::getInstance()->getNamespaceInfo()->
338 getCategoryLinkType( $index );
339 }
340 }