MediaWiki  1.34.0
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 }
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:117
QuickTemplate\msg
msg( $msgKey)
Definition: QuickTemplate.php:124
QuickTemplate\$config
$config
Definition: QuickTemplate.php:35
QuickTemplate\msgWiki
msgWiki( $msgKey)
An ugly, ugly hack.
Definition: QuickTemplate.php:133
wfMessage
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Definition: GlobalFunctions.php:1264
QuickTemplate\setRef
setRef( $name, &$value)
Definition: QuickTemplate.php:91
QuickTemplate\getSkin
getSkin()
Get the Skin object related to this object.
Definition: QuickTemplate.php:166
QuickTemplate\getHTML
getHTML()
Fetch the output of a QuickTemplate and return it.
Definition: QuickTemplate.php:176
Config
Interface for configuration instances.
Definition: Config.php:28
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
Definition: GlobalFunctions.php:1044
wfDebug
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
Definition: GlobalFunctions.php:913
QuickTemplate\execute
execute()
Main function, used by classes that subclass QuickTemplate to show the actual HTML output.
QuickTemplate\text
text( $str)
Definition: QuickTemplate.php:107
QuickTemplate\__construct
__construct(Config $config=null)
Definition: QuickTemplate.php:40
QuickTemplate\$data
array $data
Definition: QuickTemplate.php:32
QuickTemplate\extend
extend( $name, $value)
extends the value of data with name $name with the value $value
Definition: QuickTemplate.php:64
QuickTemplate
Generic wrapper for template functions, with interface compatible with what we use of PHPTAL 0....
Definition: QuickTemplate.php:27
QuickTemplate\haveData
haveData( $str)
Definition: QuickTemplate.php:146
QuickTemplate\html
html( $str)
Definition: QuickTemplate.php:116
$wgOut
$wgOut
Definition: Setup.php:886
QuickTemplate\haveMsg
haveMsg( $msgKey)
Definition: QuickTemplate.php:156