r77983 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r77982‎ | r77983 | r77984 >
Date:15:02, 7 December 2010
Author:dantman
Status:ok
Tags:
Comment:
Reduce code duplication in Vector by combining portal markup generation into a single method.
Modified paths:
  • /trunk/phase3/skins/Vector.php (modified) (history)

Diff [purge]

Index: trunk/phase3/skins/Vector.php
@@ -587,62 +587,51 @@
588588 case 'SEARCH':
589589 break;
590590 case 'TOOLBOX':
591 -?>
592 -<div class="portal" id="p-tb">
593 - <h5<?php $this->html('userlangattributes') ?>><?php $this->msg( 'toolbox' ) ?></h5>
594 - <div class="body">
595 - <ul>
596 -<?php
597 - foreach ( $this->getToolbox() as $key => $tbitem ): ?>
598 - <?php echo $this->makeListItem($key, $tbitem); ?>
599 -
600 -<?php
601 - endforeach;
602 - wfRunHooks( 'SkinTemplateToolboxEnd', array( &$this ) ); ?>
603 - </ul>
604 - </div>
605 -</div>
606 -<?php
 591+ $this->renderPortal( "tb", $this->getToolbox(), "toolbox", "SkinTemplateToolboxEnd" );
607592 break;
608593 case 'LANGUAGES':
609594 if ( $this->data['language_urls'] ) {
610 -?>
611 -<div class="portal" id="p-lang">
612 - <h5<?php $this->html('userlangattributes') ?>><?php $this->msg( 'otherlanguages' ) ?></h5>
613 - <div class="body">
614 - <ul>
615 - <?php foreach ( $this->data['language_urls'] as $key => $langlink ): ?>
616 - <?php echo $this->makeListItem($key, $langlink); ?>
617 -
618 - <?php endforeach; ?>
619 - </ul>
620 - </div>
621 -</div>
622 -<?php
 595+ $this->renderPortal("lang", $this->data['language_urls'], "otherlanguages");
623596 }
624597 break;
625598 default:
626 -?>
 599+ $this->renderPortal($name, $content);
 600+ break;
 601+ }
 602+ echo "\n<!-- /{$name} -->\n";
 603+ }
 604+ }
 605+
 606+ private function renderPortal($name, $content, $msg=null, $hook=null) {
 607+ if ( !isset($msg) ) {
 608+ $msg = $name;
 609+ }
 610+ ?>
627611 <div class="portal" id='<?php echo Sanitizer::escapeId( "p-$name" ) ?>'<?php echo $this->skin->tooltip( 'p-' . $name ) ?>>
628 - <h5<?php $this->html('userlangattributes') ?>><?php $out = wfMsg( $name ); if ( wfEmptyMsg( $name, $out ) ) echo htmlspecialchars( $name ); else echo htmlspecialchars( $out ); ?></h5>
 612+ <h5<?php $this->html('userlangattributes') ?>><?php $out = wfMsg( $msg ); if ( wfEmptyMsg( $msg, $out ) ) echo htmlspecialchars( $msg ); else echo htmlspecialchars( $out ); ?></h5>
629613 <div class="body">
630 - <?php if ( is_array( $content ) ): ?>
 614+<?php
 615+ if ( is_array( $content ) ): ?>
631616 <ul>
632 - <?php foreach( $content as $key => $val ): ?>
 617+<?php
 618+ foreach( $content as $key => $val ): ?>
633619 <?php echo $this->makeListItem($key, $val); ?>
634620
635 - <?php endforeach; ?>
 621+<?php
 622+ endforeach;
 623+ if ( isset($hook) ) {
 624+ wfRunHooks( $hook, array( &$this ) );
 625+ }
 626+ ?>
636627 </ul>
637 - <?php else: ?>
 628+<?php
 629+ else: ?>
638630 <?php echo $content; /* Allow raw HTML block to be defined by extensions */ ?>
639 - <?php endif; ?>
 631+<?php
 632+ endif; ?>
640633 </div>
641634 </div>
642635 <?php
643 - break;
644 - }
645 - echo "\n<!-- /{$name} -->\n";
646 - }
647636 }
648637
649638 /**

Status & tagging log