From 7dbd56950b7eea282b35bc697b0208e799b0453e Mon Sep 17 00:00:00 2001 From: Antoine Musso Date: Thu, 2 Sep 2004 03:24:01 +0000 Subject: [PATCH] New system to generate $wgValidSkinNames by listing available dirs. Skins using PHPTal will not load and the software fallback to the standard skin. Added 2 samples for skin designers and updated doc --- docs/skin.doc | 30 ++++++++++++++++++++++++------ includes/Skin.php | 21 ++++++++++++++++++++- includes/User.php | 21 ++++++++++++++++----- skins/Chick.php | 2 ++ skins/DaVinci.php | 4 +++- skins/Mono.php | 4 +++- skins/MonoBook.php | 2 ++ skins/MySkin.php | 3 +++ skins/Skin.sample | 19 +++++++++++++++++++ skins/SkinPHPTal.sample | 27 +++++++++++++++++++++++++++ skins/WikimediaWiki.php | 3 ++- 11 files changed, 121 insertions(+), 15 deletions(-) create mode 100644 skins/Skin.sample create mode 100644 skins/SkinPHPTal.sample diff --git a/docs/skin.doc b/docs/skin.doc index 0f0bc8b46d..3b7a74ed08 100644 --- a/docs/skin.doc +++ b/docs/skin.doc @@ -1,13 +1,24 @@ SKIN.DOC -This document describes the overall architecture of MediaWiki's -HTML rendering code. It is placed here rather than in comments -in the code itself to help reduce the code size. +This document describes the overall architecture of MediaWiki's HTML rendering +code as well as some history about the skin system. It is placed here rather +than in comments in the code itself to help reduce the code size. -Unfortunately there isn't any documentation, and the code's in -a bit of a mess right now during the transition from the old skin -code to the new template-based skin code in 1.3. +== Version 1.4 == + +MediaWiki still use the PHPTal skin system introduced in version 1.3 but some +changes have been made to the file organisation. + +PHP class and PHPTal templates have been moved to /skins/ (respectivly from +/includes/ and /templates/). This way skin designer and end user just stick to +one directory. + +Two samples are provided to start with, one for PHPTal use (SkinPHPTal.sample) +and one without (Skin.sample). + + +== Version 1.3 == The following might help a bit though. @@ -28,3 +39,10 @@ pages. The default 1.3 skin is MonoBook and it uses the SkinPHPTAL class. To change the layout, just edit the PHPTal template (templates/xhtml_slim.pt) as well as the stylesheets (stylesheets/monobook/*). + + +== pre 1.3 version == + +Unfortunately there isn't any documentation, and the code's in a bit of a mess +right now during the transition from the old skin code to the new template-based +skin code in 1.3. diff --git a/includes/Skin.php b/includes/Skin.php index 3fc0b843a4..7b2923447e 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -12,7 +12,8 @@ require_once( 'Image.php' ); # file names in ./skins/. For display purposes, the Language class has # internationalized names # -/* private */ $wgValidSkinNames = array( +/* +$wgValidSkinNames = array( 'standard' => 'Standard', 'nostalgia' => 'Nostalgia', 'cologneblue' => 'CologneBlue' @@ -26,6 +27,24 @@ if( $wgUsePHPTal ) { $wgValidSkinNames['myskin'] = 'MySkin'; $wgValidSkinNames['chick'] = 'Chick'; } +*/ + +# Get a list of all skins available in /skins/ +# Build using the regular expression '^(.*).php$' +# Array keys are all lower case, array value keep the case used by filename +# + +$skinDir = dir($IP.'/skins'); + +# while code from www.php.net +while (false !== ($file = $skinDir->read())) { + if(preg_match('/^(.*).php$/',$file, $matches)) { + $aSkin = $matches[1]; + $wgValidSkinNames[strtolower($aSkin)] = $aSkin; + } +} +$skinDir->close(); +unset($matches); require_once( 'RecentChange.php' ); diff --git a/includes/User.php b/includes/User.php index 9e37b01f97..4cbc03f21d 100644 --- a/includes/User.php +++ b/includes/User.php @@ -434,10 +434,12 @@ class User { return in_array( 'bot', $this->mRights ); } + # Load a skin if it doesn't exist or return it + # FIXME : need to check the old failback system [AV] function &getSkin() { - global $IP; + global $IP, $wgUsePHPTal; if ( ! isset( $this->mSkin ) ) { - # get all skin names available from SkinNames.php + # get all skin names available $skinNames = Skin::getSkinNames(); # get the user skin $userSkin = $this->getOption( 'skin' ); @@ -449,8 +451,8 @@ class User { 0 => 'Standard', 1 => 'Nostalgia', 2 => 'CologneBlue'); - # if phptal is enabled we should have monobook skin that superseed - # the good old SkinStandard. + # if phptal is enabled we should have monobook skin that + # superseed the good old SkinStandard. if ( isset( $skinNames['monobook'] ) ) { $fallback[0] = 'MonoBook'; } @@ -465,9 +467,18 @@ class User { $sn = $skinNames[$userSkin]; } - # Grab the skin class and initialise it + # Grab the skin class and initialise it. Each skin checks for PHPTal + # and will not load if it's not enabled. require_once( $IP.'/skins/'.$sn.'.php' ); + + # Check if we got if not failback to default skin $sn = 'Skin'.$sn; + if(!class_exists($sn)) { + #FIXME : should we print an error message instead of loading + # standard skin ? + $sn = 'SkinStandard'; + require_once( $IP.'/skins/Standard.php' ); + } $this->mSkin = new $sn; } return $this->mSkin; diff --git a/skins/Chick.php b/skins/Chick.php index eb17b14e11..1ac36dc201 100644 --- a/skins/Chick.php +++ b/skins/Chick.php @@ -1,4 +1,5 @@ diff --git a/skins/DaVinci.php b/skins/DaVinci.php index 13e65151ab..aff3cb6135 100644 --- a/skins/DaVinci.php +++ b/skins/DaVinci.php @@ -1,5 +1,5 @@ template = 'MonoBook'; } } + +} ?> diff --git a/skins/Mono.php b/skins/Mono.php index 7b8d629015..a15100d137 100644 --- a/skins/Mono.php +++ b/skins/Mono.php @@ -1,5 +1,5 @@ template = 'MonoBook'; } } + +} ?> diff --git a/skins/MonoBook.php b/skins/MonoBook.php index 124675be2a..949fd94445 100644 --- a/skins/MonoBook.php +++ b/skins/MonoBook.php @@ -1,4 +1,5 @@ diff --git a/skins/MySkin.php b/skins/MySkin.php index d6c155dae8..316b77b019 100644 --- a/skins/MySkin.php +++ b/skins/MySkin.php @@ -1,4 +1,5 @@ skinname = 'myskin'; } } + +} ?> diff --git a/skins/Skin.sample b/skins/Skin.sample new file mode 100644 index 0000000000..c011c143f5 --- /dev/null +++ b/skins/Skin.sample @@ -0,0 +1,19 @@ + diff --git a/skins/SkinPHPTal.sample b/skins/SkinPHPTal.sample new file mode 100644 index 0000000000..ad8f8ad600 --- /dev/null +++ b/skins/SkinPHPTal.sample @@ -0,0 +1,27 @@ +skinname = 'name of your skin all lower case'; + $this->template = 'phptal template used do not put the .pt'; + } + +# Override method below +# + +} + +} +?> diff --git a/skins/WikimediaWiki.php b/skins/WikimediaWiki.php index 78236e7ab8..0cb9dbdbe1 100644 --- a/skins/WikimediaWiki.php +++ b/skins/WikimediaWiki.php @@ -2,6 +2,7 @@ # Tentative to make a skin for wikimedia.org # $Id$ +if($wgUsePHPTal) { require_once($IP.'/includes/SkinPHPTal.php'); $wgExtraSkins['wikimediawiki'] = 'Wikimediawiki'; @@ -74,5 +75,5 @@ class SkinWikimediawiki extends SkinMonoBook { } } - +} ?> -- 2.20.1