r73268 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r73267‎ | r73268 | r73269 >
Date:01:21, 18 September 2010
Author:kaldari
Status:ok (Comments)
Tags:
Comment:
retain form state (interface not yet localizable)
Modified paths:
  • /trunk/extensions/CentralNotice/SpecialBannerAllocation.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CentralNotice/SpecialBannerAllocation.php
@@ -6,7 +6,9 @@
77 }
88
99 class SpecialBannerAllocation extends UnlistedSpecialPage {
10 - var $centralNoticeError;
 10+ public $project = 'wikipedia';
 11+ public $language = 'en';
 12+ public $location = 'US';
1113
1214 function __construct() {
1315 // Register special page
@@ -21,6 +23,12 @@
2224 */
2325 function execute( $sub ) {
2426 global $wgOut, $wgUser, $wgRequest, $wgScriptPath, $wgNoticeProjects, $wgLanguageCode;
 27+
 28+ if ( $wgRequest->wasPosted() ) {
 29+ $this->project = $wgRequest->getText( 'project', 'wikipedia' );
 30+ $this->language = $wgRequest->getText( 'language', 'en' );
 31+ $this->location = $wgRequest->getText( 'country', 'US' );
 32+ }
2533
2634 // Begin output
2735 $this->setHeaders();
@@ -58,7 +66,7 @@
5967 $htmlOut .= Xml::openElement( 'td' );
6068 $htmlOut .= Xml::openElement( 'select', array( 'name' => 'project' ) );
6169 foreach ( $wgNoticeProjects as $value ) {
62 - $htmlOut .= Xml::option( $value, $value, $value == 'wikipedia' );
 70+ $htmlOut .= Xml::option( $value, $value, $value == $this->project );
6371 }
6472 $htmlOut .= Xml::closeElement( 'select' );
6573 $htmlOut .= Xml::closeElement( 'td' );
@@ -74,11 +82,7 @@
7583 ksort( $languages );
7684 $htmlOut .= Xml::openElement( 'select', array( 'name' => 'language' ) );
7785 foreach( $languages as $code => $name ) {
78 - $htmlOut .= Xml::option(
79 - wfMsg( 'centralnotice-language-listing', $code, $name ),
80 - $code,
81 - $code == 'en'
82 - );
 86+ $htmlOut .= Xml::option( wfMsg( 'centralnotice-language-listing', $code, $name ), $code, $code == $this->language );
8387 }
8488 $htmlOut .= Xml::closeElement( 'select' );
8589 $htmlOut .= Xml::closeElement( 'td' );
@@ -89,11 +93,7 @@
9094 $countries = CentralNoticeDB::getCountriesList();
9195 $htmlOut .= Xml::openElement( 'select', array( 'name' => 'country' ) );
9296 foreach( $countries as $code => $name ) {
93 - $htmlOut .= Xml::option(
94 - $name,
95 - $code,
96 - $code == 'US'
97 - );
 97+ $htmlOut .= Xml::option( $name, $code, $code == $this->location );
9898 }
9999 $htmlOut .= Xml::closeElement( 'select' );
100100 $htmlOut .= Xml::closeElement( 'td' );

Comments

#Comment by Nikerabbit (talk | contribs)   07:05, 18 September 2010
+public $project = 'wikipedia';

Is there need to have these public? It's always easy to go from protected -> public or adding a getter/setter, but the other direction can be hard.

+$this->location = $wgRequest->getText( 'country', 'US' );

You could also use this to not repeat the default value twice:

$this->location = $wgRequest->getText( 'country', $this->location );

Status & tagging log