From ab81f0f2ae600b3300a113dbcff4e72bcfcff026 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Thu, 25 Nov 2004 05:31:49 +0000 Subject: [PATCH] Rearrange the new template system a bit to make things less verbose in most cases, and easier to reuse... --- includes/SkinTemplate.php | 83 +++++++++++++++++++---- skins/MonoBook.php | 138 +++++++++++++++++++------------------- 2 files changed, 138 insertions(+), 83 deletions(-) diff --git a/includes/SkinTemplate.php b/includes/SkinTemplate.php index 63b0c5d09e..8dddf57540 100644 --- a/includes/SkinTemplate.php +++ b/includes/SkinTemplate.php @@ -97,7 +97,7 @@ class SkinTemplate extends Skin { var $stylename; /** - * For QuickTemplate, name or reference to callback function which + * For QuickTemplate, the name of the subclass which * will actually fill the template. * * In PHPTal mode, name of PHPTal template to be used. @@ -118,7 +118,7 @@ class SkinTemplate extends Skin { parent::initPage( $out ); $this->skinname = 'monobook'; $this->stylename = 'monobook'; - $this->template = 'MonoBookTemplate'; + $this->template = 'QuickTemplate'; } /** @@ -132,8 +132,8 @@ class SkinTemplate extends Skin { * @return object * @access private */ - function &setupTemplate( $callback, $repository=false, $cache_dir=false ) { - return new QuickTemplate( $callback ); + function &setupTemplate( $classname, $repository=false, $cache_dir=false ) { + return new $classname(); } /** @@ -703,12 +703,10 @@ class SkinTemplate extends Skin { $nav_urls['contributions'] = false; } $nav_urls['emailuser'] = false; - if ( 0 != $wgUser->getID() ) { # show only to signed in users - if($id) { # can only email non-anons - $nav_urls['emailuser'] = array( - 'href' => $this->makeSpecialUrl('Emailuser', "target=" . $wgTitle->getPartialURL() ) - ); - } + if( $this->showEmailUser( $id ) ) { + $nav_urls['emailuser'] = array( + 'href' => $this->makeSpecialUrl('Emailuser', "target=" . $wgTitle->getPartialURL() ) + ); } wfProfileOut( $fname ); return $nav_urls; @@ -875,27 +873,84 @@ class SkinTemplate extends Skin { * compatible with what we use of PHPTAL 0.7. */ class QuickTemplate { - function QuickTemplate( $callback, $repository=false, $cache_dir=false ) { - $this->outputCallback = $callback; + /** + * @access public + */ + function QuickTemplate() { $this->data = array(); $this->translator = null; } + /** + * @access public + */ function set( $name, $value ) { $this->data[$name] = $value; } + /** + * @access public + */ function setRef($name, &$value) { $this->data[$name] =& $value; } + /** + * @access public + */ function setTranslator( &$t ) { $this->translator = &$t; } + /** + * @access public + */ function execute() { - return call_user_func_array( $this->outputCallback, - array( &$this->data, &$this->translator ) ); + echo "Override this function."; + } + + + /** + * @access private + */ + function text( $str ) { + echo htmlspecialchars( $this->data[$str] ); + } + + /** + * @access private + */ + function html( $str ) { + echo $this->data[$str]; + } + + /** + * @access private + */ + function msg( $str ) { + echo htmlspecialchars( $this->translator->translate( $str ) ); + } + + /** + * @access private + */ + function msgHtml( $str ) { + echo $this->translator->translate( $str ); + } + + /** + * @access private + */ + function haveData( $str ) { + return $this->data[$str]; + } + + /** + * @access private + */ + function haveMsg( $str ) { + $msg = $this->translator->translate( $str ); + return ($msg != '-') && ($msg != ''); # ???? } } diff --git a/skins/MonoBook.php b/skins/MonoBook.php index 30f7e69b89..566c56095c 100644 --- a/skins/MonoBook.php +++ b/skins/MonoBook.php @@ -28,51 +28,50 @@ class SkinMonoBook extends SkinTemplate { $this->template = 'MonoBookTemplate'; } } - -/** - * Template filter callback for MonoBook skin. - * Takes an associative array of data set from a SkinTemplate-based - * class, and a wrapper for MediaWiki's localization database, and - * outputs a formatted page. - * - * @param array $data - * @param MediaWiki_I18N $translator - * @access private - */ -function MonoBookTemplate( &$data, &$translator ) { + +class MonoBookTemplate extends QuickTemplate { + /** + * Template filter callback for MonoBook skin. + * Takes an associative array of data set from a SkinTemplate-based + * class, and a wrapper for MediaWiki's localization database, and + * outputs a formatted page. + * + * @access private + */ + function execute() { ?> - + - - - <?php echo htmlspecialchars( $data['pagetitle'] ) ?> - - - - - - - - + data['jsvarurl' ]) { ?> + + data['usercss' ]) { ?> + data['userjs' ]) { ?> + data['userjsprev']) { ?> - ondblclick="" - class=""> + data['body_ondblclick']) { ?>ondblclick="text('body_ondblclick') ?>" + data['nsclass' ]) { ?>class="text('nsclass') ?>">
-
-

+ data['sitenotice']) { ?>
html('sitenotice') ?>
+

text('title') ?>

-

translate('tagline')) ?>

-
-
-
+

msg('tagline') ?>

+
html('subtitle') ?>
+ data['undelete']) { ?>
html('undelete') ?>
+ data['newtalk'] ) { ?>
html('newtalk') ?>
- - + html('bodytext') ?> + data['catlinks']) { ?>
@@ -82,7 +81,7 @@ function MonoBookTemplate( &$data, &$translator ) {
Views
    - $action) { + data['content_actions'] as $key => $action) { ?>
  • class="" >
-
translate('personaltools')) ?>
+
msg('personaltools') ?>
-
translate('navigation')) ?>
+
msg('navigation') ?>
    - + data['navigation_urls'] as $navlink) { ?>
  • @@ -121,46 +120,46 @@ function MonoBookTemplate( &$data, &$translator ) {
-
translate('toolbox')) ?>
+
msg('toolbox') ?>
    - + data['notspecialpage']) { foreach( array( 'whatlinkshere', 'recentchangeslinked' ) as $special ) { ?>
  • translate($special)) ?>
  • + echo htmlspecialchars($this->data['nav_urls'][$special]['href']) + ?>">msg($special) ?> - -
  • translate($special)) ?>
  • + data['nav_urls'][$special]) {?>
  • msg($special) ?>
-
-
translate('otherlanguages')) ?>
+ data['language_urls'] ) { ?>
+
msg('otherlanguages') ?>
    - + data['language_urls'] as $langlink) { ?>
  • @@ -173,22 +172,23 @@ function MonoBookTemplate( &$data, &$translator ) {
- + html('reporttime') ?> \ No newline at end of file -- 2.20.1