2 # This program is free software; you can redistribute it and/or modify
3 # it under the terms of the GNU General Public License as published by
4 # the Free Software Foundation; either version 2 of the License, or
5 # (at your option) any later version.
7 # This program is distributed in the hope that it will be useful,
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 # GNU General Public License for more details.
12 # You should have received a copy of the GNU General Public License along
13 # with this program; if not, write to the Free Software Foundation, Inc.,
14 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15 # http://www.gnu.org/copyleft/gpl.html
18 * Generic PHPTal (http://phptal.sourceforge.net/) skin
19 * Based on Brion's smarty skin
20 * Copyright (C) Gabriel Wicke -- http://www.aulinx.de/
22 * The guts of this have moved to SkinTemplate.php
24 * Make sure the appropriate version of PHPTAL is installed (0.7.0 for PHP4,
25 * or 1.0.0 for PHP5) and available in the include_path. The system PEAR
28 * If PEAR or PHPTAL can't be loaded, it will try to gracefully fall back.
29 * Turn on MediaWiki's debug log to see it complain.
36 * This is not a valid entry point, perform no further processing unless
37 * MEDIAWIKI is defined
39 if( defined( 'MEDIAWIKI' ) ) {
41 require_once 'GlobalFunctions.php';
42 require_once 'SkinTemplate.php';
44 if( version_compare( phpversion(), "5.0", "lt" ) ) {
45 define( 'OLD_PHPTAL', true );
46 # PEAR and PHPTAL 0.7.x must be installed and in include_path
48 define( 'NEW_PHPTAL', true );
49 # PEAR and PHPTAL 1.0.x must be installed and in include_path
52 @include_once
'PEAR.php';
53 if( !class_exists( 'PEAR' ) ) {
54 wfDebug( 'PHPTAL-based skin couldn\'t include PEAR.php' );
57 // PHPTAL may be in the libs dir direct, or under HTML/Template.
58 // Try them both to be safe.
59 @include_once
'HTML/Template/PHPTAL.php';
60 if( !class_exists( 'PHPTAL' ) ) {
61 @include_once
'PHPTAL.php';
64 if( !class_exists( 'PHPTAL' ) ) {
65 wfDebug( 'PHPTAL-based skin couldn\'t include PHPTAL.php' );
72 class SkinPHPTal
extends SkinTemplate
{
74 function initPage( &$out ) {
75 parent
::initPage( $out );
76 $this->skinname
= 'monobook';
77 $this->stylename
= 'monobook';
78 $this->template
= 'MonoBook';
82 * If using PHPTAL 0.7 on PHP 4.x, return a PHPTAL template object.
83 * If using PHPTAL 1.0 on PHP 5.x, return a bridge object.
87 function &setupTemplate( $file, $repository=false, $cache_dir=false ) {
88 if( defined( 'NEW_PHPTAL' ) ) {
89 return new PHPTAL_version_bridge( $file . '.pt', $repository, $cache_dir );
91 return new PHPTAL( $file . '.pt', $repository, $cache_dir );
96 * Output the string, or print error message if it's
97 * an error object of the appropriate type.
102 function printOrError( &$str ) {
103 if( PEAR
::isError( $str ) ) {
104 echo $str->toString(), "\n";
116 class PHPTAL_version_bridge
{
117 function PHPTAL_version_bridge( $file, $repository=false, $cache_dir=false ) {
118 $this->tpl
=& new PHPTAL( $file );
120 $this->tpl
->setTemplateRepository( $repository );
124 function set( $name, $value ) {
125 $this->tpl
->$name = $value;
128 function setRef($name, &$value) {
129 $this->set( $name, $value );
132 function setTranslator( &$t ) {
133 $this->tpl
->setTranslator( $t );
140 return $this->tpl
->execute();
143 catch (Exception $e) {
144 echo "<div class='error' style='background: white; white-space: pre; position: absolute; z-index: 9999; border: solid 2px black; padding: 4px;'>We caught an exception...\n ";
152 } // end of if( class_exists( 'PHPTAL' ) )
153 } // end of if( class_exists( 'PEAR' ) )
154 } // end of if( defined( 'MEDIAWIKI' ) )