r94316 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r94315‎ | r94316 | r94317 >
Date:01:44, 12 August 2011
Author:kaldari
Status:resolved (Comments)
Tags:
Comment:
adding filters to central notice campaign setting logs
Modified paths:
  • /trunk/extensions/CentralNotice/CentralNotice.i18n.php (modified) (history)
  • /trunk/extensions/CentralNotice/CentralNoticeLogPager.php (modified) (history)
  • /trunk/extensions/CentralNotice/centralnotice.css (modified) (history)
  • /trunk/extensions/CentralNotice/special/SpecialCentralNotice.php (modified) (history)
  • /trunk/extensions/CentralNotice/special/SpecialCentralNoticeLogs.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CentralNotice/special/SpecialCentralNotice.php
@@ -240,17 +240,19 @@
241241 return Xml::tags( 'tr', $attribs, implode( "\n", $cells ) ) . "\n";
242242 }
243243
244 - function dateSelector( $prefix, $timestamp = null ) {
245 - if ( $this->editable ) {
246 - // Default ranges...
247 - $years = range( 2008, 2014 );
248 - $months = range( 1, 12 );
249 - $months = array_map( array( $this, 'addZero' ), $months );
250 - $days = range( 1 , 31 );
251 - $days = array_map( array( $this, 'addZero' ), $days );
252 -
253 - // Normalize timestamp format. If no timestamp passed, defaults to now.
254 - $ts = wfTimestamp( TS_MW, $timestamp );
 244+ public static function dateSelector( $prefix, $editable, $timestamp = null ) {
 245+ if ( $editable ) {
 246+ $years = range( 2010, 2016 );
 247+ $months = CentralNotice::paddedRange( 1, 12 );
 248+ $days = CentralNotice::paddedRange( 1, 31 );
 249+
 250+ // Normalize timestamp format. If no timestamp is passed, default to now. If -1 is
 251+ // passed, set no defaults.
 252+ if ( $timestamp === -1 ) {
 253+ $ts = '00000000';
 254+ } else {
 255+ $ts = wfTimestamp( TS_MW, $timestamp );
 256+ }
255257
256258 $fields = array(
257259 array( "month", "centralnotice-month", $months, substr( $ts, 4, 2 ) ),
@@ -258,20 +260,17 @@
259261 array( "year", "centralnotice-year", $years, substr( $ts, 0, 4 ) ),
260262 );
261263
262 - return $this->createSelector( $prefix, $fields );
 264+ return CentralNotice::createSelector( $prefix, $fields );
263265 } else {
264266 global $wgLang;
265267 return $wgLang->date( $timestamp );
266268 }
267269 }
268270
269 - function timeSelector( $prefix, $timestamp = null ) {
270 - if ( $this->editable ) {
271 - // Default ranges...
272 - $minutes = range( 0, 59 ); // formerly in 15-minute increments
273 - $minutes = array_map( array( $this, 'addZero' ), $minutes );
274 - $hours = range( 0 , 23 );
275 - $hours = array_map( array( $this, 'addZero' ), $hours );
 271+ public static function timeSelector( $prefix, $editable, $timestamp = null ) {
 272+ if ( $editable ) {
 273+ $minutes = CentralNotice::paddedRange( 0, 59 );
 274+ $hours = CentralNotice::paddedRange( 0 , 23 );
276275
277276 // Normalize timestamp format...
278277 $ts = wfTimestamp( TS_MW, $timestamp );
@@ -281,7 +280,7 @@
282281 array( "min", "centralnotice-min", $minutes, substr( $ts, 10, 2 ) ),
283282 );
284283
285 - return $this->createSelector( $prefix, $fields );
 284+ return CentralNotice::createSelector( $prefix, $fields );
286285 } else {
287286 global $wgLang;
288287 return $wgLang->time( $timestamp );
@@ -290,15 +289,15 @@
291290
292291 /**
293292 * Build a set of select lists. Used by dateSelector and timeSelector.
294 - * @param $prefix string
295 - * @param $fields array
 293+ * @param $prefix string to identify selector set, for example, 'start' or 'end'
 294+ * @param $fields array of select lists to build
296295 */
297 - private function createSelector( $prefix, $fields ) {
 296+ public static function createSelector( $prefix, $fields ) {
298297 $out = '';
299298 foreach ( $fields as $data ) {
300299 list( $field, $label, $set, $current ) = $data;
301300 $out .= Xml::listDropDown( "{$prefix}[{$field}]",
302 - $this->dropDownList( wfMsg( $label ), $set ),
 301+ CentralNotice::dropDownList( wfMsg( $label ), $set ),
303302 '',
304303 $current );
305304 }
@@ -533,12 +532,12 @@
534533 // Start Date
535534 $htmlOut .= Xml::openElement( 'tr' );
536535 $htmlOut .= Xml::tags( 'td', array(), wfMsgHtml( 'centralnotice-start-date' ) );
537 - $htmlOut .= Xml::tags( 'td', array(), $this->dateSelector( 'start', $startTimestamp ) );
 536+ $htmlOut .= Xml::tags( 'td', array(), $this->dateSelector( 'start', $this->editable, $startTimestamp ) );
538537 $htmlOut .= Xml::closeElement( 'tr' );
539538 // Start Time
540539 $htmlOut .= Xml::openElement( 'tr' );
541540 $htmlOut .= Xml::tags( 'td', array(), wfMsgHtml( 'centralnotice-start-time' ) );
542 - $htmlOut .= Xml::tags( 'td', array(), $this->timeSelector( 'start', $startTimestamp ) );
 541+ $htmlOut .= Xml::tags( 'td', array(), $this->timeSelector( 'start', $this->editable, $startTimestamp ) );
543542 $htmlOut .= Xml::closeElement( 'tr' );
544543 // Project
545544 $htmlOut .= Xml::openElement( 'tr' );
@@ -846,22 +845,22 @@
847846 // Start Date
848847 $htmlOut .= Xml::openElement( 'tr' );
849848 $htmlOut .= Xml::tags( 'td', array(), wfMsgHtml( 'centralnotice-start-date' ) );
850 - $htmlOut .= Xml::tags( 'td', array(), $this->dateSelector( 'start', $startTimestamp ) );
 849+ $htmlOut .= Xml::tags( 'td', array(), $this->dateSelector( 'start', $this->editable, $startTimestamp ) );
851850 $htmlOut .= Xml::closeElement( 'tr' );
852851 // Start Time
853852 $htmlOut .= Xml::openElement( 'tr' );
854853 $htmlOut .= Xml::tags( 'td', array(), wfMsgHtml( 'centralnotice-start-time' ) );
855 - $htmlOut .= Xml::tags( 'td', array(), $this->timeSelector( 'start', $startTimestamp ) );
 854+ $htmlOut .= Xml::tags( 'td', array(), $this->timeSelector( 'start', $this->editable, $startTimestamp ) );
856855 $htmlOut .= Xml::closeElement( 'tr' );
857856 // End Date
858857 $htmlOut .= Xml::openElement( 'tr' );
859858 $htmlOut .= Xml::tags( 'td', array(), wfMsgHtml( 'centralnotice-end-date' ) );
860 - $htmlOut .= Xml::tags( 'td', array(), $this->dateSelector( 'end', $endTimestamp ) );
 859+ $htmlOut .= Xml::tags( 'td', array(), $this->dateSelector( 'end', $this->editable, $endTimestamp ) );
861860 $htmlOut .= Xml::closeElement( 'tr' );
862861 // End Time
863862 $htmlOut .= Xml::openElement( 'tr' );
864863 $htmlOut .= Xml::tags( 'td', array(), wfMsgHtml( 'centralnotice-end-time' ) );
865 - $htmlOut .= Xml::tags( 'td', array(), $this->timeSelector( 'end', $endTimestamp ) );
 864+ $htmlOut .= Xml::tags( 'td', array(), $this->timeSelector( 'end', $this->editable, $endTimestamp ) );
866865 $htmlOut .= Xml::closeElement( 'tr' );
867866 // Project
868867 $htmlOut .= Xml::openElement( 'tr' );
@@ -1641,15 +1640,16 @@
16421641 }
16431642 return $dropDown;
16441643 }
1645 -
1646 - function addZero( $text ) {
1647 - // Prepend a 0 for text needing it
1648 - if ( strlen( $text ) == 1 ) {
1649 - $text = "0{$text}";
 1644+
 1645+ public static function paddedRange( $begin, $end ) {
 1646+ $unpaddedRange = range( $begin, $end );
 1647+ $paddedRange = array();
 1648+ foreach ( $unpaddedRange as $number ) {
 1649+ $paddedRange[] = sprintf( "%02d", $number ); // pad number with 0 if needed
16501650 }
1651 - return $text;
 1651+ return $paddedRange;
16521652 }
1653 -
 1653+
16541654 function showError( $message ) {
16551655 global $wgOut;
16561656 $wgOut->wrapWikiMsg( "<div class='cn-error'>\n$1\n</div>", $message );
Index: trunk/extensions/CentralNotice/special/SpecialCentralNoticeLogs.php
@@ -70,10 +70,56 @@
7171 $htmlOut .= Xml::label( wfMsg( 'centralnotice-banner-settings' ), 'banner' );
7272
7373 $htmlOut .= Xml::closeElement( 'div' );
 74+
 75+ if ( $this->logType == 'campaignsettings' ) {
 76+
 77+ $reset = $wgRequest->getVal( 'centralnoticelogreset' );
 78+
 79+ $startArray = $wgRequest->getArray( 'start' );
 80+ if ( $wgRequest->wasPosted() && $startArray && !$reset ) {
 81+ $filterTimestamp = $startArray['year'] .
 82+ $startArray['month'] .
 83+ $startArray['day'] . '000000'
 84+ ;
 85+ } else { // Default
 86+ $filterTimestamp = -1;
 87+ }
 88+
 89+ $filters = Xml::openElement( 'span', array( 'class' => 'cn-log-filter' ) );
 90+ $filters .= Xml::label( wfMsg( 'centralnotice-date' ), 'start[month]', array( 'class' => 'cn-log-filter-label' ) );
 91+ $filters .= CentralNotice::dateSelector( 'start', true, $filterTimestamp );
 92+ $filters .= Xml::closeElement( 'span' );
 93+
 94+ $filters .= Xml::openElement( 'span', array( 'class' => 'cn-log-filter' ) );
 95+ $filters .= Xml::label( wfMsg( 'centralnotice-notice' ), 'campaign', array( 'class' => 'cn-log-filter-label' ) );
 96+ $filters .= Xml::input( 'campaign', 25, ( $reset ? '' : $wgRequest->getVal( 'campaign' ) ) );
 97+ $filters .= Xml::closeElement( 'span' );
 98+
 99+ $filters .= Xml::submitButton( wfMsg( 'centralnotice-apply-filters' ),
 100+ array(
 101+ 'id' => 'centralnoticesubmit',
 102+ 'name' => 'centralnoticesubmit',
 103+ 'class' => 'cn-filter-buttons',
 104+ )
 105+ );
 106+ $filters .= Xml::submitButton( 'Clear filters',
 107+ array(
 108+ 'id' => 'centralnoticelogreset',
 109+ 'name' => 'centralnoticelogreset',
 110+ 'class' => 'cn-filter-buttons',
 111+ )
 112+ );
 113+
 114+ $htmlOut .= Xml::fieldset( wfMsg( 'centralnotice-filters' ),
 115+ $filters,
 116+ array( 'class' => 'cn-bannerpreview')
 117+ );
 118+ }
 119+
74120 $htmlOut .= Xml::closeElement( 'form' );
75121
76122 // End log selection fieldset
77 - $htmlOut .= Xml::closeElement( 'fieldset' );
 123+ //$htmlOut .= Xml::closeElement( 'fieldset' );
78124
79125 $wgOut->addHTML( $htmlOut );
80126
@@ -99,7 +145,7 @@
100146 $htmlOut = '';
101147
102148 // Begin log fieldset
103 - $htmlOut .= Xml::openElement( 'fieldset', array( 'class' => 'prefsection' ) );
 149+ //$htmlOut .= Xml::openElement( 'fieldset', array( 'class' => 'prefsection' ) );
104150
105151 // Show paginated list of log entries
106152 $htmlOut .= Xml::tags( 'div',
Index: trunk/extensions/CentralNotice/centralnotice.css
@@ -61,6 +61,7 @@
6262 width: auto;
6363 }
6464 #preferences table#cn-campaign-logs td.primary {
 65+ white-space: nowrap;
6566 background-color: #F0F0F0;
6667 }
6768 #preferences .cn-new-value {
@@ -72,6 +73,15 @@
7374 #preferences .cn-log-label {
7475 font-weight: bold;
7576 }
 77+#preferences .cn-log-filter {
 78+ margin-right: 1.5em;
 79+}
 80+#preferences .cn-log-filter-label {
 81+ margin-right: 0.5em;
 82+}
 83+#preferences .cn-filter-buttons {
 84+ margin-right: 0.5em;
 85+}
7686 #preferences #cn-log-switcher label {
7787 margin-right: 1em;
7888 }
Index: trunk/extensions/CentralNotice/CentralNotice.i18n.php
@@ -168,6 +168,9 @@
169169 'centralnotice-landingpages' => 'Landing pages',
170170 'centralnotice-banner-content' => 'Banner content',
171171 'centralnotice-banner-content-changed' => 'Changed',
 172+ 'centralnotice-filters' => 'Filters',
 173+ 'centralnotice-date' => 'Date',
 174+ 'centralnotice-apply-filters' => 'Apply filters',
172175 );
173176
174177 /** Message documentation (Message documentation)
Index: trunk/extensions/CentralNotice/CentralNoticeLogPager.php
@@ -4,6 +4,7 @@
55 var $viewPage, $special;
66
77 function __construct( $special ) {
 8+ global $wgRequest;
89 $this->special = $special;
910 parent::__construct();
1011
@@ -25,10 +26,31 @@
2627 * Pull log entries from the database
2728 */
2829 function getQueryInfo() {
29 - return array(
 30+ global $wgRequest;
 31+
 32+ $dateArray = $wgRequest->getArray( 'start' );
 33+ $filterDate = $dateArray['year'] . $dateArray['month'] . $dateArray['day'];
 34+ $filterCampaign = $wgRequest->getVal( 'campaign' );
 35+ $reset = $wgRequest->getVal( 'centralnoticelogreset' );
 36+
 37+ $info = array(
3038 'tables' => array( 'cn_notice_log' ),
3139 'fields' => '*',
 40+ 'conds' => array()
3241 );
 42+
 43+ if ( !$reset ) {
 44+ $date1 = intval( $filterDate.'000000' );
 45+ $date2 = intval( ( $filterDate + 1 ).'000000' );
 46+ if ( $filterDate > 0 ) {
 47+ $info['conds'][] = "notlog_timestamp >= $date1 AND notlog_timestamp < $date2";
 48+ }
 49+ if ( $filterCampaign ) {
 50+ $info['conds'][] = "notlog_not_name LIKE '$filterCampaign'";
 51+ }
 52+ }
 53+
 54+ return $info;
3355 }
3456
3557 /**

Follow-up revisions

RevisionCommit summaryAuthorDate
r94823adding qqq translation instructionskaldari21:41, 17 August 2011
r95271follow-up for r94316, making year range dynamickaldari22:45, 22 August 2011

Comments

#Comment by Nikerabbit (talk | contribs)   06:56, 17 August 2011

The messages need documentation if they are going to be translated properly, see https://translatewiki.net/wiki/Thread:Support/About_MediaWiki:Centralnotice-filters/he

#Comment by Kaldari (talk | contribs)   21:41, 17 August 2011

Fixed in r94823.

#Comment by Awjrichards (talk | contribs)   23:19, 19 August 2011
+	public static function dateSelector( $prefix, $editable, $timestamp = null ) {
+		if ( $editable ) {
+			$years = range( 2010, 2016 );

Is this introducing a y2k-like problem? Like in 2017 CentralNotice will break and the world will end because of this? This seems like an arbitrary and strange range to me. Could selecting the upper (and lower?) bound of the range be done dynamically?

#Comment by Kaldari (talk | contribs)   01:24, 23 August 2011

Fixed in r95271.

Status & tagging log