Index: trunk/extensions/EducationProgram/specials/SpecialEducationProgram.php |
— | — | @@ -19,6 +19,7 @@ |
20 | 20 | * @since 0.1 |
21 | 21 | */ |
22 | 22 | public function __construct() { |
| 23 | + $this->cacheExpiry = 3600; |
23 | 24 | parent::__construct( 'EducationProgram' ); |
24 | 25 | } |
25 | 26 | |
— | — | @@ -32,53 +33,48 @@ |
33 | 34 | public function execute( $subPage ) { |
34 | 35 | parent::execute( $subPage ); |
35 | 36 | |
36 | | - $cache = wfGetCache( CACHE_ANYTHING ); |
37 | | - $cacheKey = wfMemcKey( get_class( $this ), $this->getLanguage()->getCode() ); |
38 | | - $cachedHTML = $cache->get( $cacheKey ); |
| 37 | + $this->displayNavigation(); |
39 | 38 | |
40 | | - $out = $this->getOutput(); |
| 39 | + $this->addCachedHTML( array( $this, 'displaySummaryTable' ) ); |
41 | 40 | |
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(); |
50 | 42 | } |
51 | 43 | |
52 | 44 | /** |
| 45 | + * Display a table with a basic summary of what the extension is handling. |
| 46 | + * |
53 | 47 | * @since 0.1 |
| 48 | + * |
| 49 | + * @return string |
54 | 50 | */ |
55 | 51 | protected function displaySummaryTable() { |
56 | | - $out = $this->getOutput(); |
| 52 | + $html = Html::openElement( 'table', array( 'class' => 'wikitable ep-summary' ) ); |
57 | 53 | |
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>'; |
59 | 55 | |
60 | | - $out->addHTML( '<tr>' . Html::element( 'th', array( 'colspan' => 2 ), wfMsg( 'ep-summary-table-header' ) ) . '</tr>' ); |
61 | | - |
62 | 56 | $summaryData = $this->getSummaryInfo(); |
63 | 57 | |
64 | 58 | foreach ( $summaryData as $stat => $value ) { |
65 | | - $out->addHTML( '<tr>' ); |
| 59 | + $html .= '<tr>'; |
66 | 60 | |
67 | | - $out->addHtml( Html::rawElement( |
| 61 | + $html .= Html::rawElement( |
68 | 62 | 'th', |
69 | 63 | array( 'class' => 'ep-summary-name' ), |
70 | 64 | wfMsgExt( strtolower( get_called_class() ) . '-summary-' . $stat, 'parseinline' ) |
71 | | - ) ); |
| 65 | + ); |
72 | 66 | |
73 | | - $out->addHTML( Html::rawElement( |
| 67 | + $html .= Html::rawElement( |
74 | 68 | 'td', |
75 | 69 | array( 'class' => 'ep-summary-value' ), |
76 | 70 | $value |
77 | | - ) ); |
| 71 | + ); |
78 | 72 | |
79 | | - $out->addHTML( '</tr>' ); |
| 73 | + $html .= '</tr>'; |
80 | 74 | } |
81 | 75 | |
82 | | - $out->addHTML( Html::closeElement( 'table' ) ); |
| 76 | + $html .= Html::closeElement( 'table' ); |
| 77 | + |
| 78 | + return $html; |
83 | 79 | } |
84 | 80 | |
85 | 81 | protected function getSummaryInfo() { |
Index: trunk/extensions/EducationProgram/specials/SpecialCachedPage.php |
— | — | @@ -110,6 +110,7 @@ |
111 | 111 | |
112 | 112 | /** |
113 | 113 | * 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. |
114 | 115 | * |
115 | 116 | * @since 0.1 |
116 | 117 | * |
— | — | @@ -119,31 +120,36 @@ |
120 | 121 | * @return string |
121 | 122 | */ |
122 | 123 | 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 ); |
134 | 126 | } |
| 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 | + ); |
135 | 136 | |
136 | | - $segments = array(); |
| 137 | + if ( !empty( $chosenIntervals ) ) { |
| 138 | + $intervals = array_intersect_key( $intervals, array_flip( $chosenIntervals ) ); |
| 139 | + } |
137 | 140 | |
138 | | - foreach ( $intervals as $name => $length ) { |
139 | | - $value = floor( $seconds / $length ); |
| 141 | + $segments = array(); |
140 | 142 | |
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 | + } |
144 | 150 | } |
| 151 | + |
| 152 | + return $this->getLanguage()->listToText( $segments ); |
145 | 153 | } |
146 | | - |
147 | | - return $this->getLanguage()->listToText( $segments ); |
148 | 154 | } |
149 | 155 | |
150 | 156 | /** |
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php |
— | — | @@ -787,7 +787,7 @@ |
788 | 788 | 'cachedspecial-viewing-cached-ts' => 'You are viewing a cached version of this page, which might not be completely actual.', |
789 | 789 | 'cachedspecial-refresh-now' => 'View latest.', |
790 | 790 | |
791 | | - // Durations |
| 791 | + // Durations, back compat for MW < 1.20 |
792 | 792 | 'duration-seconds' => '$1 {{PLURAL:$1|second|seconds}}', |
793 | 793 | 'duration-minutes' => '$1 {{PLURAL:$1|minute|minutes}}', |
794 | 794 | 'duration-hours' => '$1 {{PLURAL:$1|hour|hours}}', |