diff options
Diffstat (limited to 'includes/context')
-rw-r--r-- | includes/context/ContextSource.php | 2 | ||||
-rw-r--r-- | includes/context/DerivativeContext.php | 25 | ||||
-rw-r--r-- | includes/context/IContextSource.php | 2 | ||||
-rw-r--r-- | includes/context/RequestContext.php | 19 |
4 files changed, 36 insertions, 12 deletions
diff --git a/includes/context/ContextSource.php b/includes/context/ContextSource.php index 33f51cb9..e13cfa88 100644 --- a/includes/context/ContextSource.php +++ b/includes/context/ContextSource.php @@ -125,7 +125,7 @@ abstract class ContextSource implements IContextSource { /** * Get the Language object * - * @deprecated 1.19 Use getLanguage instead + * @deprecated since 1.19 Use getLanguage instead * @return Language */ public function getLang() { diff --git a/includes/context/DerivativeContext.php b/includes/context/DerivativeContext.php index b9a70068..fd9bf963 100644 --- a/includes/context/DerivativeContext.php +++ b/includes/context/DerivativeContext.php @@ -100,7 +100,10 @@ class DerivativeContext extends ContextSource { * * @param Title $t */ - public function setTitle( Title $t ) { + public function setTitle( $t ) { + if ( $t !== null && !$t instanceof Title ) { + throw new MWException( __METHOD__ . " expects an instance of Title" ); + } $this->title = $t; } @@ -209,7 +212,7 @@ class DerivativeContext extends ContextSource { /** * Set the Language object * - * @deprecated 1.19 Use setLanguage instead + * @deprecated since 1.19 Use setLanguage instead * @param Language|string $l Language instance or language code */ public function setLang( $l ) { @@ -237,7 +240,7 @@ class DerivativeContext extends ContextSource { } /** - * @deprecated 1.19 Use getLanguage instead + * @deprecated since 1.19 Use getLanguage instead * @return Language */ public function getLang() { @@ -281,4 +284,20 @@ class DerivativeContext extends ContextSource { return $this->getContext()->getSkin(); } } + + /** + * Get a message using the current context. + * + * This can't just inherit from ContextSource, since then + * it would set only the original context, and not take + * into account any changes. + * + * @param String Message name + * @param Variable number of message arguments + * @return Message + */ + public function msg() { + $args = func_get_args(); + return call_user_func_array( 'wfMessage', $args )->setContext( $this ); + } } diff --git a/includes/context/IContextSource.php b/includes/context/IContextSource.php index c7b221b9..35d5aed6 100644 --- a/includes/context/IContextSource.php +++ b/includes/context/IContextSource.php @@ -79,7 +79,7 @@ interface IContextSource { /** * Get the Language object * - * @deprecated 1.19 Use getLanguage instead + * @deprecated since 1.19 Use getLanguage instead * @return Language */ public function getLang(); diff --git a/includes/context/RequestContext.php b/includes/context/RequestContext.php index 6aefc98e..01ec57c0 100644 --- a/includes/context/RequestContext.php +++ b/includes/context/RequestContext.php @@ -90,7 +90,10 @@ class RequestContext implements IContextSource { * * @param Title $t */ - public function setTitle( Title $t ) { + public function setTitle( $t ) { + if ( $t !== null && !$t instanceof Title ) { + throw new MWException( __METHOD__ . " expects an instance of Title" ); + } $this->title = $t; // Erase the WikiPage so a new one with the new title gets created. $this->wikipage = null; @@ -233,7 +236,7 @@ class RequestContext implements IContextSource { /** * Set the Language object * - * @deprecated 1.19 Use setLanguage instead + * @deprecated since 1.19 Use setLanguage instead * @param Language|string $l Language instance or language code */ public function setLang( $l ) { @@ -261,7 +264,7 @@ class RequestContext implements IContextSource { } /** - * @deprecated 1.19 Use getLanguage instead + * @deprecated since 1.19 Use getLanguage instead * @return Language */ public function getLang() { @@ -401,10 +404,10 @@ class RequestContext implements IContextSource { */ public function exportSession() { return array( - 'ip' => $this->getRequest()->getIP(), - 'headers' => $this->getRequest()->getAllHeaders(), + 'ip' => $this->getRequest()->getIP(), + 'headers' => $this->getRequest()->getAllHeaders(), 'sessionId' => session_id(), - 'userId' => $this->getUser()->getId() + 'userId' => $this->getUser()->getId() ); } @@ -417,7 +420,9 @@ class RequestContext implements IContextSource { * This will setup the session from the given ID. This is useful when * background scripts inherit context when acting on behalf of a user. * - * $param array $params Result of RequestContext::exportSession() + * @note suhosin.session.encrypt may interfere with this method. + * + * @param array $params Result of RequestContext::exportSession() * @return ScopedCallback * @throws MWException * @since 1.21 |