Merge "Make DBAccessBase use DBConnRef, rename $wiki, and hide getLoadBalancer()"
[lhc/web/wiklou.git] / includes / specialpage / RedirectSpecialArticle.php
1 <?php
2 /**
3 * Shortcuts to construct a special page alias.
4 *
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.
9 *
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.
14 *
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
19 *
20 * @file
21 * @ingroup SpecialPage
22 */
23
24 /**
25 * Superclass for any RedirectSpecialPage which redirects the user
26 * to a particular article (as opposed to user contributions, logs, etc.).
27 *
28 * For security reasons these special pages are restricted to pass on
29 * the following subset of GET parameters to the target page while
30 * removing all others:
31 *
32 * - useskin, uselang, printable: to alter the appearance of the resulting page
33 *
34 * - redirect: allows viewing one's user page or talk page even if it is a
35 * redirect.
36 *
37 * - rdfrom: allows redirecting to one's user page or talk page from an
38 * external wiki with the "Redirect from..." notice.
39 *
40 * - limit, offset: Useful for linking to history of one's own user page or
41 * user talk page. For example, this would be a link to "the last edit to your
42 * user talk page in the year 2010":
43 * https://en.wikipedia.org/wiki/Special:MyPage?offset=20110000000000&limit=1&action=history
44 *
45 * - feed: would allow linking to the current user's RSS feed for their user
46 * talk page:
47 * https://en.wikipedia.org/w/index.php?title=Special:MyTalk&action=history&feed=rss
48 *
49 * - preloadtitle: Can be used to provide a default section title for a
50 * preloaded new comment on one's own talk page.
51 *
52 * - summary : Can be used to provide a default edit summary for a preloaded
53 * edit to one's own user page or talk page.
54 *
55 * - preview: Allows showing/hiding preview on first edit regardless of user
56 * preference, useful for preloaded edits where you know preview wouldn't be
57 * useful.
58 *
59 * - redlink: Affects the message the user sees if their talk page/user talk
60 * page does not currently exist. Avoids confusion for newbies with no user
61 * pages over why they got a "permission error" following this link:
62 * https://en.wikipedia.org/w/index.php?title=Special:MyPage&redlink=1
63 *
64 * - debug: determines whether the debug parameter is passed to load.php,
65 * which disables reformatting and allows scripts to be debugged. Useful
66 * when debugging scripts that manipulate one's own user page or talk page.
67 *
68 * @par Hook extension:
69 * Extensions can add to the redirect parameters list by using the hook
70 * RedirectSpecialArticleRedirectParams
71 *
72 * This hook allows extensions which add GET parameters like FlaggedRevs to
73 * retain those parameters when redirecting using special pages.
74 *
75 * @par Hook extension example:
76 * @code
77 * $wgHooks['RedirectSpecialArticleRedirectParams'][] =
78 * 'MyExtensionHooks::onRedirectSpecialArticleRedirectParams';
79 * public static function onRedirectSpecialArticleRedirectParams( &$redirectParams ) {
80 * $redirectParams[] = 'stable';
81 * return true;
82 * }
83 * @endcode
84 *
85 * @ingroup SpecialPage
86 */
87 abstract class RedirectSpecialArticle extends RedirectSpecialPage {
88 function __construct( $name ) {
89 parent::__construct( $name );
90 $redirectParams = [
91 'action',
92 'redirect', 'rdfrom',
93 # Options for preloaded edits
94 'preload', 'preloadparams', 'editintro', 'preloadtitle', 'summary', 'nosummary',
95 # Options for overriding user settings
96 'preview', 'minor', 'watchthis',
97 # Options for history/diffs
98 'section', 'oldid', 'diff', 'dir',
99 'limit', 'offset', 'feed',
100 # Misc options
101 'redlink',
102 # Options for action=raw; missing ctype can break JS or CSS in some browsers
103 'ctype', 'maxage', 'smaxage',
104 ];
105
106 Hooks::run( "RedirectSpecialArticleRedirectParams", [ &$redirectParams ] );
107 $this->mAllowedRedirectParams = $redirectParams;
108 }
109
110 /**
111 * @inheritDoc
112 */
113 public function getRedirectQuery( $subpage ) {
114 $query = parent::getRedirectQuery( $subpage );
115 $title = $this->getRedirect( $subpage );
116 // Avoid double redirect for action=edit&redlink=1 for existing pages
117 // (compare to the check in EditPage::edit)
118 if (
119 $query && isset( $query['action'] ) && isset( $query['redlink'] ) &&
120 ( $query['action'] === 'edit' || $query['action'] === 'submit' ) &&
121 (bool)$query['redlink'] &&
122 $title instanceof Title &&
123 $title->exists()
124 ) {
125 return false;
126 }
127 return $query;
128 }
129
130 }