r80988 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r80987‎ | r80988 | r80989 >
Date:20:56, 25 January 2011
Author:btongminh
Status:ok (Comments)
Tags:
Comment:
HTMLForm: All section headers and footers. Added an optional second $section parameter to addHeaderText and addFooterText.
Modified paths:
  • /trunk/phase3/includes/HTMLForm.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/HTMLForm.php
@@ -92,6 +92,8 @@
9393 protected $mPre = '';
9494 protected $mHeader = '';
9595 protected $mFooter = '';
 96+ protected $mSectionHeaders = array();
 97+ protected $mSectionFooters = array();
9698 protected $mPost = '';
9799 protected $mId;
98100
@@ -309,13 +311,31 @@
310312 * Add header text, inside the form.
311313 * @param $msg String complete text of message to display
312314 */
313 - function addHeaderText( $msg ) { $this->mHeader .= $msg; }
 315+ function addHeaderText( $msg, $section = null ) {
 316+ if ( is_null( $section ) ) {
 317+ $this->mHeader .= $msg;
 318+ } else {
 319+ if ( !isset( $this->mSectionHeaders[$section] ) ) {
 320+ $this->mSectionHeaders[$section] = '';
 321+ }
 322+ $this->mSectionHeaders[$section] .= $msg;
 323+ }
 324+ }
314325
315326 /**
316327 * Add footer text, inside the form.
317328 * @param $msg String complete text of message to display
318329 */
319 - function addFooterText( $msg ) { $this->mFooter .= $msg; }
 330+ function addFooterText( $msg, $section = null ) {
 331+ if ( is_null( $section ) ) {
 332+ $this->mFooter .= $msg;
 333+ } else {
 334+ if ( !isset( $this->mSectionFooters[$section] ) ) {
 335+ $this->mSectionFooters[$section] = '';
 336+ }
 337+ $this->mSectionFooters[$section] .= $msg;
 338+ }
 339+ }
320340
321341 /**
322342 * Add text to the end of the display.
@@ -633,7 +653,13 @@
634654 } elseif ( is_array( $value ) ) {
635655 $section = $this->displaySection( $value, $key );
636656 $legend = wfMsg( "{$this->mMessagePrefix}-$key" );
637 - $subsectionHtml .= Xml::fieldset( $legend, $section ) . "\n";
 657+ if ( isset( $this->mSectionHeaders[$key] ) ) {
 658+ $section = $this->mSectionHeaders[$key] . $section;
 659+ }
 660+ if ( isset( $this->mSectionFooters[$key] ) ) {
 661+ $section .= $this->mSectionFooters[$key];
 662+ }
 663+ $subsectionHtml .= Xml::fieldset( $legend, $section ) . "\n";
638664 }
639665 }
640666

Follow-up revisions

RevisionCommit summaryAuthorDate
r91185Follow-up r80988: fix function documentationbtongminh17:35, 30 June 2011

Comments

#Comment by Aaron Schulz (talk | contribs)   01:10, 15 June 2011

$section = $this->displaySection( $value, $key );

+if ( isset( $this->mSectionHeaders[$key] ) ) { +$section = $this->mSectionHeaders[$key] . $section; +}

Is $section supposed to be overridden like that?

Also, the function comments are out of data.

#Comment by Bryan (talk | contribs)   17:36, 30 June 2011

Yes, you want to add the section heading to the top of the section.

#Comment by Aaron Schulz (talk | contribs)   17:39, 30 June 2011

Haha, I didn't see the . $section bit.

Status & tagging log