Completed
Branch master (246348)
by
unknown
22:34
created

SpecialPage::maxIncludeCacheTime()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
nc 2
nop 0
dl 0
loc 3
rs 10
c 2
b 0
f 0
1
<?php
2
use MediaWiki\MediaWikiServices;
3
4
/**
5
 * Parent class for all special pages.
6
 *
7
 * This program is free software; you can redistribute it and/or modify
8
 * it under the terms of the GNU General Public License as published by
9
 * the Free Software Foundation; either version 2 of the License, or
10
 * (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License along
18
 * with this program; if not, write to the Free Software Foundation, Inc.,
19
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
 * http://www.gnu.org/copyleft/gpl.html
21
 *
22
 * @file
23
 * @ingroup SpecialPage
24
 */
25
26
use MediaWiki\Auth\AuthManager;
27
28
/**
29
 * Parent class for all special pages.
30
 *
31
 * Includes some static functions for handling the special page list deprecated
32
 * in favor of SpecialPageFactory.
33
 *
34
 * @ingroup SpecialPage
35
 */
36
class SpecialPage {
37
	// The canonical name of this special page
38
	// Also used for the default <h1> heading, @see getDescription()
39
	protected $mName;
40
41
	// The local name of this special page
42
	private $mLocalName;
43
44
	// Minimum user level required to access this page, or "" for anyone.
45
	// Also used to categorise the pages in Special:Specialpages
46
	protected $mRestriction;
47
48
	// Listed in Special:Specialpages?
49
	private $mListed;
50
51
	// Whether or not this special page is being included from an article
52
	protected $mIncluding;
53
54
	// Whether the special page can be included in an article
55
	protected $mIncludable;
56
57
	/**
58
	 * Current request context
59
	 * @var IContextSource
60
	 */
61
	protected $mContext;
62
63
	/**
64
	 * Get a localised Title object for a specified special page name
65
	 *
66
	 * @since 1.9
67
	 * @since 1.21 $fragment parameter added
68
	 *
69
	 * @param string $name
70
	 * @param string|bool $subpage Subpage string, or false to not use a subpage
71
	 * @param string $fragment The link fragment (after the "#")
72
	 * @return Title
73
	 * @throws MWException
74
	 */
75
	public static function getTitleFor( $name, $subpage = false, $fragment = '' ) {
76
		$name = SpecialPageFactory::getLocalNameFor( $name, $subpage );
77
78
		return Title::makeTitle( NS_SPECIAL, $name, $fragment );
79
	}
80
81
	/**
82
	 * Get a localised Title object for a page name with a possibly unvalidated subpage
83
	 *
84
	 * @param string $name
85
	 * @param string|bool $subpage Subpage string, or false to not use a subpage
86
	 * @return Title|null Title object or null if the page doesn't exist
87
	 */
88
	public static function getSafeTitleFor( $name, $subpage = false ) {
89
		$name = SpecialPageFactory::getLocalNameFor( $name, $subpage );
90
		if ( $name ) {
91
			return Title::makeTitleSafe( NS_SPECIAL, $name );
92
		} else {
93
			return null;
94
		}
95
	}
96
97
	/**
98
	 * Default constructor for special pages
99
	 * Derivative classes should call this from their constructor
100
	 *     Note that if the user does not have the required level, an error message will
101
	 *     be displayed by the default execute() method, without the global function ever
102
	 *     being called.
103
	 *
104
	 *     If you override execute(), you can recover the default behavior with userCanExecute()
105
	 *     and displayRestrictionError()
106
	 *
107
	 * @param string $name Name of the special page, as seen in links and URLs
108
	 * @param string $restriction User right required, e.g. "block" or "delete"
109
	 * @param bool $listed Whether the page is listed in Special:Specialpages
110
	 * @param callable|bool $function Unused
111
	 * @param string $file Unused
112
	 * @param bool $includable Whether the page can be included in normal pages
113
	 */
114
	public function __construct(
115
		$name = '', $restriction = '', $listed = true,
116
		$function = false, $file = '', $includable = false
117
	) {
118
		$this->mName = $name;
119
		$this->mRestriction = $restriction;
120
		$this->mListed = $listed;
121
		$this->mIncludable = $includable;
122
	}
123
124
	/**
125
	 * Get the name of this Special Page.
126
	 * @return string
127
	 */
128
	function getName() {
129
		return $this->mName;
130
	}
131
132
	/**
133
	 * Get the permission that a user must have to execute this page
134
	 * @return string
135
	 */
136
	function getRestriction() {
137
		return $this->mRestriction;
138
	}
139
140
	// @todo FIXME: Decide which syntax to use for this, and stick to it
141
	/**
142
	 * Whether this special page is listed in Special:SpecialPages
143
	 * @since 1.3 (r3583)
144
	 * @return bool
145
	 */
146
	function isListed() {
147
		return $this->mListed;
148
	}
149
150
	/**
151
	 * Set whether this page is listed in Special:Specialpages, at run-time
152
	 * @since 1.3
153
	 * @param bool $listed
154
	 * @return bool
155
	 */
156
	function setListed( $listed ) {
157
		return wfSetVar( $this->mListed, $listed );
158
	}
159
160
	/**
161
	 * Get or set whether this special page is listed in Special:SpecialPages
162
	 * @since 1.6
163
	 * @param bool $x
164
	 * @return bool
165
	 */
166
	function listed( $x = null ) {
167
		return wfSetVar( $this->mListed, $x );
168
	}
169
170
	/**
171
	 * Whether it's allowed to transclude the special page via {{Special:Foo/params}}
172
	 * @return bool
173
	 */
174
	public function isIncludable() {
175
		return $this->mIncludable;
176
	}
177
178
	/**
179
	 * How long to cache page when it is being included.
180
	 *
181
	 * @note If cache time is not 0, then the current user becomes an anon
182
	 *   if you want to do any per-user customizations, than this method
183
	 *   must be overriden to return 0.
184
	 * @since 1.26
185
	 * @return int Time in seconds, 0 to disable caching altogether,
186
	 *  false to use the parent page's cache settings
187
	 */
188
	public function maxIncludeCacheTime() {
189
		return $this->getConfig()->get( 'MiserMode' ) ? $this->getCacheTTL() : 0;
190
	}
191
192
	/**
193
	 * @return int Seconds that this page can be cached
194
	 */
195
	protected function getCacheTTL() {
196
		return 60 * 60;
197
	}
198
199
	/**
200
	 * Whether the special page is being evaluated via transclusion
201
	 * @param bool $x
202
	 * @return bool
203
	 */
204
	function including( $x = null ) {
205
		return wfSetVar( $this->mIncluding, $x );
206
	}
207
208
	/**
209
	 * Get the localised name of the special page
210
	 * @return string
211
	 */
212
	function getLocalName() {
213
		if ( !isset( $this->mLocalName ) ) {
214
			$this->mLocalName = SpecialPageFactory::getLocalNameFor( $this->mName );
215
		}
216
217
		return $this->mLocalName;
218
	}
219
220
	/**
221
	 * Is this page expensive (for some definition of expensive)?
222
	 * Expensive pages are disabled or cached in miser mode.  Originally used
223
	 * (and still overridden) by QueryPage and subclasses, moved here so that
224
	 * Special:SpecialPages can safely call it for all special pages.
225
	 *
226
	 * @return bool
227
	 */
228
	public function isExpensive() {
229
		return false;
230
	}
231
232
	/**
233
	 * Is this page cached?
234
	 * Expensive pages are cached or disabled in miser mode.
235
	 * Used by QueryPage and subclasses, moved here so that
236
	 * Special:SpecialPages can safely call it for all special pages.
237
	 *
238
	 * @return bool
239
	 * @since 1.21
240
	 */
241
	public function isCached() {
242
		return false;
243
	}
244
245
	/**
246
	 * Can be overridden by subclasses with more complicated permissions
247
	 * schemes.
248
	 *
249
	 * @return bool Should the page be displayed with the restricted-access
250
	 *   pages?
251
	 */
252
	public function isRestricted() {
253
		// DWIM: If anons can do something, then it is not restricted
254
		return $this->mRestriction != '' && !User::groupHasPermission( '*', $this->mRestriction );
255
	}
256
257
	/**
258
	 * Checks if the given user (identified by an object) can execute this
259
	 * special page (as defined by $mRestriction).  Can be overridden by sub-
260
	 * classes with more complicated permissions schemes.
261
	 *
262
	 * @param User $user The user to check
263
	 * @return bool Does the user have permission to view the page?
264
	 */
265
	public function userCanExecute( User $user ) {
266
		return $user->isAllowed( $this->mRestriction );
267
	}
268
269
	/**
270
	 * Output an error message telling the user what access level they have to have
271
	 * @throws PermissionsError
272
	 */
273
	function displayRestrictionError() {
274
		throw new PermissionsError( $this->mRestriction );
275
	}
276
277
	/**
278
	 * Checks if userCanExecute, and if not throws a PermissionsError
279
	 *
280
	 * @since 1.19
281
	 * @return void
282
	 * @throws PermissionsError
283
	 */
284
	public function checkPermissions() {
285
		if ( !$this->userCanExecute( $this->getUser() ) ) {
286
			$this->displayRestrictionError();
287
		}
288
	}
289
290
	/**
291
	 * If the wiki is currently in readonly mode, throws a ReadOnlyError
292
	 *
293
	 * @since 1.19
294
	 * @return void
295
	 * @throws ReadOnlyError
296
	 */
297
	public function checkReadOnly() {
298
		if ( wfReadOnly() ) {
299
			throw new ReadOnlyError;
300
		}
301
	}
302
303
	/**
304
	 * If the user is not logged in, throws UserNotLoggedIn error
305
	 *
306
	 * The user will be redirected to Special:Userlogin with the given message as an error on
307
	 * the form.
308
	 *
309
	 * @since 1.23
310
	 * @param string $reasonMsg [optional] Message key to be displayed on login page
311
	 * @param string $titleMsg [optional] Passed on to UserNotLoggedIn constructor
312
	 * @throws UserNotLoggedIn
313
	 */
314
	public function requireLogin(
315
		$reasonMsg = 'exception-nologin-text', $titleMsg = 'exception-nologin'
316
	) {
317
		if ( $this->getUser()->isAnon() ) {
318
			throw new UserNotLoggedIn( $reasonMsg, $titleMsg );
319
		}
320
	}
321
322
	/**
323
	 * Tells if the special page does something security-sensitive and needs extra defense against
324
	 * a stolen account (e.g. a reauthentication). What exactly that will mean is decided by the
325
	 * authentication framework.
326
	 * @return bool|string False or the argument for AuthManager::securitySensitiveOperationStatus().
327
	 *   Typically a special page needing elevated security would return its name here.
328
	 */
329
	protected function getLoginSecurityLevel() {
330
		return false;
331
	}
332
333
	/**
334
	 * Verifies that the user meets the security level, possibly reauthenticating them in the process.
335
	 *
336
	 * This should be used when the page does something security-sensitive and needs extra defense
337
	 * against a stolen account (e.g. a reauthentication). The authentication framework will make
338
	 * an extra effort to make sure the user account is not compromised. What that exactly means
339
	 * will depend on the system and user settings; e.g. the user might be required to log in again
340
	 * unless their last login happened recently, or they might be given a second-factor challenge.
341
	 *
342
	 * Calling this method will result in one if these actions:
343
	 * - return true: all good.
344
	 * - return false and set a redirect: caller should abort; the redirect will take the user
345
	 *   to the login page for reauthentication, and back.
346
	 * - throw an exception if there is no way for the user to meet the requirements without using
347
	 *   a different access method (e.g. this functionality is only available from a specific IP).
348
	 *
349
	 * Note that this does not in any way check that the user is authorized to use this special page
350
	 * (use checkPermissions() for that).
351
	 *
352
	 * @param string $level A security level. Can be an arbitrary string, defaults to the page name.
353
	 * @return bool False means a redirect to the reauthentication page has been set and processing
354
	 *   of the special page should be aborted.
355
	 * @throws ErrorPageError If the security level cannot be met, even with reauthentication.
356
	 */
357
	protected function checkLoginSecurityLevel( $level = null ) {
358
		$level = $level ?: $this->getName();
359
		$securityStatus = AuthManager::singleton()->securitySensitiveOperationStatus( $level );
360
		if ( $securityStatus === AuthManager::SEC_OK ) {
361
			return true;
362
		} elseif ( $securityStatus === AuthManager::SEC_REAUTH ) {
363
			$request = $this->getRequest();
364
			$title = SpecialPage::getTitleFor( 'Userlogin' );
365
			$query = [
366
				'returnto' => $this->getFullTitle()->getPrefixedDBkey(),
367
				'returntoquery' => wfArrayToCgi( array_diff_key( $request->getQueryValues(),
368
					[ 'title' => true ] ) ),
369
				'force' => $level,
370
			];
371
			$url = $title->getFullURL( $query, false, PROTO_HTTPS );
372
373
			$this->getOutput()->redirect( $url );
374
			return false;
375
		}
376
377
		$titleMessage = wfMessage( 'specialpage-securitylevel-not-allowed-title' );
378
		$errorMessage = wfMessage( 'specialpage-securitylevel-not-allowed' );
379
		throw new ErrorPageError( $titleMessage, $errorMessage );
380
	}
381
382
	/**
383
	 * Return an array of subpages beginning with $search that this special page will accept.
384
	 *
385
	 * For example, if a page supports subpages "foo", "bar" and "baz" (as in Special:PageName/foo,
386
	 * etc.):
387
	 *
388
	 *   - `prefixSearchSubpages( "ba" )` should return `array( "bar", "baz" )`
389
	 *   - `prefixSearchSubpages( "f" )` should return `array( "foo" )`
390
	 *   - `prefixSearchSubpages( "z" )` should return `array()`
391
	 *   - `prefixSearchSubpages( "" )` should return `array( foo", "bar", "baz" )`
392
	 *
393
	 * @param string $search Prefix to search for
394
	 * @param int $limit Maximum number of results to return (usually 10)
395
	 * @param int $offset Number of results to skip (usually 0)
396
	 * @return string[] Matching subpages
397
	 */
398
	public function prefixSearchSubpages( $search, $limit, $offset ) {
399
		$subpages = $this->getSubpagesForPrefixSearch();
400
		if ( !$subpages ) {
401
			return [];
402
		}
403
404
		return self::prefixSearchArray( $search, $limit, $subpages, $offset );
405
	}
406
407
	/**
408
	 * Return an array of subpages that this special page will accept for prefix
409
	 * searches. If this method requires a query you might instead want to implement
410
	 * prefixSearchSubpages() directly so you can support $limit and $offset. This
411
	 * method is better for static-ish lists of things.
412
	 *
413
	 * @return string[] subpages to search from
414
	 */
415
	protected function getSubpagesForPrefixSearch() {
416
		return [];
417
	}
418
419
	/**
420
	 * Perform a regular substring search for prefixSearchSubpages
421
	 * @param string $search Prefix to search for
422
	 * @param int $limit Maximum number of results to return (usually 10)
423
	 * @param int $offset Number of results to skip (usually 0)
424
	 * @return string[] Matching subpages
425
	 */
426
	protected function prefixSearchString( $search, $limit, $offset ) {
427
		$title = Title::newFromText( $search );
428
		if ( !$title || !$title->canExist() ) {
429
			// No prefix suggestion in special and media namespace
430
			return [];
431
		}
432
433
		$searchEngine = MediaWikiServices::getInstance()->newSearchEngine();
434
		$searchEngine->setLimitOffset( $limit, $offset );
435
		$searchEngine->setNamespaces( [] );
436
		$result = $searchEngine->defaultPrefixSearch( $search );
437
		return array_map( function( Title $t ) {
438
			return $t->getPrefixedText();
439
		}, $result );
440
	}
441
442
	/**
443
	 * Helper function for implementations of prefixSearchSubpages() that
444
	 * filter the values in memory (as opposed to making a query).
445
	 *
446
	 * @since 1.24
447
	 * @param string $search
448
	 * @param int $limit
449
	 * @param array $subpages
450
	 * @param int $offset
451
	 * @return string[]
452
	 */
453
	protected static function prefixSearchArray( $search, $limit, array $subpages, $offset ) {
454
		$escaped = preg_quote( $search, '/' );
455
		return array_slice( preg_grep( "/^$escaped/i",
456
			array_slice( $subpages, $offset ) ), 0, $limit );
457
	}
458
459
	/**
460
	 * Sets headers - this should be called from the execute() method of all derived classes!
461
	 */
462
	function setHeaders() {
463
		$out = $this->getOutput();
464
		$out->setArticleRelated( false );
465
		$out->setRobotPolicy( $this->getRobotPolicy() );
466
		$out->setPageTitle( $this->getDescription() );
467
		if ( $this->getConfig()->get( 'UseMediaWikiUIEverywhere' ) ) {
468
			$out->addModuleStyles( [
469
				'mediawiki.ui.input',
470
				'mediawiki.ui.radio',
471
				'mediawiki.ui.checkbox',
472
			] );
473
		}
474
	}
475
476
	/**
477
	 * Entry point.
478
	 *
479
	 * @since 1.20
480
	 *
481
	 * @param string|null $subPage
482
	 */
483
	final public function run( $subPage ) {
484
		/**
485
		 * Gets called before @see SpecialPage::execute.
486
		 * Return false to prevent calling execute() (since 1.27+).
487
		 *
488
		 * @since 1.20
489
		 *
490
		 * @param SpecialPage $this
491
		 * @param string|null $subPage
492
		 */
493
		if ( !Hooks::run( 'SpecialPageBeforeExecute', [ $this, $subPage ] ) ) {
494
			return;
495
		}
496
497
		if ( $this->beforeExecute( $subPage ) === false ) {
498
			return;
499
		}
500
		$this->execute( $subPage );
501
		$this->afterExecute( $subPage );
502
503
		/**
504
		 * Gets called after @see SpecialPage::execute.
505
		 *
506
		 * @since 1.20
507
		 *
508
		 * @param SpecialPage $this
509
		 * @param string|null $subPage
510
		 */
511
		Hooks::run( 'SpecialPageAfterExecute', [ $this, $subPage ] );
512
	}
513
514
	/**
515
	 * Gets called before @see SpecialPage::execute.
516
	 * Return false to prevent calling execute() (since 1.27+).
517
	 *
518
	 * @since 1.20
519
	 *
520
	 * @param string|null $subPage
521
	 * @return bool|void
522
	 */
523
	protected function beforeExecute( $subPage ) {
524
		// No-op
525
	}
526
527
	/**
528
	 * Gets called after @see SpecialPage::execute.
529
	 *
530
	 * @since 1.20
531
	 *
532
	 * @param string|null $subPage
533
	 */
534
	protected function afterExecute( $subPage ) {
535
		// No-op
536
	}
537
538
	/**
539
	 * Default execute method
540
	 * Checks user permissions
541
	 *
542
	 * This must be overridden by subclasses; it will be made abstract in a future version
543
	 *
544
	 * @param string|null $subPage
545
	 */
546
	public function execute( $subPage ) {
547
		$this->setHeaders();
548
		$this->checkPermissions();
549
		$this->checkLoginSecurityLevel( $this->getLoginSecurityLevel() );
550
		$this->outputHeader();
551
	}
552
553
	/**
554
	 * Outputs a summary message on top of special pages
555
	 * Per default the message key is the canonical name of the special page
556
	 * May be overridden, i.e. by extensions to stick with the naming conventions
557
	 * for message keys: 'extensionname-xxx'
558
	 *
559
	 * @param string $summaryMessageKey Message key of the summary
560
	 */
561
	function outputHeader( $summaryMessageKey = '' ) {
562
		global $wgContLang;
563
564
		if ( $summaryMessageKey == '' ) {
565
			$msg = $wgContLang->lc( $this->getName() ) . '-summary';
566
		} else {
567
			$msg = $summaryMessageKey;
568
		}
569
		if ( !$this->msg( $msg )->isDisabled() && !$this->including() ) {
570
			$this->getOutput()->wrapWikiMsg(
571
				"<div class='mw-specialpage-summary'>\n$1\n</div>", $msg );
572
		}
573
	}
574
575
	/**
576
	 * Returns the name that goes in the \<h1\> in the special page itself, and
577
	 * also the name that will be listed in Special:Specialpages
578
	 *
579
	 * Derived classes can override this, but usually it is easier to keep the
580
	 * default behavior.
581
	 *
582
	 * @return string
583
	 */
584
	function getDescription() {
585
		return $this->msg( strtolower( $this->mName ) )->text();
586
	}
587
588
	/**
589
	 * Get a self-referential title object
590
	 *
591
	 * @param string|bool $subpage
592
	 * @return Title
593
	 * @deprecated since 1.23, use SpecialPage::getPageTitle
594
	 */
595
	function getTitle( $subpage = false ) {
596
		return $this->getPageTitle( $subpage );
597
	}
598
599
	/**
600
	 * Get a self-referential title object
601
	 *
602
	 * @param string|bool $subpage
603
	 * @return Title
604
	 * @since 1.23
605
	 */
606
	function getPageTitle( $subpage = false ) {
607
		return self::getTitleFor( $this->mName, $subpage );
608
	}
609
610
	/**
611
	 * Sets the context this SpecialPage is executed in
612
	 *
613
	 * @param IContextSource $context
614
	 * @since 1.18
615
	 */
616
	public function setContext( $context ) {
617
		$this->mContext = $context;
618
	}
619
620
	/**
621
	 * Gets the context this SpecialPage is executed in
622
	 *
623
	 * @return IContextSource|RequestContext
624
	 * @since 1.18
625
	 */
626 View Code Duplication
	public function getContext() {
627
		if ( $this->mContext instanceof IContextSource ) {
628
			return $this->mContext;
629
		} else {
630
			wfDebug( __METHOD__ . " called and \$mContext is null. " .
631
				"Return RequestContext::getMain(); for sanity\n" );
632
633
			return RequestContext::getMain();
634
		}
635
	}
636
637
	/**
638
	 * Get the WebRequest being used for this instance
639
	 *
640
	 * @return WebRequest
641
	 * @since 1.18
642
	 */
643
	public function getRequest() {
644
		return $this->getContext()->getRequest();
645
	}
646
647
	/**
648
	 * Get the OutputPage being used for this instance
649
	 *
650
	 * @return OutputPage
651
	 * @since 1.18
652
	 */
653
	public function getOutput() {
654
		return $this->getContext()->getOutput();
655
	}
656
657
	/**
658
	 * Shortcut to get the User executing this instance
659
	 *
660
	 * @return User
661
	 * @since 1.18
662
	 */
663
	public function getUser() {
664
		return $this->getContext()->getUser();
665
	}
666
667
	/**
668
	 * Shortcut to get the skin being used for this instance
669
	 *
670
	 * @return Skin
671
	 * @since 1.18
672
	 */
673
	public function getSkin() {
674
		return $this->getContext()->getSkin();
675
	}
676
677
	/**
678
	 * Shortcut to get user's language
679
	 *
680
	 * @return Language
681
	 * @since 1.19
682
	 */
683
	public function getLanguage() {
684
		return $this->getContext()->getLanguage();
685
	}
686
687
	/**
688
	 * Shortcut to get main config object
689
	 * @return Config
690
	 * @since 1.24
691
	 */
692
	public function getConfig() {
693
		return $this->getContext()->getConfig();
694
	}
695
696
	/**
697
	 * Return the full title, including $par
698
	 *
699
	 * @return Title
700
	 * @since 1.18
701
	 */
702
	public function getFullTitle() {
703
		return $this->getContext()->getTitle();
704
	}
705
706
	/**
707
	 * Return the robot policy. Derived classes that override this can change
708
	 * the robot policy set by setHeaders() from the default 'noindex,nofollow'.
709
	 *
710
	 * @return string
711
	 * @since 1.23
712
	 */
713
	protected function getRobotPolicy() {
714
		return 'noindex,nofollow';
715
	}
716
717
	/**
718
	 * Wrapper around wfMessage that sets the current context.
719
	 *
720
	 * @since 1.16
721
	 * @return Message
722
	 * @see wfMessage
723
	 */
724
	public function msg( /* $args */ ) {
725
		$message = call_user_func_array(
726
			[ $this->getContext(), 'msg' ],
727
			func_get_args()
728
		);
729
		// RequestContext passes context to wfMessage, and the language is set from
730
		// the context, but setting the language for Message class removes the
731
		// interface message status, which breaks for example usernameless gender
732
		// invocations. Restore the flag when not including special page in content.
733
		if ( $this->including() ) {
734
			$message->setInterfaceMessageFlag( false );
735
		}
736
737
		return $message;
738
	}
739
740
	/**
741
	 * Adds RSS/atom links
742
	 *
743
	 * @param array $params
744
	 */
745
	protected function addFeedLinks( $params ) {
746
		$feedTemplate = wfScript( 'api' );
747
748
		foreach ( $this->getConfig()->get( 'FeedClasses' ) as $format => $class ) {
749
			$theseParams = $params + [ 'feedformat' => $format ];
750
			$url = wfAppendQuery( $feedTemplate, $theseParams );
751
			$this->getOutput()->addFeedLink( $format, $url );
752
		}
753
	}
754
755
	/**
756
	 * Adds help link with an icon via page indicators.
757
	 * Link target can be overridden by a local message containing a wikilink:
758
	 * the message key is: lowercase special page name + '-helppage'.
759
	 * @param string $to Target MediaWiki.org page title or encoded URL.
760
	 * @param bool $overrideBaseUrl Whether $url is a full URL, to avoid MW.o.
761
	 * @since 1.25
762
	 */
763 View Code Duplication
	public function addHelpLink( $to, $overrideBaseUrl = false ) {
764
		global $wgContLang;
765
		$msg = $this->msg( $wgContLang->lc( $this->getName() ) . '-helppage' );
766
767
		if ( !$msg->isDisabled() ) {
768
			$helpUrl = Skin::makeUrl( $msg->plain() );
769
			$this->getOutput()->addHelpLink( $helpUrl, true );
770
		} else {
771
			$this->getOutput()->addHelpLink( $to, $overrideBaseUrl );
772
		}
773
	}
774
775
	/**
776
	 * Get the group that the special page belongs in on Special:SpecialPage
777
	 * Use this method, instead of getGroupName to allow customization
778
	 * of the group name from the wiki side
779
	 *
780
	 * @return string Group of this special page
781
	 * @since 1.21
782
	 */
783
	public function getFinalGroupName() {
784
		$name = $this->getName();
785
786
		// Allow overbidding the group from the wiki side
787
		$msg = $this->msg( 'specialpages-specialpagegroup-' . strtolower( $name ) )->inContentLanguage();
788
		if ( !$msg->isBlank() ) {
789
			$group = $msg->text();
790
		} else {
791
			// Than use the group from this object
792
			$group = $this->getGroupName();
793
		}
794
795
		return $group;
796
	}
797
798
	/**
799
	 * Indicates whether this special page may perform database writes
800
	 *
801
	 * @return bool
802
	 * @since 1.27
803
	 */
804
	public function doesWrites() {
805
		return false;
806
	}
807
808
	/**
809
	 * Under which header this special page is listed in Special:SpecialPages
810
	 * See messages 'specialpages-group-*' for valid names
811
	 * This method defaults to group 'other'
812
	 *
813
	 * @return string
814
	 * @since 1.21
815
	 */
816
	protected function getGroupName() {
817
		return 'other';
818
	}
819
820
	/**
821
	 * Call wfTransactionalTimeLimit() if this request was POSTed
822
	 * @since 1.26
823
	 */
824
	protected function useTransactionalTimeLimit() {
825
		if ( $this->getRequest()->wasPosted() ) {
826
			wfTransactionalTimeLimit();
827
		}
828
	}
829
}
830