MediaWiki master
QuickTemplate.php
Go to the documentation of this file.
1<?php
21namespace MediaWiki\Skin;
22
24use MediaWiki\HookContainer\ProtectedHookAccessorTrait;
26
63abstract class QuickTemplate {
64 use ProtectedHookAccessorTrait;
65
69 public $data;
70
72 protected $config;
73
75 private $deprecated = [];
76
80 public function __construct( ?Config $config = null ) {
81 $this->data = [];
82 if ( $config === null ) {
83 wfDebug( __METHOD__ . ' was called with no Config instance passed to it' );
84 $config = MediaWikiServices::getInstance()->getMainConfig();
85 }
86 $this->config = $config;
87 }
88
96 public function deprecate( string $name, string $version ) {
97 $this->deprecated[$name] = $version;
98 }
99
105 public function set( $name, $value ) {
106 $this->data[$name] = $value;
107 }
108
115 public function extend( $name, $value ) {
116 if ( $this->haveData( $name ) ) {
117 $this->data[$name] .= $value;
118 } else {
119 $this->data[$name] = $value;
120 }
121 }
122
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 return !wfMessage( $msgKey )->isDisabled();
195 }
196
202 public function getSkin() {
203 return $this->data['skin'];
204 }
205
212 public function getHTML() {
213 ob_start();
214 $this->execute();
215 $html = ob_get_contents();
216 ob_end_clean();
217 return $html;
218 }
219}
220
222class_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:32
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...