http://www.mediawiki.org/wiki/Special:Code/MediaWiki/94316
Revision: 94316
Author: kaldari
Date: 2011-08-12 01:44:13 +0000 (Fri, 12 Aug 2011)
Log Message:
-----------
adding filters to central notice campaign setting logs
Modified Paths:
--------------
trunk/extensions/CentralNotice/CentralNotice.i18n.php
trunk/extensions/CentralNotice/CentralNoticeLogPager.php
trunk/extensions/CentralNotice/centralnotice.css
trunk/extensions/CentralNotice/special/SpecialCentralNotice.php
trunk/extensions/CentralNotice/special/SpecialCentralNoticeLogs.php
Modified: trunk/extensions/CentralNotice/CentralNotice.i18n.php
===================================================================
--- trunk/extensions/CentralNotice/CentralNotice.i18n.php 2011-08-12
01:35:14 UTC (rev 94315)
+++ trunk/extensions/CentralNotice/CentralNotice.i18n.php 2011-08-12
01:44:13 UTC (rev 94316)
@@ -168,6 +168,9 @@
'centralnotice-landingpages' => 'Landing pages',
'centralnotice-banner-content' => 'Banner content',
'centralnotice-banner-content-changed' => 'Changed',
+ 'centralnotice-filters' => 'Filters',
+ 'centralnotice-date' => 'Date',
+ 'centralnotice-apply-filters' => 'Apply filters',
);
/** Message documentation (Message documentation)
Modified: trunk/extensions/CentralNotice/CentralNoticeLogPager.php
===================================================================
--- trunk/extensions/CentralNotice/CentralNoticeLogPager.php 2011-08-12
01:35:14 UTC (rev 94315)
+++ trunk/extensions/CentralNotice/CentralNoticeLogPager.php 2011-08-12
01:44:13 UTC (rev 94316)
@@ -4,6 +4,7 @@
var $viewPage, $special;
function __construct( $special ) {
+ global $wgRequest;
$this->special = $special;
parent::__construct();
@@ -25,10 +26,31 @@
* Pull log entries from the database
*/
function getQueryInfo() {
- return array(
+ global $wgRequest;
+
+ $dateArray = $wgRequest->getArray( 'start' );
+ $filterDate = $dateArray['year'] . $dateArray['month'] .
$dateArray['day'];
+ $filterCampaign = $wgRequest->getVal( 'campaign' );
+ $reset = $wgRequest->getVal( 'centralnoticelogreset' );
+
+ $info = array(
'tables' => array( 'cn_notice_log' ),
'fields' => '*',
+ 'conds' => array()
);
+
+ if ( !$reset ) {
+ $date1 = intval( $filterDate.'000000' );
+ $date2 = intval( ( $filterDate + 1 ).'000000' );
+ if ( $filterDate > 0 ) {
+ $info['conds'][] = "notlog_timestamp >= $date1
AND notlog_timestamp < $date2";
+ }
+ if ( $filterCampaign ) {
+ $info['conds'][] = "notlog_not_name LIKE
'$filterCampaign'";
+ }
+ }
+
+ return $info;
}
/**
Modified: trunk/extensions/CentralNotice/centralnotice.css
===================================================================
--- trunk/extensions/CentralNotice/centralnotice.css 2011-08-12 01:35:14 UTC
(rev 94315)
+++ trunk/extensions/CentralNotice/centralnotice.css 2011-08-12 01:44:13 UTC
(rev 94316)
@@ -61,6 +61,7 @@
width: auto;
}
#preferences table#cn-campaign-logs td.primary {
+ white-space: nowrap;
background-color: #F0F0F0;
}
#preferences .cn-new-value {
@@ -72,6 +73,15 @@
#preferences .cn-log-label {
font-weight: bold;
}
+#preferences .cn-log-filter {
+ margin-right: 1.5em;
+}
+#preferences .cn-log-filter-label {
+ margin-right: 0.5em;
+}
+#preferences .cn-filter-buttons {
+ margin-right: 0.5em;
+}
#preferences #cn-log-switcher label {
margin-right: 1em;
}
Modified: trunk/extensions/CentralNotice/special/SpecialCentralNotice.php
===================================================================
--- trunk/extensions/CentralNotice/special/SpecialCentralNotice.php
2011-08-12 01:35:14 UTC (rev 94315)
+++ trunk/extensions/CentralNotice/special/SpecialCentralNotice.php
2011-08-12 01:44:13 UTC (rev 94316)
@@ -240,17 +240,19 @@
return Xml::tags( 'tr', $attribs, implode( "\n", $cells ) ) .
"\n";
}
- function dateSelector( $prefix, $timestamp = null ) {
- if ( $this->editable ) {
- // Default ranges...
- $years = range( 2008, 2014 );
- $months = range( 1, 12 );
- $months = array_map( array( $this, 'addZero' ), $months
);
- $days = range( 1 , 31 );
- $days = array_map( array( $this, 'addZero' ), $days );
-
- // Normalize timestamp format. If no timestamp passed,
defaults to now.
- $ts = wfTimestamp( TS_MW, $timestamp );
+ public static function dateSelector( $prefix, $editable, $timestamp =
null ) {
+ if ( $editable ) {
+ $years = range( 2010, 2016 );
+ $months = CentralNotice::paddedRange( 1, 12 );
+ $days = CentralNotice::paddedRange( 1, 31 );
+
+ // Normalize timestamp format. If no timestamp is
passed, default to now. If -1 is
+ // passed, set no defaults.
+ if ( $timestamp === -1 ) {
+ $ts = '00000000';
+ } else {
+ $ts = wfTimestamp( TS_MW, $timestamp );
+ }
$fields = array(
array( "month", "centralnotice-month", $months,
substr( $ts, 4, 2 ) ),
@@ -258,20 +260,17 @@
array( "year", "centralnotice-year", $years,
substr( $ts, 0, 4 ) ),
);
- return $this->createSelector( $prefix, $fields );
+ return CentralNotice::createSelector( $prefix, $fields
);
} else {
global $wgLang;
return $wgLang->date( $timestamp );
}
}
- function timeSelector( $prefix, $timestamp = null ) {
- if ( $this->editable ) {
- // Default ranges...
- $minutes = range( 0, 59 ); // formerly in 15-minute
increments
- $minutes = array_map( array( $this, 'addZero' ),
$minutes );
- $hours = range( 0 , 23 );
- $hours = array_map( array( $this, 'addZero' ), $hours );
+ public static function timeSelector( $prefix, $editable, $timestamp =
null ) {
+ if ( $editable ) {
+ $minutes = CentralNotice::paddedRange( 0, 59 );
+ $hours = CentralNotice::paddedRange( 0 , 23 );
// Normalize timestamp format...
$ts = wfTimestamp( TS_MW, $timestamp );
@@ -281,7 +280,7 @@
array( "min", "centralnotice-min", $minutes,
substr( $ts, 10, 2 ) ),
);
- return $this->createSelector( $prefix, $fields );
+ return CentralNotice::createSelector( $prefix, $fields
);
} else {
global $wgLang;
return $wgLang->time( $timestamp );
@@ -290,15 +289,15 @@
/**
* Build a set of select lists. Used by dateSelector and timeSelector.
- * @param $prefix string
- * @param $fields array
+ * @param $prefix string to identify selector set, for example, 'start'
or 'end'
+ * @param $fields array of select lists to build
*/
- private function createSelector( $prefix, $fields ) {
+ public static function createSelector( $prefix, $fields ) {
$out = '';
foreach ( $fields as $data ) {
list( $field, $label, $set, $current ) = $data;
$out .= Xml::listDropDown( "{$prefix}[{$field}]",
- $this->dropDownList( wfMsg( $label ), $set ),
+ CentralNotice::dropDownList( wfMsg( $label ),
$set ),
'',
$current );
}
@@ -533,12 +532,12 @@
// Start Date
$htmlOut .= Xml::openElement( 'tr' );
$htmlOut .= Xml::tags( 'td', array(), wfMsgHtml(
'centralnotice-start-date' ) );
- $htmlOut .= Xml::tags( 'td', array(),
$this->dateSelector( 'start', $startTimestamp ) );
+ $htmlOut .= Xml::tags( 'td', array(),
$this->dateSelector( 'start', $this->editable, $startTimestamp ) );
$htmlOut .= Xml::closeElement( 'tr' );
// Start Time
$htmlOut .= Xml::openElement( 'tr' );
$htmlOut .= Xml::tags( 'td', array(), wfMsgHtml(
'centralnotice-start-time' ) );
- $htmlOut .= Xml::tags( 'td', array(),
$this->timeSelector( 'start', $startTimestamp ) );
+ $htmlOut .= Xml::tags( 'td', array(),
$this->timeSelector( 'start', $this->editable, $startTimestamp ) );
$htmlOut .= Xml::closeElement( 'tr' );
// Project
$htmlOut .= Xml::openElement( 'tr' );
@@ -846,22 +845,22 @@
// Start Date
$htmlOut .= Xml::openElement( 'tr' );
$htmlOut .= Xml::tags( 'td', array(), wfMsgHtml(
'centralnotice-start-date' ) );
- $htmlOut .= Xml::tags( 'td', array(),
$this->dateSelector( 'start', $startTimestamp ) );
+ $htmlOut .= Xml::tags( 'td', array(),
$this->dateSelector( 'start', $this->editable, $startTimestamp ) );
$htmlOut .= Xml::closeElement( 'tr' );
// Start Time
$htmlOut .= Xml::openElement( 'tr' );
$htmlOut .= Xml::tags( 'td', array(), wfMsgHtml(
'centralnotice-start-time' ) );
- $htmlOut .= Xml::tags( 'td', array(),
$this->timeSelector( 'start', $startTimestamp ) );
+ $htmlOut .= Xml::tags( 'td', array(),
$this->timeSelector( 'start', $this->editable, $startTimestamp ) );
$htmlOut .= Xml::closeElement( 'tr' );
// End Date
$htmlOut .= Xml::openElement( 'tr' );
$htmlOut .= Xml::tags( 'td', array(), wfMsgHtml(
'centralnotice-end-date' ) );
- $htmlOut .= Xml::tags( 'td', array(),
$this->dateSelector( 'end', $endTimestamp ) );
+ $htmlOut .= Xml::tags( 'td', array(),
$this->dateSelector( 'end', $this->editable, $endTimestamp ) );
$htmlOut .= Xml::closeElement( 'tr' );
// End Time
$htmlOut .= Xml::openElement( 'tr' );
$htmlOut .= Xml::tags( 'td', array(), wfMsgHtml(
'centralnotice-end-time' ) );
- $htmlOut .= Xml::tags( 'td', array(),
$this->timeSelector( 'end', $endTimestamp ) );
+ $htmlOut .= Xml::tags( 'td', array(),
$this->timeSelector( 'end', $this->editable, $endTimestamp ) );
$htmlOut .= Xml::closeElement( 'tr' );
// Project
$htmlOut .= Xml::openElement( 'tr' );
@@ -1641,15 +1640,16 @@
}
return $dropDown;
}
-
- function addZero( $text ) {
- // Prepend a 0 for text needing it
- if ( strlen( $text ) == 1 ) {
- $text = "0{$text}";
+
+ public static function paddedRange( $begin, $end ) {
+ $unpaddedRange = range( $begin, $end );
+ $paddedRange = array();
+ foreach ( $unpaddedRange as $number ) {
+ $paddedRange[] = sprintf( "%02d", $number ); // pad
number with 0 if needed
}
- return $text;
+ return $paddedRange;
}
-
+
function showError( $message ) {
global $wgOut;
$wgOut->wrapWikiMsg( "<div class='cn-error'>\n$1\n</div>",
$message );
Modified: trunk/extensions/CentralNotice/special/SpecialCentralNoticeLogs.php
===================================================================
--- trunk/extensions/CentralNotice/special/SpecialCentralNoticeLogs.php
2011-08-12 01:35:14 UTC (rev 94315)
+++ trunk/extensions/CentralNotice/special/SpecialCentralNoticeLogs.php
2011-08-12 01:44:13 UTC (rev 94316)
@@ -70,10 +70,56 @@
$htmlOut .= Xml::label( wfMsg( 'centralnotice-banner-settings'
), 'banner' );
$htmlOut .= Xml::closeElement( 'div' );
+
+ if ( $this->logType == 'campaignsettings' ) {
+
+ $reset = $wgRequest->getVal( 'centralnoticelogreset' );
+
+ $startArray = $wgRequest->getArray( 'start' );
+ if ( $wgRequest->wasPosted() && $startArray && !$reset
) {
+ $filterTimestamp = $startArray['year'] .
+ $startArray['month'] .
+ $startArray['day'] . '000000'
+ ;
+ } else { // Default
+ $filterTimestamp = -1;
+ }
+
+ $filters = Xml::openElement( 'span', array( 'class' =>
'cn-log-filter' ) );
+ $filters .= Xml::label( wfMsg( 'centralnotice-date' ),
'start[month]', array( 'class' => 'cn-log-filter-label' ) );
+ $filters .= CentralNotice::dateSelector( 'start', true,
$filterTimestamp );
+ $filters .= Xml::closeElement( 'span' );
+
+ $filters .= Xml::openElement( 'span', array( 'class' =>
'cn-log-filter' ) );
+ $filters .= Xml::label( wfMsg( 'centralnotice-notice'
), 'campaign', array( 'class' => 'cn-log-filter-label' ) );
+ $filters .= Xml::input( 'campaign', 25, ( $reset ? '' :
$wgRequest->getVal( 'campaign' ) ) );
+ $filters .= Xml::closeElement( 'span' );
+
+ $filters .= Xml::submitButton( wfMsg(
'centralnotice-apply-filters' ),
+ array(
+ 'id' => 'centralnoticesubmit',
+ 'name' => 'centralnoticesubmit',
+ 'class' => 'cn-filter-buttons',
+ )
+ );
+ $filters .= Xml::submitButton( 'Clear filters',
+ array(
+ 'id' => 'centralnoticelogreset',
+ 'name' => 'centralnoticelogreset',
+ 'class' => 'cn-filter-buttons',
+ )
+ );
+
+ $htmlOut .= Xml::fieldset( wfMsg(
'centralnotice-filters' ),
+ $filters,
+ array( 'class' => 'cn-bannerpreview')
+ );
+ }
+
$htmlOut .= Xml::closeElement( 'form' );
// End log selection fieldset
- $htmlOut .= Xml::closeElement( 'fieldset' );
+ //$htmlOut .= Xml::closeElement( 'fieldset' );
$wgOut->addHTML( $htmlOut );
@@ -99,7 +145,7 @@
$htmlOut = '';
// Begin log fieldset
- $htmlOut .= Xml::openElement( 'fieldset', array( 'class' =>
'prefsection' ) );
+ //$htmlOut .= Xml::openElement( 'fieldset', array( 'class' =>
'prefsection' ) );
// Show paginated list of log entries
$htmlOut .= Xml::tags( 'div',
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs