Removing leecruft. No, you sure as hell couldn't defer it.
[lhc/web/wiklou.git] / includes / SkinPHPTal.php
1 <?php
2 if ( ! defined( 'MEDIAWIKI' ) )
3 die( -1 );
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.
8 #
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.
13 #
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
18
19 /**
20 * Generic PHPTal (http://phptal.sourceforge.net/) skin
21 * Based on Brion's smarty skin
22 * Copyright (C) Gabriel Wicke -- http://www.aulinx.de/
23 *
24 * The guts of this have moved to SkinTemplate.php
25 *
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
28 * directory is good.
29 *
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.
32 *
33 * @package MediaWiki
34 * @subpackage Skins
35 */
36
37 require_once 'GlobalFunctions.php';
38 require_once 'SkinTemplate.php';
39
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
43 } else {
44 define( 'NEW_PHPTAL', true );
45 # PEAR and PHPTAL 1.0.x must be installed and in include_path
46 }
47
48 @include_once 'PEAR.php';
49 if( !class_exists( 'PEAR' ) ) {
50 wfDebug( 'PHPTAL-based skin couldn\'t include PEAR.php' );
51 } else {
52
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';
58 }
59
60 if( !class_exists( 'PHPTAL' ) ) {
61 wfDebug( 'PHPTAL-based skin couldn\'t include PHPTAL.php' );
62 } else {
63
64 /**
65 *
66 * @package MediaWiki
67 */
68 class SkinPHPTal extends SkinTemplate {
69 /** */
70 function initPage( &$out ) {
71 parent::initPage( $out );
72 $this->skinname = 'monobook';
73 $this->stylename = 'monobook';
74 $this->template = 'MonoBook';
75 }
76
77 /**
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.
80 * @return object
81 * @access private
82 */
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 );
86 } else {
87 return new PHPTAL( $file . '.pt', $repository, $cache_dir );
88 }
89 }
90
91 /**
92 * Output the string, or print error message if it's
93 * an error object of the appropriate type.
94 *
95 * @param mixed $str
96 * @access private
97 */
98 function printOrError( &$str ) {
99 if( PEAR::isError( $str ) ) {
100 echo $str->toString(), "\n";
101 } else {
102 echo $str;
103 }
104 }
105 }
106
107 /**
108 * @todo document
109 * @package MediaWiki
110 * @subpackage Skins
111 */
112 class PHPTAL_version_bridge {
113 function PHPTAL_version_bridge( $file, $repository=false, $cache_dir=false ) {
114 $this->tpl =& new PHPTAL( $file );
115 if( $repository ) {
116 $this->tpl->setTemplateRepository( $repository );
117 }
118 }
119
120 function set( $name, $value ) {
121 $this->tpl->$name = $value;
122 }
123
124 function setRef($name, &$value) {
125 $this->set( $name, $value );
126 }
127
128 function setTranslator( &$t ) {
129 $this->tpl->setTranslator( $t );
130 }
131
132 function execute() {
133 /*
134 try {
135 */
136 return $this->tpl->execute();
137 /*
138 }
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 ";
141 echo $e;
142 echo "</div>";
143 }
144 */
145 }
146 }
147
148 } // end of if( class_exists( 'PHPTAL' ) )
149 } // end of if( class_exists( 'PEAR' ) )
150 ?>