MediaWiki  master
QuickTemplate.php
Go to the documentation of this file.
1 <?php
21 use MediaWiki\HookContainer\ProtectedHookAccessorTrait;
23 
29 abstract class QuickTemplate {
30  use ProtectedHookAccessorTrait;
31 
35  public $data;
36 
38  protected $config;
39 
43  public function __construct( Config $config = null ) {
44  $this->data = [];
45  if ( $config === null ) {
46  wfDebug( __METHOD__ . ' was called with no Config instance passed to it' );
47  $config = MediaWikiServices::getInstance()->getMainConfig();
48  }
49  $this->config = $config;
50  }
51 
57  public function set( $name, $value ) {
58  $this->data[$name] = $value;
59  }
60 
67  public function extend( $name, $value ) {
68  if ( $this->haveData( $name ) ) {
69  $this->data[$name] .= $value;
70  } else {
71  $this->data[$name] = $value;
72  }
73  }
74 
83  public function get( $name, $default = null ) {
84  return $this->data[$name] ?? $default;
85  }
86 
91  abstract public function execute();
92 
97  protected function text( $str ) {
98  echo htmlspecialchars( $this->data[$str] );
99  }
100 
105  public function html( $str ) {
106  echo $this->data[$str];
107  }
108 
112  public function msg( $msgKey ) {
113  echo htmlspecialchars( wfMessage( $msgKey )->text() );
114  }
115 
120  private function haveData( $str ) {
121  return isset( $this->data[$str] );
122  }
123 
128  protected function haveMsg( $msgKey ) {
129  $msg = wfMessage( $msgKey );
130  return $msg->exists() && !$msg->isDisabled();
131  }
132 
138  public function getSkin() {
139  return $this->data['skin'];
140  }
141 
148  public function getHTML() {
149  ob_start();
150  $this->execute();
151  $html = ob_get_contents();
152  ob_end_clean();
153  return $html;
154  }
155 }
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:146
QuickTemplate\msg
msg( $msgKey)
Definition: QuickTemplate.php:112
QuickTemplate\$config
Config $config
Definition: QuickTemplate.php:38
wfMessage
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Definition: GlobalFunctions.php:1198
QuickTemplate\getSkin
getSkin()
Get the Skin object related to this object.
Definition: QuickTemplate.php:138
QuickTemplate\getHTML
getHTML()
Fetch the output of a QuickTemplate and return it.
Definition: QuickTemplate.php:148
Config
Interface for configuration instances.
Definition: Config.php:28
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:97
QuickTemplate\__construct
__construct(Config $config=null)
Definition: QuickTemplate.php:43
QuickTemplate\$data
array $data
Definition: QuickTemplate.php:35
QuickTemplate\extend
extend( $name, $value)
extends the value of data with name $name with the value $value
Definition: QuickTemplate.php:67
QuickTemplate
Generic wrapper for template functions, with interface compatible with what we use of PHPTAL 0....
Definition: QuickTemplate.php:29
QuickTemplate\haveData
haveData( $str)
Definition: QuickTemplate.php:120
QuickTemplate\html
html( $str)
Definition: QuickTemplate.php:105
QuickTemplate\haveMsg
haveMsg( $msgKey)
Definition: QuickTemplate.php:128