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
21 namespace MediaWiki\SpecialPage
;
24 use MediaWiki\Title\Title
;
27 * Shortcut to construct a special page alias.
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 = [];
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 );
57 $this->showNoRedirectPage();
62 * If the special page is a redirect, then get the Title object it redirects to.
65 * @param string|null $subpage
68 abstract public function getRedirect( $subpage );
71 * Return part of the request string for a special redirect page
72 * This allows passing, e.g. action=history to Special:Mypage, etc.
75 * @param string|null $subpage
78 public function getRedirectQuery( $subpage ) {
80 $request = $this->getRequest();
82 foreach ( array_merge( $this->mAllowedRedirectParams
,
83 [ 'uselang', 'useskin', 'variant', 'debug', 'safemode' ] // parameters which can be passed to all pages
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 ) {
96 return count( $params )
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
110 public function personallyIdentifiableTarget() {
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' );