MediaWiki 1.42.1
QuickTemplate.php
Go to the documentation of this file.
1<?php
22use MediaWiki\HookContainer\ProtectedHookAccessorTrait;
24
61abstract class QuickTemplate {
62 use ProtectedHookAccessorTrait;
63
67 public $data;
68
70 protected $config;
71
73 private $deprecated = [];
74
78 public function __construct( Config $config = null ) {
79 $this->data = [];
80 if ( $config === null ) {
81 wfDebug( __METHOD__ . ' was called with no Config instance passed to it' );
82 $config = MediaWikiServices::getInstance()->getMainConfig();
83 }
84 $this->config = $config;
85 }
86
94 public function deprecate( string $name, string $version ) {
95 $this->deprecated[$name] = $version;
96 }
97
103 public function set( $name, $value ) {
104 $this->data[$name] = $value;
105 }
106
113 public function extend( $name, $value ) {
114 if ( $this->haveData( $name ) ) {
115 $this->data[$name] .= $value;
116 } else {
117 $this->data[$name] = $value;
118 }
119 }
120
126 private function checkDeprecationStatus( string $name ) {
127 $deprecated = $this->deprecated[ $name ] ?? false;
128 if ( $deprecated ) {
130 'QuickTemplate::(get/html/text/haveData) with parameter `' . $name . '`',
131 $deprecated
132 );
133 }
134 }
135
144 public function get( $name, $default = null ) {
145 $this->checkDeprecationStatus( $name );
146 return $this->data[$name] ?? $default;
147 }
148
153 abstract public function execute();
154
159 protected function text( $str ) {
160 $this->checkDeprecationStatus( $str );
161 echo htmlspecialchars( $this->data[$str] );
162 }
163
168 public function html( $str ) {
169 $this->checkDeprecationStatus( $str );
170 echo $this->data[$str];
171 }
172
176 public function msg( $msgKey ) {
177 echo htmlspecialchars( wfMessage( $msgKey )->text() );
178 }
179
184 private function haveData( $str ) {
185 $this->checkDeprecationStatus( $str );
186 return isset( $this->data[$str] );
187 }
188
193 protected function haveMsg( $msgKey ) {
194 $msg = wfMessage( $msgKey );
195 return $msg->exists() && !$msg->isDisabled();
196 }
197
203 public function getSkin() {
204 return $this->data['skin'];
205 }
206
213 public function getHTML() {
214 ob_start();
215 $this->execute();
216 $html = ob_get_contents();
217 ob_end_clean();
218 return $html;
219 }
220}
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
Service locator for MediaWiki core services.
PHP-based skin template that holds data.
getSkin()
Get the Skin object related to this object.
__construct(Config $config=null)
getHTML()
Fetch the output of a QuickTemplate and return it.
extend( $name, $value)
extends the value of data with name $name with the value $value
execute()
Main function, used by classes that subclass QuickTemplate to show the actual HTML output.
haveMsg( $msgKey)
deprecate(string $name, string $version)
Sets a template key as deprecated.
Interface for configuration instances.
Definition Config.php:32