* page list.
* @ingroup SpecialPage
*/
-class SpecialPage {
+class SpecialPage extends ContextSource {
// The canonical name of this special page
// Also used for the default <h1> heading, @see getDescription()
- /*private*/ var $mName;
+ protected $mName;
// The local name of this special page
private $mLocalName;
/**
* Current request context
- * @var RequestContext
+ * @var IContextSource
*/
protected $mContext;
* Return categorised listable special pages which are available
* for the current user, and everyone.
*
+ * @param $user User object to check permissions, $wgUser will be used
+ * if not provided
* @return Associative array mapping page's name to its SpecialPage object
* @deprecated since 1.18 call SpecialPageFactory method directly
*/
- static function getUsablePages() {
- return SpecialPageFactory::getUsablePages();
+ static function getUsablePages( User $user = null ) {
+ return SpecialPageFactory::getUsablePages( $user );
}
/**
* page, and true if it was successful.
*
* @param $title Title object
- * @param $context RequestContext
+ * @param $context IContextSource
* @param $including Bool output is being captured for use in {{special:whatever}}
* @return Bool
* @deprecated since 1.18 call SpecialPageFactory method directly
*/
- public static function executePath( &$title, RequestContext &$context, $including = false ) {
+ public static function executePath( &$title, IContextSource &$context, $including = false ) {
return SpecialPageFactory::executePath( $title, $context, $including );
}
- /**
- * Just like executePath() except it returns the HTML instead of outputting it
- * Returns false if there was no such special page, or a title object if it was
- * a redirect.
- *
- * @param $title Title
- * @return String: HTML fragment
- * @deprecated since 1.18 call SpecialPageFactory method directly
- */
- static function capturePath( &$title ) {
- return SpecialPageFactory::capturePath( $title );
- }
-
/**
* Get the local name for a specified canonical name
*
* @param $file String: file which is included by execute(). It is also constructed from $name by default
* @param $includable Bool: whether the page can be included in normal pages
*/
- public function __construct( $name = '', $restriction = '', $listed = true, $function = false, $file = 'default', $includable = false ) {
+ public function __construct(
+ $name = '', $restriction = '', $listed = true,
+ $function = false, $file = 'default', $includable = false
+ ) {
$this->init( $name, $restriction, $listed, $function, $file, $includable );
}
throw new PermissionsError( $this->mRestriction );
}
+ /**
+ * Checks if userCanExecute, and if not throws a PermissionsError
+ *
+ * @since 1.19
+ */
+ public function checkPermissions() {
+ if ( !$this->userCanExecute( $this->getUser() ) ) {
+ $this->displayRestrictionError();
+ }
+ }
+
+ /**
+ * If the wiki is currently in readonly mode, throws a ReadOnlyError
+ *
+ * @since 1.19
+ * @throws ReadOnlyError
+ */
+ public function checkReadOnly() {
+ if ( wfReadOnly() ) {
+ throw new ReadOnlyError;
+ }
+ }
+
/**
* Sets headers - this should be called from the execute() method of all derived classes!
*/
*/
function execute( $par ) {
$this->setHeaders();
+ $this->checkPermissions();
- if ( $this->userCanExecute( $this->getUser() ) ) {
- $func = $this->mFunction;
- // only load file if the function does not exist
- if(!is_callable($func) and $this->mFile) {
- require_once( $this->mFile );
- }
- $this->outputHeader();
- call_user_func( $func, $par, $this );
- } else {
- $this->displayRestrictionError();
+ $func = $this->mFunction;
+ // only load file if the function does not exist
+ if( !is_callable($func) && $this->mFile ) {
+ require_once( $this->mFile );
}
+ $this->outputHeader();
+ call_user_func( $func, $par, $this );
}
/**
} else {
$msg = $summaryMessageKey;
}
- if ( !wfMessage( $msg )->isBlank() and ! $this->including() ) {
- $this->getOutput()->wrapWikiMsg( "<div class='mw-specialpage-summary'>\n$1\n</div>", $msg );
+ if ( !$this->msg( $msg )->isBlank() && !$this->including() ) {
+ $this->getOutput()->wrapWikiMsg(
+ "<div class='mw-specialpage-summary'>\n$1\n</div>", $msg );
}
}
* @return String
*/
function getDescription() {
- return wfMsg( strtolower( $this->mName ) );
+ return $this->msg( strtolower( $this->mName ) )->text();
}
/**
return self::getTitleFor( $this->mName, $subpage );
}
- /**
- * Sets the context this SpecialPage is executed in
- *
- * @param $context RequestContext
- * @since 1.18
- */
- public function setContext( $context ) {
- $this->mContext = $context;
- }
-
- /**
- * Gets the context this SpecialPage is executed in
- *
- * @return RequestContext
- * @since 1.18
- */
- public function getContext() {
- if ( $this->mContext instanceof RequestContext ) {
- return $this->mContext;
- } else {
- wfDebug( __METHOD__ . " called and \$mContext is null. Return RequestContext::getMain(); for sanity\n" );
- return RequestContext::getMain();
- }
- }
-
- /**
- * Get the WebRequest being used for this instance
- *
- * @return WebRequest
- * @since 1.18
- */
- public function getRequest() {
- return $this->getContext()->getRequest();
- }
-
- /**
- * Get the OutputPage being used for this instance
- *
- * @return OutputPage
- * @since 1.18
- */
- public function getOutput() {
- return $this->getContext()->getOutput();
- }
-
- /**
- * Shortcut to get the skin being used for this instance
- *
- * @return User
- * @since 1.18
- */
- public function getUser() {
- return $this->getContext()->getUser();
- }
-
- /**
- * Shortcut to get the skin being used for this instance
- *
- * @return Skin
- * @since 1.18
- */
- public function getSkin() {
- return $this->getContext()->getSkin();
- }
-
- /**
- * Shortcut to get user's language
- *
- * @return Language
- * @since 1.19
- */
- public function getLang() {
- return $this->getContext()->getLang();
- }
-
/**
* Return the full title, including $par
*
}
/**
- * Wrapper around wfMessage that sets the current context. Currently this
- * is only the title.
+ * Wrapper around wfMessage that sets the current context.
*
* @return Message
* @see wfMessage
*/
public function msg( /* $args */ ) {
- return call_user_func_array( 'wfMessage', func_get_args() )->title( $this->getFullTitle() );
+ // Note: can't use func_get_args() directly as second or later item in
+ // a parameter list until PHP 5.3 or you get a fatal error.
+ // Works fine as the first parameter, which appears elsewhere in the
+ // code base. Sighhhh.
+ $args = func_get_args();
+ return call_user_func_array( array( $this->getContext(), 'msg' ), $args );
}
/**
* @param $params array
*/
protected function addFeedLinks( $params ) {
- global $wgFeedClasses, $wgOut;
+ global $wgFeedClasses;
$feedTemplate = wfScript( 'api' ) . '?';
foreach( $wgFeedClasses as $format => $class ) {
$theseParams = $params + array( 'feedformat' => $format );
$url = $feedTemplate . wfArrayToCGI( $theseParams );
- $wgOut->addFeedLink( $format, $url );
+ $this->getOutput()->addFeedLink( $format, $url );
}
}
}
protected function getForm() {
$this->fields = $this->getFormFields();
- // Give hooks a chance to alter the form, adding extra fields or text etc
- wfRunHooks( "Special{$this->getName()}ModifyFormFields", array( &$this->fields ) );
-
$form = new HTMLForm( $this->fields, $this->getContext() );
$form->setSubmitCallback( array( $this, 'onSubmit' ) );
- $form->setWrapperLegend( wfMessage( strtolower( $this->getName() ) . '-legend' ) );
- $form->addHeaderText( wfMessage( strtolower( $this->getName() ) . '-text' )->parseAsBlock() );
+ $form->setWrapperLegend( $this->msg( strtolower( $this->getName() ) . '-legend' ) );
+ $form->addHeaderText(
+ $this->msg( strtolower( $this->getName() ) . '-text' )->parseAsBlock() );
// Retain query parameters (uselang etc)
- $params = array_diff_key( $this->getRequest()->getQueryValues(), array( 'title' => null ) );
+ $params = array_diff_key(
+ $this->getRequest()->getQueryValues(), array( 'title' => null ) );
$form->addHiddenField( 'redirectparams', wfArrayToCGI( $params ) );
$form->addPreText( $this->preText() );
$this->setHeaders();
// This will throw exceptions if there's a problem
- $this->userCanExecute( $this->getUser() );
+ $this->checkExecutePermissions( $this->getUser() );
$form = $this->getForm();
if ( $form->show() ) {
protected function setParameter( $par ){}
/**
- * Checks if the given user (identified by an object) can perform this action. Can be
- * overridden by sub-classes with more complicated permissions schemes. Failures here
- * must throw subclasses of ErrorPageError
- *
- * @param $user User: the user to check, or null to use the context user
+ * Called from execute() to check if the given user can perform this action.
+ * Failures here must throw subclasses of ErrorPageError.
+ * @param $user User
* @return Bool true
* @throws ErrorPageError
*/
- public function userCanExecute( User $user ) {
- if ( $this->requiresWrite() && wfReadOnly() ) {
- throw new ReadOnlyError();
- }
-
- if ( $this->getRestriction() !== null && !$user->isAllowed( $this->getRestriction() ) ) {
- throw new PermissionsError( $this->getRestriction() );
- }
+ protected function checkExecutePermissions( User $user ) {
+ $this->checkPermissions();
if ( $this->requiresUnblock() && $user->isBlocked() ) {
$block = $user->mBlock;
throw new UserBlockedError( $block );
}
+ if ( $this->requiresWrite() ) {
+ $this->checkReadOnly();
+ }
+
return true;
}
* Shortcut to construct a special page which is unlisted by default
* @ingroup SpecialPage
*/
-class UnlistedSpecialPage extends SpecialPage
-{
+class UnlistedSpecialPage extends SpecialPage {
function __construct( $name, $restriction = '', $function = false, $file = 'default' ) {
parent::__construct( $name, $restriction, false, $function, $file );
}
* Shortcut to construct an includable special page
* @ingroup SpecialPage
*/
-class IncludableSpecialPage extends SpecialPage
-{
- function __construct( $name, $restriction = '', $listed = true, $function = false, $file = 'default' ) {
+class IncludableSpecialPage extends SpecialPage {
+ function __construct(
+ $name, $restriction = '', $listed = true, $function = false, $file = 'default'
+ ) {
parent::__construct( $name, $restriction, $listed, $function, $file, true );
}
}
abstract class SpecialRedirectToSpecial extends RedirectSpecialPage {
-
var $redirName, $redirSubpage;
- function __construct( $name, $redirName, $redirSubpage = false, $allowedRedirectParams = array(), $addedRedirectParams = array() ) {
+ function __construct(
+ $name, $redirName, $redirSubpage = false,
+ $allowedRedirectParams = array(), $addedRedirectParams = array()
+ ) {
parent::__construct( $name );
$this->redirName = $redirName;
$this->redirSubpage = $redirSubpage;
}
/**
- * ListAdmins --> ListUsers/admin
+ * ListAdmins --> ListUsers/sysop
*/
class SpecialListAdmins extends SpecialRedirectToSpecial {
function __construct(){
- parent::__construct( 'ListAdmins', 'ListUsers', 'sysop' );
+ parent::__construct( 'Listadmins', 'Listusers', 'sysop' );
}
}
/**
- * ListBots --> ListUsers/admin
+ * ListBots --> ListUsers/bot
*/
class SpecialListBots extends SpecialRedirectToSpecial {
function __construct(){
- parent::__construct( 'ListAdmins', 'ListUsers', 'bot' );
+ parent::__construct( 'Listbots', 'Listusers', 'bot' );
}
}
function __construct() {
parent::__construct( 'Mypage' );
$this->mAllowedRedirectParams = array( 'action' , 'preload' , 'editintro',
- 'section', 'oldid', 'diff', 'dir' );
+ 'section', 'oldid', 'diff', 'dir',
+ // Options for action=raw; missing ctype can break JS or CSS in some browsers
+ 'ctype', 'maxage', 'smaxage' );
}
function getRedirect( $subpage ) {
- global $wgUser;
if ( strval( $subpage ) !== '' ) {
- return Title::makeTitle( NS_USER, $wgUser->getName() . '/' . $subpage );
+ return Title::makeTitle( NS_USER, $this->getUser()->getName() . '/' . $subpage );
} else {
- return Title::makeTitle( NS_USER, $wgUser->getName() );
+ return Title::makeTitle( NS_USER, $this->getUser()->getName() );
}
}
}
}
function getRedirect( $subpage ) {
- global $wgUser;
if ( strval( $subpage ) !== '' ) {
- return Title::makeTitle( NS_USER_TALK, $wgUser->getName() . '/' . $subpage );
+ return Title::makeTitle( NS_USER_TALK, $this->getUser()->getName() . '/' . $subpage );
} else {
- return Title::makeTitle( NS_USER_TALK, $wgUser->getName() );
+ return Title::makeTitle( NS_USER_TALK, $this->getUser()->getName() );
}
}
}
}
function getRedirect( $subpage ) {
- global $wgUser;
- return SpecialPage::getTitleFor( 'Contributions', $wgUser->getName() );
+ return SpecialPage::getTitleFor( 'Contributions', $this->getUser()->getName() );
}
}
}
function getRedirect( $subpage ) {
- global $wgUser;
- return SpecialPage::getTitleFor( 'Listfiles', $wgUser->getName() );
+ return SpecialPage::getTitleFor( 'Listfiles', $this->getUser()->getName() );
}
}
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;
}