r114326 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r114325‎ | r114326 | r114327 >
Date:23:03, 20 March 2012
Author:catrope
Status:ok
Tags:
Comment:
Revert r114067, r114071, r114075, r114079, r114081, r114082, r114084, r114086, r114088, r114089, r114101, r114118, r114137, r114147, r114164, r114172, r114175, r114180, r114208, r114209, r114215, r114219, r114226, r114321, r114322.

This reverts the SpecialCachedPage and formatDuration sagas, with some collateral damage here and there. All of these revisions are tagged with 'gerritmigration' and will be resubmitted into Gerrit after the Gerrit switchover. See also http://lists.wikimedia.org/pipermail/wikitech-l/2012-March/059124.html
Modified paths:
  • /trunk/phase3/includes/AutoLoader.php (modified) (history)
  • /trunk/phase3/includes/CacheHelper.php (deleted) (history)
  • /trunk/phase3/includes/actions/CachedAction.php (deleted) (history)
  • /trunk/phase3/includes/objectcache/MemcachedClient.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialCachedPage.php (deleted) (history)
  • /trunk/phase3/languages/Language.php (modified) (history)
  • /trunk/phase3/languages/classes/LanguageKaa.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)
  • /trunk/phase3/maintenance/language/messages.inc (modified) (history)
  • /trunk/phase3/tests/phpunit/languages/LanguageTest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/language/messages.inc
@@ -1749,11 +1749,6 @@
17501750 'allpagesbadtitle',
17511751 'allpages-bad-ns',
17521752 ),
1753 - 'cachedspecial' => array(
1754 - 'cachedspecial-viewing-cached-ttl',
1755 - 'cachedspecial-viewing-cached-ts',
1756 - 'cachedspecial-refresh-now',
1757 - ),
17581753 'categories' => array(
17591754 'categories',
17601755 'categories-summary',
@@ -3691,17 +3686,6 @@
36923687 'api-error-uploaddisabled',
36933688 'api-error-verification-error',
36943689 ),
3695 - 'duration' => array(
3696 - 'duration-seconds',
3697 - 'duration-minutes',
3698 - 'duration-hours',
3699 - 'duration-days',
3700 - 'duration-weeks',
3701 - 'duration-years',
3702 - 'duration-decades',
3703 - 'duration-centuries',
3704 - 'duration-millennia'
3705 - ),
37063690 );
37073691
37083692 /** Comments for each block */
@@ -3939,6 +3923,4 @@
39403924 'logging-irc' => 'For IRC, see bug 34508. Do not change',
39413925 'feedback' => 'Feedback',
39423926 'apierrors' => 'API errors',
3943 - 'duration' => 'Durations',
3944 - 'cachedspecial' => 'SpecialCachedPage',
39453927 );
Index: trunk/phase3/tests/phpunit/languages/LanguageTest.php
@@ -23,12 +23,12 @@
2424 'convertDoubleWidth() with the full alphabet and digits'
2525 );
2626 }
27 -
 27+
2828 /** @dataProvider provideFormattableTimes */
2929 function testFormatTimePeriod( $seconds, $format, $expected, $desc ) {
3030 $this->assertEquals( $expected, $this->lang->formatTimePeriod( $seconds, $format ), $desc );
3131 }
32 -
 32+
3333 function provideFormattableTimes() {
3434 return array(
3535 array( 9.45, array(), '9.5s', 'formatTimePeriod() rounding (<10s)' ),
@@ -62,7 +62,7 @@
6363 array( 176460.55, array(), '2d 1h 1m 1s', 'formatTimePeriod() rounding, recursion, (>48h)' ),
6464 array( 176460.55, array( 'noabbrevs' => true ), '2 days 1 hour 1 minute 1 second', 'formatTimePeriod() rounding, recursion, (>48h)' ),
6565 );
66 -
 66+
6767 }
6868
6969 function testTruncate() {
@@ -224,7 +224,7 @@
225225 "sprintfDate('$format', '$ts'): $msg"
226226 );
227227
228 - date_default_timezone_set( $oldTZ );
 228+ date_default_timezone_set( $oldTZ );
229229 }
230230
231231 function provideSprintfDateSamples() {
@@ -537,48 +537,48 @@
538538 return array(
539539 array(
540540 0,
541 - '0 B',
542 - 'Zero bytes'
 541+ "0 B",
 542+ "Zero bytes"
543543 ),
544544 array(
545545 1024,
546 - '1 KB',
547 - '1 kilobyte'
 546+ "1 KB",
 547+ "1 kilobyte"
548548 ),
549549 array(
550550 1024 * 1024,
551 - '1 MB',
552 - '1,024 megabytes'
 551+ "1 MB",
 552+ "1,024 megabytes"
553553 ),
554554 array(
555555 1024 * 1024 * 1024,
556 - '1 GB',
557 - '1 gigabytes'
 556+ "1 GB",
 557+ "1 gigabytes"
558558 ),
559559 array(
560560 pow( 1024, 4 ),
561 - '1 TB',
562 - '1 terabyte'
 561+ "1 TB",
 562+ "1 terabyte"
563563 ),
564564 array(
565565 pow( 1024, 5 ),
566 - '1 PB',
567 - '1 petabyte'
 566+ "1 PB",
 567+ "1 petabyte"
568568 ),
569569 array(
570570 pow( 1024, 6 ),
571 - '1 EB',
572 - '1,024 exabyte'
 571+ "1 EB",
 572+ "1,024 exabyte"
573573 ),
574574 array(
575575 pow( 1024, 7 ),
576 - '1 ZB',
577 - '1 zetabyte'
 576+ "1 ZB",
 577+ "1 zetabyte"
578578 ),
579579 array(
580580 pow( 1024, 8 ),
581 - '1 YB',
582 - '1 yottabyte'
 581+ "1 YB",
 582+ "1 yottabyte"
583583 ),
584584 // How big!? THIS BIG!
585585 );
@@ -599,194 +599,59 @@
600600 return array(
601601 array(
602602 0,
603 - '0bps',
604 - '0 bits per second'
 603+ "0bps",
 604+ "0 bits per second"
605605 ),
606606 array(
607607 999,
608 - '999bps',
609 - '999 bits per second'
 608+ "999bps",
 609+ "999 bits per second"
610610 ),
611611 array(
612612 1000,
613 - '1kbps',
614 - '1 kilobit per second'
 613+ "1kbps",
 614+ "1 kilobit per second"
615615 ),
616616 array(
617617 1000 * 1000,
618 - '1Mbps',
619 - '1 megabit per second'
 618+ "1Mbps",
 619+ "1 megabit per second"
620620 ),
621621 array(
622622 pow( 10, 9 ),
623 - '1Gbps',
624 - '1 gigabit per second'
 623+ "1Gbps",
 624+ "1 gigabit per second"
625625 ),
626626 array(
627627 pow( 10, 12 ),
628 - '1Tbps',
629 - '1 terabit per second'
 628+ "1Tbps",
 629+ "1 terabit per second"
630630 ),
631631 array(
632632 pow( 10, 15 ),
633 - '1Pbps',
634 - '1 petabit per second'
 633+ "1Pbps",
 634+ "1 petabit per second"
635635 ),
636636 array(
637637 pow( 10, 18 ),
638 - '1Ebps',
639 - '1 exabit per second'
 638+ "1Ebps",
 639+ "1 exabit per second"
640640 ),
641641 array(
642642 pow( 10, 21 ),
643 - '1Zbps',
644 - '1 zetabit per second'
 643+ "1Zbps",
 644+ "1 zetabit per second"
645645 ),
646646 array(
647647 pow( 10, 24 ),
648 - '1Ybps',
649 - '1 yottabit per second'
 648+ "1Ybps",
 649+ "1 yottabit per second"
650650 ),
651651 array(
652652 pow( 10, 27 ),
653 - '1,000Ybps',
654 - '1,000 yottabits per second'
 653+ "1,000Ybps",
 654+ "1,000 yottabits per second"
655655 ),
656656 );
657657 }
658 -
659 - /**
660 - * @dataProvider provideFormatDuration
661 - */
662 - function testFormatDuration( $duration, $expected, $intervals = array() ) {
663 - $this->assertEquals(
664 - $expected,
665 - $this->lang->formatDuration( $duration, $intervals ),
666 - "formatDuration('$duration'): $expected"
667 - );
668 - }
669 -
670 - function provideFormatDuration() {
671 - return array(
672 - array(
673 - 0,
674 - '0 seconds',
675 - ),
676 - array(
677 - 1,
678 - '1 second',
679 - ),
680 - array(
681 - 2,
682 - '2 seconds',
683 - ),
684 - array(
685 - 60,
686 - '1 minute',
687 - ),
688 - array(
689 - 2 * 60,
690 - '2 minutes',
691 - ),
692 - array(
693 - 3600,
694 - '1 hour',
695 - ),
696 - array(
697 - 2 * 3600,
698 - '2 hours',
699 - ),
700 - array(
701 - 24 * 3600,
702 - '1 day',
703 - ),
704 - array(
705 - 2 * 86400,
706 - '2 days',
707 - ),
708 - array(
709 - 365.25 * 86400, // 365.25 * 86400 = 31557600
710 - '1 year',
711 - ),
712 - array(
713 - 2 * 31557600,
714 - '2 years',
715 - ),
716 - array(
717 - 10 * 31557600,
718 - '1 decade',
719 - ),
720 - array(
721 - 20 * 31557600,
722 - '2 decades',
723 - ),
724 - array(
725 - 100 * 31557600,
726 - '1 century',
727 - ),
728 - array(
729 - 200 * 31557600,
730 - '2 centuries',
731 - ),
732 - array(
733 - 1000 * 31557600,
734 - '1 millennium',
735 - ),
736 - array(
737 - 2000 * 31557600,
738 - '2 millennia',
739 - ),
740 - array(
741 - 9001,
742 - '2 hours, 30 minutes and 1 second'
743 - ),
744 - array(
745 - 3601,
746 - '1 hour and 1 second'
747 - ),
748 - array(
749 - 31557600 + 2 * 86400 + 9000,
750 - '1 year, 2 days, 2 hours and 30 minutes'
751 - ),
752 - array(
753 - 42 * 1000 * 31557600 + 42,
754 - '42 millennia and 42 seconds'
755 - ),
756 - array(
757 - 60,
758 - '60 seconds',
759 - array( 'seconds' ),
760 - ),
761 - array(
762 - 61,
763 - '61 seconds',
764 - array( 'seconds' ),
765 - ),
766 - array(
767 - 1,
768 - '1 second',
769 - array( 'seconds' ),
770 - ),
771 - array(
772 - 31557600 + 2 * 86400 + 9000,
773 - '1 year, 2 days and 150 minutes',
774 - array( 'years', 'days', 'minutes' ),
775 - ),
776 - array(
777 - 42,
778 - '0 days',
779 - array( 'years', 'days' ),
780 - ),
781 - array(
782 - 31557600 + 2 * 86400 + 9000,
783 - '1 year, 2 days and 150 minutes',
784 - array( 'minutes', 'days', 'years' ),
785 - ),
786 - array(
787 - 42,
788 - '0 days',
789 - array( 'days', 'years' ),
790 - ),
791 - );
792 - }
793658 }
Index: trunk/phase3/includes/CacheHelper.php
@@ -1,339 +0,0 @@
2 -<?php
3 -
4 -/**
5 - * Interface for all classes implementing CacheHelper functionality.
6 - *
7 - * @since 1.20
8 - *
9 - * @licence GNU GPL v2 or later
10 - * @author Jeroen De Dauw < jeroendedauw@gmail.com >
11 - */
12 -interface ICacheHelper {
13 -
14 - /**
15 - * Sets if the cache should be enabled or not.
16 - *
17 - * @since 1.20
18 - * @param boolean $cacheEnabled
19 - */
20 - function setCacheEnabled( $cacheEnabled );
21 -
22 - /**
23 - * Initializes the caching.
24 - * Should be called before the first time anything is added via addCachedHTML.
25 - *
26 - * @since 1.20
27 - *
28 - * @param integer|null $cacheExpiry Sets the cache expirty, either ttl in seconds or unix timestamp.
29 - * @param boolean|null $cacheEnabled Sets if the cache should be enabled or not.
30 - */
31 - function startCache( $cacheExpiry = null, $cacheEnabled = null );
32 -
33 - /**
34 - * Get a cached value if available or compute it if not and then cache it if possible.
35 - * The provided $computeFunction is only called when the computation needs to happen
36 - * and should return a result value. $args are arguments that will be passed to the
37 - * compute function when called.
38 - *
39 - * @since 1.20
40 - *
41 - * @param {function} $computeFunction
42 - * @param array|mixed $args
43 - * @param string|null $key
44 - *
45 - * @return mixed
46 - */
47 - function getCachedValue( $computeFunction, $args = array(), $key = null );
48 -
49 - /**
50 - * Saves the HTML to the cache in case it got recomputed.
51 - * Should be called after the last time anything is added via addCachedHTML.
52 - *
53 - * @since 1.20
54 - */
55 - function saveCache();
56 -
57 - /**
58 - * Sets the time to live for the cache, in seconds or a unix timestamp indicating the point of expiry..
59 - *
60 - * @since 1.20
61 - *
62 - * @param integer $cacheExpiry
63 - */
64 - function setExpirey( $cacheExpiry );
65 -
66 -}
67 -
68 -/**
69 - * Helper class for caching various elements in a single cache entry.
70 - *
71 - * To get a cached value or compute it, use getCachedValue like this:
72 - * $this->getCachedValue( $callback );
73 - *
74 - * To add HTML that should be cached, use addCachedHTML like this:
75 - * $this->addCachedHTML( $callback );
76 - *
77 - * The callback function is only called when needed, so do all your expensive
78 - * computations here. This function should returns the HTML to be cached.
79 - * It should not add anything to the PageOutput object!
80 - *
81 - * Before the first addCachedHTML call, you should call $this->startCache();
82 - * After adding the last HTML that should be cached, call $this->saveCache();
83 - *
84 - * @since 1.20
85 - *
86 - * @file CacheHelper.php
87 - *
88 - * @licence GNU GPL v2 or later
89 - * @author Jeroen De Dauw < jeroendedauw@gmail.com >
90 - */
91 -class CacheHelper implements ICacheHelper {
92 -
93 - /**
94 - * The time to live for the cache, in seconds or a unix timestamp indicating the point of expiry.
95 - *
96 - * @since 1.20
97 - * @var integer
98 - */
99 - protected $cacheExpiry = 3600;
100 -
101 - /**
102 - * List of HTML chunks to be cached (if !hasCached) or that where cashed (of hasCached).
103 - * If no cached already, then the newly computed chunks are added here,
104 - * if it as cached already, chunks are removed from this list as they are needed.
105 - *
106 - * @since 1.20
107 - * @var array
108 - */
109 - protected $cachedChunks;
110 -
111 - /**
112 - * Indicates if the to be cached content was already cached.
113 - * Null if this information is not available yet.
114 - *
115 - * @since 1.20
116 - * @var boolean|null
117 - */
118 - protected $hasCached = null;
119 -
120 - /**
121 - * If the cache is enabled or not.
122 - *
123 - * @since 1.20
124 - * @var boolean
125 - */
126 - protected $cacheEnabled = true;
127 -
128 - /**
129 - * Function that gets called when initialization is done.
130 - *
131 - * @since 1.20
132 - * @var function
133 - */
134 - protected $onInitHandler = false;
135 -
136 - /**
137 - * Sets if the cache should be enabled or not.
138 - *
139 - * @since 1.20
140 - * @param boolean $cacheEnabled
141 - */
142 - public function setCacheEnabled( $cacheEnabled ) {
143 - $this->cacheEnabled = $cacheEnabled;
144 - }
145 -
146 - /**
147 - * Initializes the caching.
148 - * Should be called before the first time anything is added via addCachedHTML.
149 - *
150 - * @since 1.20
151 - *
152 - * @param integer|null $cacheExpiry Sets the cache expirty, either ttl in seconds or unix timestamp.
153 - * @param boolean|null $cacheEnabled Sets if the cache should be enabled or not.
154 - */
155 - public function startCache( $cacheExpiry = null, $cacheEnabled = null ) {
156 - if ( is_null( $this->hasCached ) ) {
157 - if ( !is_null( $cacheExpiry ) ) {
158 - $this->cacheExpiry = $cacheExpiry;
159 - }
160 -
161 - if ( !is_null( $cacheEnabled ) ) {
162 - $this->setCacheEnabled( $cacheEnabled );
163 - }
164 -
165 - $this->initCaching();
166 - }
167 - }
168 -
169 - /**
170 - * Returns a message that notifies the user he/she is looking at
171 - * a cached version of the page, including a refresh link.
172 - *
173 - * @since 1.20
174 - *
175 - * @param IContextSource $context
176 - *
177 - * @return string
178 - */
179 - public function getCachedNotice( IContextSource $context ) {
180 - $refreshArgs = $context->getRequest()->getQueryValues();
181 - unset( $refreshArgs['title'] );
182 - $refreshArgs['action'] = 'purge';
183 -
184 - $subPage = $context->getTitle()->getFullText();
185 - $subPage = explode( '/', $subPage, 2 );
186 - $subPage = count( $subPage ) > 1 ? $subPage[1] : false;
187 -
188 - $refreshLink = Linker::link(
189 - $context->getTitle( $subPage ),
190 - $context->msg( 'cachedspecial-refresh-now' )->escaped(),
191 - array(),
192 - $refreshArgs
193 - );
194 -
195 - if ( $this->cacheExpiry < 86400 * 3650 ) {
196 - $message = $context->msg(
197 - 'cachedspecial-viewing-cached-ttl',
198 - $context->getLanguage()->formatDuration( $this->cacheExpiry )
199 - )->escaped();
200 - }
201 - else {
202 - $message = $context->msg(
203 - 'cachedspecial-viewing-cached-ts'
204 - )->escaped();
205 - }
206 -
207 - return $message . ' ' . $refreshLink;
208 - }
209 -
210 - /**
211 - * Initializes the caching if not already done so.
212 - * Should be called before any of the caching functionality is used.
213 - *
214 - * @since 1.20
215 - */
216 - protected function initCaching() {
217 - if ( $this->cacheEnabled && is_null( $this->hasCached ) ) {
218 - $cachedChunks = wfGetCache( CACHE_ANYTHING )->get( $this->getCacheKeyString() );
219 -
220 - $this->hasCached = is_array( $cachedChunks );
221 - $this->cachedChunks = $this->hasCached ? $cachedChunks : array();
222 -
223 - if ( $this->onInitHandler !== false ) {
224 - call_user_func( $this->onInitHandler, $this->hasCached );
225 - }
226 - }
227 - }
228 -
229 - /**
230 - * Get a cached value if available or compute it if not and then cache it if possible.
231 - * The provided $computeFunction is only called when the computation needs to happen
232 - * and should return a result value. $args are arguments that will be passed to the
233 - * compute function when called.
234 - *
235 - * @since 1.20
236 - *
237 - * @param {function} $computeFunction
238 - * @param array|mixed $args
239 - * @param string|null $key
240 - *
241 - * @return mixed
242 - */
243 - public function getCachedValue( $computeFunction, $args = array(), $key = null ) {
244 - $this->initCaching();
245 -
246 - if ( $this->cacheEnabled && $this->hasCached ) {
247 - $value = null;
248 -
249 - if ( is_null( $key ) ) {
250 - $itemKey = array_keys( array_slice( $this->cachedChunks, 0, 1 ) );
251 - $itemKey = array_shift( $itemKey );
252 -
253 - if ( !is_integer( $itemKey ) ) {
254 - wfWarn( "Attempted to get item with non-numeric key while the next item in the queue has a key ($itemKey) in " . __METHOD__ );
255 - }
256 - elseif ( is_null( $itemKey ) ) {
257 - wfWarn( "Attempted to get an item while the queue is empty in " . __METHOD__ );
258 - }
259 - else {
260 - $value = array_shift( $this->cachedChunks );
261 - }
262 - }
263 - else {
264 - if ( array_key_exists( $key, $this->cachedChunks ) ) {
265 - $value = $this->cachedChunks[$key];
266 - unset( $this->cachedChunks[$key] );
267 - }
268 - else {
269 - wfWarn( "There is no item with key '$key' in this->cachedChunks in " . __METHOD__ );
270 - }
271 - }
272 - }
273 - else {
274 - if ( !is_array( $args ) ) {
275 - $args = array( $args );
276 - }
277 -
278 - $value = call_user_func_array( $computeFunction, $args );
279 -
280 - if ( $this->cacheEnabled ) {
281 - if ( is_null( $key ) ) {
282 - $this->cachedChunks[] = $value;
283 - }
284 - else {
285 - $this->cachedChunks[$key] = $value;
286 - }
287 - }
288 - }
289 -
290 - return $value;
291 - }
292 -
293 - /**
294 - * Saves the HTML to the cache in case it got recomputed.
295 - * Should be called after the last time anything is added via addCachedHTML.
296 - *
297 - * @since 1.20
298 - */
299 - public function saveCache() {
300 - if ( $this->cacheEnabled && $this->hasCached === false && !empty( $this->cachedChunks ) ) {
301 - wfGetCache( CACHE_ANYTHING )->set( $this->getCacheKeyString(), $this->cachedChunks, $this->cacheExpiry );
302 - }
303 - }
304 -
305 - /**
306 - * Sets the time to live for the cache, in seconds or a unix timestamp indicating the point of expiry..
307 - *
308 - * @since 1.20
309 - *
310 - * @param integer $cacheExpiry
311 - */
312 - public function setExpirey( $cacheExpiry ) {
313 - $this->cacheExpiry = $cacheExpiry;
314 - }
315 -
316 - /**
317 - * Returns the cache key to use to cache this page's HTML output.
318 - * Is constructed from the special page name and language code.
319 - *
320 - * @since 1.20
321 - *
322 - * @return string
323 - */
324 - protected function getCacheKeyString() {
325 - return call_user_func_array( 'wfMemcKey', $this->cacheKey );
326 - }
327 -
328 - public function setCacheKey( array $cacheKey ) {
329 - $this->cacheKey = $cacheKey;
330 - }
331 -
332 - public function purge() {
333 - $this->hasCached = false;
334 - }
335 -
336 - public function setOnInitializedHandler( $handlerFunction ) {
337 - $this->onInitHandler = $handlerFunction;
338 - }
339 -
340 -}
Index: trunk/phase3/includes/actions/CachedAction.php
@@ -1,170 +0,0 @@
2 -<?php
3 -
4 -/**
5 - * Abstract action class with scaffolding for caching HTML and other values
6 - * in a single blob.
7 - *
8 - * Before using any of the cahing functionality, call startCache.
9 - * After the last call to either getCachedValue or addCachedHTML, call saveCache.
10 - *
11 - * To get a cached value or compute it, use getCachedValue like this:
12 - * $this->getCachedValue( $callback );
13 - *
14 - * To add HTML that should be cached, use addCachedHTML like this:
15 - * $this->addCachedHTML( $callback );
16 - *
17 - * The callback function is only called when needed, so do all your expensive
18 - * computations here. This function should returns the HTML to be cached.
19 - * It should not add anything to the PageOutput object!
20 - *
21 - * @since 1.20
22 - *
23 - * @file CachedAction.php
24 - * @ingroup Action
25 - *
26 - * @licence GNU GPL v2 or later
27 - * @author Jeroen De Dauw < jeroendedauw@gmail.com >
28 - */
29 -abstract class CachedAction extends FormlessAction implements ICacheHelper {
30 -
31 - /**
32 - * CacheHelper object to which we foreward the non-SpecialPage specific caching work.
33 - * Initialized in startCache.
34 - *
35 - * @since 1.20
36 - * @var CacheHelper
37 - */
38 - protected $cacheHelper;
39 -
40 - /**
41 - * If the cache is enabled or not.
42 - *
43 - * @since 1.20
44 - * @var boolean
45 - */
46 - protected $cacheEnabled = true;
47 -
48 - /**
49 - * Sets if the cache should be enabled or not.
50 - *
51 - * @since 1.20
52 - * @param boolean $cacheEnabled
53 - */
54 - public function setCacheEnabled( $cacheEnabled ) {
55 - $this->cacheHelper->setCacheEnabled( $cacheEnabled );
56 - }
57 -
58 - /**
59 - * Initializes the caching.
60 - * Should be called before the first time anything is added via addCachedHTML.
61 - *
62 - * @since 1.20
63 - *
64 - * @param integer|null $cacheExpiry Sets the cache expirty, either ttl in seconds or unix timestamp.
65 - * @param boolean|null $cacheEnabled Sets if the cache should be enabled or not.
66 - */
67 - public function startCache( $cacheExpiry = null, $cacheEnabled = null ) {
68 - $this->cacheHelper = new CacheHelper();
69 -
70 - $this->cacheHelper->setCacheEnabled( $this->cacheEnabled );
71 - $this->cacheHelper->setOnInitializedHandler( array( $this, 'onCacheInitialized' ) );
72 -
73 - $keyArgs = $this->getCacheKey();
74 -
75 - if ( array_key_exists( 'action', $keyArgs ) && $keyArgs['action'] === 'purge' ) {
76 - unset( $keyArgs['action'] );
77 - }
78 -
79 - $this->cacheHelper->setCacheKey( $keyArgs );
80 -
81 - if ( $this->getRequest()->getText( 'action' ) === 'purge' ) {
82 - $this->cacheHelper->purge();
83 - }
84 -
85 - $this->cacheHelper->startCache( $cacheExpiry, $cacheEnabled );
86 - }
87 -
88 - /**
89 - * Get a cached value if available or compute it if not and then cache it if possible.
90 - * The provided $computeFunction is only called when the computation needs to happen
91 - * and should return a result value. $args are arguments that will be passed to the
92 - * compute function when called.
93 - *
94 - * @since 1.20
95 - *
96 - * @param {function} $computeFunction
97 - * @param array|mixed $args
98 - * @param string|null $key
99 - *
100 - * @return mixed
101 - */
102 - public function getCachedValue( $computeFunction, $args = array(), $key = null ) {
103 - return $this->cacheHelper->getCachedValue( $computeFunction, $args, $key );
104 - }
105 -
106 - /**
107 - * Add some HTML to be cached.
108 - * This is done by providing a callback function that should
109 - * return the HTML to be added. It will only be called if the
110 - * item is not in the cache yet or when the cache has been invalidated.
111 - *
112 - * @since 1.20
113 - *
114 - * @param {function} $computeFunction
115 - * @param array $args
116 - * @param string|null $key
117 - */
118 - public function addCachedHTML( $computeFunction, $args = array(), $key = null ) {
119 - $this->getOutput()->addHTML( $this->cacheHelper->getCachedValue( $computeFunction, $args, $key ) );
120 - }
121 -
122 - /**
123 - * Saves the HTML to the cache in case it got recomputed.
124 - * Should be called after the last time anything is added via addCachedHTML.
125 - *
126 - * @since 1.20
127 - */
128 - public function saveCache() {
129 - $this->cacheHelper->saveCache();
130 - }
131 -
132 - /**
133 - * Sets the time to live for the cache, in seconds or a unix timestamp indicating the point of expiry..
134 - *
135 - * @since 1.20
136 - *
137 - * @param integer $cacheExpiry
138 - */
139 - public function setExpirey( $cacheExpiry ) {
140 - $this->cacheHelper->setExpirey( $cacheExpiry );
141 - }
142 -
143 - /**
144 - * Returns the variables used to constructed the cache key in an array.
145 - *
146 - * @since 1.20
147 - *
148 - * @return array
149 - */
150 - protected function getCacheKey() {
151 - return array(
152 - get_class( $this->page ),
153 - $this->getName(),
154 - $this->getLanguage()->getCode()
155 - );
156 - }
157 -
158 - /**
159 - * Gets called after the cache got initialized.
160 - *
161 - * @since 1.20
162 - *
163 - * @param boolean $hasCached
164 - */
165 - public function onCacheInitialized( $hasCached ) {
166 - if ( $hasCached ) {
167 - $this->getOutput()->setSubtitle( $this->cacheHelper->getCachedNotice( $this->getContext() ) );
168 - }
169 - }
170 -
171 -}
\ No newline at end of file
Index: trunk/phase3/includes/AutoLoader.php
@@ -27,7 +27,6 @@
2828 'BadTitleError' => 'includes/Exception.php',
2929 'BaseTemplate' => 'includes/SkinTemplate.php',
3030 'Block' => 'includes/Block.php',
31 - 'CacheHelper' => 'includes/CacheHelper.php',
3231 'Category' => 'includes/Category.php',
3332 'Categoryfinder' => 'includes/Categoryfinder.php',
3433 'CategoryPage' => 'includes/CategoryPage.php',
@@ -121,7 +120,6 @@
122121 'Http' => 'includes/HttpFunctions.php',
123122 'HttpError' => 'includes/Exception.php',
124123 'HttpRequest' => 'includes/HttpFunctions.old.php',
125 - 'ICacheHelper' => 'includes/CacheHelper.php',
126124 'IcuCollation' => 'includes/Collation.php',
127125 'IdentityCollation' => 'includes/Collation.php',
128126 'ImageGallery' => 'includes/ImageGallery.php',
@@ -260,7 +258,6 @@
261259 'ZipDirectoryReader' => 'includes/ZipDirectoryReader.php',
262260
263261 # includes/actions
264 - 'CachedAction' => 'includes/actions/CachedAction.php',
265262 'CreditsAction' => 'includes/actions/CreditsAction.php',
266263 'DeleteAction' => 'includes/actions/DeleteAction.php',
267264 'EditAction' => 'includes/actions/EditAction.php',
@@ -827,7 +824,6 @@
828825 'SpecialBlockList' => 'includes/specials/SpecialBlockList.php',
829826 'SpecialBlockme' => 'includes/specials/SpecialBlockme.php',
830827 'SpecialBookSources' => 'includes/specials/SpecialBooksources.php',
831 - 'SpecialCachedPage' => 'includes/specials/SpecialCachedPage.php',
832828 'SpecialCategories' => 'includes/specials/SpecialCategories.php',
833829 'SpecialChangeEmail' => 'includes/specials/SpecialChangeEmail.php',
834830 'SpecialChangePassword' => 'includes/specials/SpecialChangePassword.php',
Index: trunk/phase3/includes/specials/SpecialCachedPage.php
@@ -1,169 +0,0 @@
2 -<?php
3 -
4 -/**
5 - * Abstract special page class with scaffolding for caching HTML and other values
6 - * in a single blob.
7 - *
8 - * Before using any of the cahing functionality, call startCache.
9 - * After the last call to either getCachedValue or addCachedHTML, call saveCache.
10 - *
11 - * To get a cached value or compute it, use getCachedValue like this:
12 - * $this->getCachedValue( $callback );
13 - *
14 - * To add HTML that should be cached, use addCachedHTML like this:
15 - * $this->addCachedHTML( $callback );
16 - *
17 - * The callback function is only called when needed, so do all your expensive
18 - * computations here. This function should returns the HTML to be cached.
19 - * It should not add anything to the PageOutput object!
20 - *
21 - * @since 1.20
22 - *
23 - * @file SpecialCachedPage.php
24 - * @ingroup SpecialPage
25 - *
26 - * @licence GNU GPL v2 or later
27 - * @author Jeroen De Dauw < jeroendedauw@gmail.com >
28 - */
29 -abstract class SpecialCachedPage extends SpecialPage implements ICacheHelper {
30 -
31 - /**
32 - * CacheHelper object to which we foreward the non-SpecialPage specific caching work.
33 - * Initialized in startCache.
34 - *
35 - * @since 1.20
36 - * @var CacheHelper
37 - */
38 - protected $cacheHelper;
39 -
40 - /**
41 - * If the cache is enabled or not.
42 - *
43 - * @since 1.20
44 - * @var boolean
45 - */
46 - protected $cacheEnabled = true;
47 -
48 - /**
49 - * Sets if the cache should be enabled or not.
50 - *
51 - * @since 1.20
52 - * @param boolean $cacheEnabled
53 - */
54 - public function setCacheEnabled( $cacheEnabled ) {
55 - $this->cacheHelper->setCacheEnabled( $cacheEnabled );
56 - }
57 -
58 - /**
59 - * Initializes the caching.
60 - * Should be called before the first time anything is added via addCachedHTML.
61 - *
62 - * @since 1.20
63 - *
64 - * @param integer|null $cacheExpiry Sets the cache expirty, either ttl in seconds or unix timestamp.
65 - * @param boolean|null $cacheEnabled Sets if the cache should be enabled or not.
66 - */
67 - public function startCache( $cacheExpiry = null, $cacheEnabled = null ) {
68 - $this->cacheHelper = new CacheHelper();
69 -
70 - $this->cacheHelper->setCacheEnabled( $this->cacheEnabled );
71 - $this->cacheHelper->setOnInitializedHandler( array( $this, 'onCacheInitialized' ) );
72 -
73 - $keyArgs = $this->getCacheKey();
74 -
75 - if ( array_key_exists( 'action', $keyArgs ) && $keyArgs['action'] === 'purge' ) {
76 - unset( $keyArgs['action'] );
77 - }
78 -
79 - $this->cacheHelper->setCacheKey( $keyArgs );
80 -
81 - if ( $this->getRequest()->getText( 'action' ) === 'purge' ) {
82 - $this->cacheHelper->purge();
83 - }
84 -
85 - $this->cacheHelper->startCache( $cacheExpiry, $cacheEnabled );
86 - }
87 -
88 - /**
89 - * Get a cached value if available or compute it if not and then cache it if possible.
90 - * The provided $computeFunction is only called when the computation needs to happen
91 - * and should return a result value. $args are arguments that will be passed to the
92 - * compute function when called.
93 - *
94 - * @since 1.20
95 - *
96 - * @param {function} $computeFunction
97 - * @param array|mixed $args
98 - * @param string|null $key
99 - *
100 - * @return mixed
101 - */
102 - public function getCachedValue( $computeFunction, $args = array(), $key = null ) {
103 - return $this->cacheHelper->getCachedValue( $computeFunction, $args, $key );
104 - }
105 -
106 - /**
107 - * Add some HTML to be cached.
108 - * This is done by providing a callback function that should
109 - * return the HTML to be added. It will only be called if the
110 - * item is not in the cache yet or when the cache has been invalidated.
111 - *
112 - * @since 1.20
113 - *
114 - * @param {function} $computeFunction
115 - * @param array $args
116 - * @param string|null $key
117 - */
118 - public function addCachedHTML( $computeFunction, $args = array(), $key = null ) {
119 - $this->getOutput()->addHTML( $this->cacheHelper->getCachedValue( $computeFunction, $args, $key ) );
120 - }
121 -
122 - /**
123 - * Saves the HTML to the cache in case it got recomputed.
124 - * Should be called after the last time anything is added via addCachedHTML.
125 - *
126 - * @since 1.20
127 - */
128 - public function saveCache() {
129 - $this->cacheHelper->saveCache();
130 - }
131 -
132 - /**
133 - * Sets the time to live for the cache, in seconds or a unix timestamp indicating the point of expiry..
134 - *
135 - * @since 1.20
136 - *
137 - * @param integer $cacheExpiry
138 - */
139 - public function setExpirey( $cacheExpiry ) {
140 - $this->cacheHelper->setExpirey( $cacheExpiry );
141 - }
142 -
143 - /**
144 - * Returns the variables used to constructed the cache key in an array.
145 - *
146 - * @since 1.20
147 - *
148 - * @return array
149 - */
150 - protected function getCacheKey() {
151 - return array(
152 - $this->mName,
153 - $this->getLanguage()->getCode()
154 - );
155 - }
156 -
157 - /**
158 - * Gets called after the cache got initialized.
159 - *
160 - * @since 1.20
161 - *
162 - * @param boolean $hasCached
163 - */
164 - public function onCacheInitialized( $hasCached ) {
165 - if ( $hasCached ) {
166 - $this->getOutput()->setSubtitle( $this->cacheHelper->getCachedNotice( $this->getContext() ) );
167 - }
168 - }
169 -
170 -}
Index: trunk/phase3/includes/objectcache/MemcachedClient.php
@@ -344,20 +344,11 @@
345345 return false;
346346 }
347347
348 - /**
349 - * @param $key
350 - * @param $timeout int
351 - * @return bool
352 - */
353348 public function lock( $key, $timeout = 0 ) {
354349 /* stub */
355350 return true;
356351 }
357352
358 - /**
359 - * @param $key
360 - * @return bool
361 - */
362353 public function unlock( $key ) {
363354 /* stub */
364355 return true;
@@ -480,7 +471,7 @@
481472 $this->stats['get_multi'] = 1;
482473 }
483474 $sock_keys = array();
484 - $socks = array();
 475+
485476 foreach ( $keys as $key ) {
486477 $sock = $this->get_sock( $key );
487478 if ( !is_resource( $sock ) ) {
@@ -494,7 +485,6 @@
495486 $sock_keys[$sock][] = $key;
496487 }
497488
498 - $gather = array();
499489 // Send out the requests
500490 foreach ( $socks as $sock ) {
501491 $cmd = 'get';
@@ -589,7 +579,6 @@
590580 return array();
591581 }
592582
593 - $ret = array();
594583 while ( true ) {
595584 $res = fgets( $sock );
596585 $ret[] = $res;
@@ -755,9 +744,6 @@
756745 $this->_dead_host( $host );
757746 }
758747
759 - /**
760 - * @param $host
761 - */
762748 function _dead_host( $host ) {
763749 $parts = explode( ':', $host );
764750 $ip = $parts[0];
@@ -788,8 +774,8 @@
789775 }
790776
791777 $hv = is_array( $key ) ? intval( $key[0] ) : $this->_hashfunc( $key );
 778+
792779 if ( $this->_buckets === null ) {
793 - $bu = array();
794780 foreach ( $this->_servers as $v ) {
795781 if ( is_array( $v ) ) {
796782 for( $i = 0; $i < $v[1]; $i++ ) {
@@ -865,8 +851,7 @@
866852 $this->stats[$cmd] = 1;
867853 }
868854 if ( !$this->_safe_fwrite( $sock, "$cmd $key $amt\r\n" ) ) {
869 - $this->_dead_sock( $sock );
870 - return null;
 855+ return $this->_dead_sock( $sock );
871856 }
872857
873858 $line = fgets( $sock );
@@ -1013,8 +998,7 @@
1014999 }
10151000 }
10161001 if ( !$this->_safe_fwrite( $sock, "$cmd $key $flags $exp $len\r\n$val\r\n" ) ) {
1017 - $this->_dead_sock( $sock );
1018 - return false;
 1002+ return $this->_dead_sock( $sock );
10191003 }
10201004
10211005 $line = trim( fgets( $sock ) );
@@ -1054,8 +1038,7 @@
10551039 }
10561040
10571041 if ( !$this->_connect_sock( $sock, $host ) ) {
1058 - $this->_dead_host( $host );
1059 - return null;
 1042+ return $this->_dead_host( $host );
10601043 }
10611044
10621045 // Do not buffer writes
@@ -1066,9 +1049,6 @@
10671050 return $this->_cache_sock[$host];
10681051 }
10691052
1070 - /**
1071 - * @param $str string
1072 - */
10731053 function _debugprint( $str ) {
10741054 print( $str );
10751055 }
@@ -1100,9 +1080,6 @@
11011081
11021082 /**
11031083 * Original behaviour
1104 - * @param $f
1105 - * @param $buf
1106 - * @param $len bool
11071084 * @return int
11081085 */
11091086 function _safe_fwrite( $f, $buf, $len = false ) {
@@ -1116,7 +1093,6 @@
11171094
11181095 /**
11191096 * Flush the read buffer of a stream
1120 - * @param $f Resource
11211097 */
11221098 function _flush_read_buffer( $f ) {
11231099 if ( !is_resource( $f ) ) {
Index: trunk/phase3/languages/Language.php
@@ -1910,52 +1910,6 @@
19111911 }
19121912
19131913 /**
1914 - * Takes a number of seconds and turns it into a text using values such as hours and minutes.
1915 - *
1916 - * @since 1.20
1917 - *
1918 - * @param integer $seconds The amount of seconds.
1919 - * @param array $chosenIntervals The intervals to enable.
1920 - *
1921 - * @return string
1922 - */
1923 - public function formatDuration( $seconds, array $chosenIntervals = array() ) {
1924 - $intervals = array(
1925 - 'millennia' => 1000 * 31557600,
1926 - 'centuries' => 100 * 31557600,
1927 - 'decades' => 10 * 31557600,
1928 - 'years' => 31557600, // 86400 * 365.25
1929 - 'weeks' => 604800,
1930 - 'days' => 86400,
1931 - 'hours' => 3600,
1932 - 'minutes' => 60,
1933 - 'seconds' => 1,
1934 - );
1935 -
1936 - if ( empty( $chosenIntervals ) ) {
1937 - $chosenIntervals = array( 'millennia', 'centuries', 'decades', 'years', 'days', 'hours', 'minutes', 'seconds' );
1938 - }
1939 -
1940 - $intervals = array_intersect_key( $intervals, array_flip( $chosenIntervals ) );
1941 - $sortedNames = array_keys( $intervals );
1942 - $smallestInterval = array_pop( $sortedNames );
1943 -
1944 - $segments = array();
1945 -
1946 - foreach ( $intervals as $name => $length ) {
1947 - $value = floor( $seconds / $length );
1948 -
1949 - if ( $value > 0 || ( $name == $smallestInterval && empty( $segments ) ) ) {
1950 - $seconds -= $value * $length;
1951 - $message = new Message( 'duration-' . $name, array( $value ) );
1952 - $segments[] = $message->inLanguage( $this )->escaped();
1953 - }
1954 - }
1955 -
1956 - return $this->listToText( $segments );
1957 - }
1958 -
1959 - /**
19601914 * Internal helper function for userDate(), userTime() and userTimeAndDate()
19611915 *
19621916 * @param $type String: can be 'date', 'time' or 'both'
@@ -3804,7 +3758,7 @@
38053759
38063760 /**
38073761 * Decode an expiry (block, protection, etc) which has come from the DB
3808 - *
 3762+ *
38093763 * @FIXME: why are we returnings DBMS-dependent strings???
38103764 *
38113765 * @param $expiry String: Database expiry String
Index: trunk/phase3/languages/classes/LanguageKaa.php
@@ -41,11 +41,11 @@
4242 }
4343
4444 /**
45 - * It fixes issue with lcfirst for transforming 'I' to 'ı'
 45+ * It fixes issue with lcfirst for transforming 'I' to 'ı'
4646 *
4747 * @param $string string
4848 *
49 - * @return mixed|string
 49+ * @return string
5050 */
5151 function lcfirst ( $string ) {
5252 if ( substr( $string, 0, 1 ) === 'I' ) {
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -2661,11 +2661,6 @@
26622662 It may contain one or more characters which cannot be used in titles.',
26632663 'allpages-bad-ns' => '{{SITENAME}} does not have namespace "$1".',
26642664
2665 -# SpecialCachedPage
2666 -'cachedspecial-viewing-cached-ttl' => 'You are viewing a cached version of this page, which can be up to $1 old.',
2667 -'cachedspecial-viewing-cached-ts' => 'You are viewing a cached version of this page, which might not be completely actual.',
2668 -'cachedspecial-refresh-now' => 'View latest.',
2669 -
26702665 # Special:Categories
26712666 'categories' => 'Categories',
26722667 'categories-summary' => '', # do not translate or duplicate this message to other languages
@@ -4825,15 +4820,4 @@
48264821 'api-error-uploaddisabled' => 'Uploading is disabled on this wiki.',
48274822 'api-error-verification-error' => 'This file might be corrupt, or have the wrong extension.',
48284823
4829 -# Durations
4830 -'duration-seconds' => '$1 {{PLURAL:$1|second|seconds}}',
4831 -'duration-minutes' => '$1 {{PLURAL:$1|minute|minutes}}',
4832 -'duration-hours' => '$1 {{PLURAL:$1|hour|hours}}',
4833 -'duration-days' => '$1 {{PLURAL:$1|day|days}}',
4834 -'duration-weeks' => '$1 {{PLURAL:$1|week|weeks}}',
4835 -'duration-years' => '$1 {{PLURAL:$1|year|years}}',
4836 -'duration-decades' => '$1 {{PLURAL:$1|decade|decades}}',
4837 -'duration-centuries' => '$1 {{PLURAL:$1|century|centuries}}',
4838 -'duration-millennia' => '$1 {{PLURAL:$1|millennium|millennia}}',
4839 -
48404824 );

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r114067adding a duration function to language that converts seconds to textjeroendedauw20:58, 17 March 2012
r114071Follow up to r114067;jeroendedauw21:13, 17 March 2012
r114075follow up to r114067, use correct languagejeroendedauw21:47, 17 March 2012
r114079Followup r114067...reedy22:14, 17 March 2012
r114081adding special page with scaffolding for caching chunks of HTMLjeroendedauw22:26, 17 March 2012
r114082Followup r114067 rename to formatDuration to match other methodsreedy22:26, 17 March 2012
r114084Unit tests for r114067reedy22:39, 17 March 2012
r114086Noralise a few of the magic numbers used in r114084reedy22:47, 17 March 2012
r114088Trim trailing whitespace...reedy22:52, 17 March 2012
r114089follow up to r114084, add tests for stuff w/ multiple unitsjeroendedauw23:26, 17 March 2012
r114101follow up to r114081: qqq, and to r114082: match renamejeroendedauw16:27, 18 March 2012
r114118Bug 35309 - formatDuration message missing/inconsistent...reedy23:22, 18 March 2012
r114137Follow up to r114081;jeroendedauw13:47, 19 March 2012
r114147Follow up to r114081; address krinkles commentjeroendedauw16:14, 19 March 2012
r114164some refactoring to allow for nicer usage in deriving classesjeroendedauw18:40, 19 March 2012
r114172update docsjeroendedauw19:24, 19 March 2012
r114175fix for r114164jeroendedauw20:05, 19 March 2012
r114180make more generic: do not assume we want to add html to the output. Also get ...jeroendedauw20:51, 19 March 2012
r114208only init if not already done sojeroendedauw22:37, 19 March 2012
r114209fix subpage linkingjeroendedauw22:49, 19 March 2012
r114215split general cache helper functionality to its own class, so we can also eas...jeroendedauw23:33, 19 March 2012
r114219follow up to r114215, fix some fails and added CachedAction implementing the ...jeroendedauw00:04, 20 March 2012
r114226added enabled field so you can disable the cache thing if you need to before ...jeroendedauw00:31, 20 March 2012
r114321handle cases where an empty array is provided by using this as default, also ...jeroendedauw22:47, 20 March 2012
r114322added some tests using the intervals paramjeroendedauw22:48, 20 March 2012

Status & tagging log