3 * Shortcuts to construct a special page alias.
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.
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.
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
21 * @ingroup SpecialPage
25 * Shortcut to construct a special page alias.
27 * @ingroup SpecialPage
29 abstract class RedirectSpecialPage
extends UnlistedSpecialPage
{
30 // Query parameters that can be passed through redirects
31 protected $mAllowedRedirectParams = [];
33 // Query parameters added by redirects
34 protected $mAddedRedirectParams = [];
37 * @param string|null $subpage
40 public function execute( $subpage ) {
41 $redirect = $this->getRedirect( $subpage );
42 $query = $this->getRedirectQuery();
43 // Redirect to a page title with possible query parameters
44 if ( $redirect instanceof Title
) {
45 $url = $redirect->getFullUrlForRedirect( $query );
46 $this->getOutput()->redirect( $url );
49 } elseif ( $redirect === true ) {
50 // Redirect to index.php with query parameters
51 $url = wfAppendQuery( wfScript( 'index' ), $query );
52 $this->getOutput()->redirect( $url );
56 $this->showNoRedirectPage();
61 * If the special page is a redirect, then get the Title object it redirects to.
64 * @param string|null $subpage
67 abstract public function getRedirect( $subpage );
70 * Return part of the request string for a special redirect page
71 * This allows passing, e.g. action=history to Special:Mypage, etc.
75 public function getRedirectQuery() {
77 $request = $this->getRequest();
79 foreach ( array_merge( $this->mAllowedRedirectParams
,
80 [ 'uselang', 'useskin', 'debug' ] // parameters which can be passed to all pages
82 if ( $request->getVal( $arg, null ) !== null ) {
83 $params[$arg] = $request->getVal( $arg );
84 } elseif ( $request->getArray( $arg, null ) !== null ) {
85 $params[$arg] = $request->getArray( $arg );
89 foreach ( $this->mAddedRedirectParams
as $arg => $val ) {
93 return count( $params )
99 * Indicate if the target of this redirect can be used to identify
100 * a particular user of this wiki (e.g., if the redirect is to the
101 * user page of a User). See T109724.
106 public function personallyIdentifiableTarget() {
110 protected function showNoRedirectPage() {
111 $class = static::class;
112 throw new MWException( "RedirectSpecialPage $class doesn't redirect!" );