r102477 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r102476‎ | r102477 | r102478 >
Date:01:42, 9 November 2011
Author:awjrichards
Status:ok
Tags:
Comment:
Modified paths:
  • /branches/wmf/1.18wmf1/extensions/CentralNotice/CentralNotice.db.php (modified) (history)
  • /branches/wmf/1.18wmf1/extensions/CentralNotice/CentralNotice.php (modified) (history)
  • /branches/wmf/1.18wmf1/extensions/CentralNotice/patches/patch-template_autolink.sql (modified) (history)
  • /branches/wmf/1.18wmf1/extensions/CentralNotice/special/SpecialBannerController.php (modified) (history)
  • /branches/wmf/1.18wmf1/extensions/CentralNotice/special/SpecialCentralNotice.php (modified) (history)

Diff [purge]

Index: branches/wmf/1.18wmf1/extensions/CentralNotice/special/SpecialBannerController.php
@@ -191,7 +191,7 @@
192192 }
193193 function setBannerHidingCookie( bannerType ) {
194194 var e = new Date();
195 - e.setTime( e.getTime() + (7*24*60*60*1000) ); // one week
 195+ e.setTime( e.getTime() + (14*24*60*60*1000) ); // two weeks
196196 var work='centralnotice_'+bannerType+'=hide; expires=' + e.toGMTString() + '; path=/';
197197 document.cookie = work;
198198 }
Property changes on: branches/wmf/1.18wmf1/extensions/CentralNotice/special/SpecialBannerController.php
___________________________________________________________________
Modified: svn:mergeinfo
199199 Merged /trunk/extensions/CentralNotice/special/SpecialBannerController.php:r100100-102469
Index: branches/wmf/1.18wmf1/extensions/CentralNotice/special/SpecialCentralNotice.php
@@ -7,12 +7,12 @@
88
99 class CentralNotice extends SpecialPage {
1010 var $editable, $centralNoticeError;
11 -
 11+
1212 function __construct() {
1313 // Register special page
1414 parent::__construct( 'CentralNotice' );
1515 }
16 -
 16+
1717 /**
1818 * Handle different types of page requests
1919 */
@@ -22,24 +22,24 @@
2323 // Begin output
2424 $this->setHeaders();
2525 $this->outputHeader();
26 -
 26+
2727 // Output ResourceLoader module for styling and javascript functions
2828 $wgOut->addModules( 'ext.centralNotice.interface' );
29 -
 29+
3030 // Check permissions
3131 $this->editable = $wgUser->isAllowed( 'centralnotice-admin' );
32 -
 32+
3333 // Initialize error variable
3434 $this->centralNoticeError = false;
3535
3636 // Show header
3737 $this->printHeader( $sub );
38 -
 38+
3939 // Begin Campaigns tab content
4040 $wgOut->addHTML( Xml::openElement( 'div', array( 'id' => 'preferences' ) ) );
41 -
 41+
4242 $method = $wgRequest->getVal( 'method' );
43 -
 43+
4444 // Switch to campaign detail interface if requested
4545 if ( $method == 'listNoticeDetail' ) {
4646 $notice = $wgRequest->getVal ( 'notice' );
@@ -47,16 +47,16 @@
4848 $wgOut->addHTML( Xml::closeElement( 'div' ) );
4949 return;
5050 }
51 -
 51+
5252 // Handle form submissions from "Manage campaigns" or "Add a campaign" interface
5353 if ( $this->editable && $wgRequest->wasPosted() ) {
54 -
 54+
5555 // Check authentication token
5656 if ( $wgUser->matchEditToken( $wgRequest->getVal( 'authtoken' ) ) ) {
57 -
 57+
5858 // Handle adding a campaign
5959 if ( $method == 'addCampaign' ) {
60 -
 60+
6161 $noticeName = $wgRequest->getVal( 'noticeName' );
6262 $start = $wgRequest->getArray( 'start' );
6363 $projects = $wgRequest->getArray( 'projects' );
@@ -69,10 +69,10 @@
7070 $this->addCampaign( $noticeName, '0', $start, $projects,
7171 $project_languages, $geotargeted, $geo_countries );
7272 }
73 -
 73+
7474 // Handle changing settings to existing campaigns
7575 } else {
76 -
 76+
7777 // Handle removing campaigns
7878 $toRemove = $wgRequest->getArray( 'removeCampaigns' );
7979 if ( $toRemove ) {
@@ -81,20 +81,20 @@
8282 $this->removeCampaign( $notice );
8383 }
8484 }
85 -
 85+
8686 // Get all the initial campaign settings for logging
8787 $allCampaignNames = $this->getAllCampaignNames();
8888 $allInitialCampaignSettings = array();
8989 foreach ( $allCampaignNames as $campaignName ) {
9090 $allInitialCampaignSettings[$campaignName] = CentralNoticeDB::getCampaignSettings( $campaignName, false );
9191 }
92 -
 92+
9393 // Handle locking/unlocking campaigns
9494 $lockedNotices = $wgRequest->getArray( 'locked' );
9595 if ( $lockedNotices ) {
9696 // Build list of campaigns to lock
9797 $unlockedNotices = array_diff( $this->getAllCampaignNames(), $lockedNotices );
98 -
 98+
9999 // Set locked/unlocked flag accordingly
100100 foreach ( $lockedNotices as $notice ) {
101101 $this->setBooleanCampaignSetting( $notice, 'locked', 1 );
@@ -109,13 +109,13 @@
110110 $this->setBooleanCampaignSetting( $notice, 'locked', 0 );
111111 }
112112 }
113 -
 113+
114114 // Handle enabling/disabling campaigns
115115 $enabledNotices = $wgRequest->getArray( 'enabled' );
116116 if ( $enabledNotices ) {
117117 // Build list of campaigns to disable
118118 $disabledNotices = array_diff( $this->getAllCampaignNames(), $enabledNotices );
119 -
 119+
120120 // Set enabled/disabled flag accordingly
121121 foreach ( $enabledNotices as $notice ) {
122122 $this->setBooleanCampaignSetting( $notice, 'enabled', 1 );
@@ -130,13 +130,13 @@
131131 $this->setBooleanCampaignSetting( $notice, 'enabled', 0 );
132132 }
133133 }
134 -
 134+
135135 // Handle setting preferred campaigns
136136 $preferredNotices = $wgRequest->getArray( 'preferred' );
137137 if ( $preferredNotices ) {
138 - // Build list of campaigns to unset
 138+ // Build list of campaigns to unset
139139 $unsetNotices = array_diff( $this->getAllCampaignNames(), $preferredNotices );
140 -
 140+
141141 // Set flag accordingly
142142 foreach ( $preferredNotices as $notice ) {
143143 $this->setBooleanCampaignSetting( $notice, 'preferred', 1 );
@@ -151,7 +151,7 @@
152152 $this->setBooleanCampaignSetting( $notice, 'preferred', 0 );
153153 }
154154 }
155 -
 155+
156156 // Get all the final campaign settings for potential logging
157157 foreach ( $allCampaignNames as $campaignName ) {
158158 $finalCampaignSettings = CentralNoticeDB::getCampaignSettings( $campaignName, false );
@@ -163,13 +163,13 @@
164164 }
165165 }
166166 }
167 -
 167+
168168 // If there were no errors, reload the page to prevent duplicate form submission
169169 if ( !$this->centralNoticeError ) {
170170 $wgOut->redirect( $this->getTitle()->getLocalUrl() );
171171 return;
172172 }
173 -
 173+
174174 } else {
175175 $this->showError( 'sessionfailure' );
176176 }
@@ -178,7 +178,7 @@
179179
180180 // Show list of campaigns
181181 $this->listNotices();
182 -
 182+
183183 // End Campaigns tab content
184184 $wgOut->addHTML( Xml::closeElement( 'div' ) );
185185 }
@@ -241,28 +241,28 @@
242242 if ( $editable ) {
243243 $dateRanges = CentralNotice::getDateRanges();
244244
245 - // Normalize timestamp format. If no timestamp is passed, default to now. If -1 is
 245+ // Normalize timestamp format. If no timestamp is passed, default to now. If -1 is
246246 // passed, set no defaults.
247247 if ( $timestamp === -1 ) {
248248 $ts = '00000000';
249249 } else {
250250 $ts = wfTimestamp( TS_MW, $timestamp );
251251 }
252 -
 252+
253253 $fields = array(
254254 array( "month", "centralnotice-month", $dateRanges['months'], substr( $ts, 4, 2 ) ),
255255 array( "day", "centralnotice-day", $dateRanges['days'], substr( $ts, 6, 2 ) ),
256256 array( "year", "centralnotice-year", $dateRanges['years'], substr( $ts, 0, 4 ) ),
257257 );
258 -
 258+
259259 return CentralNotice::createSelector( $prefix, $fields );
260260 } else {
261261 global $wgLang;
262262 return $wgLang->date( $timestamp );
263263 }
264264 }
265 -
266 - /*
 265+
 266+ /**
267267 * Get date ranges for use in date selectors
268268 * @return array of ranges for months, days, and years (padded with zeros)
269269 */
@@ -278,15 +278,15 @@
279279 if ( $editable ) {
280280 $minutes = CentralNotice::paddedRange( 0, 59 );
281281 $hours = CentralNotice::paddedRange( 0 , 23 );
282 -
 282+
283283 // Normalize timestamp format...
284284 $ts = wfTimestamp( TS_MW, $timestamp );
285 -
 285+
286286 $fields = array(
287287 array( "hour", "centralnotice-hours", $hours, substr( $ts, 8, 2 ) ),
288288 array( "min", "centralnotice-min", $minutes, substr( $ts, 10, 2 ) ),
289289 );
290 -
 290+
291291 return CentralNotice::createSelector( $prefix, $fields );
292292 } else {
293293 global $wgLang;
@@ -298,7 +298,7 @@
299299 * Build a set of select lists. Used by dateSelector and timeSelector.
300300 * @param $prefix string to identify selector set, for example, 'start' or 'end'
301301 * @param $fields array of select lists to build
302 - */
 302+ */
303303 public static function createSelector( $prefix, $fields ) {
304304 $out = '';
305305 foreach ( $fields as $data ) {
@@ -340,20 +340,20 @@
341341 __METHOD__,
342342 array( 'ORDER BY' => 'not_id DESC' )
343343 );
344 -
 344+
345345 // Begin building HTML
346346 $htmlOut = '';
347 -
 347+
348348 // Begin Manage campaigns fieldset
349349 $htmlOut .= Xml::openElement( 'fieldset', array( 'class' => 'prefsection' ) );
350 -
 350+
351351 // If there are campaigns to show...
352352 if ( $dbr->numRows( $res ) >= 1 ) {
353353 if ( $this->editable ) {
354354 $htmlOut .= Xml::openElement( 'form', array( 'method' => 'post' ) );
355355 }
356356 $htmlOut .= Xml::element( 'h2', null, wfMsg( 'centralnotice-manage' ) );
357 -
 357+
358358 // Begin table of campaigns
359359 $htmlOut .= Xml::openElement( 'table',
360360 array(
@@ -362,7 +362,7 @@
363363 'class' => 'wikitable sortable'
364364 )
365365 );
366 -
 366+
367367 // Table headers
368368 $headers = array(
369369 wfMsgHtml( 'centralnotice-notice-name' ),
@@ -378,7 +378,7 @@
379379 $headers[] = wfMsgHtml( 'centralnotice-remove' );
380380 }
381381 $htmlOut .= $this->tableRow( $headers, 'th' );
382 -
 382+
383383 // Table rows
384384 foreach ( $res as $row ) {
385385 $fields = array();
@@ -464,21 +464,21 @@
465465 $fields[] = Xml::check( 'removeCampaigns[]', false,
466466 array( 'value' => $row->not_name, 'class' => 'noshiftselect' ) );
467467 }
468 -
 468+
469469 // If campaign is currently active, set special class on table row.
470470 $attribs = array();
471 - if ( wfTimestamp() > wfTimestamp( TS_UNIX , $row->not_start )
472 - && wfTimestamp() < wfTimestamp( TS_UNIX , $row->not_end )
473 - && $row->not_enabled == '1' )
 471+ if ( wfTimestamp() > wfTimestamp( TS_UNIX , $row->not_start )
 472+ && wfTimestamp() < wfTimestamp( TS_UNIX , $row->not_end )
 473+ && $row->not_enabled == '1' )
474474 {
475475 $attribs = array( 'class' => 'cn-active-campaign' );
476476 }
477 -
 477+
478478 $htmlOut .= $this->tableRow( $fields, 'td', $attribs );
479479 }
480480 // End table of campaigns
481481 $htmlOut .= Xml::closeElement( 'table' );
482 -
 482+
483483 if ( $this->editable ) {
484484 $htmlOut .= Html::hidden( 'authtoken', $wgUser->editToken() );
485485 $htmlOut .= Xml::openElement( 'div', array( 'class' => 'cn-buttons' ) );
@@ -496,12 +496,12 @@
497497 } else {
498498 $htmlOut .= wfMsg( 'centralnotice-no-notices-exist' );
499499 }
500 -
 500+
501501 // End Manage Campaigns fieldset
502502 $htmlOut .= Xml::closeElement( 'fieldset' );
503503
504504 if ( $this->editable ) {
505 -
 505+
506506 // If there was an error, we'll need to restore the state of the form
507507 if ( $wgRequest->wasPosted() && ( $wgRequest->getVal( 'method' ) == 'addCampaign' ) ) {
508508 $startArray = $wgRequest->getArray( 'start' );
@@ -518,22 +518,22 @@
519519 $noticeProjects = array();
520520 $noticeLanguages = array();
521521 }
522 -
 522+
523523 // Begin Add a campaign fieldset
524524 $htmlOut .= Xml::openElement( 'fieldset', array( 'class' => 'prefsection' ) );
525 -
 525+
526526 // Form for adding a campaign
527527 $htmlOut .= Xml::openElement( 'form', array( 'method' => 'post' ) );
528528 $htmlOut .= Xml::element( 'h2', null, wfMsg( 'centralnotice-add-notice' ) );
529529 $htmlOut .= Html::hidden( 'title', $this->getTitle()->getPrefixedText() );
530530 $htmlOut .= Html::hidden( 'method', 'addCampaign' );
531 -
 531+
532532 $htmlOut .= Xml::openElement( 'table', array ( 'cellpadding' => 9 ) );
533 -
 533+
534534 // Name
535535 $htmlOut .= Xml::openElement( 'tr' );
536536 $htmlOut .= Xml::tags( 'td', array(), wfMsgHtml( 'centralnotice-notice-name' ) );
537 - $htmlOut .= Xml::tags( 'td', array(),
 537+ $htmlOut .= Xml::tags( 'td', array(),
538538 Xml::input( 'noticeName', 25, $wgRequest->getVal( 'noticeName' ) ) );
539539 $htmlOut .= Xml::closeElement( 'tr' );
540540 // Start Date
@@ -554,42 +554,42 @@
555555 $htmlOut .= Xml::closeElement( 'tr' );
556556 // Languages
557557 $htmlOut .= Xml::openElement( 'tr' );
558 - $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top' ),
 558+ $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top' ),
559559 wfMsgHtml( 'centralnotice-languages' ) );
560 - $htmlOut .= Xml::tags( 'td', array(),
 560+ $htmlOut .= Xml::tags( 'td', array(),
561561 $this->languageMultiSelector( $noticeLanguages ) );
562562 $htmlOut .= Xml::closeElement( 'tr' );
563563 // Countries
564564 $htmlOut .= Xml::openElement( 'tr' );
565 - $htmlOut .= Xml::tags( 'td', array(),
 565+ $htmlOut .= Xml::tags( 'td', array(),
566566 Xml::label( wfMsg( 'centralnotice-geo' ), 'geotargeted' ) );
567 - $htmlOut .= Xml::tags( 'td', array(),
568 - Xml::check( 'geotargeted', false,
 567+ $htmlOut .= Xml::tags( 'td', array(),
 568+ Xml::check( 'geotargeted', false,
569569 wfArrayMerge( $readonly, array( 'value' => 1, 'id' => 'geotargeted' ) ) ) );
570570 $htmlOut .= Xml::closeElement( 'tr' );
571 - $htmlOut .= Xml::openElement( 'tr',
 571+ $htmlOut .= Xml::openElement( 'tr',
572572 array( 'id'=>'geoMultiSelector', 'style'=>'display:none;' ) );
573 - $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top' ),
 573+ $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top' ),
574574 wfMsgHtml( 'centralnotice-countries' ) );
575575 $htmlOut .= Xml::tags( 'td', array(), $this->geoMultiSelector() );
576576 $htmlOut .= Xml::closeElement( 'tr' );
577 -
 577+
578578 $htmlOut .= Xml::closeElement( 'table' );
579579 $htmlOut .= Html::hidden( 'change', 'weight' );
580580 $htmlOut .= Html::hidden( 'authtoken', $wgUser->editToken() );
581 -
 581+
582582 // Submit button
583 - $htmlOut .= Xml::tags( 'div',
584 - array( 'class' => 'cn-buttons' ),
585 - Xml::submitButton( wfMsg( 'centralnotice-modify' ) )
 583+ $htmlOut .= Xml::tags( 'div',
 584+ array( 'class' => 'cn-buttons' ),
 585+ Xml::submitButton( wfMsg( 'centralnotice-modify' ) )
586586 );
587 -
 587+
588588 $htmlOut .= Xml::closeElement( 'form' );
589 -
 589+
590590 // End Add a campaign fieldset
591591 $htmlOut .= Xml::closeElement( 'fieldset' );
592592 }
593 -
 593+
594594 // Output HTML
595595 $wgOut->addHTML( $htmlOut );
596596 }
@@ -600,7 +600,7 @@
601601 */
602602 function listNoticeDetail( $notice ) {
603603 global $wgOut, $wgRequest, $wgUser;
604 -
 604+
605605 // Make sure notice exists
606606 if ( !CentralNoticeDB::campaignExists( $notice ) ) {
607607 $this->showError( 'centralnotice-notice-doesnt-exist' );
@@ -608,10 +608,10 @@
609609
610610 // Handle form submissions from campaign detail interface
611611 if ( $this->editable && $wgRequest->wasPosted() ) {
612 -
 612+
613613 // Check authentication token
614614 if ( $wgUser->matchEditToken( $wgRequest->getVal( 'authtoken' ) ) ) {
615 -
 615+
616616 // Handle removing campaign
617617 if ( $wgRequest->getVal( 'remove' ) ) {
618618 $this->removeCampaign( $notice );
@@ -621,30 +621,30 @@
622622 return;
623623 }
624624 }
625 -
 625+
626626 $initialCampaignSettings = CentralNoticeDB::getCampaignSettings( $notice );
627 -
 627+
628628 // Handle locking/unlocking campaign
629629 if ( $wgRequest->getCheck( 'locked' ) ) {
630630 $this->setBooleanCampaignSetting( $notice, 'locked', 1 );
631631 } else {
632632 $this->setBooleanCampaignSetting( $notice, 'locked', 0 );
633633 }
634 -
 634+
635635 // Handle enabling/disabling campaign
636636 if ( $wgRequest->getCheck( 'enabled' ) ) {
637637 $this->setBooleanCampaignSetting( $notice, 'enabled', 1 );
638638 } else {
639639 $this->setBooleanCampaignSetting( $notice, 'enabled', 0 );
640640 }
641 -
 641+
642642 // Handle setting campaign to preferred/not preferred
643643 if ( $wgRequest->getCheck( 'preferred' ) ) {
644644 $this->setBooleanCampaignSetting( $notice, 'preferred', 1 );
645645 } else {
646646 $this->setBooleanCampaignSetting( $notice, 'preferred', 0 );
647647 }
648 -
 648+
649649 // Handle updating geotargeting
650650 if ( $wgRequest->getCheck( 'geotargeted' ) ) {
651651 $this->setBooleanCampaignSetting( $notice, 'geo', 1 );
@@ -655,7 +655,7 @@
656656 } else {
657657 $this->setBooleanCampaignSetting( $notice, 'geo', 0 );
658658 }
659 -
 659+
660660 // Handle updating the start and end settings
661661 $start = $wgRequest->getArray( 'start' );
662662 $end = $wgRequest->getArray( 'end' );
@@ -674,10 +674,10 @@
675675 $end['hour'],
676676 $end['min']
677677 );
678 -
 678+
679679 $this->updateNoticeDate( $notice, $updatedStart, $updatedEnd );
680680 }
681 -
 681+
682682 // Handle adding of banners to the campaign
683683 $templatesToAdd = $wgRequest->getArray( 'addTemplates' );
684684 if ( $templatesToAdd ) {
@@ -687,7 +687,7 @@
688688 $this->addTemplateTo( $notice, $templateName, $weight[$templateId] );
689689 }
690690 }
691 -
 691+
692692 // Handle removing of banners from the campaign
693693 $templateToRemove = $wgRequest->getArray( 'removeTemplates' );
694694 if ( $templateToRemove ) {
@@ -695,7 +695,7 @@
696696 $this->removeTemplateFor( $notice, $template );
697697 }
698698 }
699 -
 699+
700700 // Handle weight changes
701701 $updatedWeights = $wgRequest->getArray( 'weight' );
702702 if ( $updatedWeights ) {
@@ -703,56 +703,56 @@
704704 $this->updateWeight( $notice, $templateId, $weight );
705705 }
706706 }
707 -
 707+
708708 // Handle new projects
709709 $projects = $wgRequest->getArray( 'projects' );
710710 if ( $projects ) {
711711 $this->updateProjects( $notice, $projects );
712712 }
713 -
 713+
714714 // Handle new project languages
715715 $projectLangs = $wgRequest->getArray( 'project_languages' );
716716 if ( $projectLangs ) {
717717 $this->updateProjectLanguages( $notice, $projectLangs );
718718 }
719 -
 719+
720720 $finalCampaignSettings = CentralNoticeDB::getCampaignSettings( $notice );
721721 $campaignId = CentralNotice::getNoticeId( $notice );
722722 $this->logCampaignChange( 'modified', $campaignId, $initialCampaignSettings, $finalCampaignSettings );
723 -
 723+
724724 // If there were no errors, reload the page to prevent duplicate form submission
725725 if ( !$this->centralNoticeError ) {
726 - $wgOut->redirect( $this->getTitle()->getLocalUrl(
 726+ $wgOut->redirect( $this->getTitle()->getLocalUrl(
727727 "method=listNoticeDetail&notice=$notice" ) );
728728 return;
729729 }
730730 } else {
731731 $this->showError( 'sessionfailure' );
732732 }
733 -
 733+
734734 }
735 -
 735+
736736 $htmlOut = '';
737 -
 737+
738738 // Begin Campaign detail fieldset
739739 $htmlOut .= Xml::openElement( 'fieldset', array( 'class' => 'prefsection' ) );
740 -
 740+
741741 if ( $this->editable ) {
742742 $htmlOut .= Xml::openElement( 'form',
743743 array(
744744 'method' => 'post',
745 - 'action' => $this->getTitle()->getLocalUrl(
 745+ 'action' => $this->getTitle()->getLocalUrl(
746746 "method=listNoticeDetail&notice=$notice" )
747747 )
748748 );
749749 }
750 -
 750+
751751 $output_detail = $this->noticeDetailForm( $notice );
752752 $output_assigned = $this->assignedTemplatesForm( $notice );
753753 $output_templates = $this->addTemplatesForm( $notice );
754 -
 754+
755755 $htmlOut .= $output_detail;
756 -
 756+
757757 // Catch for no banners so that we don't double message
758758 if ( $output_assigned == '' && $output_templates == '' ) {
759759 $htmlOut .= wfMsg( 'centralnotice-no-templates' );
@@ -776,14 +776,14 @@
777777 }
778778 if ( $this->editable ) {
779779 $htmlOut .= Html::hidden( 'authtoken', $wgUser->editToken() );
780 -
 780+
781781 // Submit button
782 - $htmlOut .= Xml::tags( 'div',
783 - array( 'class' => 'cn-buttons' ),
784 - Xml::submitButton( wfMsg( 'centralnotice-modify' ) )
 782+ $htmlOut .= Xml::tags( 'div',
 783+ array( 'class' => 'cn-buttons' ),
 784+ Xml::submitButton( wfMsg( 'centralnotice-modify' ) )
785785 );
786786 }
787 -
 787+
788788 if ( $this->editable ) {
789789 $htmlOut .= Xml::closeElement( 'form' );
790790 }
@@ -791,23 +791,23 @@
792792 $wgOut->addHTML( $htmlOut );
793793 }
794794 }
795 -
 795+
796796 /**
797797 * Create form for managing campaign settings (start date, end date, languages, etc.)
798798 */
799799 function noticeDetailForm( $notice ) {
800800 global $wgRequest;
801 -
 801+
802802 if ( $this->editable ) {
803803 $readonly = array();
804804 } else {
805805 $readonly = array( 'disabled' => 'disabled' );
806806 }
807 -
 807+
808808 $campaign = CentralNoticeDB::getCampaignSettings( $notice );
809 -
 809+
810810 if ( $campaign ) {
811 -
 811+
812812 // If there was an error, we'll need to restore the state of the form
813813 if ( $wgRequest->wasPosted() ) {
814814 $startArray = $wgRequest->getArray( 'start' );
@@ -842,7 +842,7 @@
843843 $isGeotargeted = ( $campaign['geo'] == '1' );
844844 $countries = CentralNotice::getNoticeCountries( $notice );
845845 }
846 -
 846+
847847 // Build Html
848848 $htmlOut = '';
849849 $htmlOut .= Xml::tags( 'h2', null, wfMsg( 'centralnotice-notice-heading', $notice ) );
@@ -871,72 +871,72 @@
872872 $htmlOut .= Xml::closeElement( 'tr' );
873873 // Project
874874 $htmlOut .= Xml::openElement( 'tr' );
875 - $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top' ),
 875+ $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top' ),
876876 wfMsgHtml( 'centralnotice-projects' ) );
877 - $htmlOut .= Xml::tags( 'td', array(),
 877+ $htmlOut .= Xml::tags( 'td', array(),
878878 $this->projectMultiSelector( $noticeProjects ) );
879879 $htmlOut .= Xml::closeElement( 'tr' );
880880 // Languages
881881 $htmlOut .= Xml::openElement( 'tr' );
882 - $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top' ),
 882+ $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top' ),
883883 wfMsgHtml( 'centralnotice-languages' ) );
884 - $htmlOut .= Xml::tags( 'td', array(),
 884+ $htmlOut .= Xml::tags( 'td', array(),
885885 $this->languageMultiSelector( $noticeLanguages ) );
886886 $htmlOut .= Xml::closeElement( 'tr' );
887887 // Countries
888888 $htmlOut .= Xml::openElement( 'tr' );
889 - $htmlOut .= Xml::tags( 'td', array(),
 889+ $htmlOut .= Xml::tags( 'td', array(),
890890 Xml::label( wfMsg( 'centralnotice-geo' ), 'geotargeted' ) );
891 - $htmlOut .= Xml::tags( 'td', array(),
892 - Xml::check( 'geotargeted', $isGeotargeted,
893 - wfArrayMerge(
894 - $readonly,
 891+ $htmlOut .= Xml::tags( 'td', array(),
 892+ Xml::check( 'geotargeted', $isGeotargeted,
 893+ wfArrayMerge(
 894+ $readonly,
895895 array( 'value' => $notice, 'id' => 'geotargeted' ) ) ) );
896896 $htmlOut .= Xml::closeElement( 'tr' );
897897 if ( $isGeotargeted ) {
898898 $htmlOut .= Xml::openElement( 'tr', array( 'id'=>'geoMultiSelector' ) );
899899 } else {
900 - $htmlOut .= Xml::openElement( 'tr',
 900+ $htmlOut .= Xml::openElement( 'tr',
901901 array( 'id'=>'geoMultiSelector', 'style'=>'display:none;' ) );
902902 }
903 - $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top' ),
 903+ $htmlOut .= Xml::tags( 'td', array( 'valign' => 'top' ),
904904 wfMsgHtml( 'centralnotice-countries' ) );
905905 $htmlOut .= Xml::tags( 'td', array(), $this->geoMultiSelector( $countries ) );
906906 $htmlOut .= Xml::closeElement( 'tr' );
907907 // Enabled
908908 $htmlOut .= Xml::openElement( 'tr' );
909 - $htmlOut .= Xml::tags( 'td', array(),
 909+ $htmlOut .= Xml::tags( 'td', array(),
910910 Xml::label( wfMsg( 'centralnotice-enabled' ), 'enabled' ) );
911 - $htmlOut .= Xml::tags( 'td', array(),
912 - Xml::check( 'enabled', $isEnabled,
913 - wfArrayMerge( $readonly,
 911+ $htmlOut .= Xml::tags( 'td', array(),
 912+ Xml::check( 'enabled', $isEnabled,
 913+ wfArrayMerge( $readonly,
914914 array( 'value' => $notice, 'id' => 'enabled' ) ) ) );
915915 $htmlOut .= Xml::closeElement( 'tr' );
916916 // Preferred
917917 $htmlOut .= Xml::openElement( 'tr' );
918 - $htmlOut .= Xml::tags( 'td', array(),
 918+ $htmlOut .= Xml::tags( 'td', array(),
919919 Xml::label( wfMsg( 'centralnotice-preferred' ), 'preferred' ) );
920 - $htmlOut .= Xml::tags( 'td', array(),
921 - Xml::check( 'preferred', $isPreferred,
922 - wfArrayMerge( $readonly,
 920+ $htmlOut .= Xml::tags( 'td', array(),
 921+ Xml::check( 'preferred', $isPreferred,
 922+ wfArrayMerge( $readonly,
923923 array( 'value' => $notice, 'id' => 'preferred' ) ) ) );
924924 $htmlOut .= Xml::closeElement( 'tr' );
925925 // Locked
926926 $htmlOut .= Xml::openElement( 'tr' );
927 - $htmlOut .= Xml::tags( 'td', array(),
 927+ $htmlOut .= Xml::tags( 'td', array(),
928928 Xml::label( wfMsg( 'centralnotice-locked' ), 'locked' ) );
929 - $htmlOut .= Xml::tags( 'td', array(),
930 - Xml::check( 'locked', $isLocked,
931 - wfArrayMerge( $readonly,
 929+ $htmlOut .= Xml::tags( 'td', array(),
 930+ Xml::check( 'locked', $isLocked,
 931+ wfArrayMerge( $readonly,
932932 array( 'value' => $notice, 'id' => 'locked' ) ) ) );
933933 $htmlOut .= Xml::closeElement( 'tr' );
934934 if ( $this->editable ) {
935935 // Locked
936936 $htmlOut .= Xml::openElement( 'tr' );
937 - $htmlOut .= Xml::tags( 'td', array(),
 937+ $htmlOut .= Xml::tags( 'td', array(),
938938 Xml::label( wfMsg( 'centralnotice-remove' ), 'remove' ) );
939 - $htmlOut .= Xml::tags( 'td', array(),
940 - Xml::check( 'remove', false,
 939+ $htmlOut .= Xml::tags( 'td', array(),
 940+ Xml::check( 'remove', false,
941941 array( 'value' => $notice, 'id' => 'remove' ) ) );
942942 $htmlOut .= Xml::closeElement( 'tr' );
943943 }
@@ -1022,7 +1022,7 @@
10231023 $render->siteName = 'Wikipedia';
10241024 global $wgRequest;
10251025 $render->language = $wgRequest->getVal( 'wpUserLanguage' );
1026 - try {
 1026+ try {
10271027 $preview = $render->getHtmlNotice( $row->tmp_name );
10281028 } catch ( SpecialBannerLoaderException $e ) {
10291029 $preview = wfMsg( 'centralnotice-nopreview' );
@@ -1044,7 +1044,7 @@
10451045 return $htmlOut;
10461046
10471047 }
1048 -
 1048+
10491049 function weightDropDown( $name, $selected ) {
10501050 if ( $this->editable ) {
10511051 return Xml::listDropDown( $name,
@@ -1066,20 +1066,20 @@
10671067 $pager = new CentralNoticePager( $this );
10681068 $dbr = wfGetDB( DB_SLAVE );
10691069 $res = $dbr->select( 'cn_templates', 'tmp_name', '', '', array( 'ORDER BY' => 'tmp_id' ) );
1070 -
 1070+
10711071 if ( $dbr->numRows( $res ) > 0 ) {
10721072 // Build HTML
10731073 $htmlOut = Xml::fieldset( wfMsg( "centralnotice-available-templates" ) );
1074 -
 1074+
10751075 // Show paginated list of banners
1076 - $htmlOut .= Xml::tags( 'div',
1077 - array( 'class' => 'cn-pager' ),
 1076+ $htmlOut .= Xml::tags( 'div',
 1077+ array( 'class' => 'cn-pager' ),
10781078 $pager->getNavigationBar() );
10791079 $htmlOut .= $pager->getBody();
1080 - $htmlOut .= Xml::tags( 'div',
1081 - array( 'class' => 'cn-pager' ),
 1080+ $htmlOut .= Xml::tags( 'div',
 1081+ array( 'class' => 'cn-pager' ),
10821082 $pager->getNavigationBar() );
1083 -
 1083+
10841084 $htmlOut .= Xml::closeElement( 'fieldset' );
10851085 } else {
10861086 // Nothing found
@@ -1099,8 +1099,8 @@
11001100 * @param $geo_countries array: Targeted countries
11011101 * @return true or null
11021102 */
1103 - function addCampaign( $noticeName, $enabled, $start, $projects,
1104 - $project_languages, $geotargeted, $geo_countries )
 1103+ function addCampaign( $noticeName, $enabled, $start, $projects,
 1104+ $project_languages, $geotargeted, $geo_countries )
11051105 {
11061106 if ( CentralNoticeDB::campaignExists( $noticeName ) ) {
11071107 $this->showError( 'centralnotice-notice-exists' );
@@ -1124,14 +1124,14 @@
11251125 $end['month'] = '10';
11261126 $end['year'] = $start['year'];
11271127 } else {
1128 - $end['month'] =
1129 - ( substr( $start['month'], 0, 1 ) ) == 0
1130 - ? 0 . ( intval( $start['month'] ) + 1 )
 1128+ $end['month'] =
 1129+ ( substr( $start['month'], 0, 1 ) ) == 0
 1130+ ? 0 . ( intval( $start['month'] ) + 1 )
11311131 : ( $start['month'] + 1 );
11321132 $end['year'] = $start['year'];
11331133 }
11341134
1135 - $startTs = wfTimeStamp( TS_MW, "{$start['year']}:{$start['month']}:{$start['day']} " .
 1135+ $startTs = wfTimeStamp( TS_MW, "{$start['year']}:{$start['month']}:{$start['day']} " .
11361136 "{$start['hour']}:{$start['min']}:00" );
11371137 $endTs = wfTimeStamp( TS_MW, "{$end['year']}:{$end['month']}:{$start['day']} " .
11381138 "{$start['hour']}:{$start['min']}:00" );
@@ -1145,37 +1145,37 @@
11461146 )
11471147 );
11481148 $not_id = $dbw->insertId();
1149 -
 1149+
11501150 if ( $not_id ) {
1151 -
 1151+
11521152 // Do multi-row insert for campaign projects
11531153 $insertArray = array();
11541154 foreach( $projects as $project ) {
11551155 $insertArray[] = array( 'np_notice_id' => $not_id, 'np_project' => $project );
11561156 }
1157 - $res = $dbw->insert( 'cn_notice_projects', $insertArray,
 1157+ $res = $dbw->insert( 'cn_notice_projects', $insertArray,
11581158 __METHOD__, array( 'IGNORE' ) );
1159 -
 1159+
11601160 // Do multi-row insert for campaign languages
11611161 $insertArray = array();
11621162 foreach( $project_languages as $code ) {
11631163 $insertArray[] = array( 'nl_notice_id' => $not_id, 'nl_language' => $code );
11641164 }
1165 - $res = $dbw->insert( 'cn_notice_languages', $insertArray,
 1165+ $res = $dbw->insert( 'cn_notice_languages', $insertArray,
11661166 __METHOD__, array( 'IGNORE' ) );
1167 -
 1167+
11681168 if ( $geotargeted ) {
11691169 // Do multi-row insert for campaign countries
11701170 $insertArray = array();
11711171 foreach( $geo_countries as $code ) {
11721172 $insertArray[] = array( 'nc_notice_id' => $not_id, 'nc_country' => $code );
11731173 }
1174 - $res = $dbw->insert( 'cn_notice_countries', $insertArray,
 1174+ $res = $dbw->insert( 'cn_notice_countries', $insertArray,
11751175 __METHOD__, array( 'IGNORE' ) );
11761176 }
1177 -
 1177+
11781178 $dbw->commit();
1179 -
 1179+
11801180 // Log the creation of the campaign
11811181 $beginSettings = array();
11821182 $endSettings = array(
@@ -1190,9 +1190,9 @@
11911191 'geo' => $geotargeted
11921192 );
11931193 $this->logCampaignChange( 'created', $not_id, $beginSettings, $endSettings );
1194 -
 1194+
11951195 return true;
1196 -
 1196+
11971197 } else {
11981198 return null;
11991199 }
@@ -1222,7 +1222,7 @@
12231223 // Log the removal of the campaign
12241224 $campaignId = CentralNotice::getNoticeId( $campaignName );
12251225 $this->logCampaignChange( 'removed', $campaignId );
1226 -
 1226+
12271227 $dbw = wfGetDB( DB_MASTER );
12281228 $dbw->begin();
12291229 $res = $dbw->delete( 'cn_assignments', array ( 'not_id' => $campaignId ) );
@@ -1231,7 +1231,7 @@
12321232 $res = $dbw->delete( 'cn_notice_projects', array ( 'np_notice_id' => $campaignId ) );
12331233 $res = $dbw->delete( 'cn_notice_countries', array ( 'nc_notice_id' => $campaignId ) );
12341234 $dbw->commit();
1235 -
 1235+
12361236 return true;
12371237 }
12381238 }
@@ -1281,8 +1281,8 @@
12821282 return null;
12831283 }
12841284 }
1285 -
1286 - /*
 1285+
 1286+ /**
12871287 * Lookup the name of a campaign based on the campaign ID
12881288 */
12891289 public static function getNoticeName( $noticeId ) {
@@ -1296,7 +1296,7 @@
12971297 }
12981298 return null;
12991299 }
1300 -
 1300+
13011301 static function getNoticeProjects( $noticeName ) {
13021302 // Read from the master database to avoid concurrency problems
13031303 $dbr = wfGetDB( DB_MASTER );
@@ -1304,7 +1304,7 @@
13051305 $row = $dbr->selectRow( 'cn_notices', 'not_id', array( 'not_name' => $eNoticeName ) );
13061306 $projects = array();
13071307 if ( $row ) {
1308 - $res = $dbr->select( 'cn_notice_projects', 'np_project',
 1308+ $res = $dbr->select( 'cn_notice_projects', 'np_project',
13091309 array( 'np_notice_id' => $row->not_id ) );
13101310 foreach ( $res as $projectRow ) {
13111311 $projects[] = $projectRow->np_project;
@@ -1320,7 +1320,7 @@
13211321 $row = $dbr->selectRow( 'cn_notices', 'not_id', array( 'not_name' => $eNoticeName ) );
13221322 $languages = array();
13231323 if ( $row ) {
1324 - $res = $dbr->select( 'cn_notice_languages', 'nl_language',
 1324+ $res = $dbr->select( 'cn_notice_languages', 'nl_language',
13251325 array( 'nl_notice_id' => $row->not_id ) );
13261326 foreach ( $res as $langRow ) {
13271327 $languages[] = $langRow->nl_language;
@@ -1328,7 +1328,7 @@
13291329 }
13301330 return $languages;
13311331 }
1332 -
 1332+
13331333 static function getNoticeCountries( $noticeName ) {
13341334 // Read from the master database to avoid concurrency problems
13351335 $dbr = wfGetDB( DB_MASTER );
@@ -1336,7 +1336,7 @@
13371337 $row = $dbr->selectRow( 'cn_notices', 'not_id', array( 'not_name' => $eNoticeName ) );
13381338 $countries = array();
13391339 if ( $row ) {
1340 - $res = $dbr->select( 'cn_notice_countries', 'nc_country',
 1340+ $res = $dbr->select( 'cn_notice_countries', 'nc_country',
13411341 array( 'nc_notice_id' => $row->not_id ) );
13421342 foreach ( $res as $countryRow ) {
13431343 $countries[] = $countryRow->nc_country;
@@ -1393,7 +1393,7 @@
13941394 array( 'not_name' => $noticeName )
13951395 );
13961396 }
1397 -
 1397+
13981398 /**
13991399 * Update a boolean setting on a campaign
14001400 * @param $noticeName string: Name of the campaign
@@ -1437,7 +1437,7 @@
14381438 $scriptPath = "$wgExtensionAssetsPath/CentralNotice";
14391439 if ( is_callable( array( 'LanguageNames', 'getNames' ) ) ) {
14401440 // Retrieve the list of languages in user's language (via CLDR)
1441 - $languages = LanguageNames::getNames(
 1441+ $languages = LanguageNames::getNames(
14421442 $wgLang->getCode(), // User's language
14431443 LanguageNames::FALLBACK_NORMAL, // Use fallback chain
14441444 LanguageNames::LIST_MW // Pull all languages that are in Names.php
@@ -1446,7 +1446,7 @@
14471447 // Use this as fallback if CLDR extension is not enabled
14481448 $languages = Language::getLanguageNames();
14491449 }
1450 - // Make sure the site language is in the list; a custom language code
 1450+ // Make sure the site language is in the list; a custom language code
14511451 // might not have a defined name...
14521452 if( !array_key_exists( $wgLanguageCode, $languages ) ) {
14531453 $languages[$wgLanguageCode] = $wgLanguageCode;
@@ -1468,32 +1468,32 @@
14691469 $options
14701470 );
14711471 $buttons = array();
1472 - $buttons[] = '<a href="#" onclick="selectLanguages(true);return false;">' .
 1472+ $buttons[] = '<a href="#" onclick="selectLanguages(true);return false;">' .
14731473 wfMsg( 'powersearch-toggleall' ) . '</a>';
1474 - $buttons[] = '<a href="#" onclick="selectLanguages(false);return false;">' .
 1474+ $buttons[] = '<a href="#" onclick="selectLanguages(false);return false;">' .
14751475 wfMsg( 'powersearch-togglenone' ) . '</a>';
1476 - $buttons[] = '<a href="#" onclick="top10Languages();return false;">' .
 1476+ $buttons[] = '<a href="#" onclick="top10Languages();return false;">' .
14771477 wfMsg( 'centralnotice-top-ten-languages' ) . '</a>';
14781478 $htmlOut .= Xml::tags( 'div',
14791479 array( 'style' => 'margin-top: 0.2em;' ),
1480 - '<img src="'.$scriptPath.'/up-arrow.png" style="vertical-align:baseline;"/>' .
 1480+ '<img src="'.$scriptPath.'/up-arrow.png" style="vertical-align:baseline;"/>' .
14811481 wfMsg( 'centralnotice-select', $wgLang->commaList( $buttons ) )
14821482 );
14831483 } else {
14841484 $htmlOut .= Xml::tags( 'select',
1485 - array(
1486 - 'multiple' => 'multiple',
1487 - 'size' => 4,
1488 - 'id' => 'project_languages[]',
1489 - 'name' => 'project_languages[]',
1490 - 'disabled' => 'disabled'
 1485+ array(
 1486+ 'multiple' => 'multiple',
 1487+ 'size' => 4,
 1488+ 'id' => 'project_languages[]',
 1489+ 'name' => 'project_languages[]',
 1490+ 'disabled' => 'disabled'
14911491 ),
14921492 $options
14931493 );
14941494 }
14951495 return $htmlOut;
14961496 }
1497 -
 1497+
14981498 /**
14991499 * Generates a multiple select list of all project types.
15001500 * @param $selected The name of the selected project type
@@ -1502,7 +1502,7 @@
15031503 function projectMultiSelector( $selected = array() ) {
15041504 global $wgNoticeProjects, $wgExtensionAssetsPath, $wgLang;
15051505 $scriptPath = "$wgExtensionAssetsPath/CentralNotice";
1506 -
 1506+
15071507 $options = "\n";
15081508 foreach( $wgNoticeProjects as $project ) {
15091509 $options .= Xml::option(
@@ -1518,30 +1518,30 @@
15191519 $options
15201520 );
15211521 $buttons = array();
1522 - $buttons[] = '<a href="#" onclick="selectProjects(true);return false;">' .
 1522+ $buttons[] = '<a href="#" onclick="selectProjects(true);return false;">' .
15231523 wfMsg( 'powersearch-toggleall' ) . '</a>';
1524 - $buttons[] = '<a href="#" onclick="selectProjects(false);return false;">' .
 1524+ $buttons[] = '<a href="#" onclick="selectProjects(false);return false;">' .
15251525 wfMsg( 'powersearch-togglenone' ) . '</a>';
15261526 $htmlOut .= Xml::tags( 'div',
15271527 array( 'style' => 'margin-top: 0.2em;' ),
1528 - '<img src="'.$scriptPath.'/up-arrow.png" style="vertical-align:baseline;"/>' .
 1528+ '<img src="'.$scriptPath.'/up-arrow.png" style="vertical-align:baseline;"/>' .
15291529 wfMsg( 'centralnotice-select', $wgLang->commaList( $buttons ) )
15301530 );
15311531 } else {
15321532 $htmlOut .= Xml::tags( 'select',
1533 - array(
1534 - 'multiple' => 'multiple',
1535 - 'size' => 4,
1536 - 'id' => 'projects[]',
1537 - 'name' => 'projects[]',
1538 - 'disabled' => 'disabled'
 1533+ array(
 1534+ 'multiple' => 'multiple',
 1535+ 'size' => 4,
 1536+ 'id' => 'projects[]',
 1537+ 'name' => 'projects[]',
 1538+ 'disabled' => 'disabled'
15391539 ),
15401540 $options
15411541 );
15421542 }
15431543 return $htmlOut;
15441544 }
1545 -
 1545+
15461546 function getProjectName( $value ) {
15471547 return $value; // @fixme -- use wfMsg()
15481548 }
@@ -1555,17 +1555,17 @@
15561556 )
15571557 );
15581558 }
1559 -
 1559+
15601560 function updateProjects( $notice, $newProjects ) {
15611561 $dbw = wfGetDB( DB_MASTER );
15621562 $dbw->begin();
1563 -
 1563+
15641564 // Get the previously assigned projects
15651565 $oldProjects = CentralNotice::getNoticeProjects( $notice );
1566 -
 1566+
15671567 // Get the notice id
15681568 $row = $dbw->selectRow( 'cn_notices', 'not_id', array( 'not_name' => $notice ) );
1569 -
 1569+
15701570 // Add newly assigned projects
15711571 $addProjects = array_diff( $newProjects, $oldProjects );
15721572 $insertArray = array();
@@ -1573,7 +1573,7 @@
15741574 $insertArray[] = array( 'np_notice_id' => $row->not_id, 'np_project' => $project );
15751575 }
15761576 $res = $dbw->insert( 'cn_notice_projects', $insertArray, __METHOD__, array( 'IGNORE' ) );
1577 -
 1577+
15781578 // Remove disassociated projects
15791579 $removeProjects = array_diff( $oldProjects, $newProjects );
15801580 if ( $removeProjects ) {
@@ -1581,20 +1581,20 @@
15821582 array( 'np_notice_id' => $row->not_id, 'np_project' => $removeProjects )
15831583 );
15841584 }
1585 -
 1585+
15861586 $dbw->commit();
15871587 }
15881588
15891589 function updateProjectLanguages( $notice, $newLanguages ) {
15901590 $dbw = wfGetDB( DB_MASTER );
15911591 $dbw->begin();
1592 -
 1592+
15931593 // Get the previously assigned languages
15941594 $oldLanguages = CentralNotice::getNoticeLanguages( $notice );
1595 -
 1595+
15961596 // Get the notice id
15971597 $row = $dbw->selectRow( 'cn_notices', 'not_id', array( 'not_name' => $notice ) );
1598 -
 1598+
15991599 // Add newly assigned languages
16001600 $addLanguages = array_diff( $newLanguages, $oldLanguages );
16011601 $insertArray = array();
@@ -1602,7 +1602,7 @@
16031603 $insertArray[] = array( 'nl_notice_id' => $row->not_id, 'nl_language' => $code );
16041604 }
16051605 $res = $dbw->insert( 'cn_notice_languages', $insertArray, __METHOD__, array( 'IGNORE' ) );
1606 -
 1606+
16071607 // Remove disassociated languages
16081608 $removeLanguages = array_diff( $oldLanguages, $newLanguages );
16091609 if ( $removeLanguages ) {
@@ -1610,19 +1610,19 @@
16111611 array( 'nl_notice_id' => $row->not_id, 'nl_language' => $removeLanguages )
16121612 );
16131613 }
1614 -
 1614+
16151615 $dbw->commit();
16161616 }
1617 -
 1617+
16181618 function updateCountries( $notice, $newCountries ) {
16191619 $dbw = wfGetDB( DB_MASTER );
1620 -
 1620+
16211621 // Get the previously assigned languages
16221622 $oldCountries = CentralNotice::getNoticeCountries( $notice );
1623 -
 1623+
16241624 // Get the notice id
16251625 $row = $dbw->selectRow( 'cn_notices', 'not_id', array( 'not_name' => $notice ) );
1626 -
 1626+
16271627 // Add newly assigned countries
16281628 $addCountries = array_diff( $newCountries, $oldCountries );
16291629 $insertArray = array();
@@ -1630,7 +1630,7 @@
16311631 $insertArray[] = array( 'nc_notice_id' => $row->not_id, 'nc_country' => $code );
16321632 }
16331633 $res = $dbw->insert( 'cn_notice_countries', $insertArray, __METHOD__, array( 'IGNORE' ) );
1634 -
 1634+
16351635 // Remove disassociated countries
16361636 $removeCountries = array_diff( $oldCountries, $newCountries );
16371637 if ( $removeCountries ) {
@@ -1639,7 +1639,7 @@
16401640 );
16411641 }
16421642 }
1643 -
 1643+
16441644 public static function dropDownList( $text, $values ) {
16451645 $dropDown = "*{$text}\n";
16461646 foreach ( $values as $value ) {
@@ -1647,7 +1647,7 @@
16481648 }
16491649 return $dropDown;
16501650 }
1651 -
 1651+
16521652 public static function paddedRange( $begin, $end ) {
16531653 $unpaddedRange = range( $begin, $end );
16541654 $paddedRange = array();
@@ -1662,7 +1662,7 @@
16631663 $wgOut->wrapWikiMsg( "<div class='cn-error'>\n$1\n</div>", $message );
16641664 $this->centralNoticeError = true;
16651665 }
1666 -
 1666+
16671667 /**
16681668 * Generates a multiple select list of all countries.
16691669 * @param $selected The country codes of the selected countries
@@ -1681,29 +1681,29 @@
16821682 $htmlOut = '';
16831683 if ( $this->editable ) {
16841684 $htmlOut .= Xml::tags( 'select',
1685 - array(
1686 - 'multiple' => 'multiple',
1687 - 'size' => 5,
1688 - 'id' => 'geo_countries[]',
1689 - 'name' => 'geo_countries[]'
 1685+ array(
 1686+ 'multiple' => 'multiple',
 1687+ 'size' => 5,
 1688+ 'id' => 'geo_countries[]',
 1689+ 'name' => 'geo_countries[]'
16901690 ),
16911691 $options
16921692 );
16931693 } else {
16941694 $htmlOut .= Xml::tags( 'select',
1695 - array(
1696 - 'multiple' => 'multiple',
1697 - 'size' => 5,
1698 - 'id' => 'geo_countries[]',
1699 - 'name' => 'geo_countries[]',
1700 - 'disabled' => 'disabled'
 1695+ array(
 1696+ 'multiple' => 'multiple',
 1697+ 'size' => 5,
 1698+ 'id' => 'geo_countries[]',
 1699+ 'name' => 'geo_countries[]',
 1700+ 'disabled' => 'disabled'
17011701 ),
17021702 $options
17031703 );
17041704 }
17051705 return $htmlOut;
17061706 }
1707 -
 1707+
17081708 /**
17091709 * Log any changes related to a campaign
17101710 * @param $action string: 'created', 'modified', or 'removed'
@@ -1714,16 +1714,16 @@
17151715 * @param $endAssignments array of banner assignments after changes (optional)
17161716 * @return integer: ID of log entry (or null)
17171717 */
1718 - function logCampaignChange( $action, $campaignId, $beginSettings = array(),
 1718+ function logCampaignChange( $action, $campaignId, $beginSettings = array(),
17191719 $endSettings = array(), $beginAssignments = array(), $endAssignments = array() )
17201720 {
17211721 global $wgUser;
1722 -
 1722+
17231723 // Only log the change if it is done by an actual user (rather than a testing script)
17241724 if ( $wgUser->getId() > 0 ) { // User::getID returns 0 for anonymous or non-existant users
1725 -
 1725+
17261726 $dbw = wfGetDB( DB_MASTER );
1727 -
 1727+
17281728 $log = array(
17291729 'notlog_timestamp' => $dbw->timestamp(),
17301730 'notlog_user_id' => $wgUser->getId(),
@@ -1731,18 +1731,18 @@
17321732 'notlog_not_id' => $campaignId,
17331733 'notlog_not_name' => CentralNotice::getNoticeName( $campaignId )
17341734 );
1735 -
 1735+
17361736 foreach ( $beginSettings as $key => $value ) {
17371737 $log['notlog_begin_'.$key] = $value;
17381738 }
17391739 foreach ( $endSettings as $key => $value ) {
17401740 $log['notlog_end_'.$key] = $value;
17411741 }
1742 -
 1742+
17431743 $res = $dbw->insert( 'cn_notice_log', $log );
17441744 $log_id = $dbw->insertId();
17451745 return $log_id;
1746 -
 1746+
17471747 } else {
17481748 return null;
17491749 }
Property changes on: branches/wmf/1.18wmf1/extensions/CentralNotice/special/SpecialCentralNotice.php
___________________________________________________________________
Modified: svn:mergeinfo
17501750 Merged /trunk/extensions/CentralNotice/special/SpecialCentralNotice.php:r100780
Property changes on: branches/wmf/1.18wmf1/extensions/CentralNotice/CentralNotice.php
___________________________________________________________________
Modified: svn:mergeinfo
17511751 Merged /trunk/extensions/CentralNotice/CentralNotice.php:r100100-102469
Property changes on: branches/wmf/1.18wmf1/extensions/CentralNotice/patches/patch-template_autolink.sql
___________________________________________________________________
Added: svn:mergeinfo
17521752 Merged /trunk/phase3/extensions/CentralNotice/patches/patch-template_autolink.sql:r63545-63546,63549,63643,63764,63897-63901,64113,64509,65387,65391,65555,65590,65650,65816,77555,77558-77560,77563-77565,77573
17531753 Merged /branches/wmf-deployment/extensions/CentralNotice/patches/patch-template_autolink.sql:r60970
17541754 Merged /branches/wmf/1.16wmf4/extensions/CentralNotice/patches/patch-template_autolink.sql:r67177,69199,76243,77266
17551755 Merged /trunk/extensions/CentralNotice/patches/patch-template_autolink.sql: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-91117,91146,91368-95517,100092-102468
Index: branches/wmf/1.18wmf1/extensions/CentralNotice/CentralNotice.db.php
@@ -11,25 +11,25 @@
1212 class CentralNoticeDB {
1313
1414 /* Functions */
15 - /*
 15+ /**
1616 * Return campaigns in the system within given constraints
1717 * By default returns enabled campaigns, if $enabled set to false, returns both enabled and disabled campaigns
1818 * @return an array of ids
1919 */
2020 static function getCampaigns( $project = false, $language = false, $date = false, $enabled = true, $preferred = false, $location = false ) {
2121 global $wgCentralDBname;
22 -
 22+
2323 $notices = array();
24 -
 24+
2525 // Database setup
2626 $dbr = wfGetDB( DB_SLAVE, array(), $wgCentralDBname );
27 -
 27+
2828 if ( !$date ) {
2929 $encTimestamp = $dbr->addQuotes( $dbr->timestamp() );
3030 } else {
3131 $encTimestamp = $dbr->addQuotes( $dbr->timestamp( $date ) );
3232 }
33 -
 33+
3434 $tables = array( 'cn_notices' );
3535 if ( $project ) {
3636 $tables[] = 'cn_notice_projects';
@@ -71,7 +71,7 @@
7272 foreach ( $res as $row ) {
7373 $notices[] = $row->not_id;
7474 }
75 -
 75+
7676 // If a location is passed, also pull geotargeted campaigns that match the location
7777 if ( $location ) {
7878 $tables = array( 'cn_notices', 'cn_notice_countries' );
@@ -81,7 +81,7 @@
8282 if ( $language ) {
8383 $tables[] = 'cn_notice_languages';
8484 }
85 -
 85+
8686 // Use whatever conditional arguments got passed in
8787 $conds = array(
8888 'not_geo' => 1,
@@ -98,13 +98,13 @@
9999 $conds[] = "nl_notice_id = cn_notices.not_id";
100100 $conds['nl_language'] = $language;
101101 }
102 -
 102+
103103 if ( $enabled ) {
104104 $conds['not_enabled'] = 1;
105105 }
106106 if ( $preferred ) {
107107 $conds['not_preferred'] = 1;
108 - }
 108+ }
109109 // Pull db data
110110 $res = $dbr->select(
111111 $tables,
@@ -112,7 +112,7 @@
113113 $conds,
114114 __METHOD__
115115 );
116 -
 116+
117117 // Loop through result set and return ids
118118 foreach ( $res as $row ) {
119119 $notices[] = $row->not_id;
@@ -121,8 +121,8 @@
122122
123123 return $notices;
124124 }
125 -
126 - /*
 125+
 126+ /**
127127 * Return settings for a campaign
128128 * @param $campaignName string: The name of the campaign
129129 * @param $detailed boolean: Whether or not to include targeting and banner assignment info
@@ -130,10 +130,10 @@
131131 */
132132 static function getCampaignSettings( $campaignName, $detailed = true ) {
133133 global $wgCentralDBname;
134 -
 134+
135135 // Read from the master database to avoid concurrency problems
136136 $dbr = wfGetDB( DB_MASTER, array(), $wgCentralDBname );
137 -
 137+
138138 $campaign = array();
139139
140140 // Get campaign info from database
@@ -160,7 +160,7 @@
161161 'geo' => $row->not_geo
162162 );
163163 }
164 -
 164+
165165 if ( $detailed ) {
166166 $projects = CentralNotice::getNoticeProjects( $campaignName );
167167 $languages = CentralNotice::getNoticeLanguages( $campaignName );
@@ -168,7 +168,7 @@
169169 $campaign['projects'] = implode( ", ", $projects );
170170 $campaign['languages'] = implode( ", ", $languages );
171171 $campaign['countries'] = implode( ", ", $geo_countries );
172 -
 172+
173173 $bannersIn = CentralNoticeDB::getCampaignBanners( $row->not_id, true );
174174 $bannersOut = array();
175175 // All we want are the banner names and weights
@@ -179,11 +179,11 @@
180180 // Encode into a JSON string for storage
181181 $campaign['banners'] = FormatJson::encode( $bannersOut );
182182 }
183 -
 183+
184184 return $campaign;
185185 }
186186
187 - /*
 187+ /**
188188 * Given one or more campaign ids, return all banners bound to them
189189 * @param $campaigns array of id numbers
190190 * @param $logging boolean whether or not request is for logging (optional)
@@ -191,7 +191,7 @@
192192 */
193193 static function getCampaignBanners( $campaigns, $logging = false ) {
194194 global $wgCentralDBname;
195 -
 195+
196196 // If logging, read from the master database to avoid concurrency problems
197197 if ( $logging ) {
198198 $dbr = wfGetDB( DB_MASTER, array(), $wgCentralDBname );
@@ -241,7 +241,7 @@
242242 }
243243 return $banners;
244244 }
245 -
 245+
246246 /**
247247 * Return settings for a banner
248248 * @param $bannerName string name of banner
@@ -250,16 +250,16 @@
251251 */
252252 static function getBannerSettings( $bannerName, $logging = false ) {
253253 global $wgCentralDBname;
254 -
 254+
255255 $banner = array();
256 -
 256+
257257 // If logging, read from the master database to avoid concurrency problems
258258 if ( $logging ) {
259259 $dbr = wfGetDB( DB_MASTER, array(), $wgCentralDBname );
260260 } else {
261261 $dbr = wfGetDB( DB_SLAVE, array(), $wgCentralDBname );
262262 }
263 -
 263+
264264 $row = $dbr->selectRow( 'cn_templates',
265265 array(
266266 'tmp_display_anon',
@@ -271,7 +271,7 @@
272272 array( 'tmp_name' => $bannerName ),
273273 __METHOD__
274274 );
275 -
 275+
276276 if ( $row ) {
277277 $banner = array(
278278 'anon' => $row->tmp_display_anon,
@@ -281,23 +281,23 @@
282282 'landingpages' => $row->tmp_landing_pages
283283 );
284284 }
285 -
 285+
286286 return $banner;
287287 }
288 -
 288+
289289 /**
290 - * Lookup function for active banners under a given language/project/location. This function is
 290+ * Lookup function for active banners under a given language/project/location. This function is
291291 * called by SpecialBannerListLoader::getJsonList() in order to build the banner list JSON for
292292 * each project.
293293 * @return a 2D array of running banners with associated weights and settings
294294 */
295295 static function getBannersByTarget( $project, $language, $location = null ) {
296296 global $wgCentralDBname;
297 -
 297+
298298 $campaigns = array();
299299 $dbr = wfGetDB( DB_SLAVE, array(), $wgCentralDBname );
300300 $encTimestamp = $dbr->addQuotes( $dbr->timestamp() );
301 -
 301+
302302 // Pull non-geotargeted campaigns
303303 $campaignResults1 = $dbr->select(
304304 array(
@@ -324,12 +324,12 @@
325325 $campaigns[] = $row->not_id;
326326 }
327327 if ( $location ) {
328 -
 328+
329329 // Normalize location parameter (should be an uppercase 2-letter country code)
330330 preg_match( '/[a-zA-Z][a-zA-Z]/', $location, $matches );
331331 if ( $matches ) {
332332 $location = strtoupper( $matches[0] );
333 -
 333+
334334 // Pull geotargeted campaigns
335335 $campaignResults2 = $dbr->select(
336336 array(
@@ -360,7 +360,7 @@
361361 }
362362 }
363363 }
364 -
 364+
365365 $banners = array();
366366 if ( $campaigns ) {
367367 // Pull all banners assigned to the campaigns
@@ -368,8 +368,8 @@
369369 }
370370 return $banners;
371371 }
372 -
373 - /*
 372+
 373+ /**
374374 * See if a given campaign exists in the database
375375 */
376376 public static function campaignExists( $campaignName ) {
@@ -379,8 +379,8 @@
380380 $eCampaignName = htmlspecialchars( $campaignName );
381381 return (bool)$dbr->selectRow( 'cn_notices', 'not_name', array( 'not_name' => $eCampaignName ) );
382382 }
383 -
384 - /*
 383+
 384+ /**
385385 * See if a given banner exists in the database
386386 */
387387 public static function bannerExists( $bannerName ) {
@@ -395,8 +395,8 @@
396396 return false;
397397 }
398398 }
399 -
400 - /*
 399+
 400+ /**
401401 * Return all of the available countries for geotargeting
402402 * (This should probably be moved to a core database table at some point.)
403403 */
@@ -601,6 +601,7 @@
602602 'SO'=>'Somalia',
603603 'ZA'=>'South Africa',
604604 'KR'=>'South Korea',
 605+ 'SS'=>'South Sudan',
605606 'ES'=>'Spain',
606607 'LK'=>'Sri Lanka',
607608 'SD'=>'Sudan',
Property changes on: branches/wmf/1.18wmf1/extensions/CentralNotice/CentralNotice.db.php
___________________________________________________________________
Modified: svn:mergeinfo
608609 Merged /trunk/extensions/CentralNotice/CentralNotice.db.php:r100780-102469

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r99497using Html::linkedScriptkaldari17:05, 11 October 2011
r100014removing some deprecated functionality regarding centralnotice cookieskaldari05:37, 17 October 2011
r100015correcting comment, this no longer gets inserted into the head due to changes...kaldari05:40, 17 October 2011
r100085follow-up to r99160, indexing banner nameskaldari21:00, 17 October 2011
r100780Swap...reedy03:49, 26 October 2011
r102204adding South Sudan to countries listkaldari23:01, 6 November 2011
r102273changing default cookie expiration to 2 weeks per James and Megankaldari08:58, 7 November 2011

Status & tagging log