r114070 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r114069‎ | r114070 | r114071 >
Date:21:07, 17 March 2012
Author:jeroendedauw
Status:deferred
Tags:
Comment:
follow up to r114067 and changed special:educationprogram to use new caching stuff
Modified paths:
  • /trunk/extensions/EducationProgram/EducationProgram.i18n.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialCachedPage.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialEducationProgram.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/specials/SpecialEducationProgram.php
@@ -19,6 +19,7 @@
2020 * @since 0.1
2121 */
2222 public function __construct() {
 23+ $this->cacheExpiry = 3600;
2324 parent::__construct( 'EducationProgram' );
2425 }
2526
@@ -32,53 +33,48 @@
3334 public function execute( $subPage ) {
3435 parent::execute( $subPage );
3536
36 - $cache = wfGetCache( CACHE_ANYTHING );
37 - $cacheKey = wfMemcKey( get_class( $this ), $this->getLanguage()->getCode() );
38 - $cachedHTML = $cache->get( $cacheKey );
 37+ $this->displayNavigation();
3938
40 - $out = $this->getOutput();
 39+ $this->addCachedHTML( array( $this, 'displaySummaryTable' ) );
4140
42 - if ( $this->getRequest()->getText( 'action' ) !== 'purge' && is_string( $cachedHTML ) ) {
43 - $out->clearHTML();
44 - $out->addHTML( $cachedHTML );
45 - }
46 - else {
47 - $this->displaySummaryTable();
48 - $cache->set( $cacheKey, $out->getHTML(), 3600 );
49 - }
 41+ $this->saveCache();
5042 }
5143
5244 /**
 45+ * Display a table with a basic summary of what the extension is handling.
 46+ *
5347 * @since 0.1
 48+ *
 49+ * @return string
5450 */
5551 protected function displaySummaryTable() {
56 - $out = $this->getOutput();
 52+ $html = Html::openElement( 'table', array( 'class' => 'wikitable ep-summary' ) );
5753
58 - $out->addHTML( Html::openElement( 'table', array( 'class' => 'wikitable ep-summary' ) ) );
 54+ $html .= '<tr>' . Html::element( 'th', array( 'colspan' => 2 ), wfMsg( 'ep-summary-table-header' ) ) . '</tr>';
5955
60 - $out->addHTML( '<tr>' . Html::element( 'th', array( 'colspan' => 2 ), wfMsg( 'ep-summary-table-header' ) ) . '</tr>' );
61 -
6256 $summaryData = $this->getSummaryInfo();
6357
6458 foreach ( $summaryData as $stat => $value ) {
65 - $out->addHTML( '<tr>' );
 59+ $html .= '<tr>';
6660
67 - $out->addHtml( Html::rawElement(
 61+ $html .= Html::rawElement(
6862 'th',
6963 array( 'class' => 'ep-summary-name' ),
7064 wfMsgExt( strtolower( get_called_class() ) . '-summary-' . $stat, 'parseinline' )
71 - ) );
 65+ );
7266
73 - $out->addHTML( Html::rawElement(
 67+ $html .= Html::rawElement(
7468 'td',
7569 array( 'class' => 'ep-summary-value' ),
7670 $value
77 - ) );
 71+ );
7872
79 - $out->addHTML( '</tr>' );
 73+ $html .= '</tr>';
8074 }
8175
82 - $out->addHTML( Html::closeElement( 'table' ) );
 76+ $html .= Html::closeElement( 'table' );
 77+
 78+ return $html;
8379 }
8480
8581 protected function getSummaryInfo() {
Index: trunk/extensions/EducationProgram/specials/SpecialCachedPage.php
@@ -110,6 +110,7 @@
111111
112112 /**
113113 * Returns a message with the time to live of the cache.
 114+ * Takes care of compatibility with MW < 1.20, in which Language::duration was introduced.
114115 *
115116 * @since 0.1
116117 *
@@ -119,31 +120,36 @@
120121 * @return string
121122 */
122123 protected function getDurationText( $seconds, array $chosenIntervals = array( 'years', 'days', 'hours', 'minutes', 'seconds' ) ) {
123 - $intervals = array(
124 - 'years' => 31557600, // 86400 * 365.25
125 - 'weeks' => 604800,
126 - 'days' => 86400,
127 - 'hours' => 3600,
128 - 'minutes' => 60,
129 - 'seconds' => 1,
130 - );
131 -
132 - if ( !empty( $chosenIntervals ) ) {
133 - $intervals = array_intersect_key( $intervals, array_flip( $chosenIntervals ) );
 124+ if ( method_exists( $this->getLanguage(), 'duration' ) ) {
 125+ return $this->getLanguage()->duration( $seconds, $chosenIntervals );
134126 }
 127+ else {
 128+ $intervals = array(
 129+ 'years' => 31557600, // 86400 * 365.25
 130+ 'weeks' => 604800,
 131+ 'days' => 86400,
 132+ 'hours' => 3600,
 133+ 'minutes' => 60,
 134+ 'seconds' => 1,
 135+ );
135136
136 - $segments = array();
 137+ if ( !empty( $chosenIntervals ) ) {
 138+ $intervals = array_intersect_key( $intervals, array_flip( $chosenIntervals ) );
 139+ }
137140
138 - foreach ( $intervals as $name => $length ) {
139 - $value = floor( $seconds / $length );
 141+ $segments = array();
140142
141 - if ( $value > 0 || ( $name == 'seconds' && empty( $segments ) ) ) {
142 - $seconds -= $value * $length;
143 - $segments[] = wfMsgExt( 'duration-' . $name, 'parsemag', $value );
 143+ foreach ( $intervals as $name => $length ) {
 144+ $value = floor( $seconds / $length );
 145+
 146+ if ( $value > 0 || ( $name == 'seconds' && empty( $segments ) ) ) {
 147+ $seconds -= $value * $length;
 148+ $segments[] = wfMsgExt( 'duration-' . $name, 'parsemag', $value );
 149+ }
144150 }
 151+
 152+ return $this->getLanguage()->listToText( $segments );
145153 }
146 -
147 - return $this->getLanguage()->listToText( $segments );
148154 }
149155
150156 /**
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php
@@ -787,7 +787,7 @@
788788 'cachedspecial-viewing-cached-ts' => 'You are viewing a cached version of this page, which might not be completely actual.',
789789 'cachedspecial-refresh-now' => 'View latest.',
790790
791 - // Durations
 791+ // Durations, back compat for MW < 1.20
792792 'duration-seconds' => '$1 {{PLURAL:$1|second|seconds}}',
793793 'duration-minutes' => '$1 {{PLURAL:$1|minute|minutes}}',
794794 'duration-hours' => '$1 {{PLURAL:$1|hour|hours}}',

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r114067adding a duration function to language that converts seconds to textjeroendedauw20:58, 17 March 2012

Status & tagging log