MediaWiki  REL1_23
DerivativeContext.php
Go to the documentation of this file.
00001 <?php
00032 class DerivativeContext extends ContextSource {
00036     private $request;
00037 
00041     private $title;
00042 
00046     private $wikipage;
00047 
00051     private $output;
00052 
00056     private $user;
00057 
00061     private $lang;
00062 
00066     private $skin;
00067 
00071     private $config;
00072 
00077     public function __construct( IContextSource $context ) {
00078         $this->setContext( $context );
00079     }
00080 
00086     public function setConfig( Config $s ) {
00087         $this->config = $s;
00088     }
00089 
00095     public function getConfig() {
00096         if ( !is_null( $this->config ) ) {
00097             return $this->config;
00098         } else {
00099             return $this->getContext()->getConfig();
00100         }
00101     }
00102 
00108     public function setRequest( WebRequest $r ) {
00109         $this->request = $r;
00110     }
00111 
00117     public function getRequest() {
00118         if ( !is_null( $this->request ) ) {
00119             return $this->request;
00120         } else {
00121             return $this->getContext()->getRequest();
00122         }
00123     }
00124 
00131     public function setTitle( $t ) {
00132         if ( $t !== null && !$t instanceof Title ) {
00133             throw new MWException( __METHOD__ . " expects an instance of Title" );
00134         }
00135         $this->title = $t;
00136     }
00137 
00143     public function getTitle() {
00144         if ( !is_null( $this->title ) ) {
00145             return $this->title;
00146         } else {
00147             return $this->getContext()->getTitle();
00148         }
00149     }
00150 
00159     public function canUseWikiPage() {
00160         if ( $this->wikipage !== null ) {
00161             return true;
00162         } elseif ( $this->title !== null ) {
00163             return $this->title->canExist();
00164         } else {
00165             return $this->getContext()->canUseWikiPage();
00166         }
00167     }
00168 
00175     public function setWikiPage( WikiPage $p ) {
00176         $this->wikipage = $p;
00177     }
00178 
00188     public function getWikiPage() {
00189         if ( !is_null( $this->wikipage ) ) {
00190             return $this->wikipage;
00191         } else {
00192             return $this->getContext()->getWikiPage();
00193         }
00194     }
00195 
00201     public function setOutput( OutputPage $o ) {
00202         $this->output = $o;
00203     }
00204 
00210     public function getOutput() {
00211         if ( !is_null( $this->output ) ) {
00212             return $this->output;
00213         } else {
00214             return $this->getContext()->getOutput();
00215         }
00216     }
00217 
00223     public function setUser( User $u ) {
00224         $this->user = $u;
00225     }
00226 
00232     public function getUser() {
00233         if ( !is_null( $this->user ) ) {
00234             return $this->user;
00235         } else {
00236             return $this->getContext()->getUser();
00237         }
00238     }
00239 
00246     public function setLang( $l ) {
00247         wfDeprecated( __METHOD__, '1.19' );
00248         $this->setLanguage( $l );
00249     }
00250 
00258     public function setLanguage( $l ) {
00259         if ( $l instanceof Language ) {
00260             $this->lang = $l;
00261         } elseif ( is_string( $l ) ) {
00262             $l = RequestContext::sanitizeLangCode( $l );
00263             $obj = Language::factory( $l );
00264             $this->lang = $obj;
00265         } else {
00266             throw new MWException( __METHOD__ . " was passed an invalid type of data." );
00267         }
00268     }
00269 
00274     public function getLang() {
00275         wfDeprecated( __METHOD__, '1.19' );
00276         $this->getLanguage();
00277     }
00278 
00285     public function getLanguage() {
00286         if ( !is_null( $this->lang ) ) {
00287             return $this->lang;
00288         } else {
00289             return $this->getContext()->getLanguage();
00290         }
00291     }
00292 
00298     public function setSkin( Skin $s ) {
00299         $this->skin = clone $s;
00300         $this->skin->setContext( $this );
00301     }
00302 
00308     public function getSkin() {
00309         if ( !is_null( $this->skin ) ) {
00310             return $this->skin;
00311         } else {
00312             return $this->getContext()->getSkin();
00313         }
00314     }
00315 
00327     public function msg() {
00328         $args = func_get_args();
00329 
00330         return call_user_func_array( 'wfMessage', $args )->setContext( $this );
00331     }
00332 }