MediaWiki  master
QuickTemplate.php
Go to the documentation of this file.
1 <?php
21 use MediaWiki\HookContainer\ProtectedHookAccessorTrait;
23 
30 abstract 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 }
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:180
QuickTemplate\msg
msg( $msgKey)
Definition: QuickTemplate.php:113
QuickTemplate\$config
Config $config
Definition: QuickTemplate.php:39
wfMessage
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Definition: GlobalFunctions.php:1182
QuickTemplate\getSkin
getSkin()
Get the Skin object related to this object.
Definition: QuickTemplate.php:139
QuickTemplate\getHTML
getHTML()
Fetch the output of a QuickTemplate and return it.
Definition: QuickTemplate.php:149
Config
Interface for configuration instances.
Definition: Config.php:30
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:894
QuickTemplate\execute
execute()
Main function, used by classes that subclass QuickTemplate to show the actual HTML output.
QuickTemplate\text
text( $str)
Definition: QuickTemplate.php:98
QuickTemplate\__construct
__construct(Config $config=null)
Definition: QuickTemplate.php:44
QuickTemplate\$data
array $data
Definition: QuickTemplate.php:36
QuickTemplate\extend
extend( $name, $value)
extends the value of data with name $name with the value $value
Definition: QuickTemplate.php:68
QuickTemplate
Generic wrapper for template functions, with interface compatible with what we use of PHPTAL 0....
Definition: QuickTemplate.php:30
QuickTemplate\haveData
haveData( $str)
Definition: QuickTemplate.php:121
QuickTemplate\html
html( $str)
Definition: QuickTemplate.php:106
QuickTemplate\haveMsg
haveMsg( $msgKey)
Definition: QuickTemplate.php:129