Merge "docs: Fix typo"
[mediawiki.git] / includes / specialpage / RedirectSpecialArticle.php
blob768a8161ebbb3c5f15edc508586138ce01b6a639
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 MediaWiki\Title\Title;
25 /**
26 * Helper for any RedirectSpecialPage which redirects the user
27 * to a particular article (as opposed to user contributions, logs, etc.).
29 * This is used by subclasses to create user-independent URLs pointing to
30 * pages about the current user (user page, talk page, contributions, etc.).
31 * This can let us link it statically and cache-safe within wikitext,
32 * e.g. on help pages.
34 * For security reasons these special pages are restricted to only preserve
35 * the following subset of GET parameters to the target page, while
36 * removing and/or ignoring all others.
38 * - useskin, uselang, printable: to alter the appearance of the resulting page
40 * - redirect: allows viewing one's user page or talk page even if it is a
41 * redirect.
43 * - rdfrom: allows redirecting to one's user page or talk page from an
44 * external wiki with the "Redirect from..." notice.
46 * - limit, offset: Useful for linking to history of one's own user page or
47 * user talk page. For example, this would be a link to "the last edit to your
48 * user talk page in the year 2010":
49 * https://en.wikipedia.org/wiki/Special:MyPage?offset=20110000000000&limit=1&action=history
51 * - feed: would allow linking to the current user's RSS feed for their user
52 * talk page:
53 * https://en.wikipedia.org/w/index.php?title=Special:MyTalk&action=history&feed=rss
55 * - preloadtitle: Can be used to provide a default section title for a
56 * preloaded new comment on one's own talk page.
58 * - summary : Can be used to provide a default edit summary for a preloaded
59 * edit to one's own user page or talk page.
61 * - preview: Allows showing/hiding preview on first edit regardless of user
62 * preference, useful for preloaded edits where you know preview wouldn't be
63 * useful.
65 * - redlink: Affects the message the user sees if their talk page/user talk
66 * page does not currently exist. Avoids confusion for newbies with no user
67 * pages over why they got a "permission error" following this link:
68 * https://en.wikipedia.org/w/index.php?title=Special:MyPage&redlink=1
70 * - debug: determines whether the debug parameter is passed to load.php,
71 * which disables reformatting and allows scripts to be debugged. Useful
72 * when debugging scripts that manipulate one's own user page or talk page.
74 * @par Hook extension:
75 * Extensions can add to the redirect parameters list by using the hook
76 * RedirectSpecialArticleRedirectParams
78 * This hook allows extensions which add GET parameters like FlaggedRevs to
79 * retain those parameters when redirecting using special pages.
81 * @par Hook extension example:
82 * @code
83 * $wgHooks['RedirectSpecialArticleRedirectParams'][] =
84 * 'MyExtensionHooks::onRedirectSpecialArticleRedirectParams';
85 * public static function onRedirectSpecialArticleRedirectParams( &$redirectParams ) {
86 * $redirectParams[] = 'stable';
87 * return true;
88 * }
89 * @endcode
91 * @stable to extend
92 * @ingroup SpecialPage
94 abstract class RedirectSpecialArticle extends RedirectSpecialPage {
96 /**
97 * @stable to call
99 * @param string $name
101 public function __construct( $name ) {
102 parent::__construct( $name );
103 $redirectParams = [
104 'action',
105 'redirect', 'rdfrom',
106 # Options for preloaded edits
107 'preload', 'preloadparams', 'editintro', 'preloadtitle', 'summary', 'nosummary',
108 # Options for overriding user settings
109 'preview', 'minor', 'watchthis',
110 # Options for history/diffs
111 'section', 'oldid', 'diff', 'dir',
112 'limit', 'offset', 'feed',
113 # Misc options
114 'redlink',
115 # Options for action=raw; missing ctype can break JS or CSS in some browsers
116 'ctype', 'maxage', 'smaxage',
119 $this->getHookRunner()->onRedirectSpecialArticleRedirectParams( $redirectParams );
120 $this->mAllowedRedirectParams = $redirectParams;
124 * @inheritDoc
126 public function getRedirectQuery( $subpage ) {
127 $query = parent::getRedirectQuery( $subpage );
128 $title = $this->getRedirect( $subpage );
129 // Avoid double redirect for action=edit&redlink=1 for existing pages
130 // (compare to the check in EditPage::edit)
131 if (
132 $query && isset( $query['action'] ) && isset( $query['redlink'] ) &&
133 ( $query['action'] === 'edit' || $query['action'] === 'submit' ) &&
134 (bool)$query['redlink'] &&
135 $title instanceof Title &&
136 $title->exists()
138 return false;
140 return $query;
145 /** @deprecated class alias since 1.41 */
146 class_alias( RedirectSpecialArticle::class, 'RedirectSpecialArticle' );