MediaWiki  1.29.2
RedirectSpecialPage.php
Go to the documentation of this file.
1 <?php
29 abstract class RedirectSpecialPage extends UnlistedSpecialPage {
30  // Query parameters that can be passed through redirects
31  protected $mAllowedRedirectParams = [];
32 
33  // Query parameters added by redirects
34  protected $mAddedRedirectParams = [];
35 
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->getFullUrlForRedirect( $query );
45  $this->getOutput()->redirect( $url );
46 
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 );
52 
53  return $redirect;
54  } else {
55  $class = static::class;
56  throw new MWException( "RedirectSpecialPage $class doesn't redirect!" );
57  }
58  }
59 
67  abstract public function getRedirect( $subpage );
68 
75  public function getRedirectQuery() {
76  $params = [];
77  $request = $this->getRequest();
78 
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 );
86  }
87  }
88 
89  foreach ( $this->mAddedRedirectParams as $arg => $val ) {
90  $params[$arg] = $val;
91  }
92 
93  return count( $params )
94  ? $params
95  : false;
96  }
97 
106  public function personallyIdentifiableTarget() {
107  return false;
108  }
109 }
110 
116  protected $redirName;
117 
119  protected $redirSubpage;
120 
121  function __construct(
122  $name, $redirName, $redirSubpage = false,
123  $allowedRedirectParams = [], $addedRedirectParams = []
124  ) {
125  parent::__construct( $name );
126  $this->redirName = $redirName;
127  $this->redirSubpage = $redirSubpage;
128  $this->mAllowedRedirectParams = $allowedRedirectParams;
129  $this->mAddedRedirectParams = $addedRedirectParams;
130  }
131 
136  public function getRedirect( $subpage ) {
137  if ( $this->redirSubpage === false ) {
138  return SpecialPage::getTitleFor( $this->redirName, $subpage );
139  }
140 
141  return SpecialPage::getTitleFor( $this->redirName, $this->redirSubpage );
142  }
143 }
144 
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',
225  ];
226 
227  Hooks::run( "RedirectSpecialArticleRedirectParams", [ &$redirectParams ] );
228  $this->mAllowedRedirectParams = $redirectParams;
229  }
230 }
SpecialRedirectToSpecial\$redirSubpage
string $redirSubpage
Name of subpage of redirect target.
Definition: RedirectSpecialPage.php:119
$request
error also a ContextSource you ll probably need to make sure the header is varied on $request
Definition: hooks.txt:2612
RedirectSpecialArticle\__construct
__construct( $name)
Definition: RedirectSpecialPage.php:209
SpecialRedirectToSpecial\__construct
__construct( $name, $redirName, $redirSubpage=false, $allowedRedirectParams=[], $addedRedirectParams=[])
Definition: RedirectSpecialPage.php:121
SpecialPage\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: SpecialPage.php:675
SpecialRedirectToSpecial\getRedirect
getRedirect( $subpage)
Definition: RedirectSpecialPage.php:136
UnlistedSpecialPage
Shortcut to construct a special page which is unlisted by default.
Definition: UnlistedSpecialPage.php:29
captcha-old.count
count
Definition: captcha-old.py:225
SpecialRedirectToSpecial
Definition: RedirectSpecialPage.php:114
$params
$params
Definition: styleTest.css.php:40
SpecialPage\getTitleFor
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...
Definition: SpecialPage.php:82
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:304
RedirectSpecialPage\$mAddedRedirectParams
$mAddedRedirectParams
Definition: RedirectSpecialPage.php:34
RedirectSpecialPage
Shortcut to construct a special page alias.
Definition: RedirectSpecialPage.php:29
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
wfAppendQuery
wfAppendQuery( $url, $query)
Append a query string to an existing URL, which may or may not already have query string parameters a...
Definition: GlobalFunctions.php:500
$query
null for the wiki Added should default to null in handler for backwards compatibility add a value to it if you want to add a cookie that have to vary cache options can modify $query
Definition: hooks.txt:1572
RedirectSpecialPage\$mAllowedRedirectParams
$mAllowedRedirectParams
Definition: RedirectSpecialPage.php:31
MWException
MediaWiki exception.
Definition: MWException.php:26
wfScript
wfScript( $script='index')
Get the path to a specified script file, respecting file extensions; this is a wrapper around $wgScri...
Definition: GlobalFunctions.php:3138
RedirectSpecialPage\execute
execute( $subpage)
Definition: RedirectSpecialPage.php:39
SpecialRedirectToSpecial\$redirName
string $redirName
Name of redirect target.
Definition: RedirectSpecialPage.php:116
RedirectSpecialArticle
Superclass for any RedirectSpecialPage which redirects the user to a particular article (as opposed t...
Definition: RedirectSpecialPage.php:208
SpecialPage\getRequest
getRequest()
Get the WebRequest being used for this instance.
Definition: SpecialPage.php:665
Title
Represents a title within MediaWiki.
Definition: Title.php:39
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
RedirectSpecialPage\getRedirectQuery
getRedirectQuery()
Return part of the request string for a special redirect page This allows passing,...
Definition: RedirectSpecialPage.php:75
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
RedirectSpecialPage\personallyIdentifiableTarget
personallyIdentifiableTarget()
Indicate if the target of this redirect can be used to identify a particular user of this wiki (e....
Definition: RedirectSpecialPage.php:106
RedirectSpecialPage\getRedirect
getRedirect( $subpage)
If the special page is a redirect, then get the Title object it redirects to.
Hooks\run
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:131