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