r94677 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r94676‎ | r94677 | r94678 >
Date:19:17, 16 August 2011
Author:kaldari
Status:resolved (Comments)
Tags:
Comment:
more work on campaign log filtering
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/centralnotice.js (modified) (history)
  • /trunk/extensions/CentralNotice/special/SpecialCentralNoticeLogs.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CentralNotice/special/SpecialCentralNoticeLogs.php
@@ -47,7 +47,9 @@
4848 // Begin log selection fieldset
4949 $htmlOut .= Xml::openElement( 'fieldset', array( 'class' => 'prefsection' ) );
5050
51 - $htmlOut .= Xml::openElement( 'form', array( 'method' => 'post' ) );
 51+ $title = SpecialPage::getTitleFor( 'CentralNoticeLogs' );
 52+ $actionUrl = $title->getLocalURL();
 53+ $htmlOut .= Xml::openElement( 'form', array( 'method' => 'get', 'action' => $actionUrl ) );
5254 $htmlOut .= Xml::element( 'h2', null, wfMsg( 'centralnotice-view-logs' ) );
5355 $htmlOut .= Xml::openElement( 'div', array( 'id' => 'cn-log-switcher' ) );
5456 $title = SpecialPage::getTitleFor( 'CentralNoticeLogs' );
@@ -72,48 +74,97 @@
7375 $htmlOut .= Xml::closeElement( 'div' );
7476
7577 if ( $this->logType == 'campaignsettings' ) {
76 -
 78+
7779 $reset = $wgRequest->getVal( 'centralnoticelogreset' );
 80+ $campaign = $wgRequest->getVal( 'campaign' );
 81+ $user = $wgRequest->getVal( 'user' );
 82+ $year = $wgRequest->getVal( 'year' );
 83+ if ( $year === 'other' ) $year = null;
 84+ $month = $wgRequest->getVal( 'month' );
 85+ if ( $month === 'other' ) $month = null;
 86+ $day = $wgRequest->getVal( 'day' );
 87+ if ( $day === 'other' ) $day = null;
7888
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;
 89+ $htmlOut .= Xml::openElement( 'div', array( 'id' => 'cn-log-filters-container' ) );
 90+
 91+ if ( $campaign || $user || $year || $month || $day ) { // filters on
 92+ $htmlOut .= '<a href="javascript:toggleFilterDisplay()">'.
 93+ '<img src="'.$wgExtensionAssetsPath.'/CentralNotice/collapsed.png" id="cn-collapsed-filter-arrow" style="display:none;position:relative;top:-2px;"/>'.
 94+ '<img src="'.$wgExtensionAssetsPath.'/CentralNotice/uncollapsed.png" id="cn-uncollapsed-filter-arrow" style="display:inline-block;position:relative;top:-2px;"/>'.
 95+ '</a>';
 96+ $htmlOut .= Xml::tags( 'span', array( 'style' => 'margin-left: 0.3em;' ), wfMsg( 'centralnotice-filters' ) );
 97+ $htmlOut .= Xml::openElement( 'div', array( 'id' => 'cn-log-filters' ) );
 98+ } else { // filters off
 99+ $htmlOut .= '<a href="javascript:toggleFilterDisplay()">'.
 100+ '<img src="'.$wgExtensionAssetsPath.'/CentralNotice/collapsed.png" id="cn-collapsed-filter-arrow" style="display:inline-block;position:relative;top:-2px;"/>'.
 101+ '<img src="'.$wgExtensionAssetsPath.'/CentralNotice/uncollapsed.png" id="cn-uncollapsed-filter-arrow" style="display:none;position:relative;top:-2px;"/>'.
 102+ '</a>';
 103+ $htmlOut .= Xml::tags( 'span', array( 'style' => 'margin-left: 0.3em;' ), 'Log filters' );
 104+ $htmlOut .= Xml::openElement( 'div', array( 'id' => 'cn-log-filters', 'style' => 'display:none;' ) );
87105 }
88106
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' );
 107+ $htmlOut .= Xml::openElement( 'table' );
 108+ $htmlOut .= Xml::openElement( 'tr' );
93109
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' );
 110+ $htmlOut .= Xml::openElement( 'td' );
 111+ $htmlOut .= Xml::label( wfMsg( 'centralnotice-date' ), 'month', array( 'class' => 'cn-log-filter-label' ) );
 112+ $htmlOut .= Xml::closeElement( 'td' );
 113+ $htmlOut .= Xml::openElement( 'td' );
 114+ if ( $reset ) {
 115+ $htmlOut .= $this->dateSelector();
 116+ } else {
 117+ $htmlOut .= $this->dateSelector( $year, $month, $day );
 118+ }
 119+ $htmlOut .= Xml::closeElement( 'td' );
98120
99 - $filters .= Xml::submitButton( wfMsg( 'centralnotice-apply-filters' ),
 121+ $htmlOut .= Xml::closeElement( 'tr' );
 122+ $htmlOut .= Xml::openElement( 'tr' );
 123+
 124+ $htmlOut .= Xml::openElement( 'td' );
 125+ $htmlOut .= Xml::label( wfMsg( 'centralnotice-notice' ), 'campaign', array( 'class' => 'cn-log-filter-label' ) );
 126+ $htmlOut .= Xml::closeElement( 'td' );
 127+ $htmlOut .= Xml::openElement( 'td' );
 128+ $htmlOut .= Xml::input( 'campaign', 25, ( $reset ? '' : $campaign ) );
 129+ $htmlOut .= Xml::closeElement( 'span' );
 130+ $htmlOut .= Xml::closeElement( 'td' );
 131+
 132+ $htmlOut .= Xml::closeElement( 'tr' );
 133+ $htmlOut .= Xml::openElement( 'tr' );
 134+
 135+ $htmlOut .= Xml::openElement( 'td' );
 136+ $htmlOut .= Xml::label( wfMsg( 'centralnotice-user' ), 'user', array( 'class' => 'cn-log-filter-label' ) );
 137+ $htmlOut .= Xml::closeElement( 'td' );
 138+ $htmlOut .= Xml::openElement( 'td' );
 139+ $htmlOut .= Xml::input( 'user', 25, ( $reset ? '' : $user ) );
 140+ $htmlOut .= Xml::closeElement( 'span' );
 141+ $htmlOut .= Xml::closeElement( 'td' );
 142+
 143+ $htmlOut .= Xml::closeElement( 'tr' );
 144+ $htmlOut .= Xml::openElement( 'tr' );
 145+
 146+ $htmlOut .= Xml::openElement( 'td', array( 'colspan' => 2 ) );
 147+ $htmlOut .= Xml::submitButton( wfMsg( 'centralnotice-apply-filters' ),
100148 array(
101149 'id' => 'centralnoticesubmit',
102150 'name' => 'centralnoticesubmit',
103151 'class' => 'cn-filter-buttons',
104152 )
105153 );
106 - $filters .= Xml::submitButton( wfMsg( 'centralnotice-clear-filters' ),
 154+ $link = $title->getLinkUrl();
 155+ $htmlOut .= Xml::submitButton( wfMsg( 'centralnotice-clear-filters' ),
107156 array(
108157 'id' => 'centralnoticelogreset',
109158 'name' => 'centralnoticelogreset',
110159 'class' => 'cn-filter-buttons',
 160+ 'onclick' => "window.location = '$link'; return false;",
111161 )
112162 );
 163+ $htmlOut .= Xml::closeElement( 'td' );
113164
114 - $htmlOut .= Xml::fieldset( wfMsg( 'centralnotice-filters' ),
115 - $filters,
116 - array( 'class' => 'cn-bannerpreview')
117 - );
 165+ $htmlOut .= Xml::closeElement( 'tr' );
 166+ $htmlOut .= Xml::closeElement( 'table' );
 167+ $htmlOut .= Xml::closeElement( 'div' );
 168+ $htmlOut .= Xml::closeElement( 'div' );
118169 }
119170
120171 $htmlOut .= Xml::closeElement( 'form' );
@@ -129,6 +180,28 @@
130181 $wgOut->addHTML( Xml::closeElement( 'div' ) );
131182 }
132183
 184+ private function dateSelector( $year = 0, $month = 0, $day = 0 ) {
 185+ $years = range( 2010, 2016 );
 186+ $months = CentralNotice::paddedRange( 1, 12 );
 187+ $days = CentralNotice::paddedRange( 1, 31 );
 188+
 189+ $fields = array(
 190+ array( "month", "centralnotice-month", $months, $month ),
 191+ array( "day", "centralnotice-day", $days, $day ),
 192+ array( "year", "centralnotice-year", $years, $year ),
 193+ );
 194+
 195+ $out = '';
 196+ foreach ( $fields as $data ) {
 197+ list( $field, $label, $set, $current ) = $data;
 198+ $out .= Xml::listDropDown( $field,
 199+ CentralNotice::dropDownList( wfMsg( $label ), $set ),
 200+ '',
 201+ $current );
 202+ }
 203+ return $out;
 204+ }
 205+
133206 /**
134207 * Show a log of changes.
135208 * @param $logType string: which type of log to show
Index: trunk/extensions/CentralNotice/centralnotice.css
@@ -57,9 +57,15 @@
5858 margin-left:1.6em;
5959 margin-right:1.6em;
6060 }
61 -#preferences table#cn-campaign-logs {
 61+#preferences div#cn-log-filters-container {
 62+ margin: 1em 0;
 63+}
 64+#preferences table#cn-campaign-logs, #preferences div#cn-log-filters table {
6265 width: auto;
6366 }
 67+#preferences div#cn-log-filters table td {
 68+ padding: 0.5em;
 69+}
6470 #preferences table#cn-campaign-logs td.primary {
6571 white-space: nowrap;
6672 background-color: #F0F0F0;
@@ -73,12 +79,6 @@
7480 #preferences .cn-log-label {
7581 font-weight: bold;
7682 }
77 -#preferences .cn-log-filter {
78 - margin-right: 1.5em;
79 -}
80 -#preferences .cn-log-filter-label {
81 - margin-right: 0.5em;
82 -}
8383 #preferences .cn-filter-buttons {
8484 margin-right: 0.5em;
8585 }
Index: trunk/extensions/CentralNotice/CentralNotice.i18n.php
@@ -168,7 +168,7 @@
169169 'centralnotice-landingpages' => 'Landing pages',
170170 'centralnotice-banner-content' => 'Banner content',
171171 'centralnotice-banner-content-changed' => 'Changed',
172 - 'centralnotice-filters' => 'Filters',
 172+ 'centralnotice-filters' => 'Log filters',
173173 'centralnotice-date' => 'Date',
174174 'centralnotice-apply-filters' => 'Apply filters',
175175 'centralnotice-clear-filters' => 'Clear filters',
Index: trunk/extensions/CentralNotice/CentralNoticeLogPager.php
@@ -28,9 +28,15 @@
2929 function getQueryInfo() {
3030 global $wgRequest;
3131
32 - $dateArray = $wgRequest->getArray( 'start' );
33 - $filterDate = $dateArray['year'] . $dateArray['month'] . $dateArray['day'];
 32+ $filterDate = 0;
 33+ $year = $wgRequest->getVal( 'year' );
 34+ $month = $wgRequest->getVal( 'month' );
 35+ $day = $wgRequest->getVal( 'day' );
 36+ if ( $year !== 'other' && $month !== 'other' && $day !== 'other' ) {
 37+ $filterDate = $year . $month . $day;
 38+ }
3439 $filterCampaign = $wgRequest->getVal( 'campaign' );
 40+ $filterUser = $wgRequest->getVal( 'user' );
3541 $reset = $wgRequest->getVal( 'centralnoticelogreset' );
3642
3743 $info = array(
@@ -40,14 +46,19 @@
4147 );
4248
4349 if ( !$reset ) {
44 - $date1 = intval( $filterDate.'000000' );
45 - $date2 = intval( ( $filterDate + 1 ).'000000' );
4650 if ( $filterDate > 0 ) {
 51+ $date1 = intval( $filterDate.'000000' );
 52+ $date2 = intval( ( $filterDate + 1 ).'000000' );
4753 $info['conds'][] = "notlog_timestamp >= $date1 AND notlog_timestamp < $date2";
4854 }
4955 if ( $filterCampaign ) {
5056 $info['conds'][] = "notlog_not_name LIKE '$filterCampaign'";
5157 }
 58+ if ( $filterUser ) {
 59+ $user = User::newFromName( $filterUser );
 60+ $userId = $user->getId();
 61+ $info['conds'][] = "notlog_user_id = $userId";
 62+ }
5263 }
5364
5465 return $info;
@@ -77,9 +88,9 @@
7889
7990 $htmlOut .= Xml::openElement( 'td', array( 'valign' => 'top' ) );
8091 if ( $row->notlog_action !== 'removed' ) {
81 - $htmlOut .= '<a href="javascript:toggleDisplay(\''.$row->notlog_id.'\')">'.
82 - '<img src="'.$wgExtensionAssetsPath.'/CentralNotice/collapsed.png" id="cn-collapsed-'.$row->notlog_id.'" style="display:block;vertical-align:baseline;"/>'.
83 - '<img src="'.$wgExtensionAssetsPath.'/CentralNotice/uncollapsed.png" id="cn-uncollapsed-'.$row->notlog_id.'" style="display:none;vertical-align:baseline;"/>'.
 92+ $htmlOut .= '<a href="javascript:toggleLogDisplay(\''.$row->notlog_id.'\')">'.
 93+ '<img src="'.$wgExtensionAssetsPath.'/CentralNotice/collapsed.png" id="cn-collapsed-'.$row->notlog_id.'" style="display:block;"/>'.
 94+ '<img src="'.$wgExtensionAssetsPath.'/CentralNotice/uncollapsed.png" id="cn-uncollapsed-'.$row->notlog_id.'" style="display:none;"/>'.
8495 '</a>';
8596 }
8697 $htmlOut .= Xml::closeElement( 'td' );
Index: trunk/extensions/CentralNotice/centralnotice.js
@@ -1,4 +1,4 @@
2 -function toggleDisplay( logId ) {
 2+function toggleLogDisplay( logId ) {
33 var thisCollapsed = document.getElementById( 'cn-collapsed-'+logId );
44 var thisUncollapsed = document.getElementById( 'cn-uncollapsed-'+logId );
55 var thisDetails = document.getElementById( 'cn-log-details-'+logId );
@@ -12,6 +12,20 @@
1313 thisDetails.style.display = "table-row";
1414 }
1515 }
 16+function toggleFilterDisplay() {
 17+ var thisCollapsed = document.getElementById( 'cn-collapsed-filter-arrow' );
 18+ var thisUncollapsed = document.getElementById( 'cn-uncollapsed-filter-arrow' );
 19+ var thisFilters = document.getElementById( 'cn-log-filters' );
 20+ if ( thisCollapsed.style.display == "none" ) {
 21+ thisUncollapsed.style.display = "none";
 22+ thisCollapsed.style.display = "inline-block";
 23+ thisFilters.style.display = "none";
 24+ } else {
 25+ thisCollapsed.style.display = "none";
 26+ thisUncollapsed.style.display = "inline-block";
 27+ thisFilters.style.display = "block";
 28+ }
 29+}
1630 function switchLogs( baseUrl, logType ) {
1731 encodeURIComponent( logType );
1832 window.location = baseUrl + '?log=' + logType;

Follow-up revisions

RevisionCommit summaryAuthorDate
r95295follow-up to r94677, functionalizing date range creationkaldari01:24, 23 August 2011

Comments

#Comment by Awjrichards (talk | contribs)   23:27, 19 August 2011

iirc,

+		$years = range( 2010, 2016 );
+		$months = CentralNotice::paddedRange( 1, 12 );
+		$days = CentralNotice::paddedRange( 1, 31 );

this happens in other places in CN code. I suggest functionalizing this so if it needs to change you don't need to hunt it down in every place you're doing it.

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

fixed in r95295.

Status & tagging log