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
{
34 /** @var Config $config */
38 * @param Config|null $config
40 function __construct( Config
$config = null ) {
42 if ( $config === null ) {
43 wfDebug( __METHOD__
. ' was called with no Config instance passed to it' );
44 $config = MediaWikiServices
::getInstance()->getMainConfig();
46 $this->config
= $config;
50 * Sets the value $value to $name
54 public function set( $name, $value ) {
55 $this->data
[$name] = $value;
59 * extends the value of data with name $name with the value $value
64 public function extend( $name, $value ) {
65 if ( $this->haveData( $name ) ) {
66 $this->data
[$name] .= $value;
68 $this->data
[$name] = $value;
73 * Gets the template data requested
75 * @param string $name Key for the data
76 * @param mixed|null $default Optional default (or null)
77 * @return mixed The value of the data requested or the deafult
78 * @return-taint onlysafefor_htmlnoent
80 public function get( $name, $default = null ) {
81 return $this->data
[$name] ??
$default;
85 * @deprecated since 1.31 This function is a now-redundant optimisation intended
86 * for very old versions of PHP. The use of references here makes the code
87 * more fragile and is incompatible with plans like T140664. Use set() instead.
89 * @param mixed &$value
91 public function setRef( $name, &$value ) {
92 wfDeprecated( __METHOD__
, '1.31' );
93 $this->data
[$name] =& $value;
97 * Main function, used by classes that subclass QuickTemplate
98 * to show the actual HTML output
100 abstract public function execute();
105 * @suppress SecurityCheck-DoubleEscaped $this->data can be either
107 function text( $str ) {
108 echo htmlspecialchars( $this->data
[$str] );
114 * @suppress SecurityCheck-XSS phan-taint-check cannot tell if $str is pre-escaped
116 function html( $str ) {
117 echo $this->data
[$str];
122 * @param string $msgKey
124 function msg( $msgKey ) {
125 echo htmlspecialchars( wfMessage( $msgKey )->text() );
129 * An ugly, ugly hack.
130 * @deprecated since 1.33 Use ->msg() instead.
131 * @param string $msgKey
133 function msgWiki( $msgKey ) {
134 wfDeprecated( __METHOD__
, '1.33' );
137 $text = wfMessage( $msgKey )->plain();
138 echo $wgOut->parseAsInterface( $text );
146 function haveData( $str ) {
147 return isset( $this->data
[$str] );
153 * @param string $msgKey
156 function haveMsg( $msgKey ) {
157 $msg = wfMessage( $msgKey );
158 return $msg->exists() && !$msg->isDisabled();
162 * Get the Skin object related to this object
166 public function getSkin() {
167 return $this->data
['skin'];
171 * Fetch the output of a QuickTemplate and return it
176 public function getHTML() {
179 $html = ob_get_contents();