From 22c9aa5ec073c3e7683f874357e40f27bce9e270 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bartosz=20Dziewo=C5=84ski?= Date: Mon, 9 Dec 2013 17:52:16 +0100 Subject: [PATCH] Split includes/SpecialPage.php MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Separated base classes for special pages (most of them abstract) and several actual special pages, which were previously both in the same file. Added license headings, @ingroup SpecialPage and updated class doc comments; no other changes. Most classes are now in separate files (the list of changes can be seen by diffing AutoLoader.php), with three exceptions: * SpecialListAdmins and SpecialListBots (redirects to Special:ListUsers with a parameter) joined their friend in includes/specials/SpecialListusers.php. * SpecialMycontributions, SpecialMypage, SpecialMytalk, SpecialMyuploads and SpecialAllMyUploads were moved into a new file includes/specials/SpecialMyRedirectPages.php – each of them is literally ten lines of code and any changes are likely to touch them all, separate files seem impractical. * RedirectSpecialArticle and SpecialRedirectToSpecial are in one file with their parent class RedirectSpecialPage (on a side note, I filed bug 58215 to rename them to something less silly). Change-Id: Ida87238401b182924dbe169a6278588bc2fbecfd --- includes/AutoLoader.php | 32 +- includes/specialpage/FormSpecialPage.php | 192 +++++++ .../specialpage/IncludableSpecialPage.php | 39 ++ includes/specialpage/RedirectSpecialPage.php | 206 +++++++ includes/{ => specialpage}/SpecialPage.php | 529 +----------------- includes/specialpage/UnlistedSpecialPage.php | 37 ++ includes/specials/SpecialCreateAccount.php | 44 ++ includes/specials/SpecialListusers.php | 22 + includes/specials/SpecialMyRedirectPages.php | 113 ++++ includes/specials/SpecialPermanentLink.php | 44 ++ 10 files changed, 718 insertions(+), 540 deletions(-) create mode 100644 includes/specialpage/FormSpecialPage.php create mode 100644 includes/specialpage/IncludableSpecialPage.php create mode 100644 includes/specialpage/RedirectSpecialPage.php rename includes/{ => specialpage}/SpecialPage.php (64%) create mode 100644 includes/specialpage/UnlistedSpecialPage.php create mode 100644 includes/specials/SpecialCreateAccount.php create mode 100644 includes/specials/SpecialMyRedirectPages.php create mode 100644 includes/specials/SpecialPermanentLink.php diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index 5ba689a87e..ca40d1e461 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -84,7 +84,7 @@ $wgAutoloadLocalClasses = array( 'FormlessAction' => 'includes/Action.php', 'FormAction' => 'includes/Action.php', 'FormOptions' => 'includes/FormOptions.php', - 'FormSpecialPage' => 'includes/SpecialPage.php', + 'FormSpecialPage' => 'includes/specialpage/FormSpecialPage.php', 'GitInfo' => 'includes/GitInfo.php', 'HistoryBlob' => 'includes/HistoryBlob.php', 'HistoryBlobCurStub' => 'includes/HistoryBlob.php', @@ -124,7 +124,7 @@ $wgAutoloadLocalClasses = array( 'ImageQueryPage' => 'includes/ImageQueryPage.php', 'ImportStreamSource' => 'includes/Import.php', 'ImportStringSource' => 'includes/Import.php', - 'IncludableSpecialPage' => 'includes/SpecialPage.php', + 'IncludableSpecialPage' => 'includes/specialpage/IncludableSpecialPage.php', 'IndexPager' => 'includes/Pager.php', 'Interwiki' => 'includes/interwiki/Interwiki.php', 'LCStore' => 'includes/cache/LocalisationCache.php', @@ -175,8 +175,8 @@ $wgAutoloadLocalClasses = array( 'RawMessage' => 'includes/Message.php', 'RdfMetaData' => 'includes/Metadata.php', 'ReadOnlyError' => 'includes/Exception.php', - 'RedirectSpecialArticle' => 'includes/SpecialPage.php', - 'RedirectSpecialPage' => 'includes/SpecialPage.php', + 'RedirectSpecialArticle' => 'includes/specialpage/RedirectSpecialPage.php', + 'RedirectSpecialPage' => 'includes/specialpage/RedirectSpecialPage.php', 'ReverseChronologicalPager' => 'includes/Pager.php', 'RevisionItem' => 'includes/RevisionList.php', 'RevisionItemBase' => 'includes/RevisionList.php', @@ -190,17 +190,17 @@ $wgAutoloadLocalClasses = array( 'SiteStatsInit' => 'includes/SiteStats.php', 'Skin' => 'includes/Skin.php', 'SkinTemplate' => 'includes/SkinTemplate.php', - 'SpecialCreateAccount' => 'includes/SpecialPage.php', - 'SpecialListAdmins' => 'includes/SpecialPage.php', - 'SpecialListBots' => 'includes/SpecialPage.php', - 'SpecialMycontributions' => 'includes/SpecialPage.php', - 'SpecialMypage' => 'includes/SpecialPage.php', - 'SpecialMytalk' => 'includes/SpecialPage.php', - 'SpecialMyuploads' => 'includes/SpecialPage.php', - 'SpecialAllMyUploads' => 'includes/SpecialPage.php', - 'SpecialPage' => 'includes/SpecialPage.php', + 'SpecialCreateAccount' => 'includes/specials/SpecialCreateAccount.php', + 'SpecialListAdmins' => 'includes/specials/SpecialListusers.php', + 'SpecialListBots' => 'includes/specials/SpecialListusers.php', + 'SpecialMycontributions' => 'includes/specials/SpecialMyRedirectPages.php', + 'SpecialMypage' => 'includes/specials/SpecialMyRedirectPages.php', + 'SpecialMytalk' => 'includes/specials/SpecialMyRedirectPages.php', + 'SpecialMyuploads' => 'includes/specials/SpecialMyRedirectPages.php', + 'SpecialAllMyUploads' => 'includes/specials/SpecialMyRedirectPages.php', + 'SpecialPage' => 'includes/specialpage/SpecialPage.php', 'SpecialPageFactory' => 'includes/SpecialPageFactory.php', - 'SpecialRedirectToSpecial' => 'includes/SpecialPage.php', + 'SpecialRedirectToSpecial' => 'includes/specialpage/RedirectSpecialPage.php', 'SquidPurgeClient' => 'includes/SquidPurgeClient.php', 'SquidPurgeClientPool' => 'includes/SquidPurgeClient.php', 'StatCounter' => 'includes/StatCounter.php', @@ -216,7 +216,7 @@ $wgAutoloadLocalClasses = array( 'TitleArray' => 'includes/TitleArray.php', 'TitleArrayFromResult' => 'includes/TitleArray.php', 'ThrottledError' => 'includes/Exception.php', - 'UnlistedSpecialPage' => 'includes/SpecialPage.php', + 'UnlistedSpecialPage' => 'includes/specialpage/UnlistedSpecialPage.php', 'UploadSourceAdapter' => 'includes/Import.php', 'UppercaseCollation' => 'includes/Collation.php', 'User' => 'includes/User.php', @@ -978,7 +978,7 @@ $wgAutoloadLocalClasses = array( 'SpecialNewpages' => 'includes/specials/SpecialNewpages.php', 'SpecialPasswordReset' => 'includes/specials/SpecialPasswordReset.php', 'SpecialPagesWithProp' => 'includes/specials/SpecialPagesWithProp.php', - 'SpecialPermanentLink' => 'includes/SpecialPage.php', + 'SpecialPermanentLink' => 'includes/specials/SpecialPermanentLink.php', 'SpecialPreferences' => 'includes/specials/SpecialPreferences.php', 'SpecialPrefixindex' => 'includes/specials/SpecialPrefixindex.php', 'SpecialProtectedpages' => 'includes/specials/SpecialProtectedpages.php', diff --git a/includes/specialpage/FormSpecialPage.php b/includes/specialpage/FormSpecialPage.php new file mode 100644 index 0000000000..90f82e0f7a --- /dev/null +++ b/includes/specialpage/FormSpecialPage.php @@ -0,0 +1,192 @@ +addPreText() + */ + protected function preText() { + return ''; + } + + /** + * Add post-text to the form + * @return String HTML which will be sent to $form->addPostText() + */ + protected function postText() { + return ''; + } + + /** + * Play with the HTMLForm if you need to more substantially + * @param $form HTMLForm + */ + protected function alterForm( HTMLForm $form ) { + } + + /** + * Get message prefix for HTMLForm + * + * @since 1.21 + * @return string + */ + protected function getMessagePrefix() { + return strtolower( $this->getName() ); + } + + /** + * Get the HTMLForm to control behavior + * @return HTMLForm|null + */ + protected function getForm() { + $this->fields = $this->getFormFields(); + + $form = new HTMLForm( $this->fields, $this->getContext(), $this->getMessagePrefix() ); + $form->setSubmitCallback( array( $this, 'onSubmit' ) ); + // If the form is a compact vertical form, then don't output this ugly + // fieldset surrounding it. + // XXX Special pages can setDisplayFormat to 'vform' in alterForm(), but that + // is called after this. + if ( !$form->isVForm() ) { + $form->setWrapperLegendMsg( $this->getMessagePrefix() . '-legend' ); + } + + $headerMsg = $this->msg( $this->getMessagePrefix() . '-text' ); + if ( !$headerMsg->isDisabled() ) { + $form->addHeaderText( $headerMsg->parseAsBlock() ); + } + + // Retain query parameters (uselang etc) + $params = array_diff_key( + $this->getRequest()->getQueryValues(), array( 'title' => null ) ); + $form->addHiddenField( 'redirectparams', wfArrayToCgi( $params ) ); + + $form->addPreText( $this->preText() ); + $form->addPostText( $this->postText() ); + $this->alterForm( $form ); + + // Give hooks a chance to alter the form, adding extra fields or text etc + wfRunHooks( "Special{$this->getName()}BeforeFormDisplay", array( &$form ) ); + + return $form; + } + + /** + * Process the form on POST submission. + * @param $data Array + * @return Bool|Array true for success, false for didn't-try, array of errors on failure + */ + abstract public function onSubmit( array $data ); + + /** + * Do something exciting on successful processing of the form, most likely to show a + * confirmation message + * @since 1.22 Default is to do nothing + */ + public function onSuccess() { + } + + /** + * Basic SpecialPage workflow: get a form, send it to the user; get some data back, + * + * @param string $par Subpage string if one was specified + */ + public function execute( $par ) { + $this->setParameter( $par ); + $this->setHeaders(); + + // This will throw exceptions if there's a problem + $this->checkExecutePermissions( $this->getUser() ); + + $form = $this->getForm(); + if ( $form->show() ) { + $this->onSuccess(); + } + } + + /** + * Maybe do something interesting with the subpage parameter + * @param string $par + */ + protected function setParameter( $par ) { + $this->par = $par; + } + + /** + * Called from execute() to check if the given user can perform this action. + * Failures here must throw subclasses of ErrorPageError. + * @param $user User + * @throws UserBlockedError + * @return Bool true + */ + protected function checkExecutePermissions( User $user ) { + $this->checkPermissions(); + + if ( $this->requiresUnblock() && $user->isBlocked() ) { + $block = $user->getBlock(); + throw new UserBlockedError( $block ); + } + + if ( $this->requiresWrite() ) { + $this->checkReadOnly(); + } + + return true; + } + + /** + * Whether this action requires the wiki not to be locked + * @return Bool + */ + public function requiresWrite() { + return true; + } + + /** + * Whether this action cannot be executed by a blocked user + * @return Bool + */ + public function requiresUnblock() { + return true; + } +} diff --git a/includes/specialpage/IncludableSpecialPage.php b/includes/specialpage/IncludableSpecialPage.php new file mode 100644 index 0000000000..2f7f69ce88 --- /dev/null +++ b/includes/specialpage/IncludableSpecialPage.php @@ -0,0 +1,39 @@ +getRedirect( $par ); + $query = $this->getRedirectQuery(); + // Redirect to a page title with possible query parameters + if ( $redirect instanceof Title ) { + $url = $redirect->getFullURL( $query ); + $this->getOutput()->redirect( $url ); + return $redirect; + } elseif ( $redirect === true ) { + // Redirect to index.php with query parameters + $url = wfAppendQuery( wfScript( 'index' ), $query ); + $this->getOutput()->redirect( $url ); + return $redirect; + } else { + $class = get_class( $this ); + throw new MWException( "RedirectSpecialPage $class doesn't redirect!" ); + } + } + + /** + * If the special page is a redirect, then get the Title object it redirects to. + * False otherwise. + * + * @param string $par Subpage string + * @return Title|bool + */ + abstract public function getRedirect( $par ); + + /** + * Return part of the request string for a special redirect page + * This allows passing, e.g. action=history to Special:Mypage, etc. + * + * @return String + */ + public function getRedirectQuery() { + $params = array(); + + foreach ( $this->mAllowedRedirectParams as $arg ) { + if ( $this->getRequest()->getVal( $arg, null ) !== null ) { + $params[$arg] = $this->getRequest()->getVal( $arg ); + } + } + + foreach ( $this->mAddedRedirectParams as $arg => $val ) { + $params[$arg] = $val; + } + + return count( $params ) + ? $params + : false; + } +} + +/** + * @ingroup SpecialPage + */ +abstract class SpecialRedirectToSpecial extends RedirectSpecialPage { + // @todo FIXME: Visibility must be declared + var $redirName, $redirSubpage; + + function __construct( + $name, $redirName, $redirSubpage = false, + $allowedRedirectParams = array(), $addedRedirectParams = array() + ) { + parent::__construct( $name ); + $this->redirName = $redirName; + $this->redirSubpage = $redirSubpage; + $this->mAllowedRedirectParams = $allowedRedirectParams; + $this->mAddedRedirectParams = $addedRedirectParams; + } + + public function getRedirect( $subpage ) { + if ( $this->redirSubpage === false ) { + return SpecialPage::getTitleFor( $this->redirName, $subpage ); + } else { + return SpecialPage::getTitleFor( $this->redirName, $this->redirSubpage ); + } + } +} + +/** + * Superclass for any RedirectSpecialPage which redirects the user + * to a particular article (as opposed to user contributions, logs, etc.). + * + * For security reasons these special pages are restricted to pass on + * the following subset of GET parameters to the target page while + * removing all others: + * + * - useskin, uselang, printable: to alter the appearance of the resulting page + * + * - redirect: allows viewing one's user page or talk page even if it is a + * redirect. + * + * - rdfrom: allows redirecting to one's user page or talk page from an + * external wiki with the "Redirect from..." notice. + * + * - 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 + * + * - 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 + * + * - preloadtitle: Can be used to provide a default section title for a + * preloaded new comment on one's own talk page. + * + * - summary : Can be used to provide a default edit summary for a preloaded + * edit to one's own user page or talk page. + * + * - preview: Allows showing/hiding preview on first edit regardless of user + * preference, useful for preloaded edits where you know preview wouldn't be + * useful. + * + * - internaledit, externaledit, mode: Allows forcing the use of the + * internal/external editor, e.g. to force the internal editor for + * short/simple preloaded edits. + * + * - 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 + * + * - debug: determines whether the debug parameter is passed to load.php, + * which disables reformatting and allows scripts to be debugged. Useful + * when debugging scripts that manipulate one's own user page or talk page. + * + * @par Hook extension: + * Extensions can add to the redirect parameters list by using the hook + * RedirectSpecialArticleRedirectParams + * + * This hook allows extensions which add GET parameters like FlaggedRevs to + * retain those parameters when redirecting using special pages. + * + * @par Hook extension example: + * @code + * $wgHooks['RedirectSpecialArticleRedirectParams'][] = + * 'MyExtensionHooks::onRedirectSpecialArticleRedirectParams'; + * public static function onRedirectSpecialArticleRedirectParams( &$redirectParams ) { + * $redirectParams[] = 'stable'; + * return true; + * } + * @endcode + * + * @ingroup SpecialPage + */ +abstract class RedirectSpecialArticle extends RedirectSpecialPage { + function __construct( $name ) { + parent::__construct( $name ); + $redirectParams = array( + 'action', + 'redirect', 'rdfrom', + # Options for preloaded edits + 'preload', 'editintro', 'preloadtitle', 'summary', 'nosummary', + # Options for overriding user settings + 'preview', 'internaledit', 'externaledit', 'mode', 'minor', 'watchthis', + # Options for history/diffs + 'section', 'oldid', 'diff', 'dir', + 'limit', 'offset', 'feed', + # Misc options + 'redlink', 'debug', + # Options for action=raw; missing ctype can break JS or CSS in some browsers + 'ctype', 'maxage', 'smaxage', + ); + + wfRunHooks( "RedirectSpecialArticleRedirectParams", array( &$redirectParams ) ); + $this->mAllowedRedirectParams = $redirectParams; + } +} diff --git a/includes/SpecialPage.php b/includes/specialpage/SpecialPage.php similarity index 64% rename from includes/SpecialPage.php rename to includes/specialpage/SpecialPage.php index f70a6dc192..e874b3e2df 100644 --- a/includes/SpecialPage.php +++ b/includes/specialpage/SpecialPage.php @@ -22,8 +22,11 @@ */ /** - * Parent special page class, also static functions for handling the special - * page list. + * Parent class for all special pages. + * + * Includes some static functions for handling the special page list deprecated + * in favor of SpecialPageFactory. + * * @ingroup SpecialPage */ class SpecialPage { @@ -957,525 +960,3 @@ class SpecialPage { return '-'; } } - -/** - * Special page which uses an HTMLForm to handle processing. This is mostly a - * clone of FormAction. More special pages should be built this way; maybe this could be - * a new structure for SpecialPages - */ -abstract class FormSpecialPage extends SpecialPage { - /** - * The sub-page of the special page. - * @var string - */ - protected $par = null; - - /** - * Get an HTMLForm descriptor array - * @return Array - */ - abstract protected function getFormFields(); - - /** - * Add pre-text to the form - * @return String HTML which will be sent to $form->addPreText() - */ - protected function preText() { - return ''; - } - - /** - * Add post-text to the form - * @return String HTML which will be sent to $form->addPostText() - */ - protected function postText() { - return ''; - } - - /** - * Play with the HTMLForm if you need to more substantially - * @param $form HTMLForm - */ - protected function alterForm( HTMLForm $form ) { - } - - /** - * Get message prefix for HTMLForm - * - * @since 1.21 - * @return string - */ - protected function getMessagePrefix() { - return strtolower( $this->getName() ); - } - - /** - * Get the HTMLForm to control behavior - * @return HTMLForm|null - */ - protected function getForm() { - $this->fields = $this->getFormFields(); - - $form = new HTMLForm( $this->fields, $this->getContext(), $this->getMessagePrefix() ); - $form->setSubmitCallback( array( $this, 'onSubmit' ) ); - // If the form is a compact vertical form, then don't output this ugly - // fieldset surrounding it. - // XXX Special pages can setDisplayFormat to 'vform' in alterForm(), but that - // is called after this. - if ( !$form->isVForm() ) { - $form->setWrapperLegendMsg( $this->getMessagePrefix() . '-legend' ); - } - - $headerMsg = $this->msg( $this->getMessagePrefix() . '-text' ); - if ( !$headerMsg->isDisabled() ) { - $form->addHeaderText( $headerMsg->parseAsBlock() ); - } - - // Retain query parameters (uselang etc) - $params = array_diff_key( - $this->getRequest()->getQueryValues(), array( 'title' => null ) ); - $form->addHiddenField( 'redirectparams', wfArrayToCgi( $params ) ); - - $form->addPreText( $this->preText() ); - $form->addPostText( $this->postText() ); - $this->alterForm( $form ); - - // Give hooks a chance to alter the form, adding extra fields or text etc - wfRunHooks( "Special{$this->getName()}BeforeFormDisplay", array( &$form ) ); - - return $form; - } - - /** - * Process the form on POST submission. - * @param $data Array - * @return Bool|Array true for success, false for didn't-try, array of errors on failure - */ - abstract public function onSubmit( array $data ); - - /** - * Do something exciting on successful processing of the form, most likely to show a - * confirmation message - * @since 1.22 Default is to do nothing - */ - public function onSuccess() { - } - - /** - * Basic SpecialPage workflow: get a form, send it to the user; get some data back, - * - * @param string $par Subpage string if one was specified - */ - public function execute( $par ) { - $this->setParameter( $par ); - $this->setHeaders(); - - // This will throw exceptions if there's a problem - $this->checkExecutePermissions( $this->getUser() ); - - $form = $this->getForm(); - if ( $form->show() ) { - $this->onSuccess(); - } - } - - /** - * Maybe do something interesting with the subpage parameter - * @param string $par - */ - protected function setParameter( $par ) { - $this->par = $par; - } - - /** - * Called from execute() to check if the given user can perform this action. - * Failures here must throw subclasses of ErrorPageError. - * @param $user User - * @throws UserBlockedError - * @return Bool true - */ - protected function checkExecutePermissions( User $user ) { - $this->checkPermissions(); - - if ( $this->requiresUnblock() && $user->isBlocked() ) { - $block = $user->getBlock(); - throw new UserBlockedError( $block ); - } - - if ( $this->requiresWrite() ) { - $this->checkReadOnly(); - } - - return true; - } - - /** - * Whether this action requires the wiki not to be locked - * @return Bool - */ - public function requiresWrite() { - return true; - } - - /** - * Whether this action cannot be executed by a blocked user - * @return Bool - */ - public function requiresUnblock() { - return true; - } -} - -/** - * Shortcut to construct a special page which is unlisted by default - * @ingroup SpecialPage - */ -class UnlistedSpecialPage extends SpecialPage { - function __construct( $name, $restriction = '', $function = false, $file = 'default' ) { - parent::__construct( $name, $restriction, false, $function, $file ); - } - - public function isListed() { - return false; - } -} - -/** - * Shortcut to construct an includable special page - * @ingroup SpecialPage - */ -class IncludableSpecialPage extends SpecialPage { - function __construct( - $name, $restriction = '', $listed = true, $function = false, $file = 'default' - ) { - parent::__construct( $name, $restriction, $listed, $function, $file, true ); - } - - public function isIncludable() { - return true; - } -} - -/** - * Shortcut to construct a special page alias. - * @ingroup SpecialPage - */ -abstract class RedirectSpecialPage extends UnlistedSpecialPage { - - // Query parameters that can be passed through redirects - protected $mAllowedRedirectParams = array(); - - // Query parameters added by redirects - protected $mAddedRedirectParams = array(); - - public function execute( $par ) { - $redirect = $this->getRedirect( $par ); - $query = $this->getRedirectQuery(); - // Redirect to a page title with possible query parameters - if ( $redirect instanceof Title ) { - $url = $redirect->getFullURL( $query ); - $this->getOutput()->redirect( $url ); - return $redirect; - } elseif ( $redirect === true ) { - // Redirect to index.php with query parameters - $url = wfAppendQuery( wfScript( 'index' ), $query ); - $this->getOutput()->redirect( $url ); - return $redirect; - } else { - $class = get_class( $this ); - throw new MWException( "RedirectSpecialPage $class doesn't redirect!" ); - } - } - - /** - * If the special page is a redirect, then get the Title object it redirects to. - * False otherwise. - * - * @param string $par Subpage string - * @return Title|bool - */ - abstract public function getRedirect( $par ); - - /** - * Return part of the request string for a special redirect page - * This allows passing, e.g. action=history to Special:Mypage, etc. - * - * @return String - */ - public function getRedirectQuery() { - $params = array(); - - foreach ( $this->mAllowedRedirectParams as $arg ) { - if ( $this->getRequest()->getVal( $arg, null ) !== null ) { - $params[$arg] = $this->getRequest()->getVal( $arg ); - } - } - - foreach ( $this->mAddedRedirectParams as $arg => $val ) { - $params[$arg] = $val; - } - - return count( $params ) - ? $params - : false; - } -} - -abstract class SpecialRedirectToSpecial extends RedirectSpecialPage { - // @todo FIXME: Visibility must be declared - var $redirName, $redirSubpage; - - function __construct( - $name, $redirName, $redirSubpage = false, - $allowedRedirectParams = array(), $addedRedirectParams = array() - ) { - parent::__construct( $name ); - $this->redirName = $redirName; - $this->redirSubpage = $redirSubpage; - $this->mAllowedRedirectParams = $allowedRedirectParams; - $this->mAddedRedirectParams = $addedRedirectParams; - } - - public function getRedirect( $subpage ) { - if ( $this->redirSubpage === false ) { - return SpecialPage::getTitleFor( $this->redirName, $subpage ); - } else { - return SpecialPage::getTitleFor( $this->redirName, $this->redirSubpage ); - } - } -} - -/** - * ListAdmins --> ListUsers/sysop - */ -class SpecialListAdmins extends SpecialRedirectToSpecial { - function __construct() { - parent::__construct( 'Listadmins', 'Listusers', 'sysop' ); - } -} - -/** - * ListBots --> ListUsers/bot - */ -class SpecialListBots extends SpecialRedirectToSpecial { - function __construct() { - parent::__construct( 'Listbots', 'Listusers', 'bot' ); - } -} - -/** - * CreateAccount --> UserLogin/signup - * @todo FIXME: This (and the rest of the login frontend) needs to die a horrible painful death - */ -class SpecialCreateAccount extends SpecialRedirectToSpecial { - function __construct() { - parent::__construct( 'CreateAccount', 'Userlogin', 'signup', array( 'returnto', 'returntoquery', 'uselang' ) ); - } - - // No reason to hide this link on Special:Specialpages - public function isListed() { - return true; - } - - protected function getGroupName() { - return 'login'; - } -} -/** - * SpecialMypage, SpecialMytalk and SpecialMycontributions special pages - * are used to get user independent links pointing to the user page, talk - * page and list of contributions. - * This can let us cache a single copy of any generated content for all - * users. - */ - -/** - * Superclass for any RedirectSpecialPage which redirects the user - * to a particular article (as opposed to user contributions, logs, etc.). - * - * For security reasons these special pages are restricted to pass on - * the following subset of GET parameters to the target page while - * removing all others: - * - * - useskin, uselang, printable: to alter the appearance of the resulting page - * - * - redirect: allows viewing one's user page or talk page even if it is a - * redirect. - * - * - rdfrom: allows redirecting to one's user page or talk page from an - * external wiki with the "Redirect from..." notice. - * - * - 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 - * - * - 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 - * - * - preloadtitle: Can be used to provide a default section title for a - * preloaded new comment on one's own talk page. - * - * - summary : Can be used to provide a default edit summary for a preloaded - * edit to one's own user page or talk page. - * - * - preview: Allows showing/hiding preview on first edit regardless of user - * preference, useful for preloaded edits where you know preview wouldn't be - * useful. - * - * - internaledit, externaledit, mode: Allows forcing the use of the - * internal/external editor, e.g. to force the internal editor for - * short/simple preloaded edits. - * - * - 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 - * - * - debug: determines whether the debug parameter is passed to load.php, - * which disables reformatting and allows scripts to be debugged. Useful - * when debugging scripts that manipulate one's own user page or talk page. - * - * @par Hook extension: - * Extensions can add to the redirect parameters list by using the hook - * RedirectSpecialArticleRedirectParams - * - * This hook allows extensions which add GET parameters like FlaggedRevs to - * retain those parameters when redirecting using special pages. - * - * @par Hook extension example: - * @code - * $wgHooks['RedirectSpecialArticleRedirectParams'][] = - * 'MyExtensionHooks::onRedirectSpecialArticleRedirectParams'; - * public static function onRedirectSpecialArticleRedirectParams( &$redirectParams ) { - * $redirectParams[] = 'stable'; - * return true; - * } - * @endcode - * @ingroup SpecialPage - */ -abstract class RedirectSpecialArticle extends RedirectSpecialPage { - function __construct( $name ) { - parent::__construct( $name ); - $redirectParams = array( - 'action', - 'redirect', 'rdfrom', - # Options for preloaded edits - 'preload', 'editintro', 'preloadtitle', 'summary', 'nosummary', - # Options for overriding user settings - 'preview', 'internaledit', 'externaledit', 'mode', 'minor', 'watchthis', - # Options for history/diffs - 'section', 'oldid', 'diff', 'dir', - 'limit', 'offset', 'feed', - # Misc options - 'redlink', 'debug', - # Options for action=raw; missing ctype can break JS or CSS in some browsers - 'ctype', 'maxage', 'smaxage', - ); - - wfRunHooks( "RedirectSpecialArticleRedirectParams", array( &$redirectParams ) ); - $this->mAllowedRedirectParams = $redirectParams; - } -} - -/** - * Shortcut to construct a special page pointing to current user user's page. - * @ingroup SpecialPage - */ -class SpecialMypage extends RedirectSpecialArticle { - function __construct() { - parent::__construct( 'Mypage' ); - } - - function getRedirect( $subpage ) { - if ( strval( $subpage ) !== '' ) { - return Title::makeTitle( NS_USER, $this->getUser()->getName() . '/' . $subpage ); - } else { - return Title::makeTitle( NS_USER, $this->getUser()->getName() ); - } - } -} - -/** - * Shortcut to construct a special page pointing to current user talk page. - * @ingroup SpecialPage - */ -class SpecialMytalk extends RedirectSpecialArticle { - function __construct() { - parent::__construct( 'Mytalk' ); - } - - function getRedirect( $subpage ) { - if ( strval( $subpage ) !== '' ) { - return Title::makeTitle( NS_USER_TALK, $this->getUser()->getName() . '/' . $subpage ); - } else { - return Title::makeTitle( NS_USER_TALK, $this->getUser()->getName() ); - } - } -} - -/** - * Shortcut to construct a special page pointing to current user contributions. - * @ingroup SpecialPage - */ -class SpecialMycontributions extends RedirectSpecialPage { - function __construct() { - parent::__construct( 'Mycontributions' ); - $this->mAllowedRedirectParams = array( 'limit', 'namespace', 'tagfilter', - 'offset', 'dir', 'year', 'month', 'feed' ); - } - - function getRedirect( $subpage ) { - return SpecialPage::getTitleFor( 'Contributions', $this->getUser()->getName() ); - } -} - -/** - * Redirect to Special:Listfiles?user=$wgUser - */ -class SpecialMyuploads extends RedirectSpecialPage { - function __construct() { - parent::__construct( 'Myuploads' ); - $this->mAllowedRedirectParams = array( 'limit', 'ilshowall', 'ilsearch' ); - } - - function getRedirect( $subpage ) { - return SpecialPage::getTitleFor( 'Listfiles', $this->getUser()->getName() ); - } -} - -/** - * Redirect Special:Listfiles?user=$wgUser&ilshowall=true - */ -class SpecialAllMyUploads extends RedirectSpecialPage { - function __construct() { - parent::__construct( 'AllMyUploads' ); - $this->mAllowedRedirectParams = array( 'limit', 'ilsearch' ); - } - - function getRedirect( $subpage ) { - $this->mAddedRedirectParams['ilshowall'] = 1; - return SpecialPage::getTitleFor( 'Listfiles', $this->getUser()->getName() ); - } -} - -/** - * Redirect from Special:PermanentLink/### to index.php?oldid=### - */ -class SpecialPermanentLink extends RedirectSpecialPage { - function __construct() { - parent::__construct( 'PermanentLink' ); - $this->mAllowedRedirectParams = array(); - } - - function getRedirect( $subpage ) { - $subpage = intval( $subpage ); - if ( $subpage === 0 ) { - # throw an error page when no subpage was given - throw new ErrorPageError( 'nopagetitle', 'nopagetext' ); - } - $this->mAddedRedirectParams['oldid'] = $subpage; - return true; - } -} diff --git a/includes/specialpage/UnlistedSpecialPage.php b/includes/specialpage/UnlistedSpecialPage.php new file mode 100644 index 0000000000..f5e2ccf7eb --- /dev/null +++ b/includes/specialpage/UnlistedSpecialPage.php @@ -0,0 +1,37 @@ + Special:UserLogin/signup. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/gpl.html + * + * @file + * @ingroup SpecialPage + */ + +/** + * Redirect page: Special:CreateAccount --> Special:UserLogin/signup. + * @todo FIXME: This (and the rest of the login frontend) needs to die a horrible painful death + * + * @ingroup SpecialPage + */ + +class SpecialCreateAccount extends SpecialRedirectToSpecial { + function __construct() { + parent::__construct( 'CreateAccount', 'Userlogin', 'signup', array( 'returnto', 'returntoquery', 'uselang' ) ); + } + + // No reason to hide this link on Special:Specialpages + public function isListed() { + return true; + } + + protected function getGroupName() { + return 'login'; + } +} diff --git a/includes/specials/SpecialListusers.php b/includes/specials/SpecialListusers.php index 8cd9173cd6..f69e177104 100644 --- a/includes/specials/SpecialListusers.php +++ b/includes/specials/SpecialListusers.php @@ -403,3 +403,25 @@ class SpecialListUsers extends IncludableSpecialPage { return 'users'; } } + +/** + * Redirect page: Special:ListAdmins --> Special:ListUsers/sysop. + * + * @ingroup SpecialPage + */ +class SpecialListAdmins extends SpecialRedirectToSpecial { + function __construct() { + parent::__construct( 'Listadmins', 'Listusers', 'sysop' ); + } +} + +/** + * Redirect page: Special:ListBots --> Special:ListUsers/bot. + * + * @ingroup SpecialPage + */ +class SpecialListBots extends SpecialRedirectToSpecial { + function __construct() { + parent::__construct( 'Listbots', 'Listusers', 'bot' ); + } +} diff --git a/includes/specials/SpecialMyRedirectPages.php b/includes/specials/SpecialMyRedirectPages.php new file mode 100644 index 0000000000..41119f96ca --- /dev/null +++ b/includes/specials/SpecialMyRedirectPages.php @@ -0,0 +1,113 @@ +getUser()->getName() . '/' . $subpage ); + } else { + return Title::makeTitle( NS_USER, $this->getUser()->getName() ); + } + } +} + +/** + * Special page pointing to current user's talk page. + * + * @ingroup SpecialPage + */ +class SpecialMytalk extends RedirectSpecialArticle { + function __construct() { + parent::__construct( 'Mytalk' ); + } + + function getRedirect( $subpage ) { + if ( strval( $subpage ) !== '' ) { + return Title::makeTitle( NS_USER_TALK, $this->getUser()->getName() . '/' . $subpage ); + } else { + return Title::makeTitle( NS_USER_TALK, $this->getUser()->getName() ); + } + } +} + +/** + * Special page pointing to current user's contributions. + * + * @ingroup SpecialPage + */ +class SpecialMycontributions extends RedirectSpecialPage { + function __construct() { + parent::__construct( 'Mycontributions' ); + $this->mAllowedRedirectParams = array( 'limit', 'namespace', 'tagfilter', + 'offset', 'dir', 'year', 'month', 'feed' ); + } + + function getRedirect( $subpage ) { + return SpecialPage::getTitleFor( 'Contributions', $this->getUser()->getName() ); + } +} + +/** + * Special page pointing to current user's uploaded files. + * + * @ingroup SpecialPage + */ +class SpecialMyuploads extends RedirectSpecialPage { + function __construct() { + parent::__construct( 'Myuploads' ); + $this->mAllowedRedirectParams = array( 'limit', 'ilshowall', 'ilsearch' ); + } + + function getRedirect( $subpage ) { + return SpecialPage::getTitleFor( 'Listfiles', $this->getUser()->getName() ); + } +} + +/** + * Special page pointing to current user's uploaded files (including old versions). + * + * @ingroup SpecialPage + */ +class SpecialAllMyUploads extends RedirectSpecialPage { + function __construct() { + parent::__construct( 'AllMyUploads' ); + $this->mAllowedRedirectParams = array( 'limit', 'ilsearch' ); + } + + function getRedirect( $subpage ) { + $this->mAddedRedirectParams['ilshowall'] = 1; + return SpecialPage::getTitleFor( 'Listfiles', $this->getUser()->getName() ); + } +} diff --git a/includes/specials/SpecialPermanentLink.php b/includes/specials/SpecialPermanentLink.php new file mode 100644 index 0000000000..6c2ffe906d --- /dev/null +++ b/includes/specials/SpecialPermanentLink.php @@ -0,0 +1,44 @@ +mAllowedRedirectParams = array(); + } + + function getRedirect( $subpage ) { + $subpage = intval( $subpage ); + if ( $subpage === 0 ) { + # throw an error page when no subpage was given + throw new ErrorPageError( 'nopagetitle', 'nopagetext' ); + } + $this->mAddedRedirectParams['oldid'] = $subpage; + return true; + } +} -- 2.20.1