MediaWiki  master
QuickTemplate.php
Go to the documentation of this file.
1 <?php
21 use MediaWiki\HookContainer\ProtectedHookAccessorTrait;
23 
60 abstract class QuickTemplate {
61  use ProtectedHookAccessorTrait;
62 
66  public $data;
67 
69  protected $config;
70 
74  public function __construct( Config $config = null ) {
75  $this->data = [];
76  if ( $config === null ) {
77  wfDebug( __METHOD__ . ' was called with no Config instance passed to it' );
78  $config = MediaWikiServices::getInstance()->getMainConfig();
79  }
80  $this->config = $config;
81  }
82 
88  public function set( $name, $value ) {
89  $this->data[$name] = $value;
90  }
91 
98  public function extend( $name, $value ) {
99  if ( $this->haveData( $name ) ) {
100  $this->data[$name] .= $value;
101  } else {
102  $this->data[$name] = $value;
103  }
104  }
105 
114  public function get( $name, $default = null ) {
115  return $this->data[$name] ?? $default;
116  }
117 
122  abstract public function execute();
123 
128  protected function text( $str ) {
129  echo htmlspecialchars( $this->data[$str] );
130  }
131 
136  public function html( $str ) {
137  echo $this->data[$str];
138  }
139 
143  public function msg( $msgKey ) {
144  echo htmlspecialchars( wfMessage( $msgKey )->text() );
145  }
146 
151  private function haveData( $str ) {
152  return isset( $this->data[$str] );
153  }
154 
159  protected function haveMsg( $msgKey ) {
160  $msg = wfMessage( $msgKey );
161  return $msg->exists() && !$msg->isDisabled();
162  }
163 
169  public function getSkin() {
170  return $this->data['skin'];
171  }
172 
179  public function getHTML() {
180  ob_start();
181  $this->execute();
182  $html = ob_get_contents();
183  ob_end_clean();
184  return $html;
185  }
186 }
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:202
QuickTemplate\msg
msg( $msgKey)
Definition: QuickTemplate.php:143
QuickTemplate\$config
Config $config
Definition: QuickTemplate.php:69
wfMessage
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Definition: GlobalFunctions.php:1183
QuickTemplate\getSkin
getSkin()
Get the Skin object related to this object.
Definition: QuickTemplate.php:169
QuickTemplate\getHTML
getHTML()
Fetch the output of a QuickTemplate and return it.
Definition: QuickTemplate.php:179
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:128
QuickTemplate\__construct
__construct(Config $config=null)
Definition: QuickTemplate.php:74
QuickTemplate\$data
array $data
Definition: QuickTemplate.php:66
QuickTemplate\extend
extend( $name, $value)
extends the value of data with name $name with the value $value
Definition: QuickTemplate.php:98
QuickTemplate
PHP-based skin template that holds data.
Definition: QuickTemplate.php:60
QuickTemplate\haveData
haveData( $str)
Definition: QuickTemplate.php:151
QuickTemplate\html
html( $str)
Definition: QuickTemplate.php:136
QuickTemplate\haveMsg
haveMsg( $msgKey)
Definition: QuickTemplate.php:159