r23283 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23282‎ | r23283 | r23284 >
Date:05:17, 23 June 2007
Author:robchurch
Status:old
Tags:
Comment:
* When viewing a cached report, show the date/time the cache was last updated
* Allow disabling report updates with $wgDisabledReports (obsoletes $wgDisableQueryPages)
Modified paths:
  • /branches/robchurch/reports/includes/DefaultSettings.php (modified) (history)
  • /branches/robchurch/reports/includes/reports/Report.php (modified) (history)
  • /branches/robchurch/reports/includes/reports/ReportCache.php (modified) (history)
  • /branches/robchurch/reports/languages/messages/MessagesEn.php (modified) (history)
  • /branches/robchurch/reports/maintenance/updateReports.php (modified) (history)
  • /branches/robchurch/reports/skins/monobook/main.css (modified) (history)

Diff [purge]

Index: branches/robchurch/reports/maintenance/updateReports.php
@@ -21,8 +21,13 @@
2222
2323 foreach( $reports as $report ) {
2424 if( class_exists( $report ) ) {
25 - echo( "{$report}:\n" );
26 - ReportCache::recache( new $report, $limit, 'updateReportsCallback' );
 25+ $obj = new $report;
 26+ if( !$obj->isDisabled() ) {
 27+ echo( "{$report}:\n" );
 28+ ReportCache::recache( $obj, $limit, 'updateReportsCallback' );
 29+ } else {
 30+ echo( "{$report} is disabled\n" );
 31+ }
2732 } else {
2833 echo( "Unknown report '{$report}'\n" );
2934 }
Index: branches/robchurch/reports/skins/monobook/main.css
@@ -1613,6 +1613,22 @@
16141614 background-color: #CC9999;
16151615 }
16161616
 1617+/* Report cache information and disabled warnings */
 1618+div.mw-report-cached,
 1619+div.mw-report-disabled {
 1620+ font-weight: bold;
 1621+ text-align: center;
 1622+ padding: 2px;
 1623+}
 1624+div.mw-report-cached {
 1625+ border: 1px solid #FFFF99;
 1626+ background-color: #FFFFCC;
 1627+}
 1628+div.mw-report-disabled {
 1629+ border: 2px solid #CC6666;
 1630+ background-color: #CC9999;
 1631+}
 1632+
16171633 /* Recreating-deleted-page warning and log entries */
16181634 div#mw-recreate-deleted-warn {
16191635 padding: 3px;
Index: branches/robchurch/reports/includes/reports/Report.php
@@ -33,6 +33,16 @@
3434 }
3535
3636 /**
 37+ * Are updates for this report disabled?
 38+ *
 39+ * @return bool
 40+ */
 41+ public function isDisabled() {
 42+ global $wgDisabledReports;
 43+ return in_array( $this->getName(), $wgDisabledReports );
 44+ }
 45+
 46+ /**
3747 * Is it appropriate to allow filtering redirects?
3848 *
3949 * @return bool
@@ -128,6 +138,12 @@
129139 public function execute( $par = false ) {
130140 global $wgOut, $wgRequest, $wgLang;
131141 $this->setHeaders();
 142+ $pager = $this->getPager();
 143+ if( $this->isDisabled() ) {
 144+ $wgOut->addHtml( '<div class="mw-report-disabled">' . wfMsgExt( 'report-disabled', 'parse' ) . '</div>' );
 145+ } elseif( $pager instanceof CachedReportPager ) {
 146+ $wgOut->addHtml( $this->getCacheInfo() );
 147+ }
132148 # Filtering UI
133149 $wgOut->addHtml(
134150 $this->buildFilterUI(
@@ -136,11 +152,7 @@
137153 )
138154 );
139155 # Report results
140 - $pager = $this->getPager();
141 - if( $pager instanceof CachedReportPager )
142 - $wgOut->addHtml( '<div class="mw-report-cached">' . wfMsgExt( 'report-cached', 'parse' ) . '</div>' );
143156 if( ( $count = $pager->getNumRows() ) > 0 ) {
144 - #$wgOut->addHtml( '<p>' . wfMsgHtml( 'report-num-results', $wgLang->formatNum( $count ) ) . '</p>' );
145157 $wgOut->addHtml( $pager->getNavigationBar() );
146158 $wgOut->addHtml( $pager->getBody() );
147159 $wgOut->addHtml( $pager->getNavigationBar() );
@@ -225,6 +237,24 @@
226238 }
227239
228240 /**
 241+ * Build a box containing information about when the
 242+ * cache for this report was last updated
 243+ *
 244+ * @return string
 245+ */
 246+ private function getCacheInfo() {
 247+ global $wgLang;
 248+ $html = '<div class="mw-report-cached">';
 249+ if( ( $ts = ReportCache::getUpdateTime( $this ) ) !== false ) {
 250+ $html .= wfMsgExt( 'report-cached-timestamp', 'parse', $wgLang->timeAndDate( $ts, true ) );
 251+ } else {
 252+ $html .= wfMsgExt( 'report-cached', 'parse' );
 253+ }
 254+ $html .= '</div>';
 255+ return $html;
 256+ }
 257+
 258+ /**
229259 * Get a list of all reports
230260 *
231261 * @return array
Index: branches/robchurch/reports/includes/reports/ReportCache.php
@@ -49,6 +49,16 @@
5050 );
5151 }
5252 $dbr->freeResult( $res );
 53+ # Update the cache state table
 54+ $dbw->replace(
 55+ 'reportcache_info',
 56+ array( 'rci_report' ),
 57+ array(
 58+ 'rci_report' => $report->getName(),
 59+ 'rci_updated' => $dbw->timestamp(),
 60+ ),
 61+ __METHOD__
 62+ );
5363 # Callback?
5464 if( is_callable( $namespaceCallback ) )
5565 call_user_func( $namespaceCallback, $report, $namespace, $rows );
@@ -74,6 +84,29 @@
7585 }
7686 return $namespaces;
7787 }
 88+
 89+ /**
 90+ * Get the timestamp of the last update to a cached
 91+ * result set, or false if not available
 92+ *
 93+ * @param Report $report Report to check
 94+ * @return mixed
 95+ */
 96+ public static function getUpdateTime( $report ) {
 97+ $dbr = wfGetDB( DB_SLAVE );
 98+ $res = $dbr->select(
 99+ 'reportcache_info',
 100+ '*',
 101+ array( 'rci_report' => $report->getName() ),
 102+ __METHOD__
 103+ );
 104+ if( $dbr->numRows( $res ) > 0 ) {
 105+ $row = $dbr->fetchObject( $res );
 106+ return wfTimestamp( TS_MW, $row->rci_updated );
 107+ } else {
 108+ return false;
 109+ }
 110+ }
78111
79112 /**
80113 * Encode a set of parameters
Index: branches/robchurch/reports/includes/DefaultSettings.php
@@ -1183,7 +1183,7 @@
11841184 * to ensure that client-side caches don't keep obsolete copies of global
11851185 * styles.
11861186 */
1187 -$wgStyleVersion = '77';
 1187+$wgStyleVersion = '78';
11881188
11891189
11901190 # Server-side caching:
@@ -2646,10 +2646,10 @@
26472647 $wgBreakFrames = false;
26482648
26492649 /**
2650 - * Set this to an array of special page names to prevent
2651 - * maintenance/updateSpecialPages.php from updating those pages.
 2650+ * Set this to an array of report names to disable
 2651+ * cache updates for those pages
26522652 */
2653 -$wgDisableQueryPageUpdate = false;
 2653+$wgDisabledReports = array();
26542654
26552655 /**
26562656 * Set this to false to disable cascading protection
Index: branches/robchurch/reports/languages/messages/MessagesEn.php
@@ -2909,7 +2909,8 @@
29102910 'report-paging-next' => 'next',
29112911 'report-paging-prev' => 'previous',
29122912 'report-cached' => 'This information is cached.',
2913 -'report-num-results' => 'Showing $1 results:',
 2913+'report-cached-timestamp' => 'This information is cached, and was last updated $1.',
 2914+'report-disabled' => 'Updates for this report are disabled at present. Data here will not be refreshed.',
29142915 'report-no-results' => 'There are no results for this report.',
29152916 'report-filter-legend' => 'Filter results',
29162917 'report-filter-namespace' => 'Namespace:',

Status & tagging log