Merge "Make DBAccessBase use DBConnRef, rename $wiki, and hide getLoadBalancer()"
[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 != '' && !MediaWikiServices::getInstance()
282 ->getPermissionManager()
283 ->groupHasPermission( '*', $this->mRestriction );
284 }
285
286 /**
287 * Checks if the given user (identified by an object) can execute this
288 * special page (as defined by $mRestriction). Can be overridden by sub-
289 * classes with more complicated permissions schemes.
290 *
291 * @param User $user The user to check
292 * @return bool Does the user have permission to view the page?
293 */
294 public function userCanExecute( User $user ) {
295 return $user->isAllowed( $this->mRestriction );
296 }
297
298 /**
299 * Output an error message telling the user what access level they have to have
300 * @throws PermissionsError
301 */
302 function displayRestrictionError() {
303 throw new PermissionsError( $this->mRestriction );
304 }
305
306 /**
307 * Checks if userCanExecute, and if not throws a PermissionsError
308 *
309 * @since 1.19
310 * @return void
311 * @throws PermissionsError
312 */
313 public function checkPermissions() {
314 if ( !$this->userCanExecute( $this->getUser() ) ) {
315 $this->displayRestrictionError();
316 }
317 }
318
319 /**
320 * If the wiki is currently in readonly mode, throws a ReadOnlyError
321 *
322 * @since 1.19
323 * @return void
324 * @throws ReadOnlyError
325 */
326 public function checkReadOnly() {
327 if ( wfReadOnly() ) {
328 throw new ReadOnlyError;
329 }
330 }
331
332 /**
333 * If the user is not logged in, throws UserNotLoggedIn error
334 *
335 * The user will be redirected to Special:Userlogin with the given message as an error on
336 * the form.
337 *
338 * @since 1.23
339 * @param string $reasonMsg [optional] Message key to be displayed on login page
340 * @param string $titleMsg [optional] Passed on to UserNotLoggedIn constructor
341 * @throws UserNotLoggedIn
342 */
343 public function requireLogin(
344 $reasonMsg = 'exception-nologin-text', $titleMsg = 'exception-nologin'
345 ) {
346 if ( $this->getUser()->isAnon() ) {
347 throw new UserNotLoggedIn( $reasonMsg, $titleMsg );
348 }
349 }
350
351 /**
352 * Tells if the special page does something security-sensitive and needs extra defense against
353 * a stolen account (e.g. a reauthentication). What exactly that will mean is decided by the
354 * authentication framework.
355 * @return bool|string False or the argument for AuthManager::securitySensitiveOperationStatus().
356 * Typically a special page needing elevated security would return its name here.
357 */
358 protected function getLoginSecurityLevel() {
359 return false;
360 }
361
362 /**
363 * Record preserved POST data after a reauthentication.
364 *
365 * This is called from checkLoginSecurityLevel() when returning from the
366 * redirect for reauthentication, if the redirect had been served in
367 * response to a POST request.
368 *
369 * The base SpecialPage implementation does nothing. If your subclass uses
370 * getLoginSecurityLevel() or checkLoginSecurityLevel(), it should probably
371 * implement this to do something with the data.
372 *
373 * @since 1.32
374 * @param array $data
375 */
376 protected function setReauthPostData( array $data ) {
377 }
378
379 /**
380 * Verifies that the user meets the security level, possibly reauthenticating them in the process.
381 *
382 * This should be used when the page does something security-sensitive and needs extra defense
383 * against a stolen account (e.g. a reauthentication). The authentication framework will make
384 * an extra effort to make sure the user account is not compromised. What that exactly means
385 * will depend on the system and user settings; e.g. the user might be required to log in again
386 * unless their last login happened recently, or they might be given a second-factor challenge.
387 *
388 * Calling this method will result in one if these actions:
389 * - return true: all good.
390 * - return false and set a redirect: caller should abort; the redirect will take the user
391 * to the login page for reauthentication, and back.
392 * - throw an exception if there is no way for the user to meet the requirements without using
393 * a different access method (e.g. this functionality is only available from a specific IP).
394 *
395 * Note that this does not in any way check that the user is authorized to use this special page
396 * (use checkPermissions() for that).
397 *
398 * @param string|null $level A security level. Can be an arbitrary string, defaults to the page
399 * name.
400 * @return bool False means a redirect to the reauthentication page has been set and processing
401 * of the special page should be aborted.
402 * @throws ErrorPageError If the security level cannot be met, even with reauthentication.
403 */
404 protected function checkLoginSecurityLevel( $level = null ) {
405 $level = $level ?: $this->getName();
406 $key = 'SpecialPage:reauth:' . $this->getName();
407 $request = $this->getRequest();
408
409 $securityStatus = AuthManager::singleton()->securitySensitiveOperationStatus( $level );
410 if ( $securityStatus === AuthManager::SEC_OK ) {
411 $uniqueId = $request->getVal( 'postUniqueId' );
412 if ( $uniqueId ) {
413 $key .= ':' . $uniqueId;
414 $session = $request->getSession();
415 $data = $session->getSecret( $key );
416 if ( $data ) {
417 $session->remove( $key );
418 $this->setReauthPostData( $data );
419 }
420 }
421 return true;
422 } elseif ( $securityStatus === AuthManager::SEC_REAUTH ) {
423 $title = self::getTitleFor( 'Userlogin' );
424 $queryParams = $request->getQueryValues();
425
426 if ( $request->wasPosted() ) {
427 $data = array_diff_assoc( $request->getValues(), $request->getQueryValues() );
428 if ( $data ) {
429 // unique ID in case the same special page is open in multiple browser tabs
430 $uniqueId = MWCryptRand::generateHex( 6 );
431 $key .= ':' . $uniqueId;
432 $queryParams['postUniqueId'] = $uniqueId;
433 $session = $request->getSession();
434 $session->persist(); // Just in case
435 $session->setSecret( $key, $data );
436 }
437 }
438
439 $query = [
440 'returnto' => $this->getFullTitle()->getPrefixedDBkey(),
441 'returntoquery' => wfArrayToCgi( array_diff_key( $queryParams, [ 'title' => true ] ) ),
442 'force' => $level,
443 ];
444 $url = $title->getFullURL( $query, false, PROTO_HTTPS );
445
446 $this->getOutput()->redirect( $url );
447 return false;
448 }
449
450 $titleMessage = wfMessage( 'specialpage-securitylevel-not-allowed-title' );
451 $errorMessage = wfMessage( 'specialpage-securitylevel-not-allowed' );
452 throw new ErrorPageError( $titleMessage, $errorMessage );
453 }
454
455 /**
456 * Return an array of subpages beginning with $search that this special page will accept.
457 *
458 * For example, if a page supports subpages "foo", "bar" and "baz" (as in Special:PageName/foo,
459 * etc.):
460 *
461 * - `prefixSearchSubpages( "ba" )` should return `[ "bar", "baz" ]`
462 * - `prefixSearchSubpages( "f" )` should return `[ "foo" ]`
463 * - `prefixSearchSubpages( "z" )` should return `[]`
464 * - `prefixSearchSubpages( "" )` should return `[ foo", "bar", "baz" ]`
465 *
466 * @param string $search Prefix to search for
467 * @param int $limit Maximum number of results to return (usually 10)
468 * @param int $offset Number of results to skip (usually 0)
469 * @return string[] Matching subpages
470 */
471 public function prefixSearchSubpages( $search, $limit, $offset ) {
472 $subpages = $this->getSubpagesForPrefixSearch();
473 if ( !$subpages ) {
474 return [];
475 }
476
477 return self::prefixSearchArray( $search, $limit, $subpages, $offset );
478 }
479
480 /**
481 * Return an array of subpages that this special page will accept for prefix
482 * searches. If this method requires a query you might instead want to implement
483 * prefixSearchSubpages() directly so you can support $limit and $offset. This
484 * method is better for static-ish lists of things.
485 *
486 * @return string[] subpages to search from
487 */
488 protected function getSubpagesForPrefixSearch() {
489 return [];
490 }
491
492 /**
493 * Perform a regular substring search for prefixSearchSubpages
494 * @param string $search Prefix to search for
495 * @param int $limit Maximum number of results to return (usually 10)
496 * @param int $offset Number of results to skip (usually 0)
497 * @return string[] Matching subpages
498 */
499 protected function prefixSearchString( $search, $limit, $offset ) {
500 $title = Title::newFromText( $search );
501 if ( !$title || !$title->canExist() ) {
502 // No prefix suggestion in special and media namespace
503 return [];
504 }
505
506 $searchEngine = MediaWikiServices::getInstance()->newSearchEngine();
507 $searchEngine->setLimitOffset( $limit, $offset );
508 $searchEngine->setNamespaces( [] );
509 $result = $searchEngine->defaultPrefixSearch( $search );
510 return array_map( function ( Title $t ) {
511 return $t->getPrefixedText();
512 }, $result );
513 }
514
515 /**
516 * Helper function for implementations of prefixSearchSubpages() that
517 * filter the values in memory (as opposed to making a query).
518 *
519 * @since 1.24
520 * @param string $search
521 * @param int $limit
522 * @param array $subpages
523 * @param int $offset
524 * @return string[]
525 */
526 protected static function prefixSearchArray( $search, $limit, array $subpages, $offset ) {
527 $escaped = preg_quote( $search, '/' );
528 return array_slice( preg_grep( "/^$escaped/i",
529 array_slice( $subpages, $offset ) ), 0, $limit );
530 }
531
532 /**
533 * Sets headers - this should be called from the execute() method of all derived classes!
534 */
535 function setHeaders() {
536 $out = $this->getOutput();
537 $out->setArticleRelated( false );
538 $out->setRobotPolicy( $this->getRobotPolicy() );
539 $out->setPageTitle( $this->getDescription() );
540 if ( $this->getConfig()->get( 'UseMediaWikiUIEverywhere' ) ) {
541 $out->addModuleStyles( [
542 'mediawiki.ui.input',
543 'mediawiki.ui.radio',
544 'mediawiki.ui.checkbox',
545 ] );
546 }
547 }
548
549 /**
550 * Entry point.
551 *
552 * @since 1.20
553 *
554 * @param string|null $subPage
555 */
556 final public function run( $subPage ) {
557 /**
558 * Gets called before @see SpecialPage::execute.
559 * Return false to prevent calling execute() (since 1.27+).
560 *
561 * @since 1.20
562 *
563 * @param SpecialPage $this
564 * @param string|null $subPage
565 */
566 if ( !Hooks::run( 'SpecialPageBeforeExecute', [ $this, $subPage ] ) ) {
567 return;
568 }
569
570 if ( $this->beforeExecute( $subPage ) === false ) {
571 return;
572 }
573 $this->execute( $subPage );
574 $this->afterExecute( $subPage );
575
576 /**
577 * Gets called after @see SpecialPage::execute.
578 *
579 * @since 1.20
580 *
581 * @param SpecialPage $this
582 * @param string|null $subPage
583 */
584 Hooks::run( 'SpecialPageAfterExecute', [ $this, $subPage ] );
585 }
586
587 /**
588 * Gets called before @see SpecialPage::execute.
589 * Return false to prevent calling execute() (since 1.27+).
590 *
591 * @since 1.20
592 *
593 * @param string|null $subPage
594 * @return bool|void
595 */
596 protected function beforeExecute( $subPage ) {
597 // No-op
598 }
599
600 /**
601 * Gets called after @see SpecialPage::execute.
602 *
603 * @since 1.20
604 *
605 * @param string|null $subPage
606 */
607 protected function afterExecute( $subPage ) {
608 // No-op
609 }
610
611 /**
612 * Default execute method
613 * Checks user permissions
614 *
615 * This must be overridden by subclasses; it will be made abstract in a future version
616 *
617 * @param string|null $subPage
618 */
619 public function execute( $subPage ) {
620 $this->setHeaders();
621 $this->checkPermissions();
622 $securityLevel = $this->getLoginSecurityLevel();
623 if ( $securityLevel !== false && !$this->checkLoginSecurityLevel( $securityLevel ) ) {
624 return;
625 }
626 $this->outputHeader();
627 }
628
629 /**
630 * Outputs a summary message on top of special pages
631 * Per default the message key is the canonical name of the special page
632 * May be overridden, i.e. by extensions to stick with the naming conventions
633 * for message keys: 'extensionname-xxx'
634 *
635 * @param string $summaryMessageKey Message key of the summary
636 */
637 function outputHeader( $summaryMessageKey = '' ) {
638 if ( $summaryMessageKey == '' ) {
639 $msg = MediaWikiServices::getInstance()->getContentLanguage()->lc( $this->getName() ) .
640 '-summary';
641 } else {
642 $msg = $summaryMessageKey;
643 }
644 if ( !$this->msg( $msg )->isDisabled() && !$this->including() ) {
645 $this->getOutput()->wrapWikiMsg(
646 "<div class='mw-specialpage-summary'>\n$1\n</div>", $msg );
647 }
648 }
649
650 /**
651 * Returns the name that goes in the \<h1\> in the special page itself, and
652 * also the name that will be listed in Special:Specialpages
653 *
654 * Derived classes can override this, but usually it is easier to keep the
655 * default behavior.
656 *
657 * @return string
658 */
659 function getDescription() {
660 return $this->msg( strtolower( $this->mName ) )->text();
661 }
662
663 /**
664 * Get a self-referential title object
665 *
666 * @param string|bool $subpage
667 * @return Title
668 * @since 1.23
669 */
670 function getPageTitle( $subpage = false ) {
671 return self::getTitleFor( $this->mName, $subpage );
672 }
673
674 /**
675 * Sets the context this SpecialPage is executed in
676 *
677 * @param IContextSource $context
678 * @since 1.18
679 */
680 public function setContext( $context ) {
681 $this->mContext = $context;
682 }
683
684 /**
685 * Gets the context this SpecialPage is executed in
686 *
687 * @return IContextSource|RequestContext
688 * @since 1.18
689 */
690 public function getContext() {
691 if ( $this->mContext instanceof IContextSource ) {
692 return $this->mContext;
693 } else {
694 wfDebug( __METHOD__ . " called and \$mContext is null. " .
695 "Return RequestContext::getMain(); for sanity\n" );
696
697 return RequestContext::getMain();
698 }
699 }
700
701 /**
702 * Get the WebRequest being used for this instance
703 *
704 * @return WebRequest
705 * @since 1.18
706 */
707 public function getRequest() {
708 return $this->getContext()->getRequest();
709 }
710
711 /**
712 * Get the OutputPage being used for this instance
713 *
714 * @return OutputPage
715 * @since 1.18
716 */
717 public function getOutput() {
718 return $this->getContext()->getOutput();
719 }
720
721 /**
722 * Shortcut to get the User executing this instance
723 *
724 * @return User
725 * @since 1.18
726 */
727 public function getUser() {
728 return $this->getContext()->getUser();
729 }
730
731 /**
732 * Shortcut to get the skin being used for this instance
733 *
734 * @return Skin
735 * @since 1.18
736 */
737 public function getSkin() {
738 return $this->getContext()->getSkin();
739 }
740
741 /**
742 * Shortcut to get user's language
743 *
744 * @return Language
745 * @since 1.19
746 */
747 public function getLanguage() {
748 return $this->getContext()->getLanguage();
749 }
750
751 /**
752 * Shortcut to get main config object
753 * @return Config
754 * @since 1.24
755 */
756 public function getConfig() {
757 return $this->getContext()->getConfig();
758 }
759
760 /**
761 * Return the full title, including $par
762 *
763 * @return Title
764 * @since 1.18
765 */
766 public function getFullTitle() {
767 return $this->getContext()->getTitle();
768 }
769
770 /**
771 * Return the robot policy. Derived classes that override this can change
772 * the robot policy set by setHeaders() from the default 'noindex,nofollow'.
773 *
774 * @return string
775 * @since 1.23
776 */
777 protected function getRobotPolicy() {
778 return 'noindex,nofollow';
779 }
780
781 /**
782 * Wrapper around wfMessage that sets the current context.
783 *
784 * @since 1.16
785 * @return Message
786 * @see wfMessage
787 */
788 public function msg( $key /* $args */ ) {
789 $message = $this->getContext()->msg( ...func_get_args() );
790 // RequestContext passes context to wfMessage, and the language is set from
791 // the context, but setting the language for Message class removes the
792 // interface message status, which breaks for example usernameless gender
793 // invocations. Restore the flag when not including special page in content.
794 if ( $this->including() ) {
795 $message->setInterfaceMessageFlag( false );
796 }
797
798 return $message;
799 }
800
801 /**
802 * Adds RSS/atom links
803 *
804 * @param array $params
805 */
806 protected function addFeedLinks( $params ) {
807 $feedTemplate = wfScript( 'api' );
808
809 foreach ( $this->getConfig()->get( 'FeedClasses' ) as $format => $class ) {
810 $theseParams = $params + [ 'feedformat' => $format ];
811 $url = wfAppendQuery( $feedTemplate, $theseParams );
812 $this->getOutput()->addFeedLink( $format, $url );
813 }
814 }
815
816 /**
817 * Adds help link with an icon via page indicators.
818 * Link target can be overridden by a local message containing a wikilink:
819 * the message key is: lowercase special page name + '-helppage'.
820 * @param string $to Target MediaWiki.org page title or encoded URL.
821 * @param bool $overrideBaseUrl Whether $url is a full URL, to avoid MW.o.
822 * @since 1.25
823 */
824 public function addHelpLink( $to, $overrideBaseUrl = false ) {
825 if ( $this->including() ) {
826 return;
827 }
828
829 $msg = $this->msg(
830 MediaWikiServices::getInstance()->getContentLanguage()->lc( $this->getName() ) .
831 '-helppage' );
832
833 if ( !$msg->isDisabled() ) {
834 $helpUrl = Skin::makeUrl( $msg->plain() );
835 $this->getOutput()->addHelpLink( $helpUrl, true );
836 } else {
837 $this->getOutput()->addHelpLink( $to, $overrideBaseUrl );
838 }
839 }
840
841 /**
842 * Get the group that the special page belongs in on Special:SpecialPage
843 * Use this method, instead of getGroupName to allow customization
844 * of the group name from the wiki side
845 *
846 * @return string Group of this special page
847 * @since 1.21
848 */
849 public function getFinalGroupName() {
850 $name = $this->getName();
851
852 // Allow overriding the group from the wiki side
853 $msg = $this->msg( 'specialpages-specialpagegroup-' . strtolower( $name ) )->inContentLanguage();
854 if ( !$msg->isBlank() ) {
855 $group = $msg->text();
856 } else {
857 // Than use the group from this object
858 $group = $this->getGroupName();
859 }
860
861 return $group;
862 }
863
864 /**
865 * Indicates whether this special page may perform database writes
866 *
867 * @return bool
868 * @since 1.27
869 */
870 public function doesWrites() {
871 return false;
872 }
873
874 /**
875 * Under which header this special page is listed in Special:SpecialPages
876 * See messages 'specialpages-group-*' for valid names
877 * This method defaults to group 'other'
878 *
879 * @return string
880 * @since 1.21
881 */
882 protected function getGroupName() {
883 return 'other';
884 }
885
886 /**
887 * Call wfTransactionalTimeLimit() if this request was POSTed
888 * @since 1.26
889 */
890 protected function useTransactionalTimeLimit() {
891 if ( $this->getRequest()->wasPosted() ) {
892 wfTransactionalTimeLimit();
893 }
894 }
895
896 /**
897 * @since 1.28
898 * @return \MediaWiki\Linker\LinkRenderer
899 */
900 public function getLinkRenderer() {
901 if ( $this->linkRenderer ) {
902 return $this->linkRenderer;
903 } else {
904 return MediaWikiServices::getInstance()->getLinkRenderer();
905 }
906 }
907
908 /**
909 * @since 1.28
910 * @param \MediaWiki\Linker\LinkRenderer $linkRenderer
911 */
912 public function setLinkRenderer( LinkRenderer $linkRenderer ) {
913 $this->linkRenderer = $linkRenderer;
914 }
915
916 /**
917 * Generate (prev x| next x) (20|50|100...) type links for paging
918 *
919 * @param int $offset
920 * @param int $limit
921 * @param array $query Optional URL query parameter string
922 * @param bool $atend Optional param for specified if this is the last page
923 * @param string|bool $subpage Optional param for specifying subpage
924 * @return string
925 */
926 protected function buildPrevNextNavigation( $offset, $limit,
927 array $query = [], $atend = false, $subpage = false
928 ) {
929 $title = $this->getPageTitle( $subpage );
930 $prevNext = new PrevNextNavigationRenderer( $this );
931
932 return $prevNext->buildPrevNextNavigation( $title, $offset, $limit, $query, $atend );
933 }
934 }