Mwalker has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/78465


Change subject: UI for Archiving Campaigns
......................................................................

UI for Archiving Campaigns

Allows the user to show/hide a campaign based on archival settings.

Also added logic that will not allow archiving if the banner is locked
or enabled.

Change-Id: I620e2a8bc23796fb9c1759330a320e1109ee1fd9
---
M CentralNotice.i18n.php
M CentralNotice.php
M includes/Campaign.php
A modules/ext.centralNotice.adminUi.campaignManager/campaignManager.css
A modules/ext.centralNotice.adminUi.campaignManager/campaignManager.js
M modules/ext.centralNotice.adminUi/adminui.common.css
M modules/ext.centralNotice.adminUi/centralnotice.css
M special/SpecialCentralNotice.php
8 files changed, 154 insertions(+), 65 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CentralNotice 
refs/changes/65/78465/1

diff --git a/CentralNotice.i18n.php b/CentralNotice.i18n.php
index fe5d04e..2b8e945 100644
--- a/CentralNotice.i18n.php
+++ b/CentralNotice.i18n.php
@@ -219,6 +219,7 @@
        '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-show' => 'Show archived campaigns',
        'centralnotice-archive-campaign' => 'Archive',
        'centralnotice-archive-campaign-title' => 'Archive 
{{PLURAL:$1|campaign|campaigns}}?',
        'centralnotice-archive-campaign-confirm' => 'Archival marks a campaign 
as permanently inactive.',
@@ -659,6 +660,7 @@
        '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-show' => 'Checkbox text that determines if 
archived campaigns are shown or hidden',
        'centralnotice-archive-campaign' => 'Translate as a 
verb.{{Identical|Archive}}',
        'centralnotice-archive-campaign-title' => 'Used as title for the dialog 
box.
 
diff --git a/CentralNotice.php b/CentralNotice.php
index 497d26a..4a503a1 100644
--- a/CentralNotice.php
+++ b/CentralNotice.php
@@ -144,6 +144,17 @@
                'jquery.cookie',
        ),
 );
+$wgResourceModules[ 'ext.centralNotice.adminUi.campaignManager' ] = array(
+       'localBasePath' => $dir . '/modules',
+       'remoteExtPath' => 'CentralNotice/modules',
+       'dependencies' => array(
+               'ext.centralNotice.adminUi',
+               'jquery.ui.dialog'
+       ),
+       'scripts'       => 
'ext.centralNotice.adminUi.campaignManager/campaignManager.js',
+       'styles'        => 
'ext.centralNotice.adminUi.campaignManager/campaignManager.css',
+       'messages'      => array( )
+);
 
 $wgResourceModules[ 'ext.centralNotice.bannerController.mobiledevice' ] = 
array(
        'localBasePath' => $dir . '/modules',
diff --git a/includes/Campaign.php b/includes/Campaign.php
index 5cd0315..46557fd 100644
--- a/includes/Campaign.php
+++ b/includes/Campaign.php
@@ -249,7 +249,7 @@
         * @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.
+        * @param bool        $archived If true: only archived; false: only 
active; null; all.
         *
         * @return array Array of campaign IDs that matched the filter.
         */
diff --git 
a/modules/ext.centralNotice.adminUi.campaignManager/campaignManager.css 
b/modules/ext.centralNotice.adminUi.campaignManager/campaignManager.css
new file mode 100644
index 0000000..4207ffb
--- /dev/null
+++ b/modules/ext.centralNotice.adminUi.campaignManager/campaignManager.css
@@ -0,0 +1,38 @@
+/**
+ * Styles specific to Special:CentralNotice
+ *
+ * This file is part of the CentralNotice Extension to MediaWiki
+ * https://www.mediawiki.org/wiki/Extension:CentralNotice
+ *
+ * @section LICENSE
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
+.cn-formsection-emphasis {
+       padding: 0.5em;
+       background-color: #FFFFFF;
+       border: 1px solid #2F6FAB;
+}
+
+.cn-buttons {
+       text-align: right;
+}
+
+.cn-active-campaign {
+       background-color: #ddffdd;
+}
\ No newline at end of file
diff --git 
a/modules/ext.centralNotice.adminUi.campaignManager/campaignManager.js 
b/modules/ext.centralNotice.adminUi.campaignManager/campaignManager.js
new file mode 100644
index 0000000..e0a01e9
--- /dev/null
+++ b/modules/ext.centralNotice.adminUi.campaignManager/campaignManager.js
@@ -0,0 +1,33 @@
+/**
+ * Backing JS for Special:CentralNotice, the campaign list view form.
+ *
+ * This file is part of the CentralNotice Extension to MediaWiki
+ * https://www.mediawiki.org/wiki/Extension:CentralNotice
+ *
+ * @section LICENSE
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+( function ( $, mw ) {
+       $( '#centralnotice-showarchived' ).click( function() {
+               if ( $( this ).prop( 'checked' ) === true ) {
+                       $( '.cn-archived-item' ).show();
+               } else {
+                       $( '.cn-archived-item' ).hide();
+               }
+       });
+} )( jQuery, mediaWiki );
diff --git a/modules/ext.centralNotice.adminUi/adminui.common.css 
b/modules/ext.centralNotice.adminUi/adminui.common.css
index 0702e7e..442f073 100644
--- a/modules/ext.centralNotice.adminUi/adminui.common.css
+++ b/modules/ext.centralNotice.adminUi/adminui.common.css
@@ -51,4 +51,9 @@
 }
 #mw-htmlform-banner-list .cn-banner-list-element {
        display: inline;
+}
+
+/* --- Archival --- */
+.cn-archived-item {
+       display: none;
 }
\ No newline at end of file
diff --git a/modules/ext.centralNotice.adminUi/centralnotice.css 
b/modules/ext.centralNotice.adminUi/centralnotice.css
index 6efddca..dec377d 100644
--- a/modules/ext.centralNotice.adminUi/centralnotice.css
+++ b/modules/ext.centralNotice.adminUi/centralnotice.css
@@ -28,9 +28,6 @@
 #preferences fieldset.prefsection div.cn-error {
        margin:0;
 }
-#preferences table tr.cn-active-campaign {
-       background-color: #ddffdd;
-}
 #preferences table#envpicker {
        margin-bottom: 1em;
 }
@@ -39,15 +36,6 @@
 }
 #preferences .cn-date-column {
        white-space:nowrap;
-}
-#preferences div.cn-buttons {
-       padding:1em;
-}
-#preferences fieldset.prefsection div.cn-buttons {
-       padding:0;
-}
-#preferences div.cn-buttons input {
-       margin-right:0.25em;
 }
 #preferences input#clone {
        margin-left:0.25em;
diff --git a/special/SpecialCentralNotice.php b/special/SpecialCentralNotice.php
index e885923..524347b 100644
--- a/special/SpecialCentralNotice.php
+++ b/special/SpecialCentralNotice.php
@@ -25,7 +25,7 @@
                $request = $this->getRequest();
 
                // Output ResourceLoader module for styling and javascript 
functions
-               $out->addModules( 'ext.centralNotice.adminUi' );
+               $out->addModules( 'ext.centralNotice.adminUi.campaignManager' );
 
                // Check permissions
                $this->editable = $this->getUser()->isAllowed( 
'centralnotice-admin' );
@@ -313,31 +313,24 @@
         * Show all campaigns found in the database, show "Add a campaign" form
         */
        function listNotices() {
-               // Get connection
-               $dbr = CNDatabase::getDb();
-
-               if ( $this->editable ) {
-                       $readonly = array();
-               } else {
-                       $readonly = array( 'disabled' => 'disabled' );
-               }
+               // Cache these commonly used properties
+               $readonly = array( 'disabled' => 'disabled' );
 
                //TODO: refactor to use Campaign::getCampaigns
                // Get all campaigns from the database
+               $dbr = CNDatabase::getDb();
                $res = $dbr->select( 'cn_notices',
                        array(
-                               'not_name',
-                               'not_start',
-                               'not_end',
-                               'not_enabled',
-                               'not_preferred',
-                               'not_geo',
-                               'not_locked',
-                               'not_archived'
+                                'not_name',
+                                'not_start',
+                                'not_end',
+                                'not_enabled',
+                                'not_preferred',
+                                'not_geo',
+                                'not_locked',
+                                'not_archived'
                        ),
-                       array(
-                               'not_archived = 0',
-                       ),
+                       array(),
                        __METHOD__,
                        array( 'ORDER BY' => 'not_id DESC' )
                );
@@ -349,11 +342,22 @@
                $htmlOut .= Xml::openElement( 'fieldset', array( 'class' => 
'prefsection' ) );
 
                // If there are campaigns to show...
-               if ( $dbr->numRows( $res ) >= 1 ) {
+               if ( $res->numRows() >= 1 ) {
                        if ( $this->editable ) {
                                $htmlOut .= Xml::openElement( 'form', array( 
'method' => 'post' ) );
+                               $htmlOut .= Html::hidden( 'authtoken', 
$this->getUser()->getEditToken() );
                        }
                        $htmlOut .= Xml::element( 'h2', null, $this->msg( 
'centralnotice-manage' )->text() );
+
+                       // Filters
+                       $htmlOut .= Xml::openElement( 'div', array( 'class' => 
'cn-formsection-emphasis' ) );
+                       $htmlOut .= Xml::checkLabel(
+                               $this->msg( 'centralnotice-archive-show' 
)->text(),
+                               'centralnotice-showarchived',
+                               'centralnotice-showarchived',
+                               false
+                       );
+                       $htmlOut .= Xml::closeElement( 'div' );
 
                        // Begin table of campaigns
                        $htmlOut .= Xml::openElement( 'table',
@@ -375,14 +379,16 @@
                                $this->msg( 'centralnotice-enabled' 
)->escaped(),
                                $this->msg( 'centralnotice-preferred' 
)->escaped(),
                                $this->msg( 'centralnotice-locked' )->escaped(),
+                               $this->msg( 'centralnotice-archive-campaign' 
)->escaped()
                        );
-                       if ( $this->editable ) {
-                               $headers[ ] = $this->msg( 
'centralnotice-archive-campaign' )->escaped();
-                       }
                        $htmlOut .= $this->tableRow( $headers, 'th' );
 
                        // Table rows
                        foreach ( $res as $row ) {
+                               $rowIsEnabled = ( $row->not_enabled == '1' );
+                               $rowIsLocked = ( $row->not_locked == '1' );
+                               $rowIsArchived = ( $row->not_archived == '1' );
+
                                $rowCells = '';
 
                                // Name
@@ -432,12 +438,12 @@
                                );
 
                                // Enabled
-                               $checked = ( $row->not_enabled == '1' );
-                               $rowCells .= Html::rawElement( 'td', array( 
'data-sort-value' => (int)$checked ),
+                               $rowCells .= Html::rawElement( 'td', array( 
'data-sort-value' => (int)$rowIsEnabled ),
                                        Xml::check(
                                                'enabled[]',
-                                               $checked,
-                                               wfArrayMerge( $readonly,
+                                               $rowIsEnabled,
+                                               array_replace(
+                                                       ( !$this->editable || 
$rowIsLocked || $rowIsArchived ) ? $readonly : array(),
                                                        array( 'value' => 
$row->not_name, 'class' => 'noshiftselect mw-cn-input-check-sort' )
                                                )
                                        )
@@ -445,50 +451,57 @@
 
                                // Preferred / Priority
                                $rowCells .= Html::rawElement( 'td', array( 
'data-sort-value' => $row->not_preferred ),
-                                       $this::prioritySelector( 
$row->not_name, $this->editable, $row->not_preferred)
+                                       $this::prioritySelector(
+                                               $row->not_name,
+                                               $this->editable && 
!$rowIsLocked && !$rowIsArchived,
+                                               $row->not_preferred
+                                       )
                                );
 
                                // Locked
-                               $checked = ( $row->not_locked == '1' );
-                               $rowCells .= Html::rawElement( 'td', array( 
'data-sort-value' => (int)$checked ),
+                               $rowCells .= Html::rawElement( 'td', array( 
'data-sort-value' => (int)$rowIsLocked ),
                                        Xml::check(
                                                'locked[]',
-                                               $checked,
-                                               wfArrayMerge( $readonly,
+                                               $rowIsLocked,
+                                               array_replace(
+                                                       ( !$this->editable || 
$rowIsArchived ) ? $readonly : array(),
                                                        array( 'value' => 
$row->not_name, 'class' => 'noshiftselect mw-cn-input-check-sort' )
                                                )
                                        )
                                );
 
-                               if ( $this->editable ) {
-                                       // Archive
-                                       $checked = false;
-                                       $rowCells .= Html::rawElement( 'td', 
array( 'data-sort-value' => (int)$checked ),
-                                               Xml::check(
-                                                       'archiveCampaigns[]',
-                                                       $checked,
+                               // Archive
+                               $rowCells .= Html::rawElement( 'td', array( 
'data-sort-value' => (int)$rowIsArchived ),
+                                       Xml::check(
+                                               'archiveCampaigns[]',
+                                               $rowIsArchived,
+                                               array_replace(
+                                                       ( !$this->editable || 
$rowIsLocked || $rowIsEnabled ) ? $readonly : array(),
                                                        array( 'value' => 
$row->not_name, 'class' => 'noshiftselect mw-cn-input-check-sort' )
                                                )
-                                       );
-                               }
+                                       )
+                               );
 
                                // If campaign is currently active, set special 
class on table row.
-                               $attribs = array();
-                               if ( wfTimestamp() > wfTimestamp( TS_UNIX, 
$row->not_start )
-                                       && wfTimestamp() < wfTimestamp( 
TS_UNIX, $row->not_end )
-                                       && $row->not_enabled == '1'
+                               $classes = array();
+                               if (
+                                       $rowIsEnabled &&
+                                       wfTimestamp() > wfTimestamp( TS_UNIX, 
$row->not_start ) &&
+                                       wfTimestamp() < wfTimestamp( TS_UNIX, 
$row->not_end )
                                ) {
-                                       $attribs = array( 'class' => 
'cn-active-campaign' );
+                                       $classes[] = 'cn-active-campaign';
+                               }
+                               if ( $rowIsArchived ) {
+                                       $classes[] = 'cn-archived-item';
                                }
 
-                               $htmlOut .= Html::rawElement( 'tr', $attribs, 
$rowCells );
+                               $htmlOut .= Html::rawElement( 'tr', array( 
'class' => $classes ), $rowCells );
                        }
                        // End table of campaigns
                        $htmlOut .= Xml::closeElement( 'table' );
 
                        if ( $this->editable ) {
-                               $htmlOut .= Html::hidden( 'authtoken', 
$this->getUser()->getEditToken() );
-                               $htmlOut .= Xml::openElement( 'div', array( 
'class' => 'cn-buttons' ) );
+                               $htmlOut .= Xml::openElement( 'div', array( 
'class' => 'cn-buttons cn-formsection-emphasis' ) );
                                $htmlOut .= Xml::submitButton( $this->msg( 
'centralnotice-modify' )->text(),
                                        array(
                                                'id'   => 'centralnoticesubmit',
@@ -565,8 +578,7 @@
                        $htmlOut .= Xml::tags( 'td', array(),
                                Xml::label( $this->msg( 'centralnotice-geo' 
)->text(), 'geotargeted' ) );
                        $htmlOut .= Xml::tags( 'td', array(),
-                               Xml::check( 'geotargeted', false,
-                                       wfArrayMerge( $readonly, array( 'value' 
=> 1, 'id' => 'geotargeted' ) ) ) );
+                               Xml::check( 'geotargeted', false, array( 
'value' => 1, 'id' => 'geotargeted' ) ) );
                        $htmlOut .= Xml::closeElement( 'tr' );
                        $htmlOut .= Xml::openElement( 'tr',
                                array( 'id'=> 'geoMultiSelector', 'style'=> 
'display:none;' ) );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I620e2a8bc23796fb9c1759330a320e1109ee1fd9
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CentralNotice
Gerrit-Branch: master
Gerrit-Owner: Mwalker <[email protected]>

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

Reply via email to