From 4ac9fa081a7c045f6a9f1cfc529d82423f485b2e Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sun, 8 Dec 2013 09:55:49 +0100 Subject: Update to MediaWiki 1.22.0 --- includes/SpecialPage.php | 160 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 116 insertions(+), 44 deletions(-) (limited to 'includes/SpecialPage.php') diff --git a/includes/SpecialPage.php b/includes/SpecialPage.php index c32738f8..a6195fc4 100644 --- a/includes/SpecialPage.php +++ b/includes/SpecialPage.php @@ -27,7 +27,6 @@ * @ingroup SpecialPage */ class SpecialPage { - // The canonical name of this special page // Also used for the default

heading, @see getDescription() protected $mName; @@ -305,12 +304,14 @@ class SpecialPage { * If you override execute(), you can recover the default behavior with userCanExecute() * and displayRestrictionError() * - * @param string $name name of the special page, as seen in links and URLs - * @param string $restriction user right required, e.g. "block" or "delete" - * @param bool $listed whether the page is listed in Special:Specialpages - * @param $function Callback|Bool: function called by execute(). By default it is constructed from $name - * @param string $file file which is included by execute(). It is also constructed from $name by default - * @param bool $includable whether the page can be included in normal pages + * @param string $name Name of the special page, as seen in links and URLs + * @param string $restriction User right required, e.g. "block" or "delete" + * @param bool $listed Whether the page is listed in Special:Specialpages + * @param Callback|Bool $function Function called by execute(). By default + * it is constructed from $name + * @param string $file File which is included by execute(). It is also + * constructed from $name by default + * @param bool $includable Whether the page can be included in normal pages */ public function __construct( $name = '', $restriction = '', $listed = true, @@ -322,12 +323,14 @@ class SpecialPage { /** * Do the real work for the constructor, mainly so __call() can intercept * calls to SpecialPage() - * @param string $name name of the special page, as seen in links and URLs - * @param string $restriction user right required, e.g. "block" or "delete" - * @param bool $listed whether the page is listed in Special:Specialpages - * @param $function Callback|Bool: function called by execute(). By default it is constructed from $name - * @param string $file file which is included by execute(). It is also constructed from $name by default - * @param bool $includable whether the page can be included in normal pages + * @param string $name Name of the special page, as seen in links and URLs + * @param string $restriction User right required, e.g. "block" or "delete" + * @param bool $listed Whether the page is listed in Special:Specialpages + * @param Callback|Bool $function Function called by execute(). By default + * it is constructed from $name + * @param string $file File which is included by execute(). It is also + * constructed from $name by default + * @param bool $includable Whether the page can be included in normal pages */ private function init( $name, $restriction, $listed, $function, $file, $includable ) { $this->mName = $name; @@ -445,7 +448,10 @@ class SpecialPage { * @return Mixed * @deprecated since 1.18 */ - function name( $x = null ) { wfDeprecated( __METHOD__, '1.18' ); return wfSetVar( $this->mName, $x ); } + function name( $x = null ) { + wfDeprecated( __METHOD__, '1.18' ); + return wfSetVar( $this->mName, $x ); + } /** * These mutators are very evil, as the relevant variables should not mutate. So @@ -454,7 +460,10 @@ class SpecialPage { * @return Mixed * @deprecated since 1.18 */ - function restriction( $x = null ) { wfDeprecated( __METHOD__, '1.18' ); return wfSetVar( $this->mRestriction, $x ); } + function restriction( $x = null ) { + wfDeprecated( __METHOD__, '1.18' ); + return wfSetVar( $this->mRestriction, $x ); + } /** * These mutators are very evil, as the relevant variables should not mutate. So @@ -463,7 +472,10 @@ class SpecialPage { * @return Mixed * @deprecated since 1.18 */ - function func( $x = null ) { wfDeprecated( __METHOD__, '1.18' ); return wfSetVar( $this->mFunction, $x ); } + function func( $x = null ) { + wfDeprecated( __METHOD__, '1.18' ); + return wfSetVar( $this->mFunction, $x ); + } /** * These mutators are very evil, as the relevant variables should not mutate. So @@ -472,7 +484,10 @@ class SpecialPage { * @return Mixed * @deprecated since 1.18 */ - function file( $x = null ) { wfDeprecated( __METHOD__, '1.18' ); return wfSetVar( $this->mFile, $x ); } + function file( $x = null ) { + wfDeprecated( __METHOD__, '1.18' ); + return wfSetVar( $this->mFile, $x ); + } /** * These mutators are very evil, as the relevant variables should not mutate. So @@ -481,7 +496,10 @@ class SpecialPage { * @return Mixed * @deprecated since 1.18 */ - function includable( $x = null ) { wfDeprecated( __METHOD__, '1.18' ); return wfSetVar( $this->mIncludable, $x ); } + function includable( $x = null ) { + wfDeprecated( __METHOD__, '1.18' ); + return wfSetVar( $this->mIncludable, $x ); + } /** * Whether the special page is being evaluated via transclusion @@ -535,7 +553,7 @@ class SpecialPage { * pages? */ public function isRestricted() { - // DWIM: If all anons can do something, then it is not restricted + // DWIM: If anons can do something, then it is not restricted return $this->mRestriction != '' && !User::groupHasPermission( '*', $this->mRestriction ); } @@ -661,7 +679,7 @@ class SpecialPage { $func = $this->mFunction; // only load file if the function does not exist if ( !is_callable( $func ) && $this->mFile ) { - require_once( $this->mFile ); + require_once $this->mFile; } $this->outputHeader(); call_user_func( $func, $subPage, $this ); @@ -734,7 +752,8 @@ class SpecialPage { if ( $this->mContext instanceof IContextSource ) { return $this->mContext; } else { - wfDebug( __METHOD__ . " called and \$mContext is null. Return RequestContext::getMain(); for sanity\n" ); + wfDebug( __METHOD__ . " called and \$mContext is null. " . + "Return RequestContext::getMain(); for sanity\n" ); return RequestContext::getMain(); } } @@ -782,7 +801,7 @@ class SpecialPage { /** * Shortcut to get user's language * - * @deprecated 1.19 Use getLanguage instead + * @deprecated since 1.19 Use getLanguage instead * @return Language * @since 1.18 */ @@ -842,11 +861,11 @@ class SpecialPage { protected function addFeedLinks( $params ) { global $wgFeedClasses; - $feedTemplate = wfScript( 'api' ) . '?'; + $feedTemplate = wfScript( 'api' ); foreach ( $wgFeedClasses as $format => $class ) { $theseParams = $params + array( 'feedformat' => $format ); - $url = $feedTemplate . wfArrayToCgi( $theseParams ); + $url = wfAppendQuery( $feedTemplate, $theseParams ); $this->getOutput()->addFeedLink( $format, $url ); } } @@ -909,6 +928,11 @@ class SpecialPage { * 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 @@ -917,17 +941,27 @@ abstract class FormSpecialPage extends SpecialPage { abstract protected function getFormFields(); /** - * Add pre- or post-text to the form + * Add pre-text to the form * @return String HTML which will be sent to $form->addPreText() */ - protected function preText() { return ''; } - protected function postText() { return ''; } + 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 ) {} + protected function alterForm( HTMLForm $form ) { + } /** * Get message prefix for HTMLForm @@ -948,9 +982,18 @@ abstract class FormSpecialPage extends SpecialPage { $form = new HTMLForm( $this->fields, $this->getContext(), $this->getMessagePrefix() ); $form->setSubmitCallback( array( $this, 'onSubmit' ) ); - $form->setWrapperLegend( $this->msg( $this->getMessagePrefix() . '-legend' ) ); - $form->addHeaderText( - $this->msg( $this->getMessagePrefix() . '-text' )->parseAsBlock() ); + // 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( @@ -977,8 +1020,10 @@ abstract class FormSpecialPage extends SpecialPage { /** * Do something exciting on successful processing of the form, most likely to show a * confirmation message + * @since 1.22 Default is to do nothing */ - abstract public function onSuccess(); + public function onSuccess() { + } /** * Basic SpecialPage workflow: get a form, send it to the user; get some data back, @@ -1000,9 +1045,11 @@ abstract class FormSpecialPage extends SpecialPage { /** * Maybe do something interesting with the subpage parameter - * @param $par String + * @param string $par */ - protected function setParameter( $par ) {} + protected function setParameter( $par ) { + $this->par = $par; + } /** * Called from execute() to check if the given user can perform this action. @@ -1090,17 +1137,16 @@ abstract class RedirectSpecialPage extends UnlistedSpecialPage { $query = $this->getRedirectQuery(); // Redirect to a page title with possible query parameters if ( $redirect instanceof Title ) { - $url = $redirect->getFullUrl( $query ); + $url = $redirect->getFullURL( $query ); $this->getOutput()->redirect( $url ); return $redirect; - // Redirect to index.php with query parameters } elseif ( $redirect === true ) { - global $wgScript; - $url = $wgScript . '?' . wfArrayToCgi( $query ); + // Redirect to index.php with query parameters + $url = wfAppendQuery( wfScript( 'index' ), $query ); $this->getOutput()->redirect( $url ); return $redirect; } else { - $class = __CLASS__; + $class = get_class( $this ); throw new MWException( "RedirectSpecialPage $class doesn't redirect!" ); } } @@ -1140,6 +1186,7 @@ abstract class RedirectSpecialPage extends UnlistedSpecialPage { } abstract class SpecialRedirectToSpecial extends RedirectSpecialPage { + // @todo FIXME: Visibility must be declared var $redirName, $redirSubpage; function __construct( @@ -1186,7 +1233,16 @@ class SpecialListBots extends SpecialRedirectToSpecial { */ class SpecialCreateAccount extends SpecialRedirectToSpecial { function __construct() { - parent::__construct( 'CreateAccount', 'Userlogin', 'signup', array( 'uselang' ) ); + 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'; } } /** @@ -1216,7 +1272,7 @@ class SpecialCreateAccount extends SpecialRedirectToSpecial { * - 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/w/index.php?title=Special:MyPage&offset=20110000000000&limit=1&action=history + * 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: @@ -1270,9 +1326,9 @@ abstract class RedirectSpecialArticle extends RedirectSpecialPage { 'action', 'redirect', 'rdfrom', # Options for preloaded edits - 'preload', 'editintro', 'preloadtitle', 'summary', + 'preload', 'editintro', 'preloadtitle', 'summary', 'nosummary', # Options for overriding user settings - 'preview', 'internaledit', 'externaledit', 'mode', + 'preview', 'internaledit', 'externaledit', 'mode', 'minor', 'watchthis', # Options for history/diffs 'section', 'oldid', 'diff', 'dir', 'limit', 'offset', 'feed', @@ -1345,7 +1401,7 @@ class SpecialMycontributions extends RedirectSpecialPage { class SpecialMyuploads extends RedirectSpecialPage { function __construct() { parent::__construct( 'Myuploads' ); - $this->mAllowedRedirectParams = array( 'limit' ); + $this->mAllowedRedirectParams = array( 'limit', 'ilshowall', 'ilsearch' ); } function getRedirect( $subpage ) { @@ -1353,6 +1409,22 @@ class SpecialMyuploads extends RedirectSpecialPage { } } +/** + * 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=### */ -- cgit v1.2.3-54-g00ecf