Index: trunk/extensions/CentralNotice/special/SpecialCentralNotice.php |
— | — | @@ -240,17 +240,19 @@ |
241 | 241 | return Xml::tags( 'tr', $attribs, implode( "\n", $cells ) ) . "\n"; |
242 | 242 | } |
243 | 243 | |
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 | + } |
255 | 257 | |
256 | 258 | $fields = array( |
257 | 259 | array( "month", "centralnotice-month", $months, substr( $ts, 4, 2 ) ), |
— | — | @@ -258,20 +260,17 @@ |
259 | 261 | array( "year", "centralnotice-year", $years, substr( $ts, 0, 4 ) ), |
260 | 262 | ); |
261 | 263 | |
262 | | - return $this->createSelector( $prefix, $fields ); |
| 264 | + return CentralNotice::createSelector( $prefix, $fields ); |
263 | 265 | } else { |
264 | 266 | global $wgLang; |
265 | 267 | return $wgLang->date( $timestamp ); |
266 | 268 | } |
267 | 269 | } |
268 | 270 | |
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 ); |
276 | 275 | |
277 | 276 | // Normalize timestamp format... |
278 | 277 | $ts = wfTimestamp( TS_MW, $timestamp ); |
— | — | @@ -281,7 +280,7 @@ |
282 | 281 | array( "min", "centralnotice-min", $minutes, substr( $ts, 10, 2 ) ), |
283 | 282 | ); |
284 | 283 | |
285 | | - return $this->createSelector( $prefix, $fields ); |
| 284 | + return CentralNotice::createSelector( $prefix, $fields ); |
286 | 285 | } else { |
287 | 286 | global $wgLang; |
288 | 287 | return $wgLang->time( $timestamp ); |
— | — | @@ -290,15 +289,15 @@ |
291 | 290 | |
292 | 291 | /** |
293 | 292 | * 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 |
296 | 295 | */ |
297 | | - private function createSelector( $prefix, $fields ) { |
| 296 | + public static function createSelector( $prefix, $fields ) { |
298 | 297 | $out = ''; |
299 | 298 | foreach ( $fields as $data ) { |
300 | 299 | list( $field, $label, $set, $current ) = $data; |
301 | 300 | $out .= Xml::listDropDown( "{$prefix}[{$field}]", |
302 | | - $this->dropDownList( wfMsg( $label ), $set ), |
| 301 | + CentralNotice::dropDownList( wfMsg( $label ), $set ), |
303 | 302 | '', |
304 | 303 | $current ); |
305 | 304 | } |
— | — | @@ -533,12 +532,12 @@ |
534 | 533 | // Start Date |
535 | 534 | $htmlOut .= Xml::openElement( 'tr' ); |
536 | 535 | $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 ) ); |
538 | 537 | $htmlOut .= Xml::closeElement( 'tr' ); |
539 | 538 | // Start Time |
540 | 539 | $htmlOut .= Xml::openElement( 'tr' ); |
541 | 540 | $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 ) ); |
543 | 542 | $htmlOut .= Xml::closeElement( 'tr' ); |
544 | 543 | // Project |
545 | 544 | $htmlOut .= Xml::openElement( 'tr' ); |
— | — | @@ -846,22 +845,22 @@ |
847 | 846 | // Start Date |
848 | 847 | $htmlOut .= Xml::openElement( 'tr' ); |
849 | 848 | $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 ) ); |
851 | 850 | $htmlOut .= Xml::closeElement( 'tr' ); |
852 | 851 | // Start Time |
853 | 852 | $htmlOut .= Xml::openElement( 'tr' ); |
854 | 853 | $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 ) ); |
856 | 855 | $htmlOut .= Xml::closeElement( 'tr' ); |
857 | 856 | // End Date |
858 | 857 | $htmlOut .= Xml::openElement( 'tr' ); |
859 | 858 | $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 ) ); |
861 | 860 | $htmlOut .= Xml::closeElement( 'tr' ); |
862 | 861 | // End Time |
863 | 862 | $htmlOut .= Xml::openElement( 'tr' ); |
864 | 863 | $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 ) ); |
866 | 865 | $htmlOut .= Xml::closeElement( 'tr' ); |
867 | 866 | // Project |
868 | 867 | $htmlOut .= Xml::openElement( 'tr' ); |
— | — | @@ -1641,15 +1640,16 @@ |
1642 | 1641 | } |
1643 | 1642 | return $dropDown; |
1644 | 1643 | } |
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 |
1650 | 1650 | } |
1651 | | - return $text; |
| 1651 | + return $paddedRange; |
1652 | 1652 | } |
1653 | | - |
| 1653 | + |
1654 | 1654 | function showError( $message ) { |
1655 | 1655 | global $wgOut; |
1656 | 1656 | $wgOut->wrapWikiMsg( "<div class='cn-error'>\n$1\n</div>", $message ); |
Index: trunk/extensions/CentralNotice/special/SpecialCentralNoticeLogs.php |
— | — | @@ -70,10 +70,56 @@ |
71 | 71 | $htmlOut .= Xml::label( wfMsg( 'centralnotice-banner-settings' ), 'banner' ); |
72 | 72 | |
73 | 73 | $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 | + |
74 | 120 | $htmlOut .= Xml::closeElement( 'form' ); |
75 | 121 | |
76 | 122 | // End log selection fieldset |
77 | | - $htmlOut .= Xml::closeElement( 'fieldset' ); |
| 123 | + //$htmlOut .= Xml::closeElement( 'fieldset' ); |
78 | 124 | |
79 | 125 | $wgOut->addHTML( $htmlOut ); |
80 | 126 | |
— | — | @@ -99,7 +145,7 @@ |
100 | 146 | $htmlOut = ''; |
101 | 147 | |
102 | 148 | // Begin log fieldset |
103 | | - $htmlOut .= Xml::openElement( 'fieldset', array( 'class' => 'prefsection' ) ); |
| 149 | + //$htmlOut .= Xml::openElement( 'fieldset', array( 'class' => 'prefsection' ) ); |
104 | 150 | |
105 | 151 | // Show paginated list of log entries |
106 | 152 | $htmlOut .= Xml::tags( 'div', |
Index: trunk/extensions/CentralNotice/centralnotice.css |
— | — | @@ -61,6 +61,7 @@ |
62 | 62 | width: auto; |
63 | 63 | } |
64 | 64 | #preferences table#cn-campaign-logs td.primary { |
| 65 | + white-space: nowrap; |
65 | 66 | background-color: #F0F0F0; |
66 | 67 | } |
67 | 68 | #preferences .cn-new-value { |
— | — | @@ -72,6 +73,15 @@ |
73 | 74 | #preferences .cn-log-label { |
74 | 75 | font-weight: bold; |
75 | 76 | } |
| 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 | +} |
76 | 86 | #preferences #cn-log-switcher label { |
77 | 87 | margin-right: 1em; |
78 | 88 | } |
Index: trunk/extensions/CentralNotice/CentralNotice.i18n.php |
— | — | @@ -168,6 +168,9 @@ |
169 | 169 | 'centralnotice-landingpages' => 'Landing pages', |
170 | 170 | 'centralnotice-banner-content' => 'Banner content', |
171 | 171 | 'centralnotice-banner-content-changed' => 'Changed', |
| 172 | + 'centralnotice-filters' => 'Filters', |
| 173 | + 'centralnotice-date' => 'Date', |
| 174 | + 'centralnotice-apply-filters' => 'Apply filters', |
172 | 175 | ); |
173 | 176 | |
174 | 177 | /** Message documentation (Message documentation) |
Index: trunk/extensions/CentralNotice/CentralNoticeLogPager.php |
— | — | @@ -4,6 +4,7 @@ |
5 | 5 | var $viewPage, $special; |
6 | 6 | |
7 | 7 | function __construct( $special ) { |
| 8 | + global $wgRequest; |
8 | 9 | $this->special = $special; |
9 | 10 | parent::__construct(); |
10 | 11 | |
— | — | @@ -25,10 +26,31 @@ |
26 | 27 | * Pull log entries from the database |
27 | 28 | */ |
28 | 29 | 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( |
30 | 38 | 'tables' => array( 'cn_notice_log' ), |
31 | 39 | 'fields' => '*', |
| 40 | + 'conds' => array() |
32 | 41 | ); |
| 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; |
33 | 55 | } |
34 | 56 | |
35 | 57 | /** |