don't try to prefill edit summary when section=new (relevant only for preload=)
[lhc/web/wiklou.git] / includes / SkinPHPTal.php
1 <?php
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.
6 #
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.
11 #
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
16
17 /**
18 * Generic PHPTal (http://phptal.sourceforge.net/) skin
19 * Based on Brion's smarty skin
20 * Copyright (C) Gabriel Wicke -- http://www.aulinx.de/
21 *
22 * The guts of this have moved to SkinTemplate.php
23 *
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
26 * directory is good.
27 *
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.
30 *
31 * @package MediaWiki
32 * @subpackage Skins
33 */
34
35 /**
36 * This is not a valid entry point, perform no further processing unless
37 * MEDIAWIKI is defined
38 */
39 if( defined( 'MEDIAWIKI' ) ) {
40
41 require_once 'GlobalFunctions.php';
42 require_once 'SkinTemplate.php';
43
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
47 } else {
48 define( 'NEW_PHPTAL', true );
49 # PEAR and PHPTAL 1.0.x must be installed and in include_path
50 }
51
52 @include_once 'PEAR.php';
53 if( !class_exists( 'PEAR' ) ) {
54 wfDebug( 'PHPTAL-based skin couldn\'t include PEAR.php' );
55 } else {
56
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';
62 }
63
64 if( !class_exists( 'PHPTAL' ) ) {
65 wfDebug( 'PHPTAL-based skin couldn\'t include PHPTAL.php' );
66 } else {
67
68 /**
69 *
70 * @package MediaWiki
71 */
72 class SkinPHPTal extends SkinTemplate {
73 /** */
74 function initPage( &$out ) {
75 parent::initPage( $out );
76 $this->skinname = 'monobook';
77 $this->stylename = 'monobook';
78 $this->template = 'MonoBook';
79 }
80
81 /**
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.
84 * @return object
85 * @access private
86 */
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 );
90 } else {
91 return new PHPTAL( $file . '.pt', $repository, $cache_dir );
92 }
93 }
94
95 /**
96 * Output the string, or print error message if it's
97 * an error object of the appropriate type.
98 *
99 * @param mixed $str
100 * @access private
101 */
102 function printOrError( &$str ) {
103 if( PEAR::isError( $str ) ) {
104 echo $str->toString(), "\n";
105 } else {
106 echo $str;
107 }
108 }
109 }
110
111 /**
112 * @todo document
113 * @package MediaWiki
114 * @subpackage Skins
115 */
116 class PHPTAL_version_bridge {
117 function PHPTAL_version_bridge( $file, $repository=false, $cache_dir=false ) {
118 $this->tpl =& new PHPTAL( $file );
119 if( $repository ) {
120 $this->tpl->setTemplateRepository( $repository );
121 }
122 }
123
124 function set( $name, $value ) {
125 $this->tpl->$name = $value;
126 }
127
128 function setRef($name, &$value) {
129 $this->set( $name, $value );
130 }
131
132 function setTranslator( &$t ) {
133 $this->tpl->setTranslator( $t );
134 }
135
136 function execute() {
137 /*
138 try {
139 */
140 return $this->tpl->execute();
141 /*
142 }
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 ";
145 echo $e;
146 echo "</div>";
147 }
148 */
149 }
150 }
151
152 } // end of if( class_exists( 'PHPTAL' ) )
153 } // end of if( class_exists( 'PEAR' ) )
154 } // end of if( defined( 'MEDIAWIKI' ) )
155 ?>