3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
20 use MediaWiki\MediaWikiServices
;
23 * Generic wrapper for template functions, with interface
24 * compatible with what we use of PHPTAL 0.7.
27 abstract class QuickTemplate
{
39 /** @var Config $config */
43 * @param Config $config
45 function __construct( Config
$config = null ) {
47 $this->translator
= new MediaWikiI18N();
48 if ( $config === null ) {
49 wfDebug( __METHOD__
. ' was called with no Config instance passed to it' );
50 $config = MediaWikiServices
::getInstance()->getMainConfig();
52 $this->config
= $config;
56 * Sets the value $value to $name
60 public function set( $name, $value ) {
61 $this->data
[$name] = $value;
65 * extends the value of data with name $name with the value $value
70 public function extend( $name, $value ) {
71 if ( $this->haveData( $name ) ) {
72 $this->data
[$name] = $this->data
[$name] . $value;
74 $this->data
[$name] = $value;
79 * Gets the template data requested
81 * @param string $name Key for the data
82 * @param mixed $default Optional default (or null)
83 * @return mixed The value of the data requested or the deafult
85 public function get( $name, $default = null ) {
86 if ( isset( $this->data
[$name] ) ) {
87 return $this->data
[$name];
94 * @deprecated since 1.31 This function is a now-redundant optimisation intended
95 * for very old versions of PHP. The use of references here makes the code
96 * more fragile and is incompatible with plans like T140664. Use set() instead.
98 * @param mixed &$value
100 public function setRef( $name, &$value ) {
101 wfDeprecated( __METHOD__
, '1.31' );
102 $this->data
[$name] =& $value;
106 * @param MediaWikiI18N &$t
107 * @deprecate since 1.31 Use BaseTemplate::msg() or Skin::msg() instead for setting
108 * message parameters.
110 public function setTranslator( &$t ) {
111 wfDeprecated( __METHOD__
, '1.31' );
112 $this->translator
= &$t;
116 * Main function, used by classes that subclass QuickTemplate
117 * to show the actual HTML output
119 abstract public function execute();
125 function text( $str ) {
126 echo htmlspecialchars( $this->data
[$str] );
133 function html( $str ) {
134 echo $this->data
[$str];
139 * @param string $msgKey
141 function msg( $msgKey ) {
142 echo htmlspecialchars( wfMessage( $msgKey )->text() );
147 * @param string $msgKey
149 function msgHtml( $msgKey ) {
150 echo wfMessage( $msgKey )->text();
154 * An ugly, ugly hack.
156 * @param string $msgKey
158 function msgWiki( $msgKey ) {
161 $text = wfMessage( $msgKey )->text();
162 echo $wgOut->parse( $text );
170 function haveData( $str ) {
171 return isset( $this->data
[$str] );
177 * @param string $msgKey
180 function haveMsg( $msgKey ) {
181 $msg = wfMessage( $msgKey );
182 return $msg->exists() && !$msg->isDisabled();
186 * Get the Skin object related to this object
190 public function getSkin() {
191 return $this->data
['skin'];
195 * Fetch the output of a QuickTemplate and return it
200 public function getHTML() {
203 $html = ob_get_contents();