123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- <?php
- use MediaWiki\MediaWikiServices;
- abstract class QuickTemplate {
-
- public $data;
-
- public $translator;
-
- protected $config;
-
- function __construct( Config $config = null ) {
- $this->data = [];
- $this->translator = new MediaWikiI18N();
- if ( $config === null ) {
- wfDebug( __METHOD__ . ' was called with no Config instance passed to it' );
- $config = MediaWikiServices::getInstance()->getMainConfig();
- }
- $this->config = $config;
- }
-
- public function set( $name, $value ) {
- $this->data[$name] = $value;
- }
-
- public function extend( $name, $value ) {
- if ( $this->haveData( $name ) ) {
- $this->data[$name] = $this->data[$name] . $value;
- } else {
- $this->data[$name] = $value;
- }
- }
-
- public function get( $name, $default = null ) {
- if ( isset( $this->data[$name] ) ) {
- return $this->data[$name];
- } else {
- return $default;
- }
- }
-
- public function setRef( $name, &$value ) {
- wfDeprecated( __METHOD__, '1.31' );
- $this->data[$name] =& $value;
- }
-
- public function setTranslator( &$t ) {
- wfDeprecated( __METHOD__, '1.31' );
- $this->translator = &$t;
- }
-
- abstract public function execute();
-
- function text( $str ) {
- echo htmlspecialchars( $this->data[$str] );
- }
-
- function html( $str ) {
- echo $this->data[$str];
- }
-
- function msg( $msgKey ) {
- echo htmlspecialchars( wfMessage( $msgKey )->text() );
- }
-
- function msgHtml( $msgKey ) {
- echo wfMessage( $msgKey )->text();
- }
-
- function msgWiki( $msgKey ) {
- global $wgOut;
- $text = wfMessage( $msgKey )->text();
- echo $wgOut->parse( $text );
- }
-
- function haveData( $str ) {
- return isset( $this->data[$str] );
- }
-
- function haveMsg( $msgKey ) {
- $msg = wfMessage( $msgKey );
- return $msg->exists() && !$msg->isDisabled();
- }
-
- public function getSkin() {
- return $this->data['skin'];
- }
-
- public function getHTML() {
- ob_start();
- $this->execute();
- $html = ob_get_contents();
- ob_end_clean();
- return $html;
- }
- }
|