From f50eab171e0db645483a0c36e0e00a0441fe8561 Mon Sep 17 00:00:00 2001 From: John Du Hart Date: Wed, 23 Nov 2011 09:53:37 +0000 Subject: [PATCH] Followup r103817, backing out ContextSource changes to SpecialPage and Action --- includes/Action.php | 87 ++++++++++++++++++++++++++++++++++++++- includes/SpecialPage.php | 88 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 173 insertions(+), 2 deletions(-) diff --git a/includes/Action.php b/includes/Action.php index fd4a0a6e23..951c74a3b5 100644 --- a/includes/Action.php +++ b/includes/Action.php @@ -23,7 +23,7 @@ * * @file */ -abstract class Action extends ContextSource { +abstract class Action { /** * Page on which we're performing the action @@ -95,6 +95,91 @@ abstract class Action extends ContextSource { return self::getClass( $name, array() ) !== null; } + /** + * Get the IContextSource in use here + * @return IContextSource + */ + public final function getContext() { + if ( $this->context instanceof IContextSource ) { + return $this->context; + } + return $this->page->getContext(); + } + + /** + * Get the WebRequest being used for this instance + * + * @return WebRequest + */ + public final function getRequest() { + return $this->getContext()->getRequest(); + } + + /** + * Get the OutputPage being used for this instance + * + * @return OutputPage + */ + public final function getOutput() { + return $this->getContext()->getOutput(); + } + + /** + * Shortcut to get the User being used for this instance + * + * @return User + */ + public final function getUser() { + return $this->getContext()->getUser(); + } + + /** + * Shortcut to get the Skin being used for this instance + * + * @return Skin + */ + public final function getSkin() { + return $this->getContext()->getSkin(); + } + + /** + * Shortcut to get the user Language being used for this instance + * + * @return Skin + */ + public final function getLanguage() { + return $this->getContext()->getLanguage(); + } + + /** + * Shortcut to get the user Language being used for this instance + * + * @deprecated 1.19 Use getLanguage instead + * @return Skin + */ + public final function getLang() { + return $this->getLanguage(); + } + + /** + * Shortcut to get the Title object from the page + * @return Title + */ + public final function getTitle() { + return $this->page->getTitle(); + } + + /** + * Get a Message object with context set + * Parameters are the same as wfMessage() + * + * @return Message object + */ + public final function msg() { + $params = func_get_args(); + return call_user_func_array( array( $this->getContext(), 'msg' ), $params ); + } + /** * Protected constructor: use Action::factory( $action, $page ) to actually build * these things in the real world diff --git a/includes/SpecialPage.php b/includes/SpecialPage.php index 64c42878ab..419c595125 100644 --- a/includes/SpecialPage.php +++ b/includes/SpecialPage.php @@ -27,7 +27,7 @@ * page list. * @ingroup SpecialPage */ -class SpecialPage extends ContextSource { +class SpecialPage { // The canonical name of this special page // Also used for the default

heading, @see getDescription() @@ -611,6 +611,92 @@ class SpecialPage extends ContextSource { return self::getTitleFor( $this->mName, $subpage ); } + /** + * Sets the context this SpecialPage is executed in + * + * @param $context IContextSource + * @since 1.18 + */ + public function setContext( $context ) { + $this->mContext = $context; + } + + /** + * Gets the context this SpecialPage is executed in + * + * @return IContextSource + * @since 1.18 + */ + public function getContext() { + if ( $this->mContext instanceof IContextSource ) { + 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 User executing 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 + * + * @deprecated 1.19 Use getLanguage instead + * @return Language + * @since 1.18 + */ + public function getLang() { + return $this->getLanguage(); + } + + /** + * Shortcut to get user's language + * + * @return Language + * @since 1.19 + */ + public function getLanguage() { + return $this->getContext()->getLanguage(); + } + /** * Return the full title, including $par * -- 2.20.1