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 ) ) {
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
* 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, $wgArticle, $wgOut, $wgUseAjax, $wgEnableMWSuggest;
$ns = $wgTitle->getNamespace();
$nsname = MWNamespace::exists( $ns ) ? MWNamespace::getCanonicalName( $ns ) : $wgTitle->getNsText();
'wgUserGroups' => $wgUser->getEffectiveGroups(),
'wgCurRevisionId' => isset( $wgArticle ) ? $wgArticle->getLatest() : 0,
'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 ) ) {
// 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 );
* @return string
*/
function getPoweredBy() {
- global $wgStylePath, $wgUser;
+ global $wgStylePath;
$url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
$text = '<a href="http://www.mediawiki.org/"><img src="' . $url . '" height="31" width="88" alt="Powered by MediaWiki" /></a>';
- wfRunHooks( 'SkinGetPoweredBy', array( &$text, $wgUser->getSkin()->getSkinName() ) );
+ wfRunHooks( 'SkinGetPoweredBy', array( &$text, $this ) );
return $text;
}
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.
}
}
+ /**
+ * 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();