r98902 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r98901‎ | r98902 | r98903 >
Date:20:39, 4 October 2011
Author:awjrichards
Status:ok
Tags:
Comment:
Modified paths:
  • /branches/wmf/1.18wmf1/extensions/CentralNotice/special/SpecialBannerAllocation.php (modified) (history)

Diff [purge]

Index: branches/wmf/1.18wmf1/extensions/CentralNotice/special/SpecialBannerAllocation.php
@@ -1,38 +1,39 @@
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 */
2217 function execute( $sub ) {
23 - global $wgOut, $wgRequest, $wgExtensionAssetsPath, $wgNoticeProjects, $wgLanguageCode;
24 -
25 - if ( $wgRequest->wasPosted() ) {
26 - $this->project = $wgRequest->getText( 'project', 'wikipedia' );
27 - $this->language = $wgRequest->getText( 'language', 'en' );
28 - $this->location = $wgRequest->getText( 'country', 'US' );
29 - }
 18+ global $wgOut, $wgRequest, $wgExtensionAssetsPath, $wgNoticeProjects, $wgLanguageCode, $wgNoticeProject;
3019
 20+ $locationSubmitted = false;
 21+
 22+ $this->project = $wgRequest->getText( 'project', $wgNoticeProject );
 23+ $this->language = $wgRequest->getText( 'language', $wgLanguageCode );
 24+
 25+ // If the form has been submitted, the country code should be passed along.
 26+ $locationSubmitted = $wgRequest->getVal( 'country' );
 27+ $this->location = $locationSubmitted ? $locationSubmitted : $this->location;
 28+
 29+ // Convert submitted location to boolean value. If it true, showList() will be called.
 30+ $locationSubmitted = (boolean) $locationSubmitted;
 31+
3132 // Begin output
3233 $this->setHeaders();
33 -
 34+
3435 // Add style file to the output headers
3536 $wgOut->addExtensionStyle( "$wgExtensionAssetsPath/CentralNotice/centralnotice.css" );
36 -
 37+
3738 // Add script file to the output headers
3839 $wgOut->addScriptFile( "$wgExtensionAssetsPath/CentralNotice/centralnotice.js" );
3940
@@ -46,96 +47,106 @@
4748 CentralNotice::printHeader();
4849
4950 // Begin Banners tab content
50 - $wgOut->addHTML( Xml::openElement( 'div', array( 'id' => 'preferences' ) ) );
51 -
 51+ $wgOut->addHTML( Html::openElement( 'div', array( 'id' => 'preferences' ) ) );
 52+
5253 $htmlOut = '';
53 -
 54+
5455 // Begin Allocation selection fieldset
55 - $htmlOut .= Xml::openElement( 'fieldset', array( 'class' => 'prefsection' ) );
56 -
57 - $htmlOut .= Xml::openElement( 'form', array( 'method' => 'post' ) );
58 - $htmlOut .= Xml::element( 'h2', null, wfMsg( 'centralnotice-view-allocation' ) );
 56+ $htmlOut .= Html::openElement( 'fieldset', array( 'class' => 'prefsection' ) );
 57+
 58+ $htmlOut .= Html::openElement( 'form', array( 'method' => 'get' ) );
 59+ $htmlOut .= Html::element( 'h2', null, wfMsg( 'centralnotice-view-allocation' ) );
5960 $htmlOut .= Xml::tags( 'p', null, wfMsg( 'centralnotice-allocation-instructions' ) );
60 -
61 - $htmlOut .= Xml::openElement( 'table', array ( 'id' => 'envpicker', 'cellpadding' => 7 ) );
62 - $htmlOut .= Xml::openElement( 'tr' );
63 - $htmlOut .= Xml::tags( 'td',
64 - array( 'style' => 'width: 20%;' ),
 61+
 62+ $htmlOut .= Html::openElement( 'table', array ( 'id' => 'envpicker', 'cellpadding' => 7 ) );
 63+ $htmlOut .= Html::openElement( 'tr' );
 64+ $htmlOut .= Xml::tags( 'td',
 65+ array( 'style' => 'width: 20%;' ),
6566 wfMsg( 'centralnotice-project-name' ) );
66 - $htmlOut .= Xml::openElement( 'td' );
67 - $htmlOut .= Xml::openElement( 'select', array( 'name' => 'project' ) );
 67+ $htmlOut .= Html::openElement( 'td' );
 68+ $htmlOut .= Html::openElement( 'select', array( 'name' => 'project' ) );
 69+
6870 foreach ( $wgNoticeProjects as $value ) {
6971 $htmlOut .= Xml::option( $value, $value, $value === $this->project );
7072 }
71 - $htmlOut .= Xml::closeElement( 'select' );
72 - $htmlOut .= Xml::closeElement( 'td' );
73 - $htmlOut .= Xml::closeElement( 'tr' );
74 - $htmlOut .= Xml::openElement( 'tr' );
75 - $htmlOut .= Xml::tags( 'td',
76 - array( 'valign' => 'top' ),
 73+
 74+ $htmlOut .= Html::closeElement( 'select' );
 75+ $htmlOut .= Html::closeElement( 'td' );
 76+ $htmlOut .= Html::closeElement( 'tr' );
 77+ $htmlOut .= Html::openElement( 'tr' );
 78+ $htmlOut .= Xml::tags( 'td',
 79+ array( 'valign' => 'top' ),
7780 wfMsg( 'centralnotice-project-lang' ) );
78 - $htmlOut .= Xml::openElement( 'td' );
79 - // Make sure the site language is in the list; a custom language code
 81+ $htmlOut .= Html::openElement( 'td' );
 82+
 83+ // Make sure the site language is in the list; a custom language code
8084 // might not have a defined name...
8185 $languages = Language::getLanguageNames( true );
8286 if( !array_key_exists( $wgLanguageCode, $languages ) ) {
8387 $languages[$wgLanguageCode] = $wgLanguageCode;
8488 }
 89+
8590 ksort( $languages );
86 - $htmlOut .= Xml::openElement( 'select', array( 'name' => 'language' ) );
 91+ $htmlOut .= Html::openElement( 'select', array( 'name' => 'language' ) );
 92+
8793 foreach( $languages as $code => $name ) {
88 - $htmlOut .= Xml::option(
89 - wfMsg( 'centralnotice-language-listing', $code, $name ),
 94+ $htmlOut .= Xml::option(
 95+ wfMsg( 'centralnotice-language-listing', $code, $name ),
9096 $code, $code === $this->language );
9197 }
92 - $htmlOut .= Xml::closeElement( 'select' );
93 - $htmlOut .= Xml::closeElement( 'td' );
94 - $htmlOut .= Xml::closeElement( 'tr' );
95 - $htmlOut .= Xml::openElement( 'tr' );
 98+
 99+ $htmlOut .= Html::closeElement( 'select' );
 100+ $htmlOut .= Html::closeElement( 'td' );
 101+ $htmlOut .= Html::closeElement( 'tr' );
 102+ $htmlOut .= Html::openElement( 'tr' );
96103 $htmlOut .= Xml::tags( 'td', array(), wfMsg( 'centralnotice-country' ) );
97 - $htmlOut .= Xml::openElement( 'td' );
 104+ $htmlOut .= Html::openElement( 'td' );
 105+
98106 $countries = CentralNoticeDB::getCountriesList();
99 - $htmlOut .= Xml::openElement( 'select', array( 'name' => 'country' ) );
 107+
 108+ $htmlOut .= Html::openElement( 'select', array( 'name' => 'country' ) );
 109+
100110 foreach( $countries as $code => $name ) {
101111 $htmlOut .= Xml::option( $name, $code, $code === $this->location );
102112 }
103 - $htmlOut .= Xml::closeElement( 'select' );
104 - $htmlOut .= Xml::closeElement( 'td' );
105 - $htmlOut .= Xml::closeElement( 'tr' );
106 - $htmlOut .= Xml::closeElement( 'table' );
107 -
108 - $htmlOut .= Xml::tags( 'div',
109 - array( 'class' => 'cn-buttons' ),
110 - Xml::submitButton( wfMsg( 'centralnotice-modify' ) )
 113+
 114+ $htmlOut .= Html::closeElement( 'select' );
 115+ $htmlOut .= Html::closeElement( 'td' );
 116+ $htmlOut .= Html::closeElement( 'tr' );
 117+ $htmlOut .= Html::closeElement( 'table' );
 118+
 119+ $htmlOut .= Xml::tags( 'div',
 120+ array( 'class' => 'cn-buttons' ),
 121+ Xml::submitButton( wfMsg( 'centralnotice-view' ) )
111122 );
112 - $htmlOut .= Xml::closeElement( 'form' );
113 -
 123+ $htmlOut .= Html::closeElement( 'form' );
 124+
114125 // End Allocation selection fieldset
115 - $htmlOut .= Xml::closeElement( 'fieldset' );
 126+ $htmlOut .= Html::closeElement( 'fieldset' );
116127
117128 $wgOut->addHTML( $htmlOut );
118 -
 129+
119130 // Handle form submissions
120 - if ( $wgRequest->wasPosted() ) {
 131+ if ( $locationSubmitted ) {
121132 $this->showList();
122133 }
123134
124135 // End Banners tab content
125 - $wgOut->addHTML( Xml::closeElement( 'div' ) );
 136+ $wgOut->addHTML( Html::closeElement( 'div' ) );
126137 }
127 -
 138+
128139 /**
129140 * Show a list of banners with allocation. Newer banners are shown first.
130141 */
131142 function showList() {
132143 global $wgOut, $wgRequest;
133 -
 144+
134145 // Begin building HTML
135146 $htmlOut = '';
136 -
 147+
137148 // Begin Allocation list fieldset
138 - $htmlOut .= Xml::openElement( 'fieldset', array( 'class' => 'prefsection' ) );
139 -
 149+ $htmlOut .= Html::openElement( 'fieldset', array( 'class' => 'prefsection' ) );
 150+
140151 $bannerLister = new SpecialBannerListLoader();
141152 $bannerLister->project = $wgRequest->getVal( 'project' );
142153 $bannerLister->language = $wgRequest->getVal( 'language' );
@@ -156,70 +167,82 @@
157168 $accountBanners = array();
158169 $anonWeight = 0;
159170 $accountWeight = 0;
 171+
160172 if ( $banners ) {
161173 foreach ( $banners as $banner ) {
162174 if ($banner['display_anon']) {
163175 $anonBanners[] = $banner;
164176 $anonWeight += $banner['weight'];
165177 }
 178+
166179 if ($banner['display_account']) {
167180 $accountBanners[] = $banner;
168181 $accountWeight += $banner['weight'];
169182 }
170183 }
 184+
171185 if ( $anonBanners ) {
172186 $htmlOut .= $this->getTable( wfMsg ( 'centralnotice-banner-anonymous' ), $anonBanners, $anonWeight );
173187 }
 188+
174189 if ( $accountBanners ) {
175190 $htmlOut .= $this->getTable( wfMsg ( 'centralnotice-banner-logged-in' ), $accountBanners, $accountWeight );
176191 }
177192 } else {
178193 $htmlOut .= Xml::tags( 'p', null, wfMsg ( 'centralnotice-no-allocation' ) );
179194 }
180 -
 195+
181196 // End Allocation list fieldset
182 - $htmlOut .= Xml::closeElement( 'fieldset' );
 197+ $htmlOut .= Html::closeElement( 'fieldset' );
183198
184199 $wgOut->addHTML( $htmlOut );
185200 }
186 -
 201+
187202 function getTable( $type, $banners, $weight ) {
188203 global $wgUser, $wgLang;
189 -
 204+
190205 $sk = $wgUser->getSkin();
191206 $viewBanner = $this->getTitleFor( 'NoticeTemplate', 'view' );
192207 $viewCampaign = $this->getTitleFor( 'CentralNotice' );
193 -
194 - $htmlOut = Xml::openElement( 'table',
 208+
 209+ $htmlOut = Html::openElement( 'table',
195210 array ( 'cellpadding' => 9, 'class' => 'wikitable sortable', 'style' => 'margin: 1em;' )
196211 );
197 - $htmlOut .= Xml::element( 'caption', array( 'style' => 'font-size: 1.2em;' ), $type );
198 - $htmlOut .= Xml::openElement( 'tr' );
199 - $htmlOut .= Xml::element( 'th', array( 'width' => '20%' ),
 212+ $htmlOut .= Html::element( 'caption', array( 'style' => 'font-size: 1.2em;' ), $type );
 213+ $htmlOut .= Html::openElement( 'tr' );
 214+ $htmlOut .= Html::element( 'th', array( 'width' => '20%' ),
200215 wfMsg ( 'centralnotice-percentage' ) );
201 - $htmlOut .= Xml::element( 'th', array( 'width' => '30%' ),
 216+ $htmlOut .= Html::element( 'th', array( 'width' => '30%' ),
202217 wfMsg ( 'centralnotice-banner' ) );
203 - $htmlOut .= Xml::element( 'th', array( 'width' => '30%' ),
 218+ $htmlOut .= Html::element( 'th', array( 'width' => '30%' ),
204219 wfMsg ( 'centralnotice-notice' ) );
205 - $htmlOut .= Xml::closeElement( 'tr' );
 220+ $htmlOut .= Html::closeElement( 'tr' );
 221+
206222 foreach ( $banners as $banner ) {
207 - $htmlOut .= Xml::openElement( 'tr' );
208 - $htmlOut .= Xml::openElement( 'td' );
 223+ $htmlOut .= Html::openElement( 'tr' );
 224+ $htmlOut .= Html::openElement( 'td' );
 225+
209226 $percentage = round( ( $banner['weight'] / $weight ) * 100, 2 );
 227+
210228 $htmlOut .= wfMsg ( 'percent', $wgLang->formatNum( $percentage ) );
211 - $htmlOut .= Xml::closeElement( 'td' );
 229+ $htmlOut .= Html::closeElement( 'td' );
212230 $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top' ),
213 - $sk->makeLinkObj( $viewBanner, htmlspecialchars( $banner['name'] ),
 231+
 232+ $sk->makeLinkObj( $viewBanner, htmlspecialchars( $banner['name'] ),
214233 'template=' . urlencode( $banner['name'] ) )
215234 );
 235+
216236 $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top' ),
217 - $sk->makeLinkObj( $viewCampaign, htmlspecialchars( $banner['campaign'] ),
 237+
 238+ $sk->makeLinkObj( $viewCampaign, htmlspecialchars( $banner['campaign'] ),
218239 'method=listNoticeDetail&notice=' . urlencode( $banner['campaign'] ) )
219240 );
220 - $htmlOut .= Xml::closeElement( 'tr' );
 241+
 242+ $htmlOut .= Html::closeElement( 'tr' );
221243 }
222 - $htmlOut .= Xml::closeElement( 'table' );
 244+
 245+ $htmlOut .= Html::closeElement( 'table' );
 246+
223247 return $htmlOut;
224248 }
225 -
226249 }
Property changes on: branches/wmf/1.18wmf1/extensions/CentralNotice/special/SpecialBannerAllocation.php
___________________________________________________________________
Modified: svn:mergeinfo
227250 Merged /trunk/extensions/CentralNotice/special/SpecialBannerAllocation.php:r95514-98901

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r95697Switched BannerAllocation form from post to get. See bug 30271.jpostlethwaite21:05, 29 August 2011
r95912Converted spaces to tabs, removed third parameter from $wgRequest->getText()....jpostlethwaite22:09, 31 August 2011
r95966Remove MEDIAWIKI constant check. No need, as this file only contains a class....siebrand12:03, 1 September 2011
r95967Replace some uses of Xml class with Html class.siebrand12:09, 1 September 2011
r95969Fix incorrect button text on Special:BannerAllocation....siebrand12:17, 1 September 2011

Status & tagging log