New system to generate $wgValidSkinNames by listing available dirs. Skins using PHPTa...
authorAntoine Musso <hashar@users.mediawiki.org>
Thu, 2 Sep 2004 03:24:01 +0000 (03:24 +0000)
committerAntoine Musso <hashar@users.mediawiki.org>
Thu, 2 Sep 2004 03:24:01 +0000 (03:24 +0000)
docs/skin.doc
includes/Skin.php
includes/User.php
skins/Chick.php
skins/DaVinci.php
skins/Mono.php
skins/MonoBook.php
skins/MySkin.php
skins/Skin.sample [new file with mode: 0644]
skins/SkinPHPTal.sample [new file with mode: 0644]
skins/WikimediaWiki.php

index 0f0bc8b..3b7a74e 100644 (file)
@@ -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.
index 3fc0b84..7b29234 100644 (file)
@@ -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' );
 
index 9e37b01..4cbc03f 100644 (file)
@@ -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;
index eb17b14..1ac36dc 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+if ($wgUsePHPTal) {
 require_once($IP.'/includes/SkinPHPTal.php');
 
 class SkinChick extends SkinPHPTal {
@@ -11,4 +12,5 @@ class SkinChick extends SkinPHPTal {
        function printSource() { return ''; }
 }
 
+}
 ?>
index 13e6515..aff3cb6 100644 (file)
@@ -1,5 +1,5 @@
 <?php
-
+if ($wgUsePHPTal) {
 require_once($IP.'/includes/SkinPHPTal.php');
 
 class SkinDaVinci extends SkinPHPTal {
@@ -9,4 +9,6 @@ class SkinDaVinci extends SkinPHPTal {
                $this->template = 'MonoBook';
        }
 }
+
+}
 ?>
index 7b8d629..a15100d 100644 (file)
@@ -1,5 +1,5 @@
 <?php
-
+if ($wgUsePHPTal) {
 require_once($IP.'/includes/SkinPHPTal.php');
 
 class SkinMono extends SkinPHPTal {
@@ -9,4 +9,6 @@ class SkinMono extends SkinPHPTal {
                $this->template = 'MonoBook';
        }
 }
+
+}
 ?>
index 124675b..949fd94 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+if ($wgUsePHPTal) {
 require_once($IP.'/includes/SkinPHPTal.php');
 
 class SkinMonoBook extends SkinPHPTal {
@@ -8,4 +9,5 @@ class SkinMonoBook extends SkinPHPTal {
        }
 }
 
+}
 ?>
index d6c155d..316b77b 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+if ($wgUsePHPTal) {
 
 require_once($IP.'/includes/SkinPHPTal.php');
 
@@ -8,4 +9,6 @@ class SkinMySkin extends SkinPHPTal {
                $this->skinname = 'myskin';
        }
 }
+
+}
 ?>
diff --git a/skins/Skin.sample b/skins/Skin.sample
new file mode 100644 (file)
index 0000000..c011c14
--- /dev/null
@@ -0,0 +1,19 @@
+<?php
+# Your class extension is defined there.
+#
+# Do NOT use PHPTal with this sample, if you want PHPTal support have a look at
+# the other sample : SkinPHPTal.sample.
+#
+# The class name MUST begin with 'Skin' and the rest is the name of the file
+# excluding '.php'
+# This file is named Skin.sample (but it should end with php). So the
+# class name will be 'Skin' . 'Skin'
+
+class SkinSkin extends Skin {
+# Override method below
+#
+
+}
+
+}
+?>
diff --git a/skins/SkinPHPTal.sample b/skins/SkinPHPTal.sample
new file mode 100644 (file)
index 0000000..ad8f8ad
--- /dev/null
@@ -0,0 +1,27 @@
+<?php
+# Test if PHPTal is enabled. If not MediaWiki will load the 'standard' skin
+# which doesnt use PHPTal
+if ($wgUsePHPTal) {
+require_once($IP.'/includes/SkinPHPTal.php');
+
+# Your class extension is defined there.
+#
+# The class name MUST begin with 'Skin' and the rest is the name of the file
+# excluding '.php'
+# This file is named SkinPHPTal.sample (but it should end with php). So the
+# class name will be 'Skin' . 'SkinPHPTal'
+
+class SkinSkinPHPTal extends SkinPHPTal {
+       function initPage( &$out ) {
+               SkinPHPTal::initPage( $out );
+               $this->skinname = 'name of your skin all lower case';
+               $this->template = 'phptal template used do not put the .pt';
+       }
+
+# Override method below
+#
+
+}
+
+}
+?>
index 78236e7..0cb9dbd 100644 (file)
@@ -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 {
        }
 }
 
-
+}
 ?>