Index: branches/wmf/1.18wmf1/extensions/CentralNotice/special/SpecialBannerAllocation.php |
— | — | @@ -1,38 +1,39 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -if ( !defined( 'MEDIAWIKI' ) ) { |
5 | | - echo "CentralNotice extension\n"; |
6 | | - exit( 1 ); |
7 | | -} |
8 | | - |
9 | 4 | class SpecialBannerAllocation extends UnlistedSpecialPage { |
10 | 5 | public $project = 'wikipedia'; |
11 | 6 | public $language = 'en'; |
12 | 7 | public $location = 'US'; |
13 | | - |
| 8 | + |
14 | 9 | function __construct() { |
15 | 10 | // Register special page |
16 | | - parent::__construct( "BannerAllocation" ); |
| 11 | + parent::__construct( 'BannerAllocation' ); |
17 | 12 | } |
18 | | - |
| 13 | + |
19 | 14 | /** |
20 | 15 | * Handle different types of page requests |
21 | 16 | */ |
22 | 17 | 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; |
30 | 19 | |
| 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 | + |
31 | 32 | // Begin output |
32 | 33 | $this->setHeaders(); |
33 | | - |
| 34 | + |
34 | 35 | // Add style file to the output headers |
35 | 36 | $wgOut->addExtensionStyle( "$wgExtensionAssetsPath/CentralNotice/centralnotice.css" ); |
36 | | - |
| 37 | + |
37 | 38 | // Add script file to the output headers |
38 | 39 | $wgOut->addScriptFile( "$wgExtensionAssetsPath/CentralNotice/centralnotice.js" ); |
39 | 40 | |
— | — | @@ -46,96 +47,106 @@ |
47 | 48 | CentralNotice::printHeader(); |
48 | 49 | |
49 | 50 | // Begin Banners tab content |
50 | | - $wgOut->addHTML( Xml::openElement( 'div', array( 'id' => 'preferences' ) ) ); |
51 | | - |
| 51 | + $wgOut->addHTML( Html::openElement( 'div', array( 'id' => 'preferences' ) ) ); |
| 52 | + |
52 | 53 | $htmlOut = ''; |
53 | | - |
| 54 | + |
54 | 55 | // 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' ) ); |
59 | 60 | $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%;' ), |
65 | 66 | 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 | + |
68 | 70 | foreach ( $wgNoticeProjects as $value ) { |
69 | 71 | $htmlOut .= Xml::option( $value, $value, $value === $this->project ); |
70 | 72 | } |
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' ), |
77 | 80 | 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 |
80 | 84 | // might not have a defined name... |
81 | 85 | $languages = Language::getLanguageNames( true ); |
82 | 86 | if( !array_key_exists( $wgLanguageCode, $languages ) ) { |
83 | 87 | $languages[$wgLanguageCode] = $wgLanguageCode; |
84 | 88 | } |
| 89 | + |
85 | 90 | ksort( $languages ); |
86 | | - $htmlOut .= Xml::openElement( 'select', array( 'name' => 'language' ) ); |
| 91 | + $htmlOut .= Html::openElement( 'select', array( 'name' => 'language' ) ); |
| 92 | + |
87 | 93 | 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 ), |
90 | 96 | $code, $code === $this->language ); |
91 | 97 | } |
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' ); |
96 | 103 | $htmlOut .= Xml::tags( 'td', array(), wfMsg( 'centralnotice-country' ) ); |
97 | | - $htmlOut .= Xml::openElement( 'td' ); |
| 104 | + $htmlOut .= Html::openElement( 'td' ); |
| 105 | + |
98 | 106 | $countries = CentralNoticeDB::getCountriesList(); |
99 | | - $htmlOut .= Xml::openElement( 'select', array( 'name' => 'country' ) ); |
| 107 | + |
| 108 | + $htmlOut .= Html::openElement( 'select', array( 'name' => 'country' ) ); |
| 109 | + |
100 | 110 | foreach( $countries as $code => $name ) { |
101 | 111 | $htmlOut .= Xml::option( $name, $code, $code === $this->location ); |
102 | 112 | } |
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' ) ) |
111 | 122 | ); |
112 | | - $htmlOut .= Xml::closeElement( 'form' ); |
113 | | - |
| 123 | + $htmlOut .= Html::closeElement( 'form' ); |
| 124 | + |
114 | 125 | // End Allocation selection fieldset |
115 | | - $htmlOut .= Xml::closeElement( 'fieldset' ); |
| 126 | + $htmlOut .= Html::closeElement( 'fieldset' ); |
116 | 127 | |
117 | 128 | $wgOut->addHTML( $htmlOut ); |
118 | | - |
| 129 | + |
119 | 130 | // Handle form submissions |
120 | | - if ( $wgRequest->wasPosted() ) { |
| 131 | + if ( $locationSubmitted ) { |
121 | 132 | $this->showList(); |
122 | 133 | } |
123 | 134 | |
124 | 135 | // End Banners tab content |
125 | | - $wgOut->addHTML( Xml::closeElement( 'div' ) ); |
| 136 | + $wgOut->addHTML( Html::closeElement( 'div' ) ); |
126 | 137 | } |
127 | | - |
| 138 | + |
128 | 139 | /** |
129 | 140 | * Show a list of banners with allocation. Newer banners are shown first. |
130 | 141 | */ |
131 | 142 | function showList() { |
132 | 143 | global $wgOut, $wgRequest; |
133 | | - |
| 144 | + |
134 | 145 | // Begin building HTML |
135 | 146 | $htmlOut = ''; |
136 | | - |
| 147 | + |
137 | 148 | // Begin Allocation list fieldset |
138 | | - $htmlOut .= Xml::openElement( 'fieldset', array( 'class' => 'prefsection' ) ); |
139 | | - |
| 149 | + $htmlOut .= Html::openElement( 'fieldset', array( 'class' => 'prefsection' ) ); |
| 150 | + |
140 | 151 | $bannerLister = new SpecialBannerListLoader(); |
141 | 152 | $bannerLister->project = $wgRequest->getVal( 'project' ); |
142 | 153 | $bannerLister->language = $wgRequest->getVal( 'language' ); |
— | — | @@ -156,70 +167,82 @@ |
157 | 168 | $accountBanners = array(); |
158 | 169 | $anonWeight = 0; |
159 | 170 | $accountWeight = 0; |
| 171 | + |
160 | 172 | if ( $banners ) { |
161 | 173 | foreach ( $banners as $banner ) { |
162 | 174 | if ($banner['display_anon']) { |
163 | 175 | $anonBanners[] = $banner; |
164 | 176 | $anonWeight += $banner['weight']; |
165 | 177 | } |
| 178 | + |
166 | 179 | if ($banner['display_account']) { |
167 | 180 | $accountBanners[] = $banner; |
168 | 181 | $accountWeight += $banner['weight']; |
169 | 182 | } |
170 | 183 | } |
| 184 | + |
171 | 185 | if ( $anonBanners ) { |
172 | 186 | $htmlOut .= $this->getTable( wfMsg ( 'centralnotice-banner-anonymous' ), $anonBanners, $anonWeight ); |
173 | 187 | } |
| 188 | + |
174 | 189 | if ( $accountBanners ) { |
175 | 190 | $htmlOut .= $this->getTable( wfMsg ( 'centralnotice-banner-logged-in' ), $accountBanners, $accountWeight ); |
176 | 191 | } |
177 | 192 | } else { |
178 | 193 | $htmlOut .= Xml::tags( 'p', null, wfMsg ( 'centralnotice-no-allocation' ) ); |
179 | 194 | } |
180 | | - |
| 195 | + |
181 | 196 | // End Allocation list fieldset |
182 | | - $htmlOut .= Xml::closeElement( 'fieldset' ); |
| 197 | + $htmlOut .= Html::closeElement( 'fieldset' ); |
183 | 198 | |
184 | 199 | $wgOut->addHTML( $htmlOut ); |
185 | 200 | } |
186 | | - |
| 201 | + |
187 | 202 | function getTable( $type, $banners, $weight ) { |
188 | 203 | global $wgUser, $wgLang; |
189 | | - |
| 204 | + |
190 | 205 | $sk = $wgUser->getSkin(); |
191 | 206 | $viewBanner = $this->getTitleFor( 'NoticeTemplate', 'view' ); |
192 | 207 | $viewCampaign = $this->getTitleFor( 'CentralNotice' ); |
193 | | - |
194 | | - $htmlOut = Xml::openElement( 'table', |
| 208 | + |
| 209 | + $htmlOut = Html::openElement( 'table', |
195 | 210 | array ( 'cellpadding' => 9, 'class' => 'wikitable sortable', 'style' => 'margin: 1em;' ) |
196 | 211 | ); |
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%' ), |
200 | 215 | wfMsg ( 'centralnotice-percentage' ) ); |
201 | | - $htmlOut .= Xml::element( 'th', array( 'width' => '30%' ), |
| 216 | + $htmlOut .= Html::element( 'th', array( 'width' => '30%' ), |
202 | 217 | wfMsg ( 'centralnotice-banner' ) ); |
203 | | - $htmlOut .= Xml::element( 'th', array( 'width' => '30%' ), |
| 218 | + $htmlOut .= Html::element( 'th', array( 'width' => '30%' ), |
204 | 219 | wfMsg ( 'centralnotice-notice' ) ); |
205 | | - $htmlOut .= Xml::closeElement( 'tr' ); |
| 220 | + $htmlOut .= Html::closeElement( 'tr' ); |
| 221 | + |
206 | 222 | 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 | + |
209 | 226 | $percentage = round( ( $banner['weight'] / $weight ) * 100, 2 ); |
| 227 | + |
210 | 228 | $htmlOut .= wfMsg ( 'percent', $wgLang->formatNum( $percentage ) ); |
211 | | - $htmlOut .= Xml::closeElement( 'td' ); |
| 229 | + $htmlOut .= Html::closeElement( 'td' ); |
212 | 230 | $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top' ), |
213 | | - $sk->makeLinkObj( $viewBanner, htmlspecialchars( $banner['name'] ), |
| 231 | + |
| 232 | + $sk->makeLinkObj( $viewBanner, htmlspecialchars( $banner['name'] ), |
214 | 233 | 'template=' . urlencode( $banner['name'] ) ) |
215 | 234 | ); |
| 235 | + |
216 | 236 | $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top' ), |
217 | | - $sk->makeLinkObj( $viewCampaign, htmlspecialchars( $banner['campaign'] ), |
| 237 | + |
| 238 | + $sk->makeLinkObj( $viewCampaign, htmlspecialchars( $banner['campaign'] ), |
218 | 239 | 'method=listNoticeDetail¬ice=' . urlencode( $banner['campaign'] ) ) |
219 | 240 | ); |
220 | | - $htmlOut .= Xml::closeElement( 'tr' ); |
| 241 | + |
| 242 | + $htmlOut .= Html::closeElement( 'tr' ); |
221 | 243 | } |
222 | | - $htmlOut .= Xml::closeElement( 'table' ); |
| 244 | + |
| 245 | + $htmlOut .= Html::closeElement( 'table' ); |
| 246 | + |
223 | 247 | return $htmlOut; |
224 | 248 | } |
225 | | - |
226 | 249 | } |
Property changes on: branches/wmf/1.18wmf1/extensions/CentralNotice/special/SpecialBannerAllocation.php |
___________________________________________________________________ |
Modified: svn:mergeinfo |
227 | 250 | Merged /trunk/extensions/CentralNotice/special/SpecialBannerAllocation.php:r95514-98901 |