MediaWiki REL1_35
QuickTemplate.php
Go to the documentation of this file.
1<?php
21use MediaWiki\HookContainer\ProtectedHookAccessorTrait;
23
30abstract class QuickTemplate {
31 use ProtectedHookAccessorTrait;
32
36 public $data;
37
39 protected $config;
40
44 public function __construct( Config $config = null ) {
45 $this->data = [];
46 if ( $config === null ) {
47 wfDebug( __METHOD__ . ' was called with no Config instance passed to it' );
48 $config = MediaWikiServices::getInstance()->getMainConfig();
49 }
50 $this->config = $config;
51 }
52
58 public function set( $name, $value ) {
59 $this->data[$name] = $value;
60 }
61
68 public function extend( $name, $value ) {
69 if ( $this->haveData( $name ) ) {
70 $this->data[$name] .= $value;
71 } else {
72 $this->data[$name] = $value;
73 }
74 }
75
84 public function get( $name, $default = null ) {
85 return $this->data[$name] ?? $default;
86 }
87
92 abstract public function execute();
93
98 protected function text( $str ) {
99 echo htmlspecialchars( $this->data[$str] );
100 }
101
106 public function html( $str ) {
107 echo $this->data[$str];
108 }
109
113 public function msg( $msgKey ) {
114 echo htmlspecialchars( wfMessage( $msgKey )->text() );
115 }
116
121 private function haveData( $str ) {
122 return isset( $this->data[$str] );
123 }
124
129 protected function haveMsg( $msgKey ) {
130 $msg = wfMessage( $msgKey );
131 return $msg->exists() && !$msg->isDisabled();
132 }
133
139 public function getSkin() {
140 return $this->data['skin'];
141 }
142
149 public function getHTML() {
150 ob_start();
151 $this->execute();
152 $html = ob_get_contents();
153 ob_end_clean();
154 return $html;
155 }
156}
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.
Generic wrapper for template functions, with interface compatible with what we use of PHPTAL 0....
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