MediaWiki master
QuickTemplate.php
Go to the documentation of this file.
1<?php
7namespace MediaWiki\Skin;
8
10use MediaWiki\HookContainer\ProtectedHookAccessorTrait;
12
49abstract class QuickTemplate {
50 use ProtectedHookAccessorTrait;
51
55 public $data;
56
58 protected $config;
59
61 private $deprecated = [];
62
66 public function __construct( ?Config $config = null ) {
67 $this->data = [];
68 if ( $config === null ) {
69 wfDebug( __METHOD__ . ' was called with no Config instance passed to it' );
70 $config = MediaWikiServices::getInstance()->getMainConfig();
71 }
72 $this->config = $config;
73 }
74
82 public function deprecate( string $name, string $version ) {
83 $this->deprecated[$name] = $version;
84 }
85
91 public function set( $name, $value ) {
92 $this->data[$name] = $value;
93 }
94
101 public function extend( $name, $value ) {
102 if ( $this->haveData( $name ) ) {
103 $this->data[$name] .= $value;
104 } else {
105 $this->data[$name] = $value;
106 }
107 }
108
112 private function checkDeprecationStatus( string $name ) {
113 $deprecated = $this->deprecated[ $name ] ?? false;
114 if ( $deprecated ) {
116 'QuickTemplate::(get/html/text/haveData) with parameter `' . $name . '`',
117 $deprecated
118 );
119 }
120 }
121
130 public function get( $name, $default = null ) {
131 $this->checkDeprecationStatus( $name );
132 return $this->data[$name] ?? $default;
133 }
134
139 abstract public function execute();
140
145 protected function text( $str ) {
146 $this->checkDeprecationStatus( $str );
147 echo htmlspecialchars( $this->data[$str] );
148 }
149
154 public function html( $str ) {
155 $this->checkDeprecationStatus( $str );
156 echo $this->data[$str];
157 }
158
162 public function msg( $msgKey ) {
163 echo htmlspecialchars( wfMessage( $msgKey )->text() );
164 }
165
170 private function haveData( $str ) {
171 $this->checkDeprecationStatus( $str );
172 return isset( $this->data[$str] );
173 }
174
179 protected function haveMsg( $msgKey ) {
180 return !wfMessage( $msgKey )->isDisabled();
181 }
182
188 public function getSkin() {
189 return $this->data['skin'];
190 }
191
198 public function getHTML() {
199 ob_start();
200 $this->execute();
201 $html = ob_get_contents();
202 ob_end_clean();
203 return $html;
204 }
205}
206
208class_alias( QuickTemplate::class, 'QuickTemplate' );
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.
static getInstance()
Returns the global default instance of the top level service locator.
PHP-based skin template that holds data.
getSkin()
Get the Skin object related to this object.
__construct(?Config $config=null)
extend( $name, $value)
extends the value of data with name $name with the value $value
deprecate(string $name, string $version)
Sets a template key as deprecated.
getHTML()
Fetch the output of a QuickTemplate and return it.
execute()
Main function, used by classes that subclass QuickTemplate to show the actual HTML output.
Interface for configuration instances.
Definition Config.php:18