MediaWiki
REL1_22
|
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 00072 public function __construct( IContextSource $context ) { 00073 $this->setContext( $context ); 00074 } 00075 00081 public function setRequest( WebRequest $r ) { 00082 $this->request = $r; 00083 } 00084 00090 public function getRequest() { 00091 if ( !is_null( $this->request ) ) { 00092 return $this->request; 00093 } else { 00094 return $this->getContext()->getRequest(); 00095 } 00096 } 00097 00103 public function setTitle( $t ) { 00104 if ( $t !== null && !$t instanceof Title ) { 00105 throw new MWException( __METHOD__ . " expects an instance of Title" ); 00106 } 00107 $this->title = $t; 00108 } 00109 00115 public function getTitle() { 00116 if ( !is_null( $this->title ) ) { 00117 return $this->title; 00118 } else { 00119 return $this->getContext()->getTitle(); 00120 } 00121 } 00122 00131 public function canUseWikiPage() { 00132 if ( $this->wikipage !== null ) { 00133 return true; 00134 } elseif ( $this->title !== null ) { 00135 return $this->title->canExist(); 00136 } else { 00137 return $this->getContext()->canUseWikiPage(); 00138 } 00139 } 00140 00147 public function setWikiPage( WikiPage $p ) { 00148 $this->wikipage = $p; 00149 } 00150 00160 public function getWikiPage() { 00161 if ( !is_null( $this->wikipage ) ) { 00162 return $this->wikipage; 00163 } else { 00164 return $this->getContext()->getWikiPage(); 00165 } 00166 } 00167 00173 public function setOutput( OutputPage $o ) { 00174 $this->output = $o; 00175 } 00176 00182 public function getOutput() { 00183 if ( !is_null( $this->output ) ) { 00184 return $this->output; 00185 } else { 00186 return $this->getContext()->getOutput(); 00187 } 00188 } 00189 00195 public function setUser( User $u ) { 00196 $this->user = $u; 00197 } 00198 00204 public function getUser() { 00205 if ( !is_null( $this->user ) ) { 00206 return $this->user; 00207 } else { 00208 return $this->getContext()->getUser(); 00209 } 00210 } 00211 00218 public function setLang( $l ) { 00219 wfDeprecated( __METHOD__, '1.19' ); 00220 $this->setLanguage( $l ); 00221 } 00222 00230 public function setLanguage( $l ) { 00231 if ( $l instanceof Language ) { 00232 $this->lang = $l; 00233 } elseif ( is_string( $l ) ) { 00234 $l = RequestContext::sanitizeLangCode( $l ); 00235 $obj = Language::factory( $l ); 00236 $this->lang = $obj; 00237 } else { 00238 throw new MWException( __METHOD__ . " was passed an invalid type of data." ); 00239 } 00240 } 00241 00246 public function getLang() { 00247 wfDeprecated( __METHOD__, '1.19' ); 00248 $this->getLanguage(); 00249 } 00250 00257 public function getLanguage() { 00258 if ( !is_null( $this->lang ) ) { 00259 return $this->lang; 00260 } else { 00261 return $this->getContext()->getLanguage(); 00262 } 00263 } 00264 00270 public function setSkin( Skin $s ) { 00271 $this->skin = clone $s; 00272 $this->skin->setContext( $this ); 00273 } 00274 00280 public function getSkin() { 00281 if ( !is_null( $this->skin ) ) { 00282 return $this->skin; 00283 } else { 00284 return $this->getContext()->getSkin(); 00285 } 00286 } 00287 00299 public function msg() { 00300 $args = func_get_args(); 00301 return call_user_func_array( 'wfMessage', $args )->setContext( $this ); 00302 } 00303 }