protected $skinname = 'standard';
// @todo Fixme: should be protected :-\
var $mTitle = null;
+ protected $mRelevantTitle = null;
+ protected $mRelevantUser = null;
/** Constructor, call parent constructor */
function __construct() {
global $wgValidSkinNames;
static $skinsInitialised = false;
- if ( !$skinsInitialised ) {
+ if ( !$skinsInitialised || !count( $wgValidSkinNames ) ) {
# Get a list of available skins
# Build using the regular expression '^(.*).php$'
# Array keys are all lower case, array value keep the case used by filename
$skinNames = Skin::getSkinNames();
$skinName = $skinNames[$key];
- $className = 'Skin' . ucfirst( $key );
+ $className = "Skin{$skinName}";
# Grab the skin class and initialise it.
if ( !class_exists( $className ) ) {
*/
function addMetadataLinks( OutputPage $out ) {
global $wgEnableDublinCoreRdf, $wgEnableCreativeCommonsRdf;
- global $wgDisableLangConversion, $wgDisableLangCanonical, $wgContLang;
+ global $wgDisableLangConversion, $wgCanonicalLanguageLinks, $wgContLang;
global $wgRightsPage, $wgRightsUrl;
if ( $out->isArticleRelated() ) {
}
}
- if ( !$wgDisableLangConversion && !$wgDisableLangCanonical
+ if ( !$wgDisableLangConversion && $wgCanonicalLanguageLinks
&& $wgContLang->hasVariants() ) {
$urlvar = $wgContLang->getURLVariant();
$this->usercss = false;
}
+ /**
+ * Whether the revision displayed is the latest revision of the page
+ *
+ * @return Boolean
+ */
+ public function isRevisionCurrent() {
+ return $this->mRevisionId == 0 || $this->mRevisionId == $this->mTitle->getLatestRevID();
+ }
+
/**
* Set the title
* @param $t Title object to use
return $this->mTitle;
}
+ /**
+ * Set the "relevant" title
+ * @see self::getRelevantTitle()
+ * @param $t Title object to use
+ */
+ public function setRelevantTitle( $t ) {
+ $this->mRelevantTitle = $t;
+ }
+
+ /**
+ * Return the "relevant" title.
+ * A "relevant" title is not necessarily the actual title of the page.
+ * Special pages like Special:MovePage use set the page they are acting on
+ * as their "relevant" title, this allows the skin system to display things
+ * such as content tabs which belong to to that page instead of displaying
+ * a basic special page tab which has almost no meaning.
+ */
+ public function getRelevantTitle() {
+ if ( isset($this->mRelevantTitle) ) {
+ return $this->mRelevantTitle;
+ }
+ return $this->mTitle;
+ }
+
+ /**
+ * Set the "relevant" user
+ * @see self::getRelevantUser()
+ * @param $u User object to use
+ */
+ public function setRelevantUser( $u ) {
+ $this->mRelevantUser = $u;
+ }
+
+ /**
+ * Return the "relevant" user.
+ * A "relevant" user is similar to a relevant title. Special pages like
+ * Special:Contributions mark the user which they are relevant to so that
+ * things like the toolbox can display the information they usually are only
+ * able to display on a user's userpage and talkpage.
+ */
+ public function getRelevantUser() {
+ if ( isset($this->mRelevantUser) ) {
+ return $this->mRelevantUser;
+ }
+ $title = $this->getRelevantTitle();
+ if( $title->getNamespace() == NS_USER || $title->getNamespace() == NS_USER_TALK ) {
+ $rootUser = strtok( $title->getText(), '/' );
+ if ( User::isIP( $rootUser ) ) {
+ $this->mRelevantUser = User::newFromName( $rootUser, false );
+ } else {
+ $user = User::newFromName( $rootUser );
+ if ( $user->isLoggedIn() ) {
+ $this->mRelevantUser = $user;
+ }
+ }
+ return $this->mRelevantUser;
+ }
+ return null;
+ }
+
/**
* Outputs the HTML generated by other functions.
* @param $out Object: instance of OutputPage
$out->out( $out->headElement( $this ) );
if ( $wgDebugComments ) {
- $out->out( "<!-- Wiki debugging output:\n" .
+ $out->out( "<!-- Debug output:\n" .
$out->mDebugtext . "-->\n" );
}
* You will only be adding bloat to the page and causing page caches to have to be purged on configuration changes.
*/
static function makeGlobalVariablesScript( $skinName ) {
- global $wgTitle, $wgUser, $wgRequest, $wgArticle, $wgOut, $wgRestrictionTypes, $wgUseAjax, $wgEnableMWSuggest;
+ global $wgTitle, $wgUser, $wgRequest, $wgOut, $wgUseAjax, $wgEnableMWSuggest;
$ns = $wgTitle->getNamespace();
$nsname = MWNamespace::exists( $ns ) ? MWNamespace::getCanonicalName( $ns ) : $wgTitle->getNsText();
'wgIsArticle' => $wgOut->isArticle(),
'wgUserName' => $wgUser->isAnon() ? null : $wgUser->getName(),
'wgUserGroups' => $wgUser->getEffectiveGroups(),
- 'wgCurRevisionId' => isset( $wgArticle ) ? $wgArticle->getLatest() : 0,
+ 'wgCurRevisionId' => $wgTitle->getLatestRevID(),
'wgCategories' => $wgOut->getCategories(),
+ 'wgBreakFrames' => $wgOut->getFrameOptions() == 'DENY',
);
- foreach ( $wgRestrictionTypes as $type ) {
+ foreach ( $wgTitle->getRestrictionTypes() as $type ) {
$vars['wgRestriction' . ucfirst( $type )] = $wgTitle->getRestrictions( $type );
}
if ( $wgUseAjax && $wgEnableMWSuggest && !$wgUser->getOption( 'disablesuggest', false ) ) {
*/
function setupUserCss( OutputPage $out ) {
global $wgRequest;
- global $wgUseSiteCss, $wgAllowUserCss, $wgAllowUserCssPrefs, $wgSquidMaxage;
+ global $wgUseSiteCss, $wgAllowUserCss, $wgAllowUserCssPrefs;
wfProfileIn( __METHOD__ );
$this->setupSkinUserCss( $out );
-
- $siteargs = array(
- 'action' => 'raw',
- 'maxage' => $wgSquidMaxage,
- );
-
// Add any extension CSS
foreach ( $out->getExtStyle() as $url ) {
$out->addStyle( $url );
global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgPageShowWatchingUsers;
- $oldid = $wgRequest->getVal( 'oldid' );
- $diff = $wgRequest->getVal( 'diff' );
-
- if ( !$wgOut->isArticle() ) {
+ if ( !is_null( $wgRequest->getVal( 'oldid' ) ) || !is_null( $wgRequest->getVal( 'diff' ) ) ) {
return '';
}
- if ( !$wgArticle instanceof Article ) {
- return '';
- }
-
- if ( isset( $oldid ) || isset( $diff ) ) {
- return '';
- }
-
- if ( 0 == $wgArticle->getID() ) {
+ if ( !$wgOut->isArticle() || !$this->mTitle->exists() ) {
return '';
}
}
function getCopyright( $type = 'detect' ) {
- global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest, $wgArticle;
+ global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest;
if ( $type == 'detect' ) {
$diff = $wgRequest->getVal( 'diff' );
- $isCur = $wgArticle && $wgArticle->isCurrent();
- if ( is_null( $diff ) && !$isCur && wfMsgForContent( 'history_copyright' ) !== '-' ) {
+ if ( is_null( $diff ) && !$this->isRevisionCurrent() && wfMsgForContent( 'history_copyright' ) !== '-' ) {
$type = 'history';
} else {
$type = 'normal';
// Allow for site and per-namespace customization of copyright notice.
$forContent = true;
- if ( isset( $wgArticle ) ) {
- wfRunHooks( 'SkinCopyrightFooter', array( $wgArticle->getTitle(), $type, &$msg, &$link, &$forContent ) );
- }
+ wfRunHooks( 'SkinCopyrightFooter', array( $this->mTitle, $type, &$msg, &$link, &$forContent ) );
if ( $forContent ) {
$out .= wfMsgForContent( $msg, $link );
global $wgStylePath;
$url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
- $img = '<a href="http://www.mediawiki.org/"><img src="' . $url . '" height="31" width="88" alt="Powered by MediaWiki" /></a>';
-
- return $img;
+ $text = '<a href="http://www.mediawiki.org/"><img src="' . $url . '" height="31" width="88" alt="Powered by MediaWiki" /></a>';
+ wfRunHooks( 'SkinGetPoweredBy', array( &$text, $this ) );
+ return $text;
}
function lastModified() {
global $wgLang, $wgArticle;
- if ( $this->mRevisionId && $this->mRevisionId != $wgArticle->getLatest() ) {
- $timestamp = Revision::getTimestampFromId( $wgArticle->getTitle(), $this->mRevisionId );
+ if ( !$this->isRevisionCurrent() ) {
+ $timestamp = Revision::getTimestampFromId( $this->mTitle, $this->mRevisionId );
} else {
$timestamp = $wgArticle->getTimestamp();
}
return $s;
}
+ /**
+ * Renders a $wgFooterIcons icon acording to the method's arguments
+ * @param $icon Array: The icon to build the html for, see $wgFooterIcons for the format of this array
+ * @param $withImage Boolean: Whether to use the icon's image or output a text-only footericon
+ */
+ function makeFooterIcon( $icon, $withImage = 'withImage' ) {
+ if ( is_string( $icon ) ) {
+ $html = $icon;
+ } else { // Assuming array
+ $url = $icon["url"];
+ unset( $icon["url"] );
+ if ( isset( $icon["src"] ) && $withImage === 'withImage' ) {
+ $html = Html::element( 'img', $icon ); // do this the lazy way, just pass icon data as an attribute array
+ } else {
+ $html = htmlspecialchars( $icon["alt"] );
+ }
+ if ( $url ) {
+ $html = Html::rawElement( 'a', array( "href" => $url ), $html );
+ }
+ }
+ return $html;
+ }
+
/**
* Gets the link to the wiki's main page.
* @return string
return $s;
}
- private function footerLink( $desc, $page ) {
+ public function footerLink( $desc, $page ) {
// if the link description has been set to "-" in the default language,
if ( wfMsgForContent( $desc ) == '-' ) {
// then it is disabled, for all languages.
* @private
*/
function editUrlOptions() {
- global $wgArticle;
-
$options = array( 'action' => 'edit' );
- if ( $this->mRevisionId && ! $wgArticle->isCurrent() ) {
+ if ( !$this->isRevisionCurrent() ) {
$options['oldid'] = intval( $this->mRevisionId );
}
}
}
+ /**
+ * Return a fully resolved style path url to images or styles stored in the common folder.
+ * This method returns a url resolved using the configured skin style path
+ * and includes the style version inside of the url.
+ * @param $name String: The name or path of a skin resource file
+ * @return String The fully resolved style path url including styleversion
+ */
+ function getCommonStylePath( $name ) {
+ global $wgStylePath, $wgStyleVersion;
+ return "$wgStylePath/common/$name?$wgStyleVersion";
+ }
+
+ /**
+ * Return a fully resolved style path url to images or styles stored in the curent skins's folder.
+ * This method returns a url resolved using the configured skin style path
+ * and includes the style version inside of the url.
+ * @param $name String: The name or path of a skin resource file
+ * @return String The fully resolved style path url including styleversion
+ */
+ function getSkinStylePath( $name ) {
+ global $wgStylePath, $wgStyleVersion;
+ return "$wgStylePath/{$this->stylename}/$name?$wgStyleVersion";
+ }
+
/* these are used extensively in SkinTemplate, but also some other places */
static function makeMainPageUrl( $urlaction = '' ) {
$title = Title::newMainPage();