MediaWiki  master
QuickTemplate.php
Go to the documentation of this file.
1 <?php
21 
27 abstract class QuickTemplate {
28 
32  public $data;
33 
35  protected $config;
36 
40  function __construct( Config $config = null ) {
41  $this->data = [];
42  if ( $config === null ) {
43  wfDebug( __METHOD__ . ' was called with no Config instance passed to it' );
44  $config = MediaWikiServices::getInstance()->getMainConfig();
45  }
46  $this->config = $config;
47  }
48 
54  public function set( $name, $value ) {
55  $this->data[$name] = $value;
56  }
57 
64  public function extend( $name, $value ) {
65  if ( $this->haveData( $name ) ) {
66  $this->data[$name] .= $value;
67  } else {
68  $this->data[$name] = $value;
69  }
70  }
71 
80  public function get( $name, $default = null ) {
81  return $this->data[$name] ?? $default;
82  }
83 
91  public function setRef( $name, &$value ) {
92  wfDeprecated( __METHOD__, '1.31' );
93  $this->data[$name] =& $value;
94  }
95 
100  abstract public function execute();
101 
107  function text( $str ) {
108  echo htmlspecialchars( $this->data[$str] );
109  }
110 
116  function html( $str ) {
117  echo $this->data[$str];
118  }
119 
124  function msg( $msgKey ) {
125  echo htmlspecialchars( wfMessage( $msgKey )->text() );
126  }
127 
133  function msgWiki( $msgKey ) {
134  wfDeprecated( __METHOD__, '1.33' );
135  global $wgOut;
136 
137  $text = wfMessage( $msgKey )->plain();
138  echo $wgOut->parseAsInterface( $text );
139  }
140 
146  function haveData( $str ) {
147  return isset( $this->data[$str] );
148  }
149 
156  function haveMsg( $msgKey ) {
157  $msg = wfMessage( $msgKey );
158  return $msg->exists() && !$msg->isDisabled();
159  }
160 
166  public function getSkin() {
167  return $this->data['skin'];
168  }
169 
176  public function getHTML() {
177  ob_start();
178  $this->execute();
179  $html = ob_get_contents();
180  ob_end_clean();
181  return $html;
182  }
183 }
msgWiki( $msgKey)
An ugly, ugly hack.
Generic wrapper for template functions, with interface compatible with what we use of PHPTAL 0...
Interface for configuration instances.
Definition: Config.php:28
getSkin()
Get the Skin object related to this object.
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
setRef( $name, &$value)
__construct(Config $config=null)
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
$wgOut
Definition: Setup.php:862
getHTML()
Fetch the output of a QuickTemplate and return it.
haveMsg( $msgKey)
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
execute()
Main function, used by classes that subclass QuickTemplate to show the actual HTML output...
extend( $name, $value)
extends the value of data with name $name with the value $value