MediaWiki REL1_37
QuickTemplate.php
Go to the documentation of this file.
1<?php
21use MediaWiki\HookContainer\ProtectedHookAccessorTrait;
23
60abstract class QuickTemplate {
61 use ProtectedHookAccessorTrait;
62
66 public $data;
67
69 protected $config;
70
74 public function __construct( Config $config = null ) {
75 $this->data = [];
76 if ( $config === null ) {
77 wfDebug( __METHOD__ . ' was called with no Config instance passed to it' );
78 $config = MediaWikiServices::getInstance()->getMainConfig();
79 }
80 $this->config = $config;
81 }
82
88 public function set( $name, $value ) {
89 $this->data[$name] = $value;
90 }
91
98 public function extend( $name, $value ) {
99 if ( $this->haveData( $name ) ) {
100 $this->data[$name] .= $value;
101 } else {
102 $this->data[$name] = $value;
103 }
104 }
105
114 public function get( $name, $default = null ) {
115 return $this->data[$name] ?? $default;
116 }
117
122 abstract public function execute();
123
128 protected function text( $str ) {
129 echo htmlspecialchars( $this->data[$str] );
130 }
131
136 public function html( $str ) {
137 echo $this->data[$str];
138 }
139
143 public function msg( $msgKey ) {
144 echo htmlspecialchars( wfMessage( $msgKey )->text() );
145 }
146
151 private function haveData( $str ) {
152 return isset( $this->data[$str] );
153 }
154
159 protected function haveMsg( $msgKey ) {
160 $msg = wfMessage( $msgKey );
161 return $msg->exists() && !$msg->isDisabled();
162 }
163
169 public function getSkin() {
170 return $this->data['skin'];
171 }
172
179 public function getHTML() {
180 ob_start();
181 $this->execute();
182 $html = ob_get_contents();
183 ob_end_clean();
184 return $html;
185 }
186}
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.
MediaWikiServices is the service locator for the application scope of MediaWiki.
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)
Interface for configuration instances.
Definition Config.php:30