Expose $wgMaxArticleSize in siteinfo query api
[mediawiki.git] / includes / specialpage / RedirectSpecialPage.php
blobea7d7831480282bfd7042989eae78291b8b0a5d2
1 <?php
2 /**
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
20 * @file
21 * @ingroup SpecialPage
24 /**
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 = [];
36 /**
37 * @param string|null $subpage
39 public function execute( $subpage ) {
40 $redirect = $this->getRedirect( $subpage );
41 $query = $this->getRedirectQuery();
42 // Redirect to a page title with possible query parameters
43 if ( $redirect instanceof Title ) {
44 $url = $redirect->getFullURL( $query );
45 $this->getOutput()->redirect( $url );
47 return $redirect;
48 } elseif ( $redirect === true ) {
49 // Redirect to index.php with query parameters
50 $url = wfAppendQuery( wfScript( 'index' ), $query );
51 $this->getOutput()->redirect( $url );
53 return $redirect;
54 } else {
55 $class = get_class( $this );
56 throw new MWException( "RedirectSpecialPage $class doesn't redirect!" );
60 /**
61 * If the special page is a redirect, then get the Title object it redirects to.
62 * False otherwise.
64 * @param string|null $subpage
65 * @return Title|bool
67 abstract public function getRedirect( $subpage );
69 /**
70 * Return part of the request string for a special redirect page
71 * This allows passing, e.g. action=history to Special:Mypage, etc.
73 * @return array|bool
75 public function getRedirectQuery() {
76 $params = [];
77 $request = $this->getRequest();
79 foreach ( array_merge( $this->mAllowedRedirectParams,
80 [ 'uselang', 'useskin', 'debug' ] // parameters which can be passed to all pages
81 ) as $arg ) {
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 ) {
90 $params[$arg] = $val;
93 return count( $params )
94 ? $params
95 : false;
98 /**
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.
103 * @since 1.27
104 * @return bool
106 public function personallyIdentifiableTarget() {
107 return false;
112 * @ingroup SpecialPage
114 abstract class SpecialRedirectToSpecial extends RedirectSpecialPage {
115 /** @var string Name of redirect target */
116 protected $redirName;
118 /** @var string Name of subpage of redirect target */
119 protected $redirSubpage;
121 function __construct(
122 $name, $redirName, $redirSubpage = false,
123 $allowedRedirectParams = [], $addedRedirectParams = []
125 parent::__construct( $name );
126 $this->redirName = $redirName;
127 $this->redirSubpage = $redirSubpage;
128 $this->mAllowedRedirectParams = $allowedRedirectParams;
129 $this->mAddedRedirectParams = $addedRedirectParams;
133 * @param string|null $subpage
134 * @return Title|bool
136 public function getRedirect( $subpage ) {
137 if ( $this->redirSubpage === false ) {
138 return SpecialPage::getTitleFor( $this->redirName, $subpage );
141 return SpecialPage::getTitleFor( $this->redirName, $this->redirSubpage );
146 * Superclass for any RedirectSpecialPage which redirects the user
147 * to a particular article (as opposed to user contributions, logs, etc.).
149 * For security reasons these special pages are restricted to pass on
150 * the following subset of GET parameters to the target page while
151 * removing all others:
153 * - useskin, uselang, printable: to alter the appearance of the resulting page
155 * - redirect: allows viewing one's user page or talk page even if it is a
156 * redirect.
158 * - rdfrom: allows redirecting to one's user page or talk page from an
159 * external wiki with the "Redirect from..." notice.
161 * - limit, offset: Useful for linking to history of one's own user page or
162 * user talk page. For example, this would be a link to "the last edit to your
163 * user talk page in the year 2010":
164 * https://en.wikipedia.org/wiki/Special:MyPage?offset=20110000000000&limit=1&action=history
166 * - feed: would allow linking to the current user's RSS feed for their user
167 * talk page:
168 * https://en.wikipedia.org/w/index.php?title=Special:MyTalk&action=history&feed=rss
170 * - preloadtitle: Can be used to provide a default section title for a
171 * preloaded new comment on one's own talk page.
173 * - summary : Can be used to provide a default edit summary for a preloaded
174 * edit to one's own user page or talk page.
176 * - preview: Allows showing/hiding preview on first edit regardless of user
177 * preference, useful for preloaded edits where you know preview wouldn't be
178 * useful.
180 * - redlink: Affects the message the user sees if their talk page/user talk
181 * page does not currently exist. Avoids confusion for newbies with no user
182 * pages over why they got a "permission error" following this link:
183 * https://en.wikipedia.org/w/index.php?title=Special:MyPage&redlink=1
185 * - debug: determines whether the debug parameter is passed to load.php,
186 * which disables reformatting and allows scripts to be debugged. Useful
187 * when debugging scripts that manipulate one's own user page or talk page.
189 * @par Hook extension:
190 * Extensions can add to the redirect parameters list by using the hook
191 * RedirectSpecialArticleRedirectParams
193 * This hook allows extensions which add GET parameters like FlaggedRevs to
194 * retain those parameters when redirecting using special pages.
196 * @par Hook extension example:
197 * @code
198 * $wgHooks['RedirectSpecialArticleRedirectParams'][] =
199 * 'MyExtensionHooks::onRedirectSpecialArticleRedirectParams';
200 * public static function onRedirectSpecialArticleRedirectParams( &$redirectParams ) {
201 * $redirectParams[] = 'stable';
202 * return true;
204 * @endcode
206 * @ingroup SpecialPage
208 abstract class RedirectSpecialArticle extends RedirectSpecialPage {
209 function __construct( $name ) {
210 parent::__construct( $name );
211 $redirectParams = [
212 'action',
213 'redirect', 'rdfrom',
214 # Options for preloaded edits
215 'preload', 'preloadparams', 'editintro', 'preloadtitle', 'summary', 'nosummary',
216 # Options for overriding user settings
217 'preview', 'minor', 'watchthis',
218 # Options for history/diffs
219 'section', 'oldid', 'diff', 'dir',
220 'limit', 'offset', 'feed',
221 # Misc options
222 'redlink',
223 # Options for action=raw; missing ctype can break JS or CSS in some browsers
224 'ctype', 'maxage', 'smaxage',
227 Hooks::run( "RedirectSpecialArticleRedirectParams", [ &$redirectParams ] );
228 $this->mAllowedRedirectParams = $redirectParams;