*/
private $title;
+ /**
+ * @var WikiPage
+ */
+ private $wikipage;
+
/**
* @var OutputPage
*/
return $this->title;
}
+ /**
+ * Check whether a WikiPage object can be get with getWikiPage().
+ * Callers should expect that an exception is thrown from getWikiPage()
+ * if this method returns false.
+ *
+ * @since 1.19
+ * @return bool
+ */
+ public function canUseWikiPage() {
+ if ( $this->wikipage !== null ) {
+ # If there's a WikiPage object set, we can for sure get it
+ return true;
+ }
+ $title = $this->getTitle();
+ if ( $title === null ) {
+ # No Title, no WikiPage
+ return false;
+ } else {
+ # Only namespaces whose pages are stored in the database can have WikiPage
+ return $title->canExist();
+ }
+ }
+
+ /**
+ * Set the WikiPage object
+ *
+ * @since 1.19
+ * @param $p WikiPage object
+ */
+ public function setWikiPage( WikiPage $p ) {
+ $this->wikipage = $p;
+ }
+
+ /**
+ * Get the WikiPage object.
+ * May throw an exception if there's no Title object set or the Title object
+ * belongs to a special namespace that doesn't have WikiPage, so use first
+ * canUseWikiPage() to check whether this method can be called safely.
+ *
+ * @since 1.19
+ * @return WikiPage
+ */
+ public function getWikiPage() {
+ if ( $this->wikipage === null ) {
+ $title = $this->getTitle();
+ if ( $title === null ) {
+ throw new MWException( __METHOD__ . ' called without Title object set' );
+ }
+ $this->wikipage = WikiPage::factory( $title );
+ }
+ return $this->wikipage;
+ }
+
/**
* @param $o OutputPage
*/
/**
* Accepts a language code and ensures it's sane. Outputs a cleaned up language
* code and replaces with $wgLanguageCode if not sane.
+ * @param $code string
+ * @return string
*/
- private static function sanitizeLangCode( $code ) {
+ public static function sanitizeLangCode( $code ) {
global $wgLanguageCode;
// BCP 47 - letter case MUST NOT carry meaning
* @param $l Mixed Language instance or language code
*/
public function setLang( $l ) {
+ wfDeprecated( __METHOD__, '1.19' );
$this->setLanguage( $l );
}
* Set the Language object
*
* @param $l Mixed Language instance or language code
+ * @since 1.19
*/
public function setLanguage( $l ) {
if ( $l instanceof Language ) {
* @return Language
*/
public function getLang() {
+ wfDeprecated( __METHOD__, '1.19' );
return $this->getLanguage();
}
* Get the Language object
*
* @return Language
+ * @since 1.19
*/
public function getLanguage() {
if ( $this->lang === null ) {
if ( $this->skin === null ) {
wfProfileIn( __METHOD__ . '-createskin' );
- global $wgHiddenPrefs;
- if( !in_array( 'skin', $wgHiddenPrefs ) ) {
- # get the user skin
- $userSkin = $this->getUser()->getOption( 'skin' );
- $userSkin = $this->getRequest()->getVal( 'useskin', $userSkin );
- } else {
- # if we're not allowing users to override, then use the default
- global $wgDefaultSkin;
- $userSkin = $wgDefaultSkin;
+ $skin = null;
+ wfRunHooks( 'RequestContextCreateSkin', array( $this, &$skin ) );
+
+ // If the hook worked try to set a skin from it
+ if ( $skin instanceof Skin ) {
+ $this->skin = $skin;
+ } elseif ( is_string($skin) ) {
+ $this->skin = Skin::newFromKey( $skin );
+ }
+
+ // If this is still null (the hook didn't run or didn't work)
+ // then go through the normal processing to load a skin
+ if ( $this->skin === null ) {
+ global $wgHiddenPrefs;
+ if( !in_array( 'skin', $wgHiddenPrefs ) ) {
+ # get the user skin
+ $userSkin = $this->getUser()->getOption( 'skin' );
+ $userSkin = $this->getRequest()->getVal( 'useskin', $userSkin );
+ } else {
+ # if we're not allowing users to override, then use the default
+ global $wgDefaultSkin;
+ $userSkin = $wgDefaultSkin;
+ }
+
+ $this->skin = Skin::newFromKey( $userSkin );
}
- $this->skin = Skin::newFromKey( $userSkin );
+ // After all that set a context on whatever skin got created
$this->skin->setContext( $this );
wfProfileOut( __METHOD__ . '-createskin' );
}