r95966 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r95965‎ | r95966 | r95967 >
Date:12:03, 1 September 2011
Author:siebrand
Status:ok
Tags:
Comment:
Remove MEDIAWIKI constant check. No need, as this file only contains a class.
Whitespace updates.
Modified paths:
  • /trunk/extensions/CentralNotice/special/SpecialBannerAllocation.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CentralNotice/special/SpecialBannerAllocation.php
@@ -1,20 +1,15 @@
22 <?php
33
4 -if ( !defined( 'MEDIAWIKI' ) ) {
5 - echo "CentralNotice extension\n";
6 - exit( 1 );
7 -}
8 -
94 class SpecialBannerAllocation extends UnlistedSpecialPage {
105 public $project = 'wikipedia';
116 public $language = 'en';
127 public $location = 'US';
13 -
 8+
149 function __construct() {
1510 // Register special page
16 - parent::__construct( "BannerAllocation" );
 11+ parent::__construct( 'BannerAllocation' );
1712 }
18 -
 13+
1914 /**
2015 * Handle different types of page requests
2116 */
@@ -22,23 +17,23 @@
2318 global $wgOut, $wgRequest, $wgExtensionAssetsPath, $wgNoticeProjects, $wgLanguageCode, $wgNoticeProject;
2419
2520 $locationSubmitted = false;
26 -
 21+
2722 $this->project = $wgRequest->getText( 'project', $wgNoticeProject );
2823 $this->language = $wgRequest->getText( 'language', $wgLanguageCode );
29 -
 24+
3025 // If the form has been submitted, the country code should be passed along.
3126 $locationSubmitted = $wgRequest->getVal( 'country' );
3227 $this->location = $locationSubmitted ? $locationSubmitted : $this->location;
33 -
 28+
3429 // Convert submitted location to boolean value. If it true, showList() will be called.
3530 $locationSubmitted = (boolean) $locationSubmitted;
3631
3732 // Begin output
3833 $this->setHeaders();
39 -
 34+
4035 // Add style file to the output headers
4136 $wgOut->addExtensionStyle( "$wgExtensionAssetsPath/CentralNotice/centralnotice.css" );
42 -
 37+
4338 // Add script file to the output headers
4439 $wgOut->addScriptFile( "$wgExtensionAssetsPath/CentralNotice/centralnotice.js" );
4540
@@ -53,74 +48,84 @@
5449
5550 // Begin Banners tab content
5651 $wgOut->addHTML( Xml::openElement( 'div', array( 'id' => 'preferences' ) ) );
57 -
 52+
5853 $htmlOut = '';
59 -
 54+
6055 // Begin Allocation selection fieldset
6156 $htmlOut .= Xml::openElement( 'fieldset', array( 'class' => 'prefsection' ) );
62 -
 57+
6358 $htmlOut .= Xml::openElement( 'form', array( 'method' => 'get' ) );
6459 $htmlOut .= Xml::element( 'h2', null, wfMsg( 'centralnotice-view-allocation' ) );
6560 $htmlOut .= Xml::tags( 'p', null, wfMsg( 'centralnotice-allocation-instructions' ) );
66 -
 61+
6762 $htmlOut .= Xml::openElement( 'table', array ( 'id' => 'envpicker', 'cellpadding' => 7 ) );
6863 $htmlOut .= Xml::openElement( 'tr' );
69 - $htmlOut .= Xml::tags( 'td',
70 - array( 'style' => 'width: 20%;' ),
 64+ $htmlOut .= Xml::tags( 'td',
 65+ array( 'style' => 'width: 20%;' ),
7166 wfMsg( 'centralnotice-project-name' ) );
7267 $htmlOut .= Xml::openElement( 'td' );
7368 $htmlOut .= Xml::openElement( 'select', array( 'name' => 'project' ) );
 69+
7470 foreach ( $wgNoticeProjects as $value ) {
7571 $htmlOut .= Xml::option( $value, $value, $value === $this->project );
7672 }
 73+
7774 $htmlOut .= Xml::closeElement( 'select' );
7875 $htmlOut .= Xml::closeElement( 'td' );
7976 $htmlOut .= Xml::closeElement( 'tr' );
8077 $htmlOut .= Xml::openElement( 'tr' );
81 - $htmlOut .= Xml::tags( 'td',
82 - array( 'valign' => 'top' ),
 78+ $htmlOut .= Xml::tags( 'td',
 79+ array( 'valign' => 'top' ),
8380 wfMsg( 'centralnotice-project-lang' ) );
8481 $htmlOut .= Xml::openElement( 'td' );
85 - // Make sure the site language is in the list; a custom language code
 82+
 83+ // Make sure the site language is in the list; a custom language code
8684 // might not have a defined name...
8785 $languages = Language::getLanguageNames( true );
8886 if( !array_key_exists( $wgLanguageCode, $languages ) ) {
8987 $languages[$wgLanguageCode] = $wgLanguageCode;
9088 }
 89+
9190 ksort( $languages );
9291 $htmlOut .= Xml::openElement( 'select', array( 'name' => 'language' ) );
 92+
9393 foreach( $languages as $code => $name ) {
94 - $htmlOut .= Xml::option(
95 - wfMsg( 'centralnotice-language-listing', $code, $name ),
 94+ $htmlOut .= Xml::option(
 95+ wfMsg( 'centralnotice-language-listing', $code, $name ),
9696 $code, $code === $this->language );
9797 }
 98+
9899 $htmlOut .= Xml::closeElement( 'select' );
99100 $htmlOut .= Xml::closeElement( 'td' );
100101 $htmlOut .= Xml::closeElement( 'tr' );
101102 $htmlOut .= Xml::openElement( 'tr' );
102103 $htmlOut .= Xml::tags( 'td', array(), wfMsg( 'centralnotice-country' ) );
103104 $htmlOut .= Xml::openElement( 'td' );
 105+
104106 $countries = CentralNoticeDB::getCountriesList();
 107+
105108 $htmlOut .= Xml::openElement( 'select', array( 'name' => 'country' ) );
 109+
106110 foreach( $countries as $code => $name ) {
107111 $htmlOut .= Xml::option( $name, $code, $code === $this->location );
108112 }
 113+
109114 $htmlOut .= Xml::closeElement( 'select' );
110115 $htmlOut .= Xml::closeElement( 'td' );
111116 $htmlOut .= Xml::closeElement( 'tr' );
112117 $htmlOut .= Xml::closeElement( 'table' );
113 -
114 - $htmlOut .= Xml::tags( 'div',
115 - array( 'class' => 'cn-buttons' ),
116 - Xml::submitButton( wfMsg( 'centralnotice-modify' ) )
 118+
 119+ $htmlOut .= Xml::tags( 'div',
 120+ array( 'class' => 'cn-buttons' ),
 121+ Xml::submitButton( wfMsg( 'centralnotice-modify' ) )
117122 );
118123 $htmlOut .= Xml::closeElement( 'form' );
119 -
 124+
120125 // End Allocation selection fieldset
121126 $htmlOut .= Xml::closeElement( 'fieldset' );
122127
123128 $wgOut->addHTML( $htmlOut );
124 -
 129+
125130 // Handle form submissions
126131 if ( $locationSubmitted ) {
127132 $this->showList();
@@ -129,19 +134,19 @@
130135 // End Banners tab content
131136 $wgOut->addHTML( Xml::closeElement( 'div' ) );
132137 }
133 -
 138+
134139 /**
135140 * Show a list of banners with allocation. Newer banners are shown first.
136141 */
137142 function showList() {
138143 global $wgOut, $wgRequest;
139 -
 144+
140145 // Begin building HTML
141146 $htmlOut = '';
142 -
 147+
143148 // Begin Allocation list fieldset
144149 $htmlOut .= Xml::openElement( 'fieldset', array( 'class' => 'prefsection' ) );
145 -
 150+
146151 $bannerLister = new SpecialBannerListLoader();
147152 $bannerLister->project = $wgRequest->getVal( 'project' );
148153 $bannerLister->language = $wgRequest->getVal( 'language' );
@@ -162,70 +167,82 @@
163168 $accountBanners = array();
164169 $anonWeight = 0;
165170 $accountWeight = 0;
 171+
166172 if ( $banners ) {
167173 foreach ( $banners as $banner ) {
168174 if ($banner['display_anon']) {
169175 $anonBanners[] = $banner;
170176 $anonWeight += $banner['weight'];
171177 }
 178+
172179 if ($banner['display_account']) {
173180 $accountBanners[] = $banner;
174181 $accountWeight += $banner['weight'];
175182 }
176183 }
 184+
177185 if ( $anonBanners ) {
178186 $htmlOut .= $this->getTable( wfMsg ( 'centralnotice-banner-anonymous' ), $anonBanners, $anonWeight );
179187 }
 188+
180189 if ( $accountBanners ) {
181190 $htmlOut .= $this->getTable( wfMsg ( 'centralnotice-banner-logged-in' ), $accountBanners, $accountWeight );
182191 }
183192 } else {
184193 $htmlOut .= Xml::tags( 'p', null, wfMsg ( 'centralnotice-no-allocation' ) );
185194 }
186 -
 195+
187196 // End Allocation list fieldset
188197 $htmlOut .= Xml::closeElement( 'fieldset' );
189198
190199 $wgOut->addHTML( $htmlOut );
191200 }
192 -
 201+
193202 function getTable( $type, $banners, $weight ) {
194203 global $wgUser, $wgLang;
195 -
 204+
196205 $sk = $wgUser->getSkin();
197206 $viewBanner = $this->getTitleFor( 'NoticeTemplate', 'view' );
198207 $viewCampaign = $this->getTitleFor( 'CentralNotice' );
199 -
200 - $htmlOut = Xml::openElement( 'table',
 208+
 209+ $htmlOut = Xml::openElement( 'table',
201210 array ( 'cellpadding' => 9, 'class' => 'wikitable sortable', 'style' => 'margin: 1em;' )
202211 );
203212 $htmlOut .= Xml::element( 'caption', array( 'style' => 'font-size: 1.2em;' ), $type );
204213 $htmlOut .= Xml::openElement( 'tr' );
205 - $htmlOut .= Xml::element( 'th', array( 'width' => '20%' ),
 214+ $htmlOut .= Xml::element( 'th', array( 'width' => '20%' ),
206215 wfMsg ( 'centralnotice-percentage' ) );
207 - $htmlOut .= Xml::element( 'th', array( 'width' => '30%' ),
 216+ $htmlOut .= Xml::element( 'th', array( 'width' => '30%' ),
208217 wfMsg ( 'centralnotice-banner' ) );
209 - $htmlOut .= Xml::element( 'th', array( 'width' => '30%' ),
 218+ $htmlOut .= Xml::element( 'th', array( 'width' => '30%' ),
210219 wfMsg ( 'centralnotice-notice' ) );
211220 $htmlOut .= Xml::closeElement( 'tr' );
 221+
212222 foreach ( $banners as $banner ) {
213223 $htmlOut .= Xml::openElement( 'tr' );
214224 $htmlOut .= Xml::openElement( 'td' );
 225+
215226 $percentage = round( ( $banner['weight'] / $weight ) * 100, 2 );
 227+
216228 $htmlOut .= wfMsg ( 'percent', $wgLang->formatNum( $percentage ) );
217229 $htmlOut .= Xml::closeElement( 'td' );
218230 $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top' ),
219 - $sk->makeLinkObj( $viewBanner, htmlspecialchars( $banner['name'] ),
 231+
 232+ $sk->makeLinkObj( $viewBanner, htmlspecialchars( $banner['name'] ),
220233 'template=' . urlencode( $banner['name'] ) )
221234 );
 235+
222236 $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top' ),
223 - $sk->makeLinkObj( $viewCampaign, htmlspecialchars( $banner['campaign'] ),
 237+
 238+ $sk->makeLinkObj( $viewCampaign, htmlspecialchars( $banner['campaign'] ),
224239 'method=listNoticeDetail&notice=' . urlencode( $banner['campaign'] ) )
225240 );
 241+
226242 $htmlOut .= Xml::closeElement( 'tr' );
227243 }
 244+
228245 $htmlOut .= Xml::closeElement( 'table' );
 246+
229247 return $htmlOut;
230248 }
231 -
232249 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r98902MFT r95697, r95912, r95966, r95967, r95969awjrichards20:39, 4 October 2011

Status & tagging log