MediaWiki  master
DerivativeContext.php
Go to the documentation of this file.
00001 <?php
00032 class DerivativeContext extends ContextSource {
00033 
00037         private $request;
00038 
00042         private $title;
00043 
00047         private $wikipage;
00048 
00052         private $output;
00053 
00057         private $user;
00058 
00062         private $lang;
00063 
00067         private $skin;
00068 
00073         public function __construct( IContextSource $context ) {
00074                 $this->setContext( $context );
00075         }
00076 
00082         public function setRequest( WebRequest $r ) {
00083                 $this->request = $r;
00084         }
00085 
00091         public function getRequest() {
00092                 if ( !is_null( $this->request ) ) {
00093                         return $this->request;
00094                 } else {
00095                         return $this->getContext()->getRequest();
00096                 }
00097         }
00098 
00104         public function setTitle( Title $t ) {
00105                 $this->title = $t;
00106         }
00107 
00113         public function getTitle() {
00114                 if ( !is_null( $this->title ) ) {
00115                         return $this->title;
00116                 } else {
00117                         return $this->getContext()->getTitle();
00118                 }
00119         }
00120 
00129         public function canUseWikiPage() {
00130                 if ( $this->wikipage !== null ) {
00131                         return true;
00132                 } elseif ( $this->title !== null ) {
00133                         return $this->title->canExist();
00134                 } else {
00135                         return $this->getContext()->canUseWikiPage();
00136                 }
00137         }
00138 
00145         public function setWikiPage( WikiPage $p ) {
00146                 $this->wikipage = $p;
00147         }
00148 
00158         public function getWikiPage() {
00159                 if ( !is_null( $this->wikipage ) ) {
00160                         return $this->wikipage;
00161                 } else {
00162                         return $this->getContext()->getWikiPage();
00163                 }
00164         }
00165 
00171         public function setOutput( OutputPage $o ) {
00172                 $this->output = $o;
00173         }
00174 
00180         public function getOutput() {
00181                 if ( !is_null( $this->output ) ) {
00182                         return $this->output;
00183                 } else {
00184                         return $this->getContext()->getOutput();
00185                 }
00186         }
00187 
00193         public function setUser( User $u ) {
00194                 $this->user = $u;
00195         }
00196 
00202         public function getUser() {
00203                 if ( !is_null( $this->user ) ) {
00204                         return $this->user;
00205                 } else {
00206                         return $this->getContext()->getUser();
00207                 }
00208         }
00209 
00216         public function setLang( $l ) {
00217                 wfDeprecated( __METHOD__, '1.19' );
00218                 $this->setLanguage( $l );
00219         }
00220 
00228         public function setLanguage( $l ) {
00229                 if ( $l instanceof Language ) {
00230                         $this->lang = $l;
00231                 } elseif ( is_string( $l ) ) {
00232                         $l = RequestContext::sanitizeLangCode( $l );
00233                         $obj = Language::factory( $l );
00234                         $this->lang = $obj;
00235                 } else {
00236                         throw new MWException( __METHOD__ . " was passed an invalid type of data." );
00237                 }
00238         }
00239 
00244         public function getLang() {
00245                 wfDeprecated( __METHOD__, '1.19' );
00246                 $this->getLanguage();
00247         }
00248 
00255         public function getLanguage() {
00256                 if ( !is_null( $this->lang ) ) {
00257                         return $this->lang;
00258                 } else {
00259                         return $this->getContext()->getLanguage();
00260                 }
00261         }
00262 
00268         public function setSkin( Skin $s ) {
00269                 $this->skin = clone $s;
00270                 $this->skin->setContext( $this );
00271         }
00272 
00278         public function getSkin() {
00279                 if ( !is_null( $this->skin ) ) {
00280                         return $this->skin;
00281                 } else {
00282                         return $this->getContext()->getSkin();
00283                 }
00284         }
00285 
00286 }
00287