Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / specialpage / RedirectSpecialPage.php
blobd464b23b961fac6412b639e0ba2f2507efb39e81
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
18 * @file
21 namespace MediaWiki\SpecialPage;
23 use LogicException;
24 use MediaWiki\Title\Title;
26 /**
27 * Shortcut to construct a special page alias.
29 * @stable to extend
31 * @ingroup SpecialPage
33 abstract class RedirectSpecialPage extends UnlistedSpecialPage {
34 /** @var array Query parameters that can be passed through redirects */
35 protected $mAllowedRedirectParams = [];
37 /** @var array Query parameters added by redirects */
38 protected $mAddedRedirectParams = [];
40 /**
41 * @stable to override
42 * @param string|null $subpage
44 public function execute( $subpage ) {
45 $redirect = $this->getRedirect( $subpage );
46 $query = $this->getRedirectQuery( $subpage );
48 if ( $redirect instanceof Title ) {
49 // Redirect to a page title with possible query parameters
50 $url = $redirect->getFullUrlForRedirect( $query );
51 $this->getOutput()->redirect( $url );
52 } elseif ( $redirect === true ) {
53 // Redirect to index.php with query parameters
54 $url = wfAppendQuery( wfScript( 'index' ), $query );
55 $this->getOutput()->redirect( $url );
56 } else {
57 $this->showNoRedirectPage();
61 /**
62 * If the special page is a redirect, then get the Title object it redirects to.
63 * False otherwise.
65 * @param string|null $subpage
66 * @return Title|bool
68 abstract public function getRedirect( $subpage );
70 /**
71 * Return part of the request string for a special redirect page
72 * This allows passing, e.g. action=history to Special:Mypage, etc.
74 * @stable to override
75 * @param string|null $subpage
76 * @return array|false
78 public function getRedirectQuery( $subpage ) {
79 $params = [];
80 $request = $this->getRequest();
82 foreach ( array_merge( $this->mAllowedRedirectParams,
83 [ 'uselang', 'useskin', 'variant', 'debug', 'safemode' ] // parameters which can be passed to all pages
84 ) as $arg ) {
85 if ( $request->getVal( $arg ) !== null ) {
86 $params[$arg] = $request->getVal( $arg );
87 } elseif ( $request->getArray( $arg ) !== null ) {
88 $params[$arg] = $request->getArray( $arg );
92 foreach ( $this->mAddedRedirectParams as $arg => $val ) {
93 $params[$arg] = $val;
96 return count( $params )
97 ? $params
98 : false;
102 * Indicate if the target of this redirect can be used to identify
103 * a particular user of this wiki (e.g., if the redirect is to the
104 * user page of a User). See T109724.
106 * @stable to override
107 * @since 1.27
108 * @return bool
110 public function personallyIdentifiableTarget() {
111 return false;
115 * @stable to override
117 protected function showNoRedirectPage() {
118 $class = static::class;
119 throw new LogicException( "RedirectSpecialPage $class doesn't redirect!" );
123 /** @deprecated class alias since 1.41 */
124 class_alias( RedirectSpecialPage::class, 'RedirectSpecialPage' );