Big change to the skin system. Php files are now in ./skins/ . Templates and stylesheets will be migrated there as well later. The main idea is to let users add new skins easily without hacking mediawiki

This commit is contained in:
Antoine Musso 2004-09-02 01:29:18 +00:00
parent 837b18f8db
commit fd758aaa3c
12 changed files with 577 additions and 65 deletions

View file

@ -8,9 +8,9 @@ if( defined( "MEDIAWIKI" ) ) {
require_once( 'Feed.php' ); // should not be called if the actual page isn't feed enabled
require_once( 'Image.php' );
# These are the INTERNAL names, which get mapped
# directly to class names. For display purposes, the
# Language class has internationalized names
# These are the INTERNAL names, which get mapped directly to class names and
# file names in ./skins/. For display purposes, the Language class has
# internationalized names
#
/* private */ $wgValidSkinNames = array(
'standard' => 'Standard',
@ -21,9 +21,9 @@ if( $wgUsePHPTal ) {
#$wgValidSkinNames[] = 'PHPTal';
#$wgValidSkinNames['davinci'] = 'DaVinci';
#$wgValidSkinNames['mono'] = 'Mono';
#$wgValidSkinNames['monobookminimal'] = 'MonoBookMinimal';
$wgValidSkinNames['monobook'] = 'MonoBook';
$wgValidSkinNames['myskin'] = 'MySkin';
#$wgValidSkinNames['monobookminimal'] = 'MonoBookMinimal';
$wgValidSkinNames['chick'] = 'Chick';
}

View file

@ -615,44 +615,5 @@ class SkinPHPTal extends Skin {
}
}
class SkinDaVinci extends SkinPHPTal {
function initPage( &$out ) {
SkinPHPTal::initPage( $out );
$this->skinname = 'davinci';
}
}
class SkinMono extends SkinPHPTal {
function initPage( &$out ) {
SkinPHPTal::initPage( $out );
$this->skinname = 'mono';
}
}
class SkinMonoBook extends SkinPHPTal {
function initPage( &$out ) {
SkinPHPTal::initPage( $out );
$this->skinname = 'monobook';
}
}
class SkinMySkin extends SkinPHPTal {
function initPage( &$out ) {
SkinPHPTal::initPage( $out );
$this->skinname = 'myskin';
}
}
class SkinChick extends SkinPHPTal {
function initPage( &$out ) {
SkinPHPTal::initPage( $out );
$this->skinname = 'chick';
$this->template = 'xhtml_minimal';
}
function suppressUrlExpansion() { return true; }
function printSource() { return ''; }
}
} // end of if( defined( 'MEDIAWIKI' ) )
?>

View file

@ -435,6 +435,7 @@ class User {
}
function &getSkin() {
global $IP;
if ( ! isset( $this->mSkin ) ) {
# get all skin names available from SkinNames.php
$skinNames = Skin::getSkinNames();
@ -445,41 +446,28 @@ class User {
if ( !isset( $skinNames[$userSkin] ) ) {
# in case the user skin could not be found find a replacement
$fallback = array(
0 => 'SkinStandard',
1 => 'SkinNostalgia',
2 => 'SkinCologneBlue');
0 => 'Standard',
1 => 'Nostalgia',
2 => 'CologneBlue');
# if phptal is enabled we should have monobook skin that superseed
# the good old SkinStandard.
if ( isset( $skinNames['monobook'] ) ) {
$fallback[0] = 'SkinMonoBook';
$fallback[0] = 'MonoBook';
}
if(is_numeric($userSkin) && isset( $fallback[$userSkin]) ){
$sn = $fallback[$userSkin];
} else {
$sn = 'SkinStandard';
$sn = 'Standard';
}
} else {
# The user skin is available
$sn = 'Skin' . $skinNames[$userSkin];
$sn = $skinNames[$userSkin];
}
# only require the needed stuff
switch($sn) {
case 'SkinMonoBook':
require_once( 'SkinPHPTal.php' );
break;
case 'SkinStandard':
require_once( 'SkinStandard.php' );
break;
case 'SkinNostalgia':
require_once( 'SkinNostalgia.php' );
break;
case 'SkinCologneBlue':
require_once( 'SkinCologneBlue.php' );
break;
}
# now we can create the skin object
# Grab the skin class and initialise it
require_once( $IP.'/skins/'.$sn.'.php' );
$sn = 'Skin'.$sn;
$this->mSkin = new $sn;
}
return $this->mSkin;

14
skins/Chick.php Normal file
View file

@ -0,0 +1,14 @@
<?php
require_once($IP.'/includes/SkinPHPTal.php');
class SkinChick extends SkinPHPTal {
function initPage( &$out ) {
SkinPHPTal::initPage( $out );
$this->skinname = 'chick';
$this->template = 'xhtml_minimal';
}
function suppressUrlExpansion() { return true; }
function printSource() { return ''; }
}
?>

274
skins/CologneBlue.php Normal file
View file

@ -0,0 +1,274 @@
<?php
# See skin.doc
class SkinCologneBlue extends Skin {
function getStylesheet()
{
return "cologneblue.css";
}
function getSkinName() {
return "cologneblue";
}
function doBeforeContent()
{
global $wgUser, $wgOut, $wgTitle, $wgSiteNotice;
$s = "";
$qb = $this->qbSetting();
$mainPageObj = Title::newMainPage();
$s .= "\n<div id='content'>\n<div id='topbar'>" .
"<table width='100%' border='0' cellspacing='0' cellpadding='8'><tr>";
$s .= "<td class='top' align='left' valign='middle' nowrap='nowrap'>";
$s .= "<a href=\"" . $mainPageObj->escapeLocalURL() . "\">";
$s .= "<span id='sitetitle'>" . wfMsg( "sitetitle" ) . "</span></a>";
$s .= "</td><td class='top' align='right' valign='bottom' width='100%'>";
$s .= $this->sysLinks();
$s .= "</td></tr><tr><td valign='top'>";
$s .= "<font size='-1'><span id='sitesub'>";
$s .= htmlspecialchars( wfMsg( "sitesubtitle" ) ) . "</span></font>";
$s .= "</td><td align='right'>" ;
$s .= "<font size='-1'><span id='langlinks'>" ;
$s .= str_replace ( "<br>" , "" , $this->otherLanguages() );
$cat = $this->getCategoryLinks();
if( $cat ) $s .= "<br />$cat\n";
$s .= "<br />" . $this->pageTitleLinks();
$s .= "</span></font>";
$s .= "</td></tr></table>\n";
$s .= "\n</div>\n<div id='article'>";
if( $wgSiteNotice ) {
$s .= "\n<div id='siteNotice'>$wgSiteNotice</div>\n";
}
$s .= $this->pageTitle();
$s .= $this->pageSubtitle() . "\n";
return $s;
}
function doAfterContent()
{
global $wgUser, $wgOut;
$s = "\n</div><br clear='all' />\n";
$s .= "\n<div id='footer'>";
$s .= "<table width='98%' border='0' cellspacing='0'><tr>";
$qb = $this->qbSetting();
if ( 1 == $qb || 3 == $qb ) { # Left
$s .= $this->getQuickbarCompensator();
}
$s .= "<td class='bottom' align='center' valign='top'>";
$s .= $this->bottomLinks();
$s .= "\n<br />" . $this->makeKnownLink( wfMsg( "mainpage" ) ) . " | "
. $this->aboutLink() . " | "
. $this->searchForm( wfMsg( "qbfind" ) );
$s .= "\n<br />" . $this->pageStats();
$s .= "</td>";
if ( 2 == $qb ) { # Right
$s .= $this->getQuickbarCompensator();
}
$s .= "</tr></table>\n</div>\n</div>\n";
if ( 0 != $qb ) { $s .= $this->quickBar(); }
return $s;
}
function doGetUserStyles()
{
global $wgUser, $wgOut, $wgStyleSheetPath;
$s = '';
$qb = $this->qbSetting();
if ( 2 == $qb ) { # Right
$s .= "#quickbar { position: absolute; right: 4px; }\n" .
"#article { margin-left: 4px; margin-right: 148px; }\n";
} else if ( 1 == $qb ) {
$s .= "#quickbar { position: absolute; left: 4px; }\n" .
"#article { margin-left: 148px; margin-right: 4px; }\n";
} else if ( 3 == $qb ) { # Floating
$s .= "#quickbar { position:absolute; left:4px } \n" .
"#topbar { margin-left: 148px }\n" .
"#article { margin-left:148px; margin-right: 4px; } \n" .
"body>#quickbar { position:fixed; left:4px; top:4px; overflow:auto ;bottom:4px;} \n"; # Hides from IE
}
$s .= parent::doGetUserStyles();
return $s;
}
function sysLinks()
{
global $wgUser, $wgLang, $wgTitle;
$li = $wgLang->specialPage("Userlogin");
$lo = $wgLang->specialPage("Userlogout");
$rt = $wgTitle->getPrefixedURL();
if ( 0 == strcasecmp( urlencode( $lo ), $rt ) ) {
$q = "";
} else {
$q = "returnto={$rt}";
}
$s = "" .
$this->makeKnownLink( wfMsg( "mainpage" ), wfMsg( "mainpage" ) )
. " | " .
$this->makeKnownLink( wfMsg( "aboutpage" ), wfMsg( "about" ) )
. " | " .
$this->makeKnownLink( wfMsg( "helppage" ), wfMsg( "help" ) )
. " | " .
$this->makeKnownLink( wfMsg( "faqpage" ), wfMsg("faq") )
. " | " .
$this->specialLink( "specialpages" ) . " | ";
if ( $wgUser->getID() )
{
$s .= $this->makeKnownLink( $lo, wfMsg( "logout" ), $q );
}
else
{
$s .= $this->makeKnownLink( $li, wfMsg( "login" ), $q );
}
return $s;
}
function quickBar()
{
global $wgOut, $wgTitle, $wgUser, $wgLang, $wgDisableUploads;
$tns=$wgTitle->getNamespace();
$s = "\n<div id='quickbar'>";
$sep = "<br />";
$s .= $this->menuHead( "qbfind" );
$s .= $this->searchForm();
$s .= $this->menuHead( "qbbrowse" )
. $this->mainPageLink()
. $sep . $this->specialLink( "recentchanges" )
. $sep . $this->specialLink( "randompage" );
if ( wfMsg ( "currentevents" ) != "-" ) $s .= $sep . $this->makeKnownLink( wfMsg( "currentevents" ), "" ) ;
$s .= "\n";
if ( $wgOut->isArticle() ) {
$s .= $this->menuHead( "qbedit" );
$s .= "<strong>" . $this->editThisPage() . "</strong>";
$s .= $sep . $this->makeKnownLink( wfMsg( "edithelppage" ), wfMsg( "edithelp" ) );
if ( 0 != $wgUser->getID() ) {
$s .= $sep . $this->moveThisPage();
}
if ( $wgUser->isSysop() ) {
$dtp = $this->deleteThisPage();
if ( "" != $dtp ) {
$s .= $sep . $dtp;
}
$ptp = $this->protectThisPage();
if ( "" != $ptp ) {
$s .= $sep . $ptp;
}
}
$s .= $sep;
$s .= $this->menuHead( "qbpageoptions" );
$s .= $this->talkLink()
. $sep . $this->commentLink()
. $sep . $this->printableLink();
if ( 0 != $wgUser->getID() ) {
$s .= $sep . $this->watchThisPage();
}
$s .= $sep;
$s .= $this->menuHead("qbpageinfo")
. $this->historyLink()
. $sep . $this->whatLinksHere()
. $sep . $this->watchPageLinksLink();
if ( Namespace::getUser() == $tns || Namespace::getTalk(Namespace::getUser()) == $tns ) {
$id=User::idFromName($wgTitle->getText());
if ($id != 0) {
$s .= $sep . $this->userContribsLink();
if ( 0 != $wgUser->getID() ) {
$s .= $sep . $this->emailUserLink();
}
}
}
$s .= $sep;
}
$s .= $this->menuHead( "qbmyoptions" );
if ( 0 != $wgUser->getID() ) {
$name = $wgUser->getName();
$tl = $this->makeKnownLink( $wgLang->getNsText(
Namespace::getTalk( Namespace::getUser() ) ) . ":{$name}",
wfMsg( "mytalk" ) );
if ( 0 != $wgUser->getNewtalk() ) { $tl .= " *"; }
$s .= $this->makeKnownLink( $wgLang->getNsText(
Namespace::getUser() ) . ":{$name}", wfMsg( "mypage" ) )
. $sep . $tl
. $sep . $this->specialLink( "watchlist" )
. $sep . $this->makeKnownLink( $wgLang->specialPage( "Contributions" ),
wfMsg( "mycontris" ), "target=" . wfUrlencode($wgUser->getName() ) )
. $sep . $this->specialLink( "preferences" )
. $sep . $this->specialLink( "userlogout" );
} else {
$s .= $this->specialLink( "userlogin" );
}
$s .= $this->menuHead( "qbspecialpages" )
. $this->specialLink( "newpages" )
. $sep . $this->specialLink( "imagelist" )
. $sep . $this->specialLink( "statistics" )
. $sep . $this->bugReportsLink();
if ( 0 != $wgUser->getID() && !$wgDisableUploads ) {
$s .= $sep . $this->specialLink( "upload" );
}
global $wgSiteSupportPage;
if( $wgSiteSupportPage) {
$s .= $sep."<a href=\"".htmlspecialchars($wgSiteSupportPage)."\" class =\"internal\">"
.wfMsg( "sitesupport" )."</a>";
}
$s .= $sep . $this->makeKnownLink( $wgLang->specialPage( "Specialpages" ), wfMsg("moredotdotdot") );
$s .= $sep . "\n</div>\n";
return $s;
}
function menuHead( $key )
{
$s = "\n<h6>" . wfMsg( $key ) . "</h6>";
return $s;
}
function searchForm( $label = "" )
{
global $wgRequest;
$search = $wgRequest->getText( 'search' );
$action = $this->escapeSearchLink();
$s = "<form id=\"search\" method=\"get\" class=\"inline\" action=\"$action\">";
if ( "" != $label ) { $s .= "{$label}: "; }
$s .= "<input type='text' name=\"search\" size='14' value=\""
. htmlspecialchars(substr($search,0,256)) . "\" />"
. "<br /><input type='submit' name=\"go\" value=\"" . htmlspecialchars( wfMsg( "go" ) ) . "\" /> <input type='submit' name=\"fulltext\" value=\"" . htmlspecialchars( wfMsg( "search" ) ) . "\" /></form>";
return $s;
}
}
?>

11
skins/DaVinci.php Normal file
View file

@ -0,0 +1,11 @@
<?php
require_once($IP.'/includes/SkinPHPTal.php');
class SkinDaVinci extends SkinPHPTal {
function initPage( &$out ) {
SkinPHPTal::initPage( $out );
$this->skinname = 'davinci';
}
}
?>

11
skins/Mono.php Normal file
View file

@ -0,0 +1,11 @@
<?php
require_once($IP.'/includes/SkinPHPTal.php');
class SkinMono extends SkinPHPTal {
function initPage( &$out ) {
SkinPHPTal::initPage( $out );
$this->skinname = 'mono';
}
}
?>

11
skins/MonoBook.php Normal file
View file

@ -0,0 +1,11 @@
<?php
require_once($IP.'/includes/SkinPHPTal.php');
class SkinMonoBook extends SkinPHPTal {
function initPage( &$out ) {
SkinPHPTal::initPage( $out );
$this->skinname = 'monobook';
}
}
?>

11
skins/MySkin.php Normal file
View file

@ -0,0 +1,11 @@
<?php
require_once($IP.'/includes/SkinPHPTal.php');
class SkinMySkin extends SkinPHPTal {
function initPage( &$out ) {
SkinPHPTal::initPage( $out );
$this->skinname = 'myskin';
}
}
?>

89
skins/Nostalgia.php Normal file
View file

@ -0,0 +1,89 @@
<?php
# See skin.doc
class SkinNostalgia extends Skin {
function initPage()
{
# ...
}
function getStylesheet()
{
return "nostalgia.css";
}
function getSkinName() {
return "nostalgia";
}
function doBeforeContent()
{
global $wgUser, $wgOut, $wgTitle, $wgSiteNotice;
$s = "\n<div id='content'>\n<div id='topbar'>";
$s .= $this->logoText( "right" );
$s .= $this->pageTitle();
$s .= $this->pageSubtitle() . "\n";
$s .= $this->topLinks() . "\n<br />";
if( $wgSiteNotice ) {
$s .= "\n<div id='siteNotice'>$wgSiteNotice</div>\n";
}
$s .= $this->pageTitleLinks();
$ol = $this->otherLanguages();
if($ol) $s .= "<br />" . $ol;
$cat = $this->getCategoryLinks();
if($cat) $s .= "<br />" . $cat;
$s .= "<br clear='all' /><hr />\n</div>\n";
$s .= "\n<div id='article'>";
return $s;
}
function topLinks()
{
global $wgOut, $wgUser;
$sep = " |\n";
$s = $this->mainPageLink() . $sep
. $this->specialLink( "recentchanges" );
if ( $wgOut->isArticle() ) {
$s .= $sep . $this->editThisPage()
. $sep . $this->historyLink();
}
if ( 0 == $wgUser->getID() ) {
$s .= $sep . $this->specialLink( "userlogin" );
} else {
$s .= $sep . $this->specialLink( "userlogout" );
}
$s .= $sep . $this->specialPagesList();
return $s;
}
function doAfterContent()
{
global $wgUser, $wgOut;
$s = "\n</div><br clear='all' />\n";
$s .= "\n<div id='footer'><hr />";
$s .= $this->bottomLinks();
$s .= "\n<br />" . $this->pageStats();
$s .= "\n<br />" . $this->mainPageLink()
. " | " . $this->aboutLink()
. " | " . $this->searchForm();
$s .= "\n</div>\n</div>\n";
return $s;
}
}
?>

65
skins/Standard.php Normal file
View file

@ -0,0 +1,65 @@
<?php
# See skin.doc
class SkinStandard extends Skin {
function getHeadScripts()
{
global $wgStylePath;
$s = parent::getHeadScripts();
if ( 3 == $this->qbSetting() ) { # Floating left
$s .= "<script language='javascript' type='text/javascript' " .
"src='{$wgStylePath}/sticky.js'></script>\n";
}
return $s;
}
function getUserStyles()
{
global $wgStylePath;
$s = '';
if ( 3 == $this->qbSetting() ) { # Floating left
$s .= "<style type='text/css'>\n" .
"@import '{$wgStylePath}/quickbar.css';\n</style>\n";
}
$s .= parent::getUserStyles();
return $s;
}
function doGetUserStyles()
{
global $wgUser, $wgOut, $wgStylePath;
$s = parent::doGetUserStyles();
$qb = $this->qbSetting();
if ( 2 == $qb ) { # Right
$s .= "#quickbar { position: absolute; top: 4px; right: 4px; " .
"border-left: 2px solid #000000; }\n" .
"#article { margin-left: 4px; margin-right: 152px; }\n";
} else if ( 1 == $qb || 3 == $qb ) {
$s .= "#quickbar { position: absolute; top: 4px; left: 4px; " .
"border-right: 1px solid gray; }\n" .
"#article { margin-left: 152px; margin-right: 4px; }\n";
}
return $s;
}
function getBodyOptions()
{
$a = parent::getBodyOptions();
if ( 3 == $this->qbSetting() ) { # Floating left
$qb = "setup(\"quickbar\")";
if($a["onload"]) {
$a["onload"] .= ";$qb";
} else {
$a["onload"] = $qb;
}
}
return $a;
}
}
?>

77
skins/WikimediaWiki.php Normal file
View file

@ -0,0 +1,77 @@
<?php
# Tentative to make a skin for wikimedia.org
# $Id$
require_once( 'Skin.php' );
require_once($IP.'/includes/SkinPHPTal.php');
$wgExtraSkins['wikimediawiki'] = 'Wikimediawiki';
class SkinWikimediawiki extends SkinMonoBook {
function initPage( &$out ) {
SkinPHPTal::initPage( $out );
$this->skinname = "wikimediawiki";
$this->template = "xhtml_slim_wikimediawiki";
}
# build array of common navigation links
function buildNavUrls () {
global $wgTitle, $wgUser, $wgRequest;
global $wgSiteSupportPage;
$action = $wgRequest->getText( 'action' );
$oldid = $wgRequest->getVal( 'oldid' );
$diff = $wgRequest->getVal( 'diff' );
// XXX: remove htmlspecialchars when tal:attributes works with i18n:attributes
$nav_urls = array();
$nav_urls['mainpage'] = array('href' => htmlspecialchars( $this->makeI18nUrl('mainpage')));
$nav_urls['randompage'] = (wfMsg('randompage') != '-') ? array('href' => htmlspecialchars( $this->makeSpecialUrl('Randompage'))) : false;
$nav_urls['recentchanges'] = (wfMsg('recentchanges') != '-') ? array('href' => htmlspecialchars( $this->makeSpecialUrl('Recentchanges'))) : false;
$nav_urls['whatlinkshere'] = array('href' => htmlspecialchars( $this->makeSpecialUrl('Whatlinkshere', 'target='.urlencode( $this->thispage ))));
$nav_urls['currentevents'] = (wfMsg('currentevents') != '-') ? array('href' => htmlspecialchars( $this->makeI18nUrl('currentevents'))) : false;
$nav_urls['portal'] = (wfMsg('portal') != '-') ? array('href' => htmlspecialchars( $this->makeI18nUrl('portal-url'))) : false;
$nav_urls['recentchangeslinked'] = array('href' => htmlspecialchars( $this->makeSpecialUrl('Recentchangeslinked', 'target='.urlencode( $this->thispage ))));
$nav_urls['bugreports'] = (wfMsg('bugreports') != '-') ? array('href' => htmlspecialchars( $this->makeI18nUrl('bugreportspage'))) : false;
$nav_urls['sitesupport'] = array('href' => htmlspecialchars( $wgSiteSupportPage));
$nav_urls['help'] = array('href' => htmlspecialchars( $this->makeI18nUrl('helppage')));
$nav_urls['upload'] = array('href' => htmlspecialchars( $this->makeSpecialUrl('Upload')));
$nav_urls['specialpages'] = array('href' => htmlspecialchars( $this->makeSpecialUrl('Specialpages')));
# Specific for mediawiki.org menu
$nav_urls['aboutmediawiki'] = (wfMsg('aboutmediawiki') != '-') ? array('href' => htmlspecialchars( $this->makeI18nUrl('aboutmediawiki-url'))) : false;
$nav_urls['projects'] = (wfMsg('projects') != '-') ? array('href' => htmlspecialchars( $this->makeI18nUrl('projects-url'))) : false;
$nav_urls['membership'] = (wfMsg('membership') != '-') ? array('href' => htmlspecialchars( $this->makeI18nUrl('membership-url'))) : false;
$nav_urls['pressroom'] = (wfMsg('pressroom') != '-') ? array('href' => htmlspecialchars( $this->makeI18nUrl('pressroom-url'))) : false;
$nav_urls['software'] = (wfMsg('software') != '-') ? array('href' => htmlspecialchars( $this->makeI18nUrl('software-url'))) : false;
$nav_urls['localchapters'] = (wfMsg('localchapters') != '-') ? array('href' => htmlspecialchars( $this->makeI18nUrl('localchapters-url'))) : false;
$nav_urls['contactus'] = (wfMsg('contactus') != '-') ? array('href' => htmlspecialchars( $this->makeI18nUrl('contactus-url'))) : false;
if( $wgTitle->getNamespace() == NS_USER || $wgTitle->getNamespace() == NS_USER_TALK ) {
$id = User::idFromName($wgTitle->getText());
$ip = User::isIP($wgTitle->getText());
} else {
$id = 0;
$ip = false;
}
if ( 0 != $wgUser->getID() ) { # show only to signed in users
if($id) {
# can only email non-anons
$nav_urls['emailuser'] = array(
'href' => htmlspecialchars( $this->makeSpecialUrl('Emailuser', "target=" . $wgTitle->getPartialURL() ) )
);
# only non-anons have contrib list
$nav_urls['contributions'] = array(
'href' => htmlspecialchars( $this->makeSpecialUrl('Contributions', "target=" . $wgTitle->getPartialURL() ) )
);
}
}
return $nav_urls;
}
}
?>