Merge "Special:Newpages feed now shows first revision instead of latest revision"
[lhc/web/wiklou.git] / includes / specialpage / RedirectSpecialPage.php
index 2e6e55a..d3e22a0 100644 (file)
  */
 abstract class RedirectSpecialPage extends UnlistedSpecialPage {
        // Query parameters that can be passed through redirects
-       protected $mAllowedRedirectParams = array();
+       protected $mAllowedRedirectParams = [];
 
        // Query parameters added by redirects
-       protected $mAddedRedirectParams = array();
+       protected $mAddedRedirectParams = [];
 
-       public function execute( $par ) {
-               $redirect = $this->getRedirect( $par );
+       /**
+        * @param string|null $subpage
+        */
+       public function execute( $subpage ) {
+               $redirect = $this->getRedirect( $subpage );
                $query = $this->getRedirectQuery();
                // Redirect to a page title with possible query parameters
                if ( $redirect instanceof Title ) {
-                       $url = $redirect->getFullURL( $query );
+                       $url = $redirect->getFullUrlForRedirect( $query );
                        $this->getOutput()->redirect( $url );
 
                        return $redirect;
@@ -49,8 +52,7 @@ abstract class RedirectSpecialPage extends UnlistedSpecialPage {
 
                        return $redirect;
                } else {
-                       $class = get_class( $this );
-                       throw new MWException( "RedirectSpecialPage $class doesn't redirect!" );
+                       $this->showNoRedirectPage();
                }
        }
 
@@ -58,22 +60,24 @@ abstract class RedirectSpecialPage extends UnlistedSpecialPage {
         * If the special page is a redirect, then get the Title object it redirects to.
         * False otherwise.
         *
-        * @param string $par Subpage string
+        * @param string|null $subpage
         * @return Title|bool
         */
-       abstract public function getRedirect( $par );
+       abstract public function getRedirect( $subpage );
 
        /**
         * Return part of the request string for a special redirect page
         * This allows passing, e.g. action=history to Special:Mypage, etc.
         *
-        * @return string
+        * @return array|bool
         */
        public function getRedirectQuery() {
-               $params = array();
+               $params = [];
                $request = $this->getRequest();
 
-               foreach ( $this->mAllowedRedirectParams as $arg ) {
+               foreach ( array_merge( $this->mAllowedRedirectParams,
+                               [ 'uselang', 'useskin', 'debug' ] // parameters which can be passed to all pages
+                       ) as $arg ) {
                        if ( $request->getVal( $arg, null ) !== null ) {
                                $params[$arg] = $request->getVal( $arg );
                        } elseif ( $request->getArray( $arg, null ) !== null ) {
@@ -89,6 +93,23 @@ abstract class RedirectSpecialPage extends UnlistedSpecialPage {
                        ? $params
                        : false;
        }
+
+       /**
+        * Indicate if the target of this redirect can be used to identify
+        * a particular user of this wiki (e.g., if the redirect is to the
+        * user page of a User). See T109724.
+        *
+        * @since 1.27
+        * @return bool
+        */
+       public function personallyIdentifiableTarget() {
+               return false;
+       }
+
+       protected function showNoRedirectPage() {
+               $class = static::class;
+               throw new MWException( "RedirectSpecialPage $class doesn't redirect!" );
+       }
 }
 
 /**
@@ -103,7 +124,7 @@ abstract class SpecialRedirectToSpecial extends RedirectSpecialPage {
 
        function __construct(
                $name, $redirName, $redirSubpage = false,
-               $allowedRedirectParams = array(), $addedRedirectParams = array()
+               $allowedRedirectParams = [], $addedRedirectParams = []
        ) {
                parent::__construct( $name );
                $this->redirName = $redirName;
@@ -112,12 +133,16 @@ abstract class SpecialRedirectToSpecial extends RedirectSpecialPage {
                $this->mAddedRedirectParams = $addedRedirectParams;
        }
 
+       /**
+        * @param string|null $subpage
+        * @return Title|bool
+        */
        public function getRedirect( $subpage ) {
                if ( $this->redirSubpage === false ) {
                        return SpecialPage::getTitleFor( $this->redirName, $subpage );
-               } else {
-                       return SpecialPage::getTitleFor( $this->redirName, $this->redirSubpage );
                }
+
+               return SpecialPage::getTitleFor( $this->redirName, $this->redirSubpage );
        }
 }
 
@@ -140,11 +165,11 @@ abstract class SpecialRedirectToSpecial extends RedirectSpecialPage {
  * - limit, offset: Useful for linking to history of one's own user page or
  * user talk page. For example, this would be a link to "the last edit to your
  * user talk page in the year 2010":
- * http://en.wikipedia.org/wiki/Special:MyPage?offset=20110000000000&limit=1&action=history
+ * https://en.wikipedia.org/wiki/Special:MyPage?offset=20110000000000&limit=1&action=history
  *
  * - feed: would allow linking to the current user's RSS feed for their user
  * talk page:
- * http://en.wikipedia.org/w/index.php?title=Special:MyTalk&action=history&feed=rss
+ * https://en.wikipedia.org/w/index.php?title=Special:MyTalk&action=history&feed=rss
  *
  * - preloadtitle: Can be used to provide a default section title for a
  * preloaded new comment on one's own talk page.
@@ -159,7 +184,7 @@ abstract class SpecialRedirectToSpecial extends RedirectSpecialPage {
  * - redlink: Affects the message the user sees if their talk page/user talk
  * page does not currently exist. Avoids confusion for newbies with no user
  * pages over why they got a "permission error" following this link:
- * http://en.wikipedia.org/w/index.php?title=Special:MyPage&redlink=1
+ * https://en.wikipedia.org/w/index.php?title=Special:MyPage&redlink=1
  *
  * - debug: determines whether the debug parameter is passed to load.php,
  * which disables reformatting and allows scripts to be debugged. Useful
@@ -187,7 +212,7 @@ abstract class SpecialRedirectToSpecial extends RedirectSpecialPage {
 abstract class RedirectSpecialArticle extends RedirectSpecialPage {
        function __construct( $name ) {
                parent::__construct( $name );
-               $redirectParams = array(
+               $redirectParams = [
                        'action',
                        'redirect', 'rdfrom',
                        # Options for preloaded edits
@@ -198,12 +223,12 @@ abstract class RedirectSpecialArticle extends RedirectSpecialPage {
                        'section', 'oldid', 'diff', 'dir',
                        'limit', 'offset', 'feed',
                        # Misc options
-                       'redlink', 'debug',
+                       'redlink',
                        # Options for action=raw; missing ctype can break JS or CSS in some browsers
                        'ctype', 'maxage', 'smaxage',
-               );
+               ];
 
-               Hooks::run( "RedirectSpecialArticleRedirectParams", array( &$redirectParams ) );
+               Hooks::run( "RedirectSpecialArticleRedirectParams", [ &$redirectParams ] );
                $this->mAllowedRedirectParams = $redirectParams;
        }
 }