X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FRequestContext.php;h=c0b49a1e8aafa9149b1c7177db3ee552982b18ea;hb=bbb0d379b9abfcd9a2f4573f1afbe2f85eb35155;hp=48cca17db1aa0c3799ba0a42cc00991fb718f45b;hpb=a04e33dd86e152d74026a54bd8f5cb490abb64a2;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/RequestContext.php b/includes/RequestContext.php index 48cca17db1..c0b49a1e8a 100644 --- a/includes/RequestContext.php +++ b/includes/RequestContext.php @@ -1,15 +1,81 @@ user; } + /** + * Set the Language object + * + * @param $l Language + */ + public function setLang( Language $l ) { + $this->lang = $l; + } + /** * Get the Language object * @@ -158,6 +233,16 @@ class RequestContext { return $this->lang; } + /** + * Set the Skin object + * + * @param $s Skin + */ + public function setSkin( Skin $s ) { + $this->skin = clone $s; + $this->skin->setContext( $this ); + } + /** * Get the Skin object * @@ -214,54 +299,6 @@ class RequestContext { } } -/** - * Interface for objects which can provide a context on request. - */ -interface IContextSource { - - /** - * Get the WebRequest object - * - * @return WebRequest - */ - public function getRequest(); - - /** - * Get the Title object - * - * @return Title - */ - public function getTitle(); - - /** - * Get the OutputPage object - * - * @return OutputPage object - */ - public function getOutput(); - - /** - * Get the User object - * - * @return User - */ - public function getUser(); - - /** - * Get the Language object - * - * @return Language - */ - public function getLang(); - - /** - * Get the Skin object - * - * @return Skin - */ - public function getSkin(); -} - /** * The simplest way of implementing IContextSource is to hold a RequestContext as a * member variable and provide accessors to it. @@ -279,6 +316,11 @@ abstract class ContextSource implements IContextSource { * @return RequestContext */ public function getContext() { + if ( $this->context === null ) { + $class = get_class( $this ); + wfDebug( __METHOD__ . " ($class): called and \$context is null. Using RequestContext::getMain() for sanity\n" ); + $this->context = RequestContext::getMain(); + } return $this->context; } @@ -297,7 +339,7 @@ abstract class ContextSource implements IContextSource { * @return WebRequest */ public function getRequest() { - return $this->context->getRequest(); + return $this->getContext()->getRequest(); } /** @@ -306,7 +348,7 @@ abstract class ContextSource implements IContextSource { * @return Title */ public function getTitle() { - return $this->context->getTitle(); + return $this->getContext()->getTitle(); } /** @@ -315,7 +357,7 @@ abstract class ContextSource implements IContextSource { * @return OutputPage object */ public function getOutput() { - return $this->context->getOutput(); + return $this->getContext()->getOutput(); } /** @@ -324,7 +366,7 @@ abstract class ContextSource implements IContextSource { * @return User */ public function getUser() { - return $this->context->getUser(); + return $this->getContext()->getUser(); } /** @@ -333,7 +375,7 @@ abstract class ContextSource implements IContextSource { * @return Language */ public function getLang() { - return $this->context->getLang(); + return $this->getContext()->getLang(); } /** @@ -342,6 +384,16 @@ abstract class ContextSource implements IContextSource { * @return Skin */ public function getSkin() { - return $this->context->getSkin(); + return $this->getContext()->getSkin(); + } + + /** + * Get a Message object with context set + * Parameters are the same as wfMessage() + * + * @return Message object + */ + public function msg( /* $args */ ) { + return call_user_func_array( array( $this->getContext(), 'msg' ), func_get_args() ); } }