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 * @stable to extend 86 * 87 * @ingroup SpecialPage 88 */ 89abstract class RedirectSpecialArticle extends RedirectSpecialPage { 90 91 /** 92 * @stable to call 93 * 94 * @param string $name 95 */ 96 public function __construct( $name ) { 97 parent::__construct( $name ); 98 $redirectParams = [ 99 'action', 100 'redirect', 'rdfrom', 101 # Options for preloaded edits 102 'preload', 'preloadparams', 'editintro', 'preloadtitle', 'summary', 'nosummary', 103 # Options for overriding user settings 104 'preview', 'minor', 'watchthis', 105 # Options for history/diffs 106 'section', 'oldid', 'diff', 'dir', 107 'limit', 'offset', 'feed', 108 # Misc options 109 'redlink', 110 # Options for action=raw; missing ctype can break JS or CSS in some browsers 111 'ctype', 'maxage', 'smaxage', 112 ]; 113 114 $this->getHookRunner()->onRedirectSpecialArticleRedirectParams( $redirectParams ); 115 $this->mAllowedRedirectParams = $redirectParams; 116 } 117 118 /** 119 * @inheritDoc 120 */ 121 public function getRedirectQuery( $subpage ) { 122 $query = parent::getRedirectQuery( $subpage ); 123 $title = $this->getRedirect( $subpage ); 124 // Avoid double redirect for action=edit&redlink=1 for existing pages 125 // (compare to the check in EditPage::edit) 126 if ( 127 $query && isset( $query['action'] ) && isset( $query['redlink'] ) && 128 ( $query['action'] === 'edit' || $query['action'] === 'submit' ) && 129 (bool)$query['redlink'] && 130 $title instanceof Title && 131 $title->exists() 132 ) { 133 return false; 134 } 135 return $query; 136 } 137 138} 139