if ( ! defined( 'MEDIAWIKI' ) )
die( 1 );
-/**
- *
- * @package MediaWiki
- * @subpackage Skins
- */
-
# See skin.txt
/**
* The main skin class that provide methods and properties for all other skins.
* This base class is also the "Standard" skin.
- * @package MediaWiki
+ *
+ * See docs/skin.txt for more information.
+ *
+ * @addtogroup Skins
*/
class Skin extends Linker {
/**#@+
var $rc_cache ; # Cache for Enhanced Recent Changes
var $rcCacheIndex ; # Recent Changes Cache Counter for visibility toggle
var $rcMoveIndex;
+ var $mWatchLinkNum = 0; // Appended to end of watch link id's
/**#@-*/
+ protected $mRevisionId; // The revision ID we're looking at, null if not applicable.
+ protected $skinname = 'standard' ;
/** Constructor, call parent constructor */
- function Skin() { parent::Linker(); }
+ function Skin() { parent::__construct(); }
/**
* Fetch the set of available skins.
* @return array of strings
* @static
*/
- static function &getSkinNames() {
+ static function getSkinNames() {
global $wgValidSkinNames;
static $skinsInitialised = false;
if ( !$skinsInitialised ) {
}
/** @return string skin name */
- function getSkinName() {
- return 'standard';
+ public function getSkinName() {
+ return $this->skinname;
}
function qbSetting() {
global $wgOut, $wgUser;
if ( $wgOut->isQuickbarSuppressed() ) { return 0; }
- $q = $wgUser->getOption( 'quickbar' );
- if ( '' == $q ) { $q = 0; }
+ $q = $wgUser->getOption( 'quickbar', 0 );
return $q;
}
function preloadExistence() {
global $wgUser, $wgTitle;
- if ( $wgTitle->isTalkPage() ) {
- $otherTab = $wgTitle->getSubjectPage();
+ // User/talk link
+ $titles = array( $wgUser->getUserPage(), $wgUser->getTalkPage() );
+
+ // Other tab link
+ if ( $wgTitle->getNamespace() == NS_SPECIAL ) {
+ // nothing
+ } elseif ( $wgTitle->isTalkPage() ) {
+ $titles[] = $wgTitle->getSubjectPage();
} else {
- $otherTab = $wgTitle->getTalkPage();
+ $titles[] = $wgTitle->getTalkPage();
}
- $lb = new LinkBatch( array(
- $wgUser->getUserPage(),
- $wgUser->getTalkPage(),
- $otherTab
- ));
+
+ $lb = new LinkBatch( $titles );
$lb->execute();
}
function outputPage( &$out ) {
global $wgDebugComments;
- wfProfileIn( 'Skin::outputPage' );
+ wfProfileIn( __METHOD__ );
$this->initPage( $out );
$out->out( $out->headElement() );
$out->out( $out->reportTime() );
$out->out( "\n</body></html>" );
+ wfProfileOut( __METHOD__ );
}
- static function makeGlobalVariablesScript( $data ) {
- $r = '<script type= "' . $data['jsmimetype'] . '">
- var skin = "' . Xml::escapeJsString( $data['skinname'] ) . '";
- var stylepath = "' . Xml::escapeJsString( $data['stylepath'] ) . '";
-
- var wgArticlePath = "' . Xml::escapeJsString( $data['articlepath'] ) . '";
- var wgScriptPath = "' . Xml::escapeJsString( $data['scriptpath'] ) . '";
- var wgServer = "' . Xml::escapeJsString( $data['serverurl'] ) . '";
-
- var wgCanonicalNamespace = "' . Xml::escapeJsString( $data['nscanonical'] ) . '";
- var wgNamespaceNumber = ' . (int)$data['nsnumber'] . ';
- var wgPageName = "' . Xml::escapeJsString( $data['titleprefixeddbkey'] ) . '";
- var wgTitle = "' . Xml::escapeJsString( $data['titletext'] ) . '";
- var wgArticleId = ' . (int)$data['articleid'] . ';
- var wgIsArticle = ' . ( $data['isarticle'] ? 'true' : 'false' ) . ';
-
- var wgUserName = ' . ( $data['username'] == NULL ? 'null' : ( '"' . Xml::escapeJsString( $data['username'] ) . '"' ) ) . ';
- var wgUserLanguage = "' . Xml::escapeJsString( $data['userlang'] ) . '";
- var wgContentLanguage = "' . Xml::escapeJsString( $data['lang'] ) . '";
- </script>
- ';
-
+ static function makeVariablesScript( $data ) {
+ global $wgJsMimeType;
+
+ $r = "<script type= \"$wgJsMimeType\">/*<![CDATA[*/\n";
+ foreach ( $data as $name => $value ) {
+ $encValue = Xml::encodeJsVar( $value );
+ $r .= "var $name = $encValue;\n";
+ }
+ $r .= "/*]]>*/</script>\n";
+
return $r;
}
- function getHeadScripts() {
- global $wgStylePath, $wgUser, $wgAllowUserJs, $wgJsMimeType, $wgStyleVersion;
+ /**
+ * Make a <script> tag containing global variables
+ * @param array $data Associative array containing one element:
+ * skinname => the skin name
+ * The odd calling convention is for backwards compatibility
+ */
+ static function makeGlobalVariablesScript( $data ) {
+ global $wgStylePath, $wgUser;
global $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang, $wgLang;
- global $wgTitle, $wgCanonicalNamespaceNames, $wgOut;
+ global $wgTitle, $wgCanonicalNamespaceNames, $wgOut, $wgArticle;
+ global $wgBreakFrames, $wgRequest;
$ns = $wgTitle->getNamespace();
$nsname = isset( $wgCanonicalNamespaceNames[ $ns ] ) ? $wgCanonicalNamespaceNames[ $ns ] : $wgTitle->getNsText();
$vars = array(
- 'jsmimetype' => $wgJsMimeType,
- 'skinname' => $this->getSkinName(),
+ 'skin' => $data['skinname'],
'stylepath' => $wgStylePath,
- 'articlepath' => $wgArticlePath,
- 'scriptpath' => $wgScriptPath,
- 'serverurl' => $wgServer,
- 'nscanonical' => $nsname,
- 'nsnumber' => $wgTitle->getNamespace(),
- 'titleprefixeddbkey' => $wgTitle->getPrefixedDBKey(),
- 'titletext' => $wgTitle->getText(),
- 'articleid' => $wgTitle->getArticleId(),
- 'isarticle' => $wgOut->isArticle(),
- 'username' => $wgUser->isAnon() ? NULL : $wgUser->getName(),
- 'userlang' => $wgLang->getCode(),
- 'lang' => $wgContLang->getCode(),
+ 'wgArticlePath' => $wgArticlePath,
+ 'wgScriptPath' => $wgScriptPath,
+ 'wgServer' => $wgServer,
+ 'wgCanonicalNamespace' => $nsname,
+ 'wgCanonicalSpecialPageName' => SpecialPage::resolveAlias( $wgTitle->getDBKey() ),
+ 'wgNamespaceNumber' => $wgTitle->getNamespace(),
+ 'wgPageName' => $wgTitle->getPrefixedDBKey(),
+ 'wgTitle' => $wgTitle->getText(),
+ 'wgAction' => $wgRequest->getText( 'action', 'view' ),
+ 'wgArticleId' => $wgTitle->getArticleId(),
+ 'wgIsArticle' => $wgOut->isArticle(),
+ 'wgUserName' => $wgUser->isAnon() ? NULL : $wgUser->getName(),
+ 'wgUserGroups' => $wgUser->isAnon() ? NULL : $wgUser->getEffectiveGroups(),
+ 'wgUserLanguage' => $wgLang->getCode(),
+ 'wgContentLanguage' => $wgContLang->getCode(),
+ 'wgBreakFrames' => $wgBreakFrames,
+ 'wgCurRevisionId' => isset( $wgArticle ) ? $wgArticle->getLatest() : 0,
);
- $r = self::makeGlobalVariablesScript( $vars );
+ global $wgLivePreview;
+ if ( $wgLivePreview && $wgUser->getOption( 'uselivepreview' ) ) {
+ $vars['wgLivepreviewMessageLoading'] = wfMsg( 'livepreview-loading' );
+ $vars['wgLivepreviewMessageReady'] = wfMsg( 'livepreview-ready' );
+ $vars['wgLivepreviewMessageFailed'] = wfMsg( 'livepreview-failed' );
+ $vars['wgLivepreviewMessageError'] = wfMsg( 'livepreview-error' );
+ }
+
+ return self::makeVariablesScript( $vars );
+ }
+
+ function getHeadScripts( $allowUserJs ) {
+ global $wgStylePath, $wgUser, $wgJsMimeType, $wgStyleVersion;
+
+ $r = self::makeGlobalVariablesScript( array( 'skinname' => $this->getSkinName() ) );
$r .= "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/wikibits.js?$wgStyleVersion\"></script>\n";
global $wgUseSiteJs;
$r .= "<script type=\"$wgJsMimeType\" src=\"".htmlspecialchars(self::makeUrl('-','action=raw&gen=js'))."\"><!-- site js --></script>\n";
}
}
- if( $wgAllowUserJs && $wgUser->isLoggedIn() ) {
+ if( $allowUserJs && $wgUser->isLoggedIn() ) {
$userpage = $wgUser->getUserPage();
$userjs = htmlspecialchars( self::makeUrl(
$userpage->getPrefixedText().'/'.$this->getSkinName().'.js',
* @return string
*/
function getUserJs() {
- $fname = 'Skin::getUserJs';
- wfProfileIn( $fname );
+ wfProfileIn( __METHOD__ );
global $wgStylePath;
$s = "/* generated javascript */\n";
$s .= "var skin = '{$this->skinname}';\nvar stylepath = '{$wgStylePath}';";
$s .= "\n\n/* MediaWiki:Common.js */\n";
- $commonJs = wfMsgForContent('Common.js');
- if ( !wfEmptyMsg ( 'Common.js', $commonJs ) ) {
+ $commonJs = wfMsgForContent('common.js');
+ if ( !wfEmptyMsg ( 'common.js', $commonJs ) ) {
$s .= $commonJs;
}
- wfProfileOut( $fname );
+ global $wgUseAjax, $wgAjaxWatch;
+ if($wgUseAjax && $wgAjaxWatch) {
+ $s .= "
+
+/* AJAX (un)watch (see /skins/common/ajaxwatch.js) */
+var wgAjaxWatch = {
+ watchMsg: '". str_replace( array("'", "\n"), array("\\'", ' '), wfMsgExt( 'watch', array() ) )."',
+ unwatchMsg: '". str_replace( array("'", "\n"), array("\\'", ' '), wfMsgExt( 'unwatch', array() ) )."',
+ watchingMsg: '". str_replace( array("'", "\n"), array("\\'", ' '), wfMsgExt( 'watching', array() ) )."',
+ unwatchingMsg: '". str_replace( array("'", "\n"), array("\\'", ' '), wfMsgExt( 'unwatching', array() ) )."'
+};";
+ }
+
+ wfProfileOut( __METHOD__ );
return $s;
- }
+ }
/**
* Return html code that include User stylesheets
}
else $a = array( 'bgcolor' => '#FFFFFF' );
if($wgOut->isArticle() && $wgUser->getOption('editondblclick') &&
- $wgTitle->userCanEdit() ) {
+ $wgTitle->userCan( 'edit' ) ) {
$s = $wgTitle->getFullURL( $this->editUrlOptions() );
$s = 'document.location = "' .wfEscapeJSString( $s ) .'";';
$a += array ('ondblclick' => $s);
$a['onload'] .= 'setupRightClickEdit()';
}
$a['class'] = 'ns-'.$wgTitle->getNamespace().' '.($wgContLang->isRTL() ? "rtl" : "ltr").
- ' '.Sanitizer::escapeId( 'page-'.$wgTitle->getPrefixedText() );
+ ' '.Sanitizer::escapeClass( 'page-'.$wgTitle->getPrefixedText() );
return $a;
}
$msg = 'viewdeleted';
}
return wfMsg( $msg,
- $this->makeKnownLink(
- $wgContLang->SpecialPage( 'Undelete/' . $wgTitle->getPrefixedDBkey() ),
+ $this->makeKnownLinkObj(
+ SpecialPage::getTitleFor( 'Undelete', $wgTitle->getPrefixedDBkey() ),
wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $n ) ) );
}
return '';
function printableLink() {
global $wgOut, $wgFeedClasses, $wgRequest;
- $baseurl = $_SERVER['REQUEST_URI'];
- if( strpos( '?', $baseurl ) == false ) {
- $baseurl .= '?';
- } else {
- $baseurl .= '&';
- }
- $baseurl = htmlspecialchars( $baseurl );
$printurl = $wgRequest->escapeAppendQuery( 'printable=yes' );
$s = "<a href=\"$printurl\">" . wfMsg( 'printableversion' ) . '</a>';
return $subpages;
}
+ /**
+ * Returns true if the IP should be shown in the header
+ */
+ function showIPinHeader() {
+ global $wgShowIPinHeader;
+ return $wgShowIPinHeader && session_id() != '';
+ }
+
function nameAndLogin() {
- global $wgUser, $wgTitle, $wgLang, $wgContLang, $wgShowIPinHeader;
+ global $wgUser, $wgTitle, $wgLang, $wgContLang;
$lo = $wgContLang->specialPage( 'Userlogout' );
$s = '';
if ( $wgUser->isAnon() ) {
- if( $wgShowIPinHeader && isset( $_COOKIE[ini_get('session.name')] ) ) {
+ if( $this->showIPinHeader() ) {
$n = wfGetIP();
$tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
}
if ($wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
- $dbr =& wfGetDB( DB_SLAVE );
+ $dbr = wfGetDB( DB_SLAVE );
$watchlist = $dbr->tableName( 'watchlist' );
$sql = "SELECT COUNT(*) AS n FROM $watchlist
WHERE wl_title='" . $dbr->strencode($wgTitle->getDBKey()) .
function getPoweredBy() {
global $wgStylePath;
$url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
- $img = '<a href="http://www.mediawiki.org/"><img src="'.$url.'" alt="MediaWiki" /></a>';
+ $img = '<a href="http://www.mediawiki.org/"><img src="'.$url.'" alt="Powered by MediaWiki" /></a>';
return $img;
}
return $s;
}
- function privacyLink() {
- $privacy = wfMsg( 'privacy' );
- if ($privacy == '-') {
+ private 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 '';
} else {
- return $this->makeKnownLink( wfMsgForContent( 'privacypage' ), $privacy);
+ // Otherwise, we display the link for the user, described in their
+ // language (which may or may not be the same as the default language),
+ // but we make the link target be the one site-wide page.
+ return $this->makeKnownLink( wfMsgForContent( $page ), wfMsg( $desc ) );
}
}
+ function privacyLink() {
+ return $this->footerLink( 'privacy', 'privacypage' );
+ }
+
function aboutLink() {
- $s = $this->makeKnownLink( wfMsgForContent( 'aboutpage' ),
- wfMsg( 'aboutsite' ) );
- return $s;
+ return $this->footerLink( 'aboutsite', 'aboutpage' );
}
function disclaimerLink() {
- $disclaimers = wfMsg( 'disclaimers' );
- if ($disclaimers == '-') {
- return '';
- } else {
- return $this->makeKnownLink( wfMsgForContent( 'disclaimerpage' ),
- $disclaimers );
- }
+ return $this->footerLink( 'disclaimers', 'disclaimerpage' );
}
function editThisPage() {
if ( ! $wgOut->isArticleRelated() ) {
$s = wfMsg( 'protectedpage' );
} else {
- if ( $wgTitle->userCanEdit() ) {
+ if ( $wgTitle->userCan( 'edit' ) ) {
$t = wfMsg( 'editthispage' );
} else {
$t = wfMsg( 'viewsource' );
function watchThisPage() {
global $wgOut, $wgTitle;
+ ++$this->mWatchLinkNum;
if ( $wgOut->isArticleRelated() ) {
if ( $wgTitle->userIsWatching() ) {
$t = wfMsg( 'unwatchthispage' );
$q = 'action=unwatch';
+ $id = "mw-unwatch-link".$this->mWatchLinkNum;
} else {
$t = wfMsg( 'watchthispage' );
$q = 'action=watch';
+ $id = 'mw-watch-link'.$this->mWatchLinkNum;
}
- $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
+ $s = $this->makeKnownLinkObj( $wgTitle, $t, $q, '', '', " id=\"$id\"" );
} else {
$s = wfMsg( 'notanarticle' );
}
function moveThisPage() {
global $wgTitle;
- if ( $wgTitle->userCanMove() ) {
+ if ( $wgTitle->userCan( 'move' ) ) {
return $this->makeKnownLinkObj( SpecialPage::getTitleFor( 'Movepage' ),
wfMsg( 'movethispage' ), 'target=' . $wgTitle->getPrefixedURL() );
} else {
return $s;
}
- function dateLink() {
- $t1 = Title::newFromText( gmdate( 'F j' ) );
- $t2 = Title::newFromText( gmdate( 'Y' ) );
-
- $id = $t1->getArticleID();
-
- if ( 0 == $id ) {
- $s = $this->makeBrokenLink( $t1->getText() );
- } else {
- $s = $this->makeKnownLink( $t1->getText() );
- }
- $s .= ', ';
-
- $id = $t2->getArticleID();
-
- if ( 0 == $id ) {
- $s .= $this->makeBrokenLink( $t2->getText() );
- } else {
- $s .= $this->makeKnownLink( $t2->getText() );
- }
- return $s;
- }
-
function talkLink() {
global $wgTitle;
/* these are used extensively in SkinTemplate, but also some other places */
static function makeMainPageUrl( $urlaction = '' ) {
$title = Title::newMainPage();
- self::checkTitle( $title, $name );
+ self::checkTitle( $title, '' );
return $title->getLocalURL( $urlaction );
}
return $title->getLocalURL( $urlaction );
}
+ static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
+ $title = SpecialPage::getSafeTitleFor( $name, $subpage );
+ return $title->getLocalURL( $urlaction );
+ }
+
static function makeI18nUrl( $name, $urlaction = '' ) {
$title = Title::newFromText( wfMsgForContent( $name ) );
self::checkTitle( $title, $name );
}
# make sure we have some title to operate on
- static function checkTitle( &$title, &$name ) {
+ static function checkTitle( &$title, $name ) {
if( !is_object( $title ) ) {
$title = Title::newFromText( $name );
if( !is_object( $title ) ) {