Adamw has submitted this change and it was merged.

Change subject: (FR #1016) Support campaign archival
......................................................................


(FR #1016) Support campaign archival

TODOs:
* Confirmation screen
* Expose previously archived campaigns in the index when desired

Change-Id: I6c013b90c9530b70367b9f562df3d657305e5a32
---
M CentralNotice.i18n.php
M includes/Campaign.php
M special/SpecialCentralNotice.php
M tests/CentralNoticeTest.php
4 files changed, 52 insertions(+), 26 deletions(-)

Approvals:
  Adamw: Verified; Looks good to me, approved



diff --git a/CentralNotice.i18n.php b/CentralNotice.i18n.php
index c5e3d65..fe5d04e 100644
--- a/CentralNotice.i18n.php
+++ b/CentralNotice.i18n.php
@@ -219,6 +219,11 @@
        'centralnotice-archive-banner-confirm' => 'Archival expands all 
included templates and sets page protection. This is not an easy action to 
reverse.',
        'centralnotice-archive-banner-cancel' => 'Cancel',
 
+       'centralnotice-archive-campaign' => 'Archive',
+       'centralnotice-archive-campaign-title' => 'Archive 
{{PLURAL:$1|campaign|campaigns}}?',
+       'centralnotice-archive-campaign-confirm' => 'Archival marks a campaign 
as permanently inactive.',
+       'centralnotice-archive-campaign-cancel' => 'Cancel',
+
        'centralnotice-delete-banner' => 'Delete',
        'centralnotice-delete-banner-title' => 'Delete 
{{PLURAL:$1|banner|banners}}?',
        'centralnotice-delete-banner-confirm' => 'Deletion removes all settings 
and messages. This action cannot be reversed. Consider archiving instead.',
@@ -653,6 +658,14 @@
 Followed by the confirmation message 
{{msg-mw|Centralnotice-archive-banner-confirm}}.',
        'centralnotice-archive-banner-confirm' => 'Used as confirmation message 
in the dialog box which has the title 
{{msg-mw|Centralnotice-archive-banner-title}}.',
        'centralnotice-archive-banner-cancel' => '{{Identical|Cancel}}',
+
+       'centralnotice-archive-campaign' => 'Translate as a 
verb.{{Identical|Archive}}',
+       'centralnotice-archive-campaign-title' => 'Used as title for the dialog 
box.
+
+Followed by the confirmation message 
{{msg-mw|Centralnotice-archive-campaign-confirm}}.',
+       'centralnotice-archive-campaign-confirm' => 'Used as confirmation 
message in the dialog box which has the title 
{{msg-mw|Centralnotice-archive-campaign-title}}.',
+       'centralnotice-archive-campaign-cancel' => '{{Identical|Cancel}}',
+
        'centralnotice-delete-banner' => 'Button label
 
 {{Identical|Delete}}',
diff --git a/includes/Campaign.php b/includes/Campaign.php
index c3b5222..5cd0315 100644
--- a/includes/Campaign.php
+++ b/includes/Campaign.php
@@ -20,6 +20,9 @@
        /** @var bool True if the campaign is currently non editable  */
        protected $locked = null;
 
+       /** @var bool True if the campaign has been moved to the archive */
+       protected $archived = null;
+
        /** @var bool True if there is geo-targeting data for ths campaign */
        protected $geotargeted = null;
 
@@ -197,6 +200,7 @@
                                 'not_enabled',
                                 'not_preferred',
                                 'not_locked',
+                                'not_archived',
                                 'not_geo',
                                 'not_buckets',
                        ),
@@ -209,6 +213,7 @@
                        $this->enabled = (bool)$row->not_enabled;
                        $this->priority = (int)$row->not_preferred;
                        $this->locked = (bool)$row->not_locked;
+                       $this->archived = (bool)$row->not_archived;
                        $this->geotargeted = (bool)$row->not_geo;
                        $this->buckets = (int)$row->not_buckets;
                } else {
@@ -244,11 +249,12 @@
         * @param null|date   $date     Campaigns must start before and end 
after this date
         *                              If the parameter is null, it takes the 
current date/time
         * @param bool        $enabled  If true, select only active campaigns. 
If false select all.
+        * @param bool        $archived If false, select only current 
campaigns. If false, select only archived. If null, select all.
         *
         * @return array Array of campaign IDs that matched the filter.
         */
        static function getCampaigns( $project = null, $language = null, 
$location = null, $date = null,
-                                     $enabled = true ) {
+                                     $enabled = true, $archived = false ) {
                $notices = array();
 
                // Database setup
@@ -274,6 +280,12 @@
 
                if ( $enabled ) {
                        $conds[ 'not_enabled' ] = 1;
+               }
+
+               if ( $archived === true ) {
+                       $conds[ 'not_archived' ] = 1;
+               } elseif ( $archived === false ) {
+                       $conds[ 'not_archived' ] = 0;
                }
 
                // common components: cn_notice_projects
@@ -352,6 +364,7 @@
                                'not_enabled',
                                'not_preferred',
                                'not_locked',
+                               'not_archived',
                                'not_geo',
                                'not_buckets',
                        ),
@@ -365,6 +378,7 @@
                                'enabled'   => $row->not_enabled,
                                'preferred' => $row->not_preferred,
                                'locked'    => $row->not_locked,
+                               'archived'  => $row->not_archived,
                                'geo'       => $row->not_geo,
                                'buckets'   => $row->not_buckets,
                        );
diff --git a/special/SpecialCentralNotice.php b/special/SpecialCentralNotice.php
index ce1fedd..e885923 100644
--- a/special/SpecialCentralNotice.php
+++ b/special/SpecialCentralNotice.php
@@ -69,15 +69,12 @@
                                        }
                                // Handle changing settings to existing 
campaigns
                                } else {
-                                       // Handle removing campaigns
-                                       $toRemove = $request->getArray( 
'removeCampaigns' );
-                                       if ( $toRemove ) {
-                                               // Remove campaigns in list
-                                               foreach ( $toRemove as $notice 
) {
-                                                       $result = 
Campaign::removeCampaign( $notice, $this->getUser() );
-                                                       if( $result !== true ) {
-                                                               
$this->showError( $result );
-                                                       }
+                                       // Handle archiving campaigns
+                                       $toArchive = $request->getArray( 
'archiveCampaigns' );
+                                       if ( $toArchive ) {
+                                               // Archive campaigns in list
+                                               foreach ( $toArchive as $notice 
) {
+                                                       
Campaign::setBooleanCampaignSetting( $notice, 'archived', 1 );
                                                }
                                        }
 
@@ -325,6 +322,7 @@
                        $readonly = array( 'disabled' => 'disabled' );
                }
 
+               //TODO: refactor to use Campaign::getCampaigns
                // Get all campaigns from the database
                $res = $dbr->select( 'cn_notices',
                        array(
@@ -334,9 +332,12 @@
                                'not_enabled',
                                'not_preferred',
                                'not_geo',
-                               'not_locked'
+                               'not_locked',
+                               'not_archived'
                        ),
-                       null,
+                       array(
+                               'not_archived = 0',
+                       ),
                        __METHOD__,
                        array( 'ORDER BY' => 'not_id DESC' )
                );
@@ -376,7 +377,7 @@
                                $this->msg( 'centralnotice-locked' )->escaped(),
                        );
                        if ( $this->editable ) {
-                               $headers[ ] = $this->msg( 
'centralnotice-remove' )->escaped();
+                               $headers[ ] = $this->msg( 
'centralnotice-archive-campaign' )->escaped();
                        }
                        $htmlOut .= $this->tableRow( $headers, 'th' );
 
@@ -460,11 +461,11 @@
                                );
 
                                if ( $this->editable ) {
-                                       // Remove
+                                       // Archive
                                        $checked = false;
                                        $rowCells .= Html::rawElement( 'td', 
array( 'data-sort-value' => (int)$checked ),
                                                Xml::check(
-                                                       'removeCampaigns[]',
+                                                       'archiveCampaigns[]',
                                                        $checked,
                                                        array( 'value' => 
$row->not_name, 'class' => 'noshiftselect mw-cn-input-check-sort' )
                                                )
@@ -640,13 +641,8 @@
                                        if ( $this->getUser()->matchEditToken( 
$request->getVal( 'authtoken' ) ) ) {
 
                                                // Handle removing campaign
-                                               if ( $request->getVal( 'remove' 
) ) {
-                                                       
Campaign::removeCampaign( $notice, $this->getUser() );
-                                                       if ( 
!$this->centralNoticeError ) {
-                                                               // Leave 
campaign detail interface
-                                                               
$this->getOutput()->redirect( $this->getTitle()->getLocalUrl() );
-                                                               return;
-                                                       }
+                                               if ( $request->getVal( 
'archive' ) ) {
+                                                       
Campaign::setBooleanCampaignSetting( $notice, 'archived', 1 );
                                                }
 
                                                $initialCampaignSettings = 
Campaign::getCampaignSettings( $notice );
@@ -867,6 +863,7 @@
                                $isEnabled = $request->getCheck( 'enabled' );
                                $priority = $request->getInt( 'priority', 
CentralNotice::NORMAL_PRIORITY );
                                $isLocked = $request->getCheck( 'locked' );
+                               $isArchived = $request->getCheck( 'archived' );
                                $noticeProjects = $request->getArray( 
'projects', array() );
                                $noticeLanguages = $request->getArray( 
'project_languages', array() );
                                $isGeotargeted = $request->getCheck( 
'geotargeted' );
@@ -878,6 +875,7 @@
                                $isEnabled = ( $campaign[ 'enabled' ] == '1' );
                                $priority = $campaign[ 'preferred' ];
                                $isLocked = ( $campaign[ 'locked' ] == '1' );
+                               $isArchived = ( $campaign[ 'archived' ] == '1' 
);
                                $noticeProjects = Campaign::getNoticeProjects( 
$notice );
                                $noticeLanguages = 
Campaign::getNoticeLanguages( $notice );
                                $isGeotargeted = ( $campaign[ 'geo' ] == '1' );
@@ -976,10 +974,10 @@
                                // Locked
                                $htmlOut .= Xml::openElement( 'tr' );
                                $htmlOut .= Xml::tags( 'td', array(),
-                                       Xml::label( $this->msg( 
'centralnotice-remove' )->text(), 'remove' ) );
+                                       Xml::label( $this->msg( 
'centralnotice-archive-campaign' )->text(), 'archive' ) );
                                $htmlOut .= Xml::tags( 'td', array(),
-                                       Xml::check( 'remove', false,
-                                               array( 'value' => $notice, 'id' 
=> 'remove' ) ) );
+                                       Xml::check( 'archive', $isArchived,
+                                               array( 'value' => $notice, 'id' 
=> 'archive' ) ) );
                                $htmlOut .= Xml::closeElement( 'tr' );
                        }
                        $htmlOut .= Xml::closeElement( 'table' );
diff --git a/tests/CentralNoticeTest.php b/tests/CentralNoticeTest.php
index 407b2c3..e50d5f9 100644
--- a/tests/CentralNoticeTest.php
+++ b/tests/CentralNoticeTest.php
@@ -41,7 +41,8 @@
                        'buckets' => '1',
                        'projects' => 'wikipedia, wikibooks',
                        'languages' => 'en, de',
-                       'countries' => 'US, AF'
+                       'countries' => 'US, AF',
+                       'archived' => 0,
                );
 
                //get User

-- 
To view, visit https://gerrit.wikimedia.org/r/78340
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I6c013b90c9530b70367b9f562df3d657305e5a32
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/CentralNotice
Gerrit-Branch: master
Gerrit-Owner: Adamw <[email protected]>
Gerrit-Reviewer: Adamw <[email protected]>
Gerrit-Reviewer: Mwalker <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to