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