Merge "maintenance: Script to rename titles for Unicode uppercasing changes"
[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 `[ "bar", "baz" ]`
460 * - `prefixSearchSubpages( "f" )` should return `[ "foo" ]`
461 * - `prefixSearchSubpages( "z" )` should return `[]`
462 * - `prefixSearchSubpages( "" )` should return `[ 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 * @since 1.23
667 */
668 function getPageTitle( $subpage = false ) {
669 return self::getTitleFor( $this->mName, $subpage );
670 }
671
672 /**
673 * Sets the context this SpecialPage is executed in
674 *
675 * @param IContextSource $context
676 * @since 1.18
677 */
678 public function setContext( $context ) {
679 $this->mContext = $context;
680 }
681
682 /**
683 * Gets the context this SpecialPage is executed in
684 *
685 * @return IContextSource|RequestContext
686 * @since 1.18
687 */
688 public function getContext() {
689 if ( $this->mContext instanceof IContextSource ) {
690 return $this->mContext;
691 } else {
692 wfDebug( __METHOD__ . " called and \$mContext is null. " .
693 "Return RequestContext::getMain(); for sanity\n" );
694
695 return RequestContext::getMain();
696 }
697 }
698
699 /**
700 * Get the WebRequest being used for this instance
701 *
702 * @return WebRequest
703 * @since 1.18
704 */
705 public function getRequest() {
706 return $this->getContext()->getRequest();
707 }
708
709 /**
710 * Get the OutputPage being used for this instance
711 *
712 * @return OutputPage
713 * @since 1.18
714 */
715 public function getOutput() {
716 return $this->getContext()->getOutput();
717 }
718
719 /**
720 * Shortcut to get the User executing this instance
721 *
722 * @return User
723 * @since 1.18
724 */
725 public function getUser() {
726 return $this->getContext()->getUser();
727 }
728
729 /**
730 * Shortcut to get the skin being used for this instance
731 *
732 * @return Skin
733 * @since 1.18
734 */
735 public function getSkin() {
736 return $this->getContext()->getSkin();
737 }
738
739 /**
740 * Shortcut to get user's language
741 *
742 * @return Language
743 * @since 1.19
744 */
745 public function getLanguage() {
746 return $this->getContext()->getLanguage();
747 }
748
749 /**
750 * Shortcut to get main config object
751 * @return Config
752 * @since 1.24
753 */
754 public function getConfig() {
755 return $this->getContext()->getConfig();
756 }
757
758 /**
759 * Return the full title, including $par
760 *
761 * @return Title
762 * @since 1.18
763 */
764 public function getFullTitle() {
765 return $this->getContext()->getTitle();
766 }
767
768 /**
769 * Return the robot policy. Derived classes that override this can change
770 * the robot policy set by setHeaders() from the default 'noindex,nofollow'.
771 *
772 * @return string
773 * @since 1.23
774 */
775 protected function getRobotPolicy() {
776 return 'noindex,nofollow';
777 }
778
779 /**
780 * Wrapper around wfMessage that sets the current context.
781 *
782 * @since 1.16
783 * @return Message
784 * @see wfMessage
785 */
786 public function msg( $key /* $args */ ) {
787 $message = $this->getContext()->msg( ...func_get_args() );
788 // RequestContext passes context to wfMessage, and the language is set from
789 // the context, but setting the language for Message class removes the
790 // interface message status, which breaks for example usernameless gender
791 // invocations. Restore the flag when not including special page in content.
792 if ( $this->including() ) {
793 $message->setInterfaceMessageFlag( false );
794 }
795
796 return $message;
797 }
798
799 /**
800 * Adds RSS/atom links
801 *
802 * @param array $params
803 */
804 protected function addFeedLinks( $params ) {
805 $feedTemplate = wfScript( 'api' );
806
807 foreach ( $this->getConfig()->get( 'FeedClasses' ) as $format => $class ) {
808 $theseParams = $params + [ 'feedformat' => $format ];
809 $url = wfAppendQuery( $feedTemplate, $theseParams );
810 $this->getOutput()->addFeedLink( $format, $url );
811 }
812 }
813
814 /**
815 * Adds help link with an icon via page indicators.
816 * Link target can be overridden by a local message containing a wikilink:
817 * the message key is: lowercase special page name + '-helppage'.
818 * @param string $to Target MediaWiki.org page title or encoded URL.
819 * @param bool $overrideBaseUrl Whether $url is a full URL, to avoid MW.o.
820 * @since 1.25
821 */
822 public function addHelpLink( $to, $overrideBaseUrl = false ) {
823 if ( $this->including() ) {
824 return;
825 }
826
827 $msg = $this->msg(
828 MediaWikiServices::getInstance()->getContentLanguage()->lc( $this->getName() ) .
829 '-helppage' );
830
831 if ( !$msg->isDisabled() ) {
832 $helpUrl = Skin::makeUrl( $msg->plain() );
833 $this->getOutput()->addHelpLink( $helpUrl, true );
834 } else {
835 $this->getOutput()->addHelpLink( $to, $overrideBaseUrl );
836 }
837 }
838
839 /**
840 * Get the group that the special page belongs in on Special:SpecialPage
841 * Use this method, instead of getGroupName to allow customization
842 * of the group name from the wiki side
843 *
844 * @return string Group of this special page
845 * @since 1.21
846 */
847 public function getFinalGroupName() {
848 $name = $this->getName();
849
850 // Allow overriding the group from the wiki side
851 $msg = $this->msg( 'specialpages-specialpagegroup-' . strtolower( $name ) )->inContentLanguage();
852 if ( !$msg->isBlank() ) {
853 $group = $msg->text();
854 } else {
855 // Than use the group from this object
856 $group = $this->getGroupName();
857 }
858
859 return $group;
860 }
861
862 /**
863 * Indicates whether this special page may perform database writes
864 *
865 * @return bool
866 * @since 1.27
867 */
868 public function doesWrites() {
869 return false;
870 }
871
872 /**
873 * Under which header this special page is listed in Special:SpecialPages
874 * See messages 'specialpages-group-*' for valid names
875 * This method defaults to group 'other'
876 *
877 * @return string
878 * @since 1.21
879 */
880 protected function getGroupName() {
881 return 'other';
882 }
883
884 /**
885 * Call wfTransactionalTimeLimit() if this request was POSTed
886 * @since 1.26
887 */
888 protected function useTransactionalTimeLimit() {
889 if ( $this->getRequest()->wasPosted() ) {
890 wfTransactionalTimeLimit();
891 }
892 }
893
894 /**
895 * @since 1.28
896 * @return \MediaWiki\Linker\LinkRenderer
897 */
898 public function getLinkRenderer() {
899 if ( $this->linkRenderer ) {
900 return $this->linkRenderer;
901 } else {
902 return MediaWikiServices::getInstance()->getLinkRenderer();
903 }
904 }
905
906 /**
907 * @since 1.28
908 * @param \MediaWiki\Linker\LinkRenderer $linkRenderer
909 */
910 public function setLinkRenderer( LinkRenderer $linkRenderer ) {
911 $this->linkRenderer = $linkRenderer;
912 }
913
914 /**
915 * Generate (prev x| next x) (20|50|100...) type links for paging
916 *
917 * @param int $offset
918 * @param int $limit
919 * @param array $query Optional URL query parameter string
920 * @param bool $atend Optional param for specified if this is the last page
921 * @param string|bool $subpage Optional param for specifying subpage
922 * @return string
923 */
924 protected function buildPrevNextNavigation( $offset, $limit,
925 array $query = [], $atend = false, $subpage = false
926 ) {
927 $title = $this->getPageTitle( $subpage );
928 $prevNext = new PrevNextNavigationRenderer( $this );
929
930 return $prevNext->buildPrevNextNavigation( $title, $offset, $limit, $query, $atend );
931 }
932 }