r95514 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r95513‎ | r95514 | r95515 >
Date:20:44, 25 August 2011
Author:awjrichards
Status:ok
Tags:
Comment:
Modified paths:
  • /branches/wmf/1.17wmf1/extensions/CentralNotice/special/SpecialBannerAllocation.php (modified) (history)
  • /branches/wmf/1.17wmf1/extensions/CentralNotice/special/SpecialHideBanners.php (modified) (history)
  • /branches/wmf/1.17wmf1/extensions/CentralNotice/special/SpecialNoticeTemplate.php (modified) (history)

Diff [purge]

Index: branches/wmf/1.17wmf1/extensions/CentralNotice/special/SpecialBannerAllocation.php
@@ -128,12 +128,8 @@
129129 * Show a list of banners with allocation. Newer banners are shown first.
130130 */
131131 function showList() {
132 - global $wgOut, $wgUser, $wgRequest, $wgLang;
 132+ global $wgOut, $wgRequest;
133133
134 - $sk = $wgUser->getSkin();
135 - $viewBanner = $this->getTitleFor( 'NoticeTemplate', 'view' );
136 - $viewCampaign = $this->getTitleFor( 'CentralNotice' );
137 -
138134 // Begin building HTML
139135 $htmlOut = '';
140136
@@ -156,38 +152,27 @@
157153
158154 $bannerList = $bannerLister->getJsonList();
159155 $banners = FormatJson::decode( $bannerList, true );
160 - $totalWeight = 0;
161 - foreach ( $banners as $banner ) {
162 - $totalWeight += $banner['weight'];
163 - }
 156+ $anonBanners = array();
 157+ $accountBanners = array();
 158+ $anonWeight = 0;
 159+ $accountWeight = 0;
164160 if ( $banners ) {
165 - $htmlOut .= Xml::openElement( 'table',
166 - array ( 'cellpadding' => 9, 'class' => 'wikitable sortable' ) );
167 - $htmlOut .= Xml::openElement( 'tr' );
168 - $htmlOut .= Xml::element( 'th', array( 'width' => '20%' ),
169 - wfMsg ( 'centralnotice-percentage' ) );
170 - $htmlOut .= Xml::element( 'th', array( 'width' => '30%' ),
171 - wfMsg ( 'centralnotice-banner' ) );
172 - $htmlOut .= Xml::element( 'th', array( 'width' => '30%' ),
173 - wfMsg ( 'centralnotice-notice' ) );
174 - $htmlOut .= Xml::closeElement( 'tr' );
175161 foreach ( $banners as $banner ) {
176 - $htmlOut .= Xml::openElement( 'tr' );
177 - $htmlOut .= Xml::openElement( 'td' );
178 - $percentage = ( $banner['weight'] / $totalWeight ) * 100;
179 - $htmlOut .= wfMsg ( 'percent', $wgLang->formatNum( $percentage ) );
180 - $htmlOut .= Xml::closeElement( 'td' );
181 - $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top' ),
182 - $sk->makeLinkObj( $viewBanner, htmlspecialchars( $banner['name'] ),
183 - 'template=' . urlencode( $banner['name'] ) )
184 - );
185 - $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top' ),
186 - $sk->makeLinkObj( $viewCampaign, htmlspecialchars( $banner['campaign'] ),
187 - 'method=listNoticeDetail&notice=' . urlencode( $banner['campaign'] ) )
188 - );
189 - $htmlOut .= Xml::closeElement( 'tr' );
 162+ if ($banner['display_anon']) {
 163+ $anonBanners[] = $banner;
 164+ $anonWeight += $banner['weight'];
 165+ }
 166+ if ($banner['display_account']) {
 167+ $accountBanners[] = $banner;
 168+ $accountWeight += $banner['weight'];
 169+ }
190170 }
191 - $htmlOut .= Xml::closeElement( 'table' );
 171+ if ( $anonBanners ) {
 172+ $htmlOut .= $this->getTable( wfMsg ( 'centralnotice-banner-anonymous' ), $anonBanners, $anonWeight );
 173+ }
 174+ if ( $accountBanners ) {
 175+ $htmlOut .= $this->getTable( wfMsg ( 'centralnotice-banner-logged-in' ), $accountBanners, $accountWeight );
 176+ }
192177 } else {
193178 $htmlOut .= Xml::tags( 'p', null, wfMsg ( 'centralnotice-no-allocation' ) );
194179 }
@@ -197,5 +182,44 @@
198183
199184 $wgOut->addHTML( $htmlOut );
200185 }
 186+
 187+ function getTable( $type, $banners, $weight ) {
 188+ global $wgUser, $wgLang;
 189+
 190+ $sk = $wgUser->getSkin();
 191+ $viewBanner = $this->getTitleFor( 'NoticeTemplate', 'view' );
 192+ $viewCampaign = $this->getTitleFor( 'CentralNotice' );
 193+
 194+ $htmlOut = Xml::openElement( 'table',
 195+ array ( 'cellpadding' => 9, 'class' => 'wikitable sortable', 'style' => 'margin: 1em;' )
 196+ );
 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%' ),
 200+ wfMsg ( 'centralnotice-percentage' ) );
 201+ $htmlOut .= Xml::element( 'th', array( 'width' => '30%' ),
 202+ wfMsg ( 'centralnotice-banner' ) );
 203+ $htmlOut .= Xml::element( 'th', array( 'width' => '30%' ),
 204+ wfMsg ( 'centralnotice-notice' ) );
 205+ $htmlOut .= Xml::closeElement( 'tr' );
 206+ foreach ( $banners as $banner ) {
 207+ $htmlOut .= Xml::openElement( 'tr' );
 208+ $htmlOut .= Xml::openElement( 'td' );
 209+ $percentage = round( ( $banner['weight'] / $weight ) * 100, 2 );
 210+ $htmlOut .= wfMsg ( 'percent', $wgLang->formatNum( $percentage ) );
 211+ $htmlOut .= Xml::closeElement( 'td' );
 212+ $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top' ),
 213+ $sk->makeLinkObj( $viewBanner, htmlspecialchars( $banner['name'] ),
 214+ 'template=' . urlencode( $banner['name'] ) )
 215+ );
 216+ $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top' ),
 217+ $sk->makeLinkObj( $viewCampaign, htmlspecialchars( $banner['campaign'] ),
 218+ 'method=listNoticeDetail&notice=' . urlencode( $banner['campaign'] ) )
 219+ );
 220+ $htmlOut .= Xml::closeElement( 'tr' );
 221+ }
 222+ $htmlOut .= Xml::closeElement( 'table' );
 223+ return $htmlOut;
 224+ }
201225
202226 }
Property changes on: branches/wmf/1.17wmf1/extensions/CentralNotice/special/SpecialBannerAllocation.php
___________________________________________________________________
Added: svn:mergeinfo
203227 Merged /trunk/phase3/extensions/CentralNotice/special/SpecialBannerAllocation.php:r63545-63546,63549,63643,63764,63897-63901,64113,64509,65387,65391,65555,65590,65650,65816,77555,77558-77560,77563-77565,77573
204228 Merged /branches/wmf-deployment/extensions/CentralNotice/special/SpecialBannerAllocation.php:r60970
205229 Merged /branches/wmf/1.16wmf4/extensions/CentralNotice/special/SpecialBannerAllocation.php:r67177,69199,76243,77266
206230 Merged /trunk/extensions/CentralNotice/special/SpecialBannerAllocation.php:r62820-67552,67557,67559-71720,71725-71731,71734-71739,71748-71753,71774-71997,72058-72131,72136-73830,73847,73850,73852,73855,73959,73963,73973,73980,73983,73991,73994-73995,74000-74321,74325-74406,75376-75470,75567,75643,75646,75674,75680,75726,75849,75889,75908,75973,76141,76145,76333,76347,76351,76356-76358,76361,76363,76462,76543,76763,77622-79761,79780,79783-80145,80147-80148,80150,80152-80602,81461-83563,83565-95513
Index: branches/wmf/1.17wmf1/extensions/CentralNotice/special/SpecialNoticeTemplate.php
@@ -47,7 +47,7 @@
4848 CentralNotice::printHeader();
4949
5050 // Begin Banners tab content
51 - $wgOut->addHTML( Xml::openElement( 'div', array( 'id' => 'preferences' ) ) );
 51+ $wgOut->addHTML( Html::openElement( 'div', array( 'id' => 'preferences' ) ) );
5252
5353 $method = $wgRequest->getVal( 'wpMethod' );
5454
@@ -121,14 +121,14 @@
122122 if ( $sub == 'view' && $wgRequest->getVal( 'wpUserLanguage' ) == 'all' ) {
123123 $template = $wgRequest->getVal( 'template' );
124124 $this->showViewAvailable( $template );
125 - $wgOut->addHTML( Xml::closeElement( 'div' ) );
 125+ $wgOut->addHTML( Html::closeElement( 'div' ) );
126126 return;
127127 }
128128
129129 // Handle viewing a specific banner
130130 if ( $sub == 'view' && $wgRequest->getText( 'template' ) != '' ) {
131131 $this->showView();
132 - $wgOut->addHTML( Xml::closeElement( 'div' ) );
 132+ $wgOut->addHTML( Html::closeElement( 'div' ) );
133133 return;
134134 }
135135
@@ -136,7 +136,7 @@
137137 // Handle showing "Add a banner" interface
138138 if ( $sub == 'add' ) {
139139 $this->showAdd();
140 - $wgOut->addHTML( Xml::closeElement( 'div' ) );
 140+ $wgOut->addHTML( Html::closeElement( 'div' ) );
141141 return;
142142 }
143143
@@ -166,7 +166,7 @@
167167 $this->showList();
168168
169169 // End Banners tab content
170 - $wgOut->addHTML( Xml::closeElement( 'div' ) );
 170+ $wgOut->addHTML( Html::closeElement( 'div' ) );
171171 }
172172
173173 /**
@@ -182,15 +182,15 @@
183183 $htmlOut = '';
184184
185185 // Begin Manage Banners fieldset
186 - $htmlOut .= Xml::openElement( 'fieldset', array( 'class' => 'prefsection' ) );
 186+ $htmlOut .= Html::openElement( 'fieldset', array( 'class' => 'prefsection' ) );
187187
188188 if ( !$pager->getNumRows() ) {
189 - $htmlOut .= Xml::element( 'p', null, wfMsg( 'centralnotice-no-templates' ) );
 189+ $htmlOut .= Html::element( 'p', null, wfMsg( 'centralnotice-no-templates' ) );
190190 } else {
191191 if ( $this->editable ) {
192 - $htmlOut .= Xml::openElement( 'form', array( 'method' => 'post' ) );
 192+ $htmlOut .= Html::openElement( 'form', array( 'method' => 'post' ) );
193193 }
194 - $htmlOut .= Xml::element( 'h2', null, wfMsg( 'centralnotice-manage-templates' ) );
 194+ $htmlOut .= Html::element( 'h2', null, wfMsg( 'centralnotice-manage-templates' ) );
195195
196196 // Show paginated list of banners
197197 $htmlOut .= Xml::tags( 'div', array( 'class' => 'cn-pager' ),
@@ -200,18 +200,18 @@
201201 $pager->getNavigationBar() );
202202
203203 if ( $this->editable ) {
204 - $htmlOut .= Xml::closeElement( 'form' );
 204+ $htmlOut .= Html::closeElement( 'form' );
205205 }
206206 }
207207
208208 if ( $this->editable ) {
209 - $htmlOut .= Xml::element( 'p' );
 209+ $htmlOut .= Html::element( 'p' );
210210 $newPage = $this->getTitle( 'add' );
211211 $htmlOut .= $sk->makeLinkObj( $newPage, wfMsgHtml( 'centralnotice-add-template' ) );
212212 }
213213
214214 // End Manage Banners fieldset
215 - $htmlOut .= Xml::closeElement( 'fieldset' );
 215+ $htmlOut .= Html::closeElement( 'fieldset' );
216216
217217 $wgOut->addHTML( $htmlOut );
218218 }
@@ -226,10 +226,10 @@
227227
228228 // Build HTML
229229 $htmlOut = '';
230 - $htmlOut .= Xml::openElement( 'fieldset', array( 'class' => 'prefsection' ) );
231 - $htmlOut .= Xml::openElement( 'form',
 230+ $htmlOut .= Html::openElement( 'fieldset', array( 'class' => 'prefsection' ) );
 231+ $htmlOut .= Html::openElement( 'form',
232232 array( 'method' => 'post', 'onsubmit' => 'return validateBannerForm(this)' ) );
233 - $htmlOut .= Xml::element( 'h2', null, wfMsg( 'centralnotice-add-template' ) );
 233+ $htmlOut .= Html::element( 'h2', null, wfMsg( 'centralnotice-add-template' ) );
234234 $htmlOut .= Html::hidden( 'wpMethod', 'addTemplate' );
235235
236236 // If there was an error, we'll need to restore the state of the form
@@ -257,22 +257,22 @@
258258 );
259259
260260 // Display settings
261 - $htmlOut .= Xml::openElement( 'p', null );
 261+ $htmlOut .= Html::openElement( 'p', null );
262262 $htmlOut .= wfMsg( 'centralnotice-banner-display' );
263263 $htmlOut .= Xml::check( 'displayAnon', $displayAnon, array( 'id' => 'displayAnon' ) );
264264 $htmlOut .= Xml::label( wfMsg( 'centralnotice-banner-anonymous' ), 'displayAnon' );
265265 $htmlOut .= Xml::check( 'displayAccount', $displayAccount,
266266 array( 'id' => 'displayAccount' ) );
267267 $htmlOut .= Xml::label( wfMsg( 'centralnotice-banner-logged-in' ), 'displayAccount' );
268 - $htmlOut .= Xml::closeElement( 'p' );
 268+ $htmlOut .= Html::closeElement( 'p' );
269269
270270 // Fundraising settings
271271 if ( $wgNoticeEnableFundraising ) {
272 - $htmlOut .= Xml::openElement( 'p', null );
 272+ $htmlOut .= Html::openElement( 'p', null );
273273 $htmlOut .= Xml::check( 'fundraising', $fundraising, array( 'id' => 'fundraising' ) );
274274 $htmlOut .= Xml::label( wfMsg( 'centralnotice-banner-fundraising' ), 'fundraising' );
275 - $htmlOut .= Xml::closeElement( 'p' );
276 - $htmlOut .= Xml::openElement( 'div',
 275+ $htmlOut .= Html::closeElement( 'p' );
 276+ $htmlOut .= Html::openElement( 'div',
277277 array( 'id' => 'fundraisingInterface', 'style' => 'display: none;' ) );
278278 $htmlOut .= Xml::tags( 'p', array(), wfMsg( 'centralnotice-banner-fundraising-help' ) );
279279 $htmlOut .= Xml::tags( 'p', array(),
@@ -282,7 +282,7 @@
283283 array( 'maxlength' => 255 )
284284 )
285285 );
286 - $htmlOut .= Xml::closeElement( 'div' );
 286+ $htmlOut .= Html::closeElement( 'div' );
287287 }
288288
289289 // Begin banner body section
@@ -298,7 +298,7 @@
299299 );
300300
301301 $htmlOut .= Xml::textarea( 'templateBody', $body, 60, 20 );
302 - $htmlOut .= Xml::closeElement( 'fieldset' );
 302+ $htmlOut .= Html::closeElement( 'fieldset' );
303303 $htmlOut .= Html::hidden( 'authtoken', $wgUser->editToken() );
304304
305305 // Submit button
@@ -307,8 +307,8 @@
308308 Xml::submitButton( wfMsg( 'centralnotice-save-banner' ) )
309309 );
310310
311 - $htmlOut .= Xml::closeElement( 'form' );
312 - $htmlOut .= Xml::closeElement( 'fieldset' );
 311+ $htmlOut .= Html::closeElement( 'form' );
 312+ $htmlOut .= Html::closeElement( 'fieldset' );
313313
314314 // Output HTML
315315 $wgOut->addHTML( $htmlOut );
@@ -338,20 +338,9 @@
339339 // Get current banner
340340 $currentTemplate = $wgRequest->getText( 'template' );
341341
342 - // Pull banner settings from database
343 - $dbr = wfGetDB( DB_SLAVE );
344 - $row = $dbr->selectRow( 'cn_templates',
345 - array(
346 - 'tmp_display_anon',
347 - 'tmp_display_account',
348 - 'tmp_fundraising',
349 - 'tmp_landing_pages'
350 - ),
351 - array( 'tmp_name' => $currentTemplate ),
352 - __METHOD__
353 - );
 342+ $bannerSettings = CentralNoticeDB::getBannerSettings( $currentTemplate );
354343
355 - if ( !$row ) {
 344+ if ( !$bannerSettings ) {
356345 $this->showError( 'centralnotice-banner-doesnt-exist' );
357346 return;
358347 } else {
@@ -359,9 +348,9 @@
360349 $htmlOut = '';
361350
362351 // Begin View Banner fieldset
363 - $htmlOut .= Xml::openElement( 'fieldset', array( 'class' => 'prefsection' ) );
 352+ $htmlOut .= Html::openElement( 'fieldset', array( 'class' => 'prefsection' ) );
364353
365 - $htmlOut .= Xml::element( 'h2', null,
 354+ $htmlOut .= Html::element( 'h2', null,
366355 wfMsg( 'centralnotice-banner-heading', $currentTemplate ) );
367356
368357 // Show preview of banner
@@ -398,14 +387,14 @@
399388 // If there are any message fields in the banner, display translation tools.
400389 if ( count( $fields[0] ) > 0 ) {
401390 if ( $this->editable ) {
402 - $htmlOut .= Xml::openElement( 'form', array( 'method' => 'post' ) );
 391+ $htmlOut .= Html::openElement( 'form', array( 'method' => 'post' ) );
403392 }
404393 $htmlOut .= Xml::fieldset(
405394 wfMsg( 'centralnotice-translate-heading', $currentTemplate ),
406395 false,
407396 array( 'id' => 'mw-centralnotice-translations-for' )
408397 );
409 - $htmlOut .= Xml::openElement( 'table',
 398+ $htmlOut .= Html::openElement( 'table',
410399 array (
411400 'cellpadding' => 9,
412401 'width' => '100%'
@@ -413,14 +402,14 @@
414403 );
415404
416405 // Table headers
417 - $htmlOut .= Xml::element( 'th', array( 'width' => '15%' ),
 406+ $htmlOut .= Html::element( 'th', array( 'width' => '15%' ),
418407 wfMsg( 'centralnotice-message' ) );
419 - $htmlOut .= Xml::element( 'th', array( 'width' => '5%' ),
 408+ $htmlOut .= Html::element( 'th', array( 'width' => '5%' ),
420409 wfMsg ( 'centralnotice-number-uses' ) );
421 - $htmlOut .= Xml::element( 'th', array( 'width' => '40%' ),
 410+ $htmlOut .= Html::element( 'th', array( 'width' => '40%' ),
422411 wfMsg ( 'centralnotice-english' ) );
423412 $languages = Language::getLanguageNames();
424 - $htmlOut .= Xml::element( 'th', array( 'width' => '40%' ),
 413+ $htmlOut .= Html::element( 'th', array( 'width' => '40%' ),
425414 $languages[$wpUserLang] );
426415
427416 // Remove duplicate message fields
@@ -438,14 +427,14 @@
439428 : "Centralnotice-{$currentTemplate}-{$field}/{$wpUserLang}";
440429
441430 // English value
442 - $htmlOut .= Xml::openElement( 'tr' );
 431+ $htmlOut .= Html::openElement( 'tr' );
443432
444433 $title = Title::newFromText( "MediaWiki:{$message}" );
445434 $htmlOut .= Xml::tags( 'td', null,
446435 $sk->makeLinkObj( $title, htmlspecialchars( $field ) )
447436 );
448437
449 - $htmlOut .= Xml::element( 'td', null, $count );
 438+ $htmlOut .= Html::element( 'td', null, $count );
450439
451440 // English text
452441 $englishText = wfMsg( 'centralnotice-message-not-set' );
@@ -461,7 +450,7 @@
462451 $englishTextExists = true;
463452 }
464453 $htmlOut .= Xml::tags( 'td', null,
465 - Xml::element( 'span',
 454+ Html::element( 'span',
466455 array(
467456 'style' => 'font-style:italic;' .
468457 ( !$englishTextExists ? 'color:silver' : '' )
@@ -489,9 +478,9 @@
490479 ( !$foreignTextExists ? 'color:red' : '' ) ) )
491480 )
492481 );
493 - $htmlOut .= Xml::closeElement( 'tr' );
 482+ $htmlOut .= Html::closeElement( 'tr' );
494483 }
495 - $htmlOut .= Xml::closeElement( 'table' );
 484+ $htmlOut .= Html::closeElement( 'table' );
496485
497486 if ( $this->editable ) {
498487 $htmlOut .= Html::hidden( 'wpUserLanguage', $wpUserLang );
@@ -505,16 +494,19 @@
506495 );
507496 }
508497
509 - $htmlOut .= Xml::closeElement( 'fieldset' );
 498+ $htmlOut .= Html::closeElement( 'fieldset' );
510499
511500 if ( $this->editable ) {
512 - $htmlOut .= Xml::closeElement( 'form' );
 501+ $htmlOut .= Html::closeElement( 'form' );
513502 }
514503
515504 // Show language selection form
516 - $htmlOut .= Xml::openElement( 'form', array( 'method' => 'post' ) );
 505+ $actionTitle = $this->getTitleFor( 'NoticeTemplate', 'view' );
 506+ $actionUrl = $actionTitle->getLocalURL();
 507+ $htmlOut .= Html::openElement( 'form', array( 'method' => 'get', 'action' => $actionUrl ) );
517508 $htmlOut .= Xml::fieldset( wfMsg( 'centralnotice-change-lang' ) );
518 - $htmlOut .= Xml::openElement( 'table', array ( 'cellpadding' => 9 ) );
 509+ $htmlOut .= Html::hidden( 'template', $currentTemplate );
 510+ $htmlOut .= Html::openElement( 'table', array ( 'cellpadding' => 9 ) );
519511 list( $lsLabel, $lsSelect ) = Xml::languageSelector( $wpUserLang );
520512
521513 $newPage = $this->getTitle( 'view' );
@@ -535,15 +527,14 @@
536528 "template=$currentTemplate&wpUserLanguage=all" )
537529 )
538530 );
539 - $htmlOut .= Xml::closeElement( 'table' );
540 - $htmlOut .= Html::hidden( 'authtoken', $wgUser->editToken() );
541 - $htmlOut .= Xml::closeElement( 'fieldset' );
542 - $htmlOut .= Xml::closeElement( 'form' );
 531+ $htmlOut .= Html::closeElement( 'table' );
 532+ $htmlOut .= Html::closeElement( 'fieldset' );
 533+ $htmlOut .= Html::closeElement( 'form' );
543534 }
544535
545536 // Show edit form
546537 if ( $this->editable ) {
547 - $htmlOut .= Xml::openElement( 'form',
 538+ $htmlOut .= Html::openElement( 'form',
548539 array(
549540 'method' => 'post',
550541 'onsubmit' => 'return validateBannerForm(this)'
@@ -560,16 +551,16 @@
561552 $landingPages = $wgRequest->getVal( 'landingPages' );
562553 $body = $wgRequest->getVal( 'templateBody', $body );
563554 } else { // Use previously stored values
564 - $displayAnon = ( $row->tmp_display_anon == 1 );
565 - $displayAccount = ( $row->tmp_display_account == 1 );
566 - $fundraising = ( $row->tmp_fundraising == 1 );
567 - $landingPages = $row->tmp_landing_pages;
 555+ $displayAnon = ( $bannerSettings['anon'] == 1 );
 556+ $displayAccount = ( $bannerSettings['account'] == 1 );
 557+ $fundraising = ( $bannerSettings['fundraising'] == 1 );
 558+ $landingPages = $bannerSettings['landingpages'];
568559 // $body default is defined prior to message interface code
569560 }
570561
571562 // Show banner settings
572563 $htmlOut .= Xml::fieldset( wfMsg( 'centralnotice-settings' ) );
573 - $htmlOut .= Xml::openElement( 'p', null );
 564+ $htmlOut .= Html::openElement( 'p', null );
574565 $htmlOut .= wfMsg( 'centralnotice-banner-display' );
575566 $htmlOut .= Xml::check( 'displayAnon', $displayAnon,
576567 wfArrayMerge( $disabled, array( 'id' => 'displayAnon' ) ) );
@@ -577,20 +568,20 @@
578569 $htmlOut .= Xml::check( 'displayAccount', $displayAccount,
579570 wfArrayMerge( $disabled, array( 'id' => 'displayAccount' ) ) );
580571 $htmlOut .= Xml::label( wfMsg( 'centralnotice-banner-logged-in' ), 'displayAccount' );
581 - $htmlOut .= Xml::closeElement( 'p' );
 572+ $htmlOut .= Html::closeElement( 'p' );
582573
583574 // Fundraising settings
584575 if ( $wgNoticeEnableFundraising ) {
585 - $htmlOut .= Xml::openElement( 'p', null );
 576+ $htmlOut .= Html::openElement( 'p', null );
586577 $htmlOut .= Xml::check( 'fundraising', $fundraising,
587578 wfArrayMerge( $disabled, array( 'id' => 'fundraising' ) ) );
588579 $htmlOut .= Xml::label( wfMsg( 'centralnotice-banner-fundraising' ),
589580 'fundraising' );
590 - $htmlOut .= Xml::closeElement( 'p' );
 581+ $htmlOut .= Html::closeElement( 'p' );
591582 if ( $fundraising ) {
592 - $htmlOut .= Xml::openElement( 'div', array( 'id'=>'fundraisingInterface' ) );
 583+ $htmlOut .= Html::openElement( 'div', array( 'id'=>'fundraisingInterface' ) );
593584 } else {
594 - $htmlOut .= Xml::openElement( 'div',
 585+ $htmlOut .= Html::openElement( 'div',
595586 array( 'id'=>'fundraisingInterface', 'style'=>'display:none;' ) );
596587 }
597588 $htmlOut .= Xml::tags( 'p', array(),
@@ -602,11 +593,11 @@
603594 array( 'maxlength' => 255 )
604595 )
605596 );
606 - $htmlOut .= Xml::closeElement( 'div' );
 597+ $htmlOut .= Html::closeElement( 'div' );
607598 }
608599
609600 // Begin banner body section
610 - $htmlOut .= Xml::closeElement( 'fieldset' );
 601+ $htmlOut .= Html::closeElement( 'fieldset' );
611602 if ( $this->editable ) {
612603 $htmlOut .= Xml::fieldset( wfMsg( 'centralnotice-edit-template' ) );
613604 $htmlOut .= wfMsg( 'centralnotice-edit-template-summary' );
@@ -623,7 +614,7 @@
624615 $htmlOut .= Xml::fieldset( wfMsg( 'centralnotice-banner' ) );
625616 }
626617 $htmlOut .= Xml::textarea( 'templateBody', $body, 60, 20, $readonly );
627 - $htmlOut .= Xml::closeElement( 'fieldset' );
 618+ $htmlOut .= Html::closeElement( 'fieldset' );
628619 if ( $this->editable ) {
629620 // Indicate which form was submitted
630621 $htmlOut .= Html::hidden( 'mainform', 'true' );
@@ -632,12 +623,12 @@
633624 array( 'class' => 'cn-buttons' ),
634625 Xml::submitButton( wfMsg( 'centralnotice-save-banner' ) )
635626 );
636 - $htmlOut .= Xml::closeElement( 'form' );
 627+ $htmlOut .= Html::closeElement( 'form' );
637628 }
638629
639630 // Show clone form
640631 if ( $this->editable ) {
641 - $htmlOut .= Xml::openElement ( 'form',
 632+ $htmlOut .= Html::openElement ( 'form',
642633 array(
643634 'method' => 'post',
644635 'action' => $this->getTitle( 'clone' )->getLocalUrl()
@@ -645,8 +636,8 @@
646637 );
647638
648639 $htmlOut .= Xml::fieldset( wfMsg( 'centralnotice-clone-notice' ) );
649 - $htmlOut .= Xml::openElement( 'table', array( 'cellpadding' => 9 ) );
650 - $htmlOut .= Xml::openElement( 'tr' );
 640+ $htmlOut .= Html::openElement( 'table', array( 'cellpadding' => 9 ) );
 641+ $htmlOut .= Html::openElement( 'tr' );
651642 $htmlOut .= Xml::inputLabel(
652643 wfMsg( 'centralnotice-clone-name' ),
653644 'newTemplate', 'newTemplate', '25' );
@@ -655,15 +646,15 @@
656647 array ( 'id' => 'clone' ) );
657648 $htmlOut .= Html::hidden( 'oldTemplate', $currentTemplate );
658649
659 - $htmlOut .= Xml::closeElement( 'tr' );
660 - $htmlOut .= Xml::closeElement( 'table' );
 650+ $htmlOut .= Html::closeElement( 'tr' );
 651+ $htmlOut .= Html::closeElement( 'table' );
661652 $htmlOut .= Html::hidden( 'authtoken', $wgUser->editToken() );
662 - $htmlOut .= Xml::closeElement( 'fieldset' );
663 - $htmlOut .= Xml::closeElement( 'form' );
 653+ $htmlOut .= Html::closeElement( 'fieldset' );
 654+ $htmlOut .= Html::closeElement( 'form' );
664655 }
665656
666657 // End View Banner fieldset
667 - $htmlOut .= Xml::closeElement( 'fieldset' );
 658+ $htmlOut .= Html::closeElement( 'fieldset' );
668659
669660 // Output HTML
670661 $wgOut->addHTML( $htmlOut );
@@ -686,9 +677,9 @@
687678 $htmlOut = '';
688679
689680 // Begin View Banner fieldset
690 - $htmlOut .= Xml::openElement( 'fieldset', array( 'class' => 'prefsection' ) );
 681+ $htmlOut .= Html::openElement( 'fieldset', array( 'class' => 'prefsection' ) );
691682
692 - $htmlOut .= Xml::element( 'h2', null, wfMsg( 'centralnotice-banner-heading', $template ) );
 683+ $htmlOut .= Html::element( 'h2', null, wfMsg( 'centralnotice-banner-heading', $template ) );
693684
694685 foreach ( $langs as $lang ) {
695686 // Link and Preview all available translations
@@ -713,7 +704,7 @@
714705 }
715706
716707 // End View Banner fieldset
717 - $htmlOut .= Xml::closeElement( 'fieldset' );
 708+ $htmlOut .= Html::closeElement( 'fieldset' );
718709
719710 return $wgOut->addHtml( $htmlOut );
720711 }
@@ -730,7 +721,7 @@
731722 $article->doEdit( $translation, '', EDIT_FORCE_BOT );
732723 }
733724
734 - private function getTemplateId ( $templateName ) {
 725+ private static function getTemplateId ( $templateName ) {
735726 $dbr = wfGetDB( DB_SLAVE );
736727 $res = $dbr->select( 'cn_templates', 'tmp_id',
737728 array( 'tmp_name' => $templateName ),
@@ -743,9 +734,20 @@
744735 }
745736 return null;
746737 }
 738+
 739+ public static function getBannerName( $bannerId ) {
 740+ $dbr = wfGetDB( DB_MASTER );
 741+ if ( is_numeric( $bannerId ) ) {
 742+ $row = $dbr->selectRow( 'cn_templates', 'tmp_name', array( 'tmp_id' => $bannerId ) );
 743+ if ( $row ) {
 744+ return $row->tmp_name;
 745+ }
 746+ }
 747+ return null;
 748+ }
747749
748 - private function removeTemplate ( $name ) {
749 - $id = $this->getTemplateId( $name );
 750+ public function removeTemplate ( $name ) {
 751+ $id = SpecialNoticeTemplate::getTemplateId( $name );
750752 $dbr = wfGetDB( DB_SLAVE );
751753 $res = $dbr->select( 'cn_assignments', 'asn_id', array( 'tmp_id' => $id ), __METHOD__ );
752754
@@ -753,6 +755,9 @@
754756 $this->showError( 'centralnotice-template-still-bound' );
755757 return;
756758 } else {
 759+ // Log the removal of the banner
 760+ $this->logBannerChange( 'removed', $id );
 761+
757762 $dbw = wfGetDB( DB_MASTER );
758763 $dbw->begin();
759764 $dbw->delete( 'cn_templates',
@@ -770,13 +775,20 @@
771776
772777 /**
773778 * Create a new banner
 779+ * @param $name string name of banner
 780+ * @param $body string content of banner
 781+ * @param $displayAnon integer flag for display to anonymous users
 782+ * @param $displayAccount integer flag for display to logged in users
 783+ * @param $fundraising integer flag for fundraising banner (optional)
 784+ * @param $landingPages string list of landing pages (optional)
 785+ * @return true or false depending on whether banner was successfully added
774786 */
775 - private function addTemplate( $name, $body, $displayAnon, $displayAccount, $fundraising,
776 - $landingPages ) {
 787+ public function addTemplate( $name, $body, $displayAnon, $displayAccount, $fundraising = 0,
 788+ $landingPages = '' ) {
777789
778790 if ( $body == '' || $name == '' ) {
779791 $this->showError( 'centralnotice-null-string' );
780 - return;
 792+ return false;
781793 }
782794
783795 // Format name so there are only letters, numbers, and underscores
@@ -805,12 +817,24 @@
806818 ),
807819 __METHOD__
808820 );
 821+ $bannerId = $dbw->insertId();
809822
810823 // Perhaps these should move into the db as blobs instead of being stored as articles
811824 $article = new Article(
812825 Title::newFromText( "centralnotice-template-{$name}", NS_MEDIAWIKI )
813826 );
814827 $article->doEdit( $body, '', EDIT_FORCE_BOT );
 828+
 829+ // Log the creation of the banner
 830+ $beginSettings = array();
 831+ $endSettings = array(
 832+ 'anon' => $displayAnon,
 833+ 'account' => $displayAccount,
 834+ 'fundraising' => $fundraising,
 835+ 'landingpages' => $landingPages
 836+ );
 837+ $this->logBannerChange( 'created', $bannerId, $beginSettings, $endSettings );
 838+
815839 return true;
816840 }
817841 }
@@ -825,6 +849,8 @@
826850 $this->showError( 'centralnotice-null-string' );
827851 return;
828852 }
 853+
 854+ $initialBannerSettings = CentralNoticeDB::getBannerSettings( $name );
829855
830856 $dbr = wfGetDB( DB_SLAVE );
831857 $res = $dbr->select( 'cn_templates', 'tmp_name',
@@ -848,7 +874,27 @@
849875 $article = new Article(
850876 Title::newFromText( "centralnotice-template-{$name}", NS_MEDIAWIKI )
851877 );
 878+
 879+ $bodyPage = Title::newFromText(
 880+ "Centralnotice-template-{$name}", NS_MEDIAWIKI );
 881+ $curRev = Revision::newFromTitle( $bodyPage );
 882+ $oldbody = $curRev ? $curRev->getText() : '';
 883+
852884 $article->doEdit( $body, '', EDIT_FORCE_BOT );
 885+
 886+ $curRev = Revision::newFromTitle( $bodyPage );
 887+ $newbody = $curRev ? $curRev->getText() : '';
 888+
 889+ //test for body changes
 890+ $contentChanged = 0;
 891+ if ($newbody !== $oldbody){
 892+ $contentChanged = 1;
 893+ }
 894+
 895+ $bannerId = SpecialNoticeTemplate::getTemplateId( $name );
 896+ $finalBannerSettings = CentralNoticeDB::getBannerSettings( $name );
 897+ $this->logBannerChange( 'modified', $bannerId, $initialBannerSettings, $finalBannerSettings, $contentChanged);
 898+
853899 return;
854900 }
855901 }
@@ -960,5 +1006,42 @@
9611007 $wgOut->wrapWikiMsg( "<div class='cn-error'>\n$1\n</div>", $message );
9621008 $this->centralNoticeError = true;
9631009 }
 1010+
 1011+ /**
 1012+ * Log setting changes related to a banner
 1013+ * @param $action string: 'created', 'modified', or 'removed'
 1014+ * @param $bannerId integer: ID of banner
 1015+ * @param $beginSettings array of banner settings before changes (optional)
 1016+ * @param $endSettings array of banner settings after changes (optional)
 1017+ * @param $beginContent banner content before changes (optional)
 1018+ * @param $endContent banner content after changes (optional)
 1019+ */
 1020+ function logBannerChange( $action, $bannerId, $beginSettings = array(),
 1021+ $endSettings = array(), $contentChanged = 0 )
 1022+ {
 1023+ global $wgUser;
 1024+
 1025+ $dbw = wfGetDB( DB_MASTER );
 1026+
 1027+ $log = array(
 1028+ 'tmplog_timestamp' => $dbw->timestamp(),
 1029+ 'tmplog_user_id' => $wgUser->getId(),
 1030+ 'tmplog_action' => $action,
 1031+ 'tmplog_template_id' => $bannerId,
 1032+ 'tmplog_template_name' => SpecialNoticeTemplate::getBannerName( $bannerId ),
 1033+ 'tmplog_content_change' => $contentChanged
 1034+ );
 1035+
 1036+ foreach ( $beginSettings as $key => $value ) {
 1037+ $log['tmplog_begin_'.$key] = $value;
 1038+ }
 1039+ foreach ( $endSettings as $key => $value ) {
 1040+ $log['tmplog_end_'.$key] = $value;
 1041+ }
 1042+
 1043+ $res = $dbw->insert( 'cn_template_log', $log );
 1044+ $log_id = $dbw->insertId();
 1045+ return $log_id;
 1046+ }
9641047
9651048 }
Property changes on: branches/wmf/1.17wmf1/extensions/CentralNotice/special/SpecialNoticeTemplate.php
___________________________________________________________________
Added: svn:mergeinfo
9661049 Merged /trunk/extensions/CentralNotice/special/SpecialNoticeTemplate.php:r62820-67552,67557,67559-71720,71725-71731,71734-71739,71748-71753,71774-71997,72058-72131,72136-73830,73847,73850,73852,73855,73959,73963,73973,73980,73983,73991,73994-73995,74000-74321,74325-74406,75376-75470,75567,75643,75646,75674,75680,75726,75849,75889,75908,75973,76141,76145,76333,76347,76351,76356-76358,76361,76363,76462,76543,76763,77622-79761,79780,79783-80145,80147-80148,80150,80152-80602,81461-83563,83565-95513
9671050 Merged /trunk/phase3/extensions/CentralNotice/special/SpecialNoticeTemplate.php:r63545-63546,63549,63643,63764,63897-63901,64113,64509,65387,65391,65555,65590,65650,65816,77555,77558-77560,77563-77565,77573
9681051 Merged /branches/wmf-deployment/extensions/CentralNotice/special/SpecialNoticeTemplate.php:r60970
9691052 Merged /branches/wmf/1.16wmf4/extensions/CentralNotice/special/SpecialNoticeTemplate.php:r67177,69199,76243,77266
Index: branches/wmf/1.17wmf1/extensions/CentralNotice/special/SpecialHideBanners.php
@@ -25,7 +25,7 @@
2626 header( 'Content-Type: image/png' );
2727 header( 'Cache-Control: no-cache' );
2828
29 - readfile( dirname( __FILE__ ) . '/1x1.png' );
 29+ readfile( dirname( __FILE__ ) . '/../1x1.png' );
3030 }
3131
3232 function setHideCookie() {
@@ -36,7 +36,7 @@
3737 } else {
3838 $cookieDomain = $wgNoticeCookieDomain;
3939 }
40 - // Hide banners for this domain
41 - setcookie( 'hidesnmessage', '1', $exp, '/', $cookieDomain, $wgCookieSecure );
 40+ // Hide fundraising banners for this domain
 41+ setcookie( 'centralnotice_fundraising', 'hide', $exp, '/', $cookieDomain, $wgCookieSecure );
4242 }
4343 }
Property changes on: branches/wmf/1.17wmf1/extensions/CentralNotice/special/SpecialHideBanners.php
___________________________________________________________________
Added: svn:mergeinfo
4444 Merged /branches/wmf/1.16wmf4/extensions/CentralNotice/special/SpecialHideBanners.php:r67177,69199,76243,77266
4545 Merged /trunk/extensions/CentralNotice/special/SpecialHideBanners.php:r62820-67552,67557,67559-71720,71725-71731,71734-71739,71748-71753,71774-71997,72058-72131,72136-73830,73847,73850,73852,73855,73959,73963,73973,73980,73983,73991,73994-73995,74000-74321,74325-74406,75376-75470,75567,75643,75646,75674,75680,75726,75849,75889,75908,75973,76141,76145,76333,76347,76351,76356-76358,76361,76363,76462,76543,76763,77622-79761,79780,79783-80145,80147-80148,80150,80152-80602,81461-83563,83565-95513
4646 Merged /trunk/phase3/extensions/CentralNotice/special/SpecialHideBanners.php:r63545-63546,63549,63643,63764,63897-63901,64113,64509,65387,65391,65555,65590,65650,65816,77555,77558-77560,77563-77565,77573
4747 Merged /branches/wmf-deployment/extensions/CentralNotice/special/SpecialHideBanners.php:r60970

Follow-up revisions

RevisionCommit summaryAuthorDate
r95515MFT r92768 - r95514awjrichards20:46, 25 August 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r92768MFT r92767, switching db reads from slave -> master for concurrency issuesawjrichards18:50, 21 July 2011
r95513Localisation updates for core and extension messages from translatewiki.netraymond20:41, 25 August 2011

Status & tagging log