2 if ( ! defined( 'MEDIAWIKI' ) )
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License along
15 # with this program; if not, write to the Free Software Foundation, Inc.,
16 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 # http://www.gnu.org/copyleft/gpl.html
20 * Generic PHPTal (http://phptal.sourceforge.net/) skin
21 * Based on Brion's smarty skin
22 * Copyright (C) Gabriel Wicke -- http://www.aulinx.de/
24 * The guts of this have moved to SkinTemplate.php
26 * Make sure the appropriate version of PHPTAL is installed (0.7.0 for PHP4,
27 * or 1.0.0 for PHP5) and available in the include_path. The system PEAR
30 * If PEAR or PHPTAL can't be loaded, it will try to gracefully fall back.
31 * Turn on MediaWiki's debug log to see it complain.
37 require_once 'GlobalFunctions.php';
38 require_once 'SkinTemplate.php';
40 if( version_compare( phpversion(), "5.0", "lt" ) ) {
41 define( 'OLD_PHPTAL', true );
42 # PEAR and PHPTAL 0.7.x must be installed and in include_path
44 define( 'NEW_PHPTAL', true );
45 # PEAR and PHPTAL 1.0.x must be installed and in include_path
48 @include_once
'PEAR.php';
49 if( !class_exists( 'PEAR' ) ) {
50 wfDebug( 'PHPTAL-based skin couldn\'t include PEAR.php' );
53 // PHPTAL may be in the libs dir direct, or under HTML/Template.
54 // Try them both to be safe.
55 @include_once
'HTML/Template/PHPTAL.php';
56 if( !class_exists( 'PHPTAL' ) ) {
57 @include_once
'PHPTAL.php';
60 if( !class_exists( 'PHPTAL' ) ) {
61 wfDebug( 'PHPTAL-based skin couldn\'t include PHPTAL.php' );
68 class SkinPHPTal
extends SkinTemplate
{
70 function initPage( &$out ) {
71 parent
::initPage( $out );
72 $this->skinname
= 'monobook';
73 $this->stylename
= 'monobook';
74 $this->template
= 'MonoBook';
78 * If using PHPTAL 0.7 on PHP 4.x, return a PHPTAL template object.
79 * If using PHPTAL 1.0 on PHP 5.x, return a bridge object.
83 function &setupTemplate( $file, $repository=false, $cache_dir=false ) {
84 if( defined( 'NEW_PHPTAL' ) ) {
85 return new PHPTAL_version_bridge( $file . '.pt', $repository, $cache_dir );
87 return new PHPTAL( $file . '.pt', $repository, $cache_dir );
92 * Output the string, or print error message if it's
93 * an error object of the appropriate type.
98 function printOrError( &$str ) {
99 if( PEAR
::isError( $str ) ) {
100 echo $str->toString(), "\n";
112 class PHPTAL_version_bridge
{
113 function PHPTAL_version_bridge( $file, $repository=false, $cache_dir=false ) {
114 $this->tpl
=& new PHPTAL( $file );
116 $this->tpl
->setTemplateRepository( $repository );
120 function set( $name, $value ) {
121 $this->tpl
->$name = $value;
124 function setRef($name, &$value) {
125 $this->set( $name, $value );
128 function setTranslator( &$t ) {
129 $this->tpl
->setTranslator( $t );
136 return $this->tpl
->execute();
139 catch (Exception $e) {
140 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 ";
148 } // end of if( class_exists( 'PHPTAL' ) )
149 } // end of if( class_exists( 'PEAR' ) )