Follow-up r89408, r86872: restore IContextSource and ContextSource, to be more carefu...
authorHappy-melon <happy-melon@users.mediawiki.org>
Mon, 27 Jun 2011 19:38:30 +0000 (19:38 +0000)
committerHappy-melon <happy-melon@users.mediawiki.org>
Mon, 27 Jun 2011 19:38:30 +0000 (19:38 +0000)
includes/AutoLoader.php
includes/RequestContext.php

index f9a83f7..3ca3d33 100644 (file)
@@ -47,6 +47,7 @@ $wgAutoloadLocalClasses = array(
        'ConfEditor' => 'includes/ConfEditor.php',
        'ConfEditorParseError' => 'includes/ConfEditor.php',
        'ConfEditorToken' => 'includes/ConfEditor.php',
+       'ContextSource' => 'includes/RequestContext.php',
        'Cookie' => 'includes/Cookie.php',
        'CookieJar' => 'includes/Cookie.php',
        'DiffHistoryBlob' => 'includes/HistoryBlob.php',
@@ -115,6 +116,7 @@ $wgAutoloadLocalClasses = array(
        'HTMLTextField' => 'includes/HTMLForm.php',
        'Http' => 'includes/HttpFunctions.php',
        'HttpRequest' => 'includes/HttpFunctions.old.php',
+       'IContextSource' => 'includes/RequestContext.php',
        'IcuCollation' => 'includes/Collation.php',
        'ImageGallery' => 'includes/ImageGallery.php',
        'ImageHistoryList' => 'includes/ImagePage.php',
index 3481bb5..be21c43 100644 (file)
@@ -217,3 +217,134 @@ 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.
+ */
+abstract class ContextSource implements IContextSource {
+
+       /**
+        * @var RequestContext
+        */
+       private $context;
+
+       /**
+        * Get the RequestContext object
+        *
+        * @return RequestContext
+        */
+       public function getContext() {
+               return $this->context;
+       }
+
+       /**
+        * Set the RequestContext object
+        *
+        * @param $context RequestContext
+        */
+       public function setContext( RequestContext $context ) {
+               $this->context = $context;
+       }
+
+       /**
+        * Get the WebRequest object
+        *
+        * @return WebRequest
+        */
+       public function getRequest() {
+               return $this->context->getRequest();
+       }
+
+       /**
+        * Get the Title object
+        *
+        * @return Title
+        */
+       public function getTitle() {
+               return $this->context->getTitle();
+       }
+
+       /**
+        * Get the OutputPage object
+        *
+        * @return OutputPage object
+        */
+       public function getOutput() {
+               return $this->context->getOutput();
+       }
+
+       /**
+        * Get the User object
+        *
+        * @return User
+        */
+       public function getUser() {
+               return $this->context->getUser();
+       }
+
+       /**
+        * Get the Language object
+        *
+        * @return Language
+        */
+       public function getLang() {
+               return $this->context->getLang();
+       }
+
+       /**
+        * Get the Skin object
+        *
+        * @return Skin
+        */
+       public function getSkin() {
+               return $this->context->getSkin();
+       }
+}
\ No newline at end of file