Index: trunk/extensions/EducationProgram/specials/SpecialStudentActivity.php |
— | — | @@ -23,6 +23,8 @@ |
24 | 24 | $this->cacheExpiry = 600; |
25 | 25 | } |
26 | 26 | |
| 27 | + protected $cachedOut; |
| 28 | + |
27 | 29 | /** |
28 | 30 | * Main method. |
29 | 31 | * |
— | — | @@ -31,31 +33,13 @@ |
32 | 34 | * @param string $subPage |
33 | 35 | */ |
34 | 36 | public function execute( $subPage ) { |
35 | | - //parent::execute( $subPage ); |
| 37 | + parent::execute( $subPage ); |
36 | 38 | |
37 | | - if ( !is_null( $this->cacheExpiry ) ) { |
38 | | - $cache = wfGetCache( CACHE_ANYTHING ); |
39 | | - $cacheKey = $this->getCacheKey(); |
40 | | - $cachedHTML = $cache->get( $cacheKey ); |
| 39 | + $this->displayNavigation(); |
41 | 40 | |
42 | | - $out = $this->getOutput(); |
| 41 | + $this->addCachedHTML( array( $this, 'displayCachedContent' ) ); |
43 | 42 | |
44 | | - if ( $this->getRequest()->getText( 'action' ) !== 'purge' && is_string( $cachedHTML ) ) { |
45 | | - $html = $cachedHTML; |
46 | | - } |
47 | | - else { |
48 | | - $this->displayCachedContent(); |
49 | | - |
50 | | - $html = $out->getHTML(); |
51 | | - $cache->set( $cacheKey, $html, $this->cacheExpiry ); |
52 | | - } |
53 | | - |
54 | | - $out->clearHTML(); |
55 | | - |
56 | | - $this->displayBeforeCached(); |
57 | | - $out->addHTML( $html ); |
58 | | - $this->displayAfterCached(); |
59 | | - } |
| 43 | + $this->saveCache(); |
60 | 44 | } |
61 | 45 | |
62 | 46 | protected function displayCachedContent() { |
— | — | @@ -63,27 +47,25 @@ |
64 | 48 | wfTimestamp( TS_MW, time() - ( EPSettings::get( 'recentActivityLimit' ) ) ) |
65 | 49 | ) ); |
66 | 50 | |
67 | | - $this->displayStudentMeter( $conds ); |
68 | | - $this->displayPager( $conds ); |
| 51 | + return $this->displayStudentMeter( $conds ) . |
| 52 | + $this->displayPager( $conds ); |
69 | 53 | } |
70 | 54 | |
71 | 55 | public function displayPager( array $conds ) { |
72 | | - $out = $this->getOutput(); |
73 | | - |
74 | 56 | $pager = new EPStudentActivityPager( $this->getContext(), $conds ); |
75 | 57 | |
76 | 58 | if ( $pager->getNumRows() ) { |
77 | | - $out->addHTML( |
| 59 | + return |
78 | 60 | $pager->getFilterControl() . |
79 | 61 | $pager->getNavigationBar() . |
80 | 62 | $pager->getBody() . |
81 | 63 | $pager->getNavigationBar() . |
82 | | - $pager->getMultipleItemControl() |
83 | | - ); |
| 64 | + $pager->getMultipleItemControl(); |
84 | 65 | } |
85 | 66 | else { |
86 | | - $out->addHTML( $pager->getFilterControl( true ) ); |
87 | | - $out->addWikiMsg( 'ep-studentactivity-noresults' ); |
| 67 | + return $pager->getFilterControl( true ) |
| 68 | + . '<br />' |
| 69 | + . wfMsgExt( 'ep-studentactivity-noresults', 'parseinline' ); |
88 | 70 | } |
89 | 71 | } |
90 | 72 | |
— | — | @@ -99,7 +81,7 @@ |
100 | 82 | |
101 | 83 | $message = $this->msg( 'ep-studentactivity-count', $studentCount )->escaped(); |
102 | 84 | |
103 | | - $this->getOutput()->addElement( 'img', array( |
| 85 | + return Html::element( 'img', array( |
104 | 86 | 'src' => EPSettings::get( 'imageDir' ) . 'student-o-meter_morethan-' . $image . '.png', |
105 | 87 | 'alt' => $message, |
106 | 88 | 'title' => $message, |
Index: trunk/extensions/EducationProgram/specials/SpecialCachedPage.php |
— | — | @@ -1,29 +1,45 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | | -class CachedOutput { |
| 4 | +/** |
| 5 | + * Abstract special page class with scaffolding for caching the HTML output. |
| 6 | + * |
| 7 | + * @since 0.1 |
| 8 | + * |
| 9 | + * @file SpecialCachedPage.php |
| 10 | + * @ingroup EducationProgram |
| 11 | + * |
| 12 | + * @licence GNU GPL v3 or later |
| 13 | + * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
| 14 | + */ |
| 15 | +abstract class SpecialCachedPage extends SpecialPage { |
5 | 16 | |
6 | 17 | /** |
7 | 18 | * The time to live for the cache, in seconds or a unix timestamp indicating the point of expiry. |
8 | 19 | * |
9 | 20 | * @since 0.1 |
10 | | - * @var integer |
| 21 | + * @var integer|null |
11 | 22 | */ |
12 | | - protected $cacheExpiry = 3600; |
| 23 | + protected $cacheExpiry = 300; |
13 | 24 | |
14 | 25 | protected $cachedChunks; |
15 | 26 | |
16 | 27 | protected $hasCached = null; |
17 | 28 | |
18 | | - protected $out; |
| 29 | + /** |
| 30 | + * Main method. |
| 31 | + * |
| 32 | + * @since 0.1 |
| 33 | + * |
| 34 | + * @param string $subPage |
| 35 | + */ |
| 36 | + public function execute( $subPage ) { |
| 37 | + //parent::execute( $subPage ); |
19 | 38 | |
20 | | - public function __construct( OutputPage $out ) { |
21 | | - $this->out = $out; |
| 39 | + if ( $this->getRequest()->getText( 'action' ) === 'purge' ) { |
| 40 | + $this->hasCached = false; |
| 41 | + } |
22 | 42 | } |
23 | 43 | |
24 | | - public function invalidateCache() { |
25 | | - $this->hasCached = false; |
26 | | - } |
27 | | - |
28 | 44 | /** |
29 | 45 | * Initializes the caching. |
30 | 46 | * Should be called ONCE before any of the caching functionality is used, |
— | — | @@ -59,17 +75,17 @@ |
60 | 76 | $html = ''; |
61 | 77 | |
62 | 78 | if ( is_null( $key ) ) { |
63 | | - $itemKey = array_flip( array_slice( $this->cachedChunks, 0, 1 ) ); |
| 79 | + $itemKey = array_keys( array_slice( $this->cachedChunks, 0, 1 ) ); |
64 | 80 | $itemKey = array_shift( $itemKey ); |
65 | 81 | |
66 | | - if ( is_integer( $itemKey ) ) { |
| 82 | + if ( !is_integer( $itemKey ) ) { |
67 | 83 | wfWarn( "Attempted to get item with non-numeric key while the next item in the queue has a key ($itemKey) in " . __METHOD__ ); |
68 | 84 | } |
69 | 85 | elseif ( is_null( $itemKey ) ) { |
70 | 86 | wfWarn( "Attempted to get an item while the queue is empty in " . __METHOD__ ); |
71 | 87 | } |
72 | 88 | else { |
73 | | - $html = array_shift( $key ); |
| 89 | + $html = array_shift( $this->cachedChunks ); |
74 | 90 | } |
75 | 91 | } |
76 | 92 | else { |
— | — | @@ -93,13 +109,9 @@ |
94 | 110 | } |
95 | 111 | } |
96 | 112 | |
97 | | - $this->addHTML( $html ); |
| 113 | + $this->getOutput()->addHTML( $html ); |
98 | 114 | } |
99 | 115 | |
100 | | - public function addHTML( $html ) { |
101 | | - $this->out->addHTML( $html ); |
102 | | - } |
103 | | - |
104 | 116 | /** |
105 | 117 | * Saves the HTML to the cache in case it got recomputed. |
106 | 118 | * Should be called after the last time anything is added via addCachedHTML. |
— | — | @@ -136,116 +148,3 @@ |
137 | 149 | } |
138 | 150 | |
139 | 151 | } |
140 | | - |
141 | | -/** |
142 | | - * Abstract special page class with scaffolding for caching the HTML output. |
143 | | - * |
144 | | - * @since 0.1 |
145 | | - * |
146 | | - * @file SpecialCachedPage.php |
147 | | - * @ingroup EducationProgram |
148 | | - * |
149 | | - * @licence GNU GPL v3 or later |
150 | | - * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
151 | | - */ |
152 | | -abstract class SpecialCachedPage extends SpecialPage { |
153 | | - |
154 | | - /** |
155 | | - * The time to live for the cache, in seconds or a unix timestamp indicating the point of expiry. |
156 | | - * |
157 | | - * @since 0.1 |
158 | | - * @var integer|null |
159 | | - */ |
160 | | - protected $cacheExpiry = null; |
161 | | - |
162 | | - protected $cachedOutput = null; |
163 | | - |
164 | | - /** |
165 | | - * Main method. |
166 | | - * |
167 | | - * @since 0.1 |
168 | | - * |
169 | | - * @param string $subPage |
170 | | - */ |
171 | | - public function execute( $subPage ) { |
172 | | - //parent::execute( $subPage ); |
173 | | - |
174 | | - if ( !is_null( $this->cacheExpiry ) ) { |
175 | | - $cache = wfGetCache( CACHE_ANYTHING ); |
176 | | - $cacheKey = $this->getCacheKey(); |
177 | | - $cachedHTML = $cache->get( $cacheKey ); |
178 | | - |
179 | | - $out = $this->getOutput(); |
180 | | - |
181 | | - if ( $this->getRequest()->getText( 'action' ) !== 'purge' && is_string( $cachedHTML ) ) { |
182 | | - $html = $cachedHTML; |
183 | | - } |
184 | | - else { |
185 | | - $this->displayCachedContent(); |
186 | | - |
187 | | - $html = $out->getHTML(); |
188 | | - $cache->set( $cacheKey, $html, $this->cacheExpiry ); |
189 | | - } |
190 | | - |
191 | | - $out->clearHTML(); |
192 | | - |
193 | | - $this->displayBeforeCached(); |
194 | | - $out->addHTML( $html ); |
195 | | - $this->displayAfterCached(); |
196 | | - } |
197 | | - } |
198 | | - |
199 | | - /** |
200 | | - * Sets the time to live for the cache, in seconds or a unix timestamp indicating the point of expiry.. |
201 | | - * |
202 | | - * @since 0.1 |
203 | | - * |
204 | | - * @param integer $cacheExpiry |
205 | | - */ |
206 | | - protected function setExpirey( $cacheExpiry ) { |
207 | | - $this->cacheExpiry = $cacheExpiry; |
208 | | - } |
209 | | - |
210 | | - /** |
211 | | - * Returns the cache key to use to cache this page's HTML output. |
212 | | - * Is constructed from the special page name and language code. |
213 | | - * |
214 | | - * @since 0.1 |
215 | | - * |
216 | | - * @return string |
217 | | - */ |
218 | | - protected function getCacheKey() { |
219 | | - return wfMemcKey( $this->mName, $this->getLanguage()->getCode() ); |
220 | | - } |
221 | | - |
222 | | - /** |
223 | | - * Display the cached content. Everything added to the output here |
224 | | - * will be cached. |
225 | | - * |
226 | | - * @since 0.1 |
227 | | - */ |
228 | | - protected function displayCachedContent() { |
229 | | - |
230 | | - } |
231 | | - |
232 | | - /** |
233 | | - * Display non-cached content that will be added to the final output |
234 | | - * before the cached HTML. |
235 | | - * |
236 | | - * @since 0.1 |
237 | | - */ |
238 | | - protected function displayBeforeCached() { |
239 | | - |
240 | | - } |
241 | | - |
242 | | - /** |
243 | | - * Display non-cached content that will be added to the final output |
244 | | - * after the cached HTML. |
245 | | - * |
246 | | - * @since 0.1 |
247 | | - */ |
248 | | - protected function displayAfterCached() { |
249 | | - |
250 | | - } |
251 | | - |
252 | | -} |
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php |
— | — | @@ -777,6 +777,9 @@ |
778 | 778 | 'epca-visible' => 'Publicly list me as Campus Ambassador', |
779 | 779 | |
780 | 780 | // Special:StudentActivity |
| 781 | + 'ep-studentactivity-noresults' => 'There are no students that where active in the last 24 hours :( |
| 782 | + |
| 783 | +You can find a full list of students on [[Special:Students|the student list]].', |
781 | 784 | 'ep-studentactivity-count' => 'There {{PLURAL:$1|is|are}} currently $1 {{PLURAL:$1|student|students}} that {{PLURAL:$1|was|where}} active in the last 24 hours.', |
782 | 785 | ); |
783 | 786 | |