https://www.mediawiki.org/wiki/Special:Code/MediaWiki/114083

Revision: 114083
Author:   jeroendedauw
Date:     2012-03-17 22:26:35 +0000 (Sat, 17 Mar 2012)
Log Message:
-----------
follow up to r114081

Modified Paths:
--------------
    trunk/extensions/EducationProgram/EducationProgram.i18n.php
    trunk/extensions/EducationProgram/EducationProgram.php

Added Paths:
-----------
    trunk/extensions/EducationProgram/compat/
    trunk/extensions/EducationProgram/compat/SpecialCachedPage.php

Removed Paths:
-------------
    trunk/extensions/EducationProgram/specials/SpecialCachedPage.php

Modified: trunk/extensions/EducationProgram/EducationProgram.i18n.php
===================================================================
--- trunk/extensions/EducationProgram/EducationProgram.i18n.php 2012-03-17 
22:26:26 UTC (rev 114082)
+++ trunk/extensions/EducationProgram/EducationProgram.i18n.php 2012-03-17 
22:26:35 UTC (rev 114083)
@@ -783,7 +783,7 @@
 You can find a full list of students on [[Special:Students|the student 
list]].',
        '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.',
 
-       // Cached special page
+       // Cached special page, back compat for MW < 1.20
        'cachedspecial-viewing-cached-ttl' => 'You are viewing a cached version 
of this page, which can be up to $1 old.',
        'cachedspecial-viewing-cached-ts' => 'You are viewing a cached version 
of this page, which might not be completely actual.',
        'cachedspecial-refresh-now' => 'View latest.',

Modified: trunk/extensions/EducationProgram/EducationProgram.php
===================================================================
--- trunk/extensions/EducationProgram/EducationProgram.php      2012-03-17 
22:26:26 UTC (rev 114082)
+++ trunk/extensions/EducationProgram/EducationProgram.php      2012-03-17 
22:26:35 UTC (rev 114083)
@@ -144,8 +144,17 @@
 $wgAutoloadClasses['SpecialCAProfile']                                 = 
dirname( __FILE__ ) . '/specials/SpecialCAProfile.php';
 $wgAutoloadClasses['SpecialAmbassadorProfile']                 = dirname( 
__FILE__ ) . '/specials/SpecialAmbassadorProfile.php';
 $wgAutoloadClasses['SpecialStudentActivity']           = dirname( __FILE__ ) . 
'/specials/SpecialStudentActivity.php';
-$wgAutoloadClasses['SpecialCachedPage']                        = dirname( 
__FILE__ ) . '/specials/SpecialCachedPage.php';
 
+// Compat classes
+foreach ( array(
+       'SpecialCachedPage' => 'SpecialCachedPage.php' // MW < 1.20
+       ) as $className => $fileName ) {
+
+       if ( !array_key_exists( $className, $wgAutoloadLocalClasses ) ) {
+               $wgAutoloadClasses[$className] = dirname( __FILE__ ) . 
'/compat/' . $fileName;
+       }
+}
+
 // Special pages
 $wgSpecialPages['MyCourses']                                           = 
'SpecialMyCourses';
 $wgSpecialPages['Institutions']                                        = 
'SpecialInstitutions';

Copied: trunk/extensions/EducationProgram/compat/SpecialCachedPage.php (from 
rev 114076, trunk/extensions/EducationProgram/specials/SpecialCachedPage.php)
===================================================================
--- trunk/extensions/EducationProgram/compat/SpecialCachedPage.php              
                (rev 0)
+++ trunk/extensions/EducationProgram/compat/SpecialCachedPage.php      
2012-03-17 22:26:35 UTC (rev 114083)
@@ -0,0 +1,261 @@
+<?php
+
+/**
+ * Abstract special page class with scaffolding for caching the HTML output.
+ *
+ * To enable the caching functionality, the cacheExpiry field should be set
+ * in the constructor.
+ *
+ * To add HTML that should be cached, use addCachedHTML like this:
+ * $this->addCachedHTML( array( $this, 'displayCachedContent' ) );
+ *
+ * After adding the last HTML that should be cached, call $this->saveCache();
+ *
+ * @since 0.1
+ *
+ * @file SpecialCachedPage.php
+ * @ingroup EducationProgram
+ *
+ * @licence GNU GPL v3 or later
+ * @author Jeroen De Dauw < [email protected] >
+ */
+abstract class SpecialCachedPage extends SpecialPage {
+
+       /**
+        * The time to live for the cache, in seconds or a unix timestamp 
indicating the point of expiry.
+        *
+        * @since 0.1
+        * @var integer|null
+        */
+       protected $cacheExpiry = null;
+
+       /**
+        * List of HTML chunks to be cached (if !hasCached) or that where 
cashed (of hasCached).
+        * If no cached already, then the newly computed chunks are added here,
+        * if it as cached already, chunks are removed from this list as they 
are needed.
+        *
+        * @since 0.1
+        * @var array
+        */
+       protected $cachedChunks;
+
+       /**
+        * Indicates if the to be cached content was already cached.
+        * Null if this information is not available yet.
+        *
+        * @since 0.1
+        * @var boolean|null
+        */
+       protected $hasCached = null;
+
+       /**
+        * Main method.
+        *
+        * @since 0.1
+        *
+        * @param string|null $subPage
+        */
+       public function execute( $subPage ) {
+               //parent::execute( $subPage );
+
+               if ( $this->getRequest()->getText( 'action' ) === 'purge' ) {
+                       $this->hasCached = false;
+               }
+
+               if ( !is_null( $this->cacheExpiry ) ) {
+                       $this->initCaching();
+
+                       if ( $this->hasCached === true ) {
+                               $this->getOutput()->setSubtitle( 
$this->getCachedNotice( $subPage ) );
+                       }
+               }
+       }
+
+       /**
+        * Returns a message that notifies the user he/she is looking at
+        * a cached version of the page, including a refresh link.
+        *
+        * @since 0.1
+        *
+        * @param string|null $subPage
+        *
+        * @return string
+        */
+       protected function getCachedNotice( $subPage ) {
+               $refreshArgs = $_GET;
+               unset( $refreshArgs['title'] );
+               $refreshArgs['action'] = 'purge';
+
+               $refreshLink = Linker::link(
+                       $this->getTitle( $subPage ),
+                       $this->msg( 'cachedspecial-refresh-now' )->escaped(),
+                       array(),
+                       $refreshArgs
+               );
+
+               if ( $this->cacheExpiry < 1000000000 ) {
+                       $message = $this->msg(
+                               'cachedspecial-viewing-cached-ttl',
+                               $this->getDurationText( $this->cacheExpiry )
+                       )->escaped();
+               }
+               else {
+                       $message = $this->msg(
+                               'cachedspecial-viewing-cached-ts'
+                       )->escaped();
+               }
+
+               return $message . ' ' . $refreshLink;
+       }
+
+       /**
+        * Returns a message with the time to live of the cache.
+        * Takes care of compatibility with MW < 1.20, in which 
Language::duration was introduced.
+        *
+        * @since 0.1
+        *
+        * @param integer $seconds
+        * @param array $chosenIntervals
+        *
+        * @return string
+        */
+       protected function getDurationText( $seconds, array $chosenIntervals = 
array( 'years', 'days', 'hours', 'minutes', 'seconds' ) ) {
+               if ( method_exists( $this->getLanguage(), 'duration' ) ) {
+                       return $this->getLanguage()->duration( $seconds, 
$chosenIntervals );
+               }
+               else {
+                       $intervals = array(
+                               'years' => 31557600, // 86400 * 365.25
+                               'weeks' => 604800,
+                               'days' => 86400,
+                               'hours' => 3600,
+                               'minutes' => 60,
+                               'seconds' => 1,
+                       );
+
+                       if ( !empty( $chosenIntervals ) ) {
+                               $intervals = array_intersect_key( $intervals, 
array_flip( $chosenIntervals ) );
+                       }
+
+                       $segments = array();
+
+                       foreach ( $intervals as $name => $length ) {
+                               $value = floor( $seconds / $length );
+
+                               if ( $value > 0 || ( $name == 'seconds' && 
empty( $segments ) ) ) {
+                                       $seconds -= $value * $length;
+                                       $segments[] = $this->msg( 'duration-' . 
$name, array( $value ) )->escaped();
+                               }
+                       }
+
+                       return $this->getLanguage()->listToText( $segments );
+               }
+       }
+
+       /**
+        * Initializes the caching if not already done so.
+        * Should be called before any of the caching functionality is used.
+        *
+        * @since 0.1
+        */
+       protected function initCaching() {
+               if ( is_null( $this->hasCached ) ) {
+                       $cachedChunks = wfGetCache( CACHE_ANYTHING )->get( 
$this->getCacheKey() );
+
+                       $this->hasCached = is_array( $cachedChunks );
+                       $this->cachedChunks = $this->hasCached ? $cachedChunks 
: array();
+               }
+       }
+
+       /**
+        * Add some HTML to be cached.
+        * This is done by providing a callback function that should
+        * return the HTML to be added. It will only be called if the
+        * item is not in the cache yet or when the cache has been invalidated.
+        *
+        * @since 0.1
+        *
+        * @param {function} $callback
+        * @param array $args
+        * @param string|null $key
+        */
+       public function addCachedHTML( $callback, $args = array(), $key = null 
) {
+               $this->initCaching();
+
+               if ( $this->hasCached ) {
+                       $html = '';
+
+                       if ( is_null( $key ) ) {
+                               $itemKey = array_keys( array_slice( 
$this->cachedChunks, 0, 1 ) );
+                               $itemKey = array_shift( $itemKey );
+
+                               if ( !is_integer( $itemKey ) ) {
+                                       wfWarn( "Attempted to get item with 
non-numeric key while the next item in the queue has a key ($itemKey) in " . 
__METHOD__ );
+                               }
+                               elseif ( is_null( $itemKey ) ) {
+                                       wfWarn( "Attempted to get an item while 
the queue is empty in " . __METHOD__ );
+                               }
+                               else {
+                                       $html = array_shift( 
$this->cachedChunks );
+                               }
+                       }
+                       else {
+                               if ( array_key_exists( $key, 
$this->cachedChunks ) ) {
+                                       $html = $this->cachedChunks[$key];
+                                       unset( $this->cachedChunks[$key] );
+                               }
+                               else {
+                                       wfWarn( "There is no item with key 
'$key' in this->cachedChunks in " . __METHOD__ );
+                               }
+                       }
+               }
+               else {
+                       $html = call_user_func_array( $callback, $args );
+
+                       if ( is_null( $key ) ) {
+                               $this->cachedChunks[] = $html;
+                       }
+                       else {
+                               $this->cachedChunks[$key] = $html;
+                       }
+               }
+
+               $this->getOutput()->addHTML( $html );
+       }
+
+       /**
+        * Saves the HTML to the cache in case it got recomputed.
+        * Should be called after the last time anything is added via 
addCachedHTML.
+        *
+        * @since 0.1
+        */
+       public function saveCache() {
+               if ( $this->hasCached === false && !empty( $this->cachedChunks 
) ) {
+                       wfGetCache( CACHE_ANYTHING )->set( 
$this->getCacheKey(), $this->cachedChunks, $this->cacheExpiry );
+               }
+       }
+
+       /**
+        * Sets the time to live for the cache, in seconds or a unix timestamp 
indicating the point of expiry..
+        *
+        * @since 0.1
+        *
+        * @param integer $cacheExpiry
+        */
+       protected function setExpirey( $cacheExpiry ) {
+               $this->cacheExpiry = $cacheExpiry;
+       }
+
+       /**
+        * Returns the cache key to use to cache this page's HTML output.
+        * Is constructed from the special page name and language code.
+        *
+        * @since 0.1
+        *
+        * @return string
+        */
+       protected function getCacheKey() {
+               return wfMemcKey( $this->mName, $this->getLanguage()->getCode() 
);
+       }
+
+}

Deleted: trunk/extensions/EducationProgram/specials/SpecialCachedPage.php
===================================================================
--- trunk/extensions/EducationProgram/specials/SpecialCachedPage.php    
2012-03-17 22:26:26 UTC (rev 114082)
+++ trunk/extensions/EducationProgram/specials/SpecialCachedPage.php    
2012-03-17 22:26:35 UTC (rev 114083)
@@ -1,261 +0,0 @@
-<?php
-
-/**
- * Abstract special page class with scaffolding for caching the HTML output.
- *
- * To enable the caching functionality, the cacheExpiry field should be set
- * in the constructor.
- *
- * To add HTML that should be cached, use addCachedHTML like this:
- * $this->addCachedHTML( array( $this, 'displayCachedContent' ) );
- *
- * After adding the last HTML that should be cached, call $this->saveCache();
- *
- * @since 0.1
- *
- * @file SpecialCachedPage.php
- * @ingroup EducationProgram
- *
- * @licence GNU GPL v3 or later
- * @author Jeroen De Dauw < [email protected] >
- */
-abstract class SpecialCachedPage extends SpecialPage {
-
-       /**
-        * The time to live for the cache, in seconds or a unix timestamp 
indicating the point of expiry.
-        *
-        * @since 0.1
-        * @var integer|null
-        */
-       protected $cacheExpiry = null;
-
-       /**
-        * List of HTML chunks to be cached (if !hasCached) or that where 
cashed (of hasCached).
-        * If no cached already, then the newly computed chunks are added here,
-        * if it as cached already, chunks are removed from this list as they 
are needed.
-        *
-        * @since 0.1
-        * @var array
-        */
-       protected $cachedChunks;
-
-       /**
-        * Indicates if the to be cached content was already cached.
-        * Null if this information is not available yet.
-        *
-        * @since 0.1
-        * @var boolean|null
-        */
-       protected $hasCached = null;
-
-       /**
-        * Main method.
-        *
-        * @since 0.1
-        *
-        * @param string|null $subPage
-        */
-       public function execute( $subPage ) {
-               //parent::execute( $subPage );
-
-               if ( $this->getRequest()->getText( 'action' ) === 'purge' ) {
-                       $this->hasCached = false;
-               }
-
-               if ( !is_null( $this->cacheExpiry ) ) {
-                       $this->initCaching();
-
-                       if ( $this->hasCached === true ) {
-                               $this->getOutput()->setSubtitle( 
$this->getCachedNotice( $subPage ) );
-                       }
-               }
-       }
-
-       /**
-        * Returns a message that notifies the user he/she is looking at
-        * a cached version of the page, including a refresh link.
-        *
-        * @since 0.1
-        *
-        * @param string|null $subPage
-        *
-        * @return string
-        */
-       protected function getCachedNotice( $subPage ) {
-               $refreshArgs = $_GET;
-               unset( $refreshArgs['title'] );
-               $refreshArgs['action'] = 'purge';
-
-               $refreshLink = Linker::link(
-                       $this->getTitle( $subPage ),
-                       $this->msg( 'cachedspecial-refresh-now' )->escaped(),
-                       array(),
-                       $refreshArgs
-               );
-
-               if ( $this->cacheExpiry < 1000000000 ) {
-                       $message = $this->msg(
-                               'cachedspecial-viewing-cached-ttl',
-                               $this->getDurationText( $this->cacheExpiry )
-                       )->escaped();
-               }
-               else {
-                       $message = $this->msg(
-                               'cachedspecial-viewing-cached-ts'
-                       )->escaped();
-               }
-
-               return $message . ' ' . $refreshLink;
-       }
-
-       /**
-        * Returns a message with the time to live of the cache.
-        * Takes care of compatibility with MW < 1.20, in which 
Language::duration was introduced.
-        *
-        * @since 0.1
-        *
-        * @param integer $seconds
-        * @param array $chosenIntervals
-        *
-        * @return string
-        */
-       protected function getDurationText( $seconds, array $chosenIntervals = 
array( 'years', 'days', 'hours', 'minutes', 'seconds' ) ) {
-               if ( method_exists( $this->getLanguage(), 'duration' ) ) {
-                       return $this->getLanguage()->duration( $seconds, 
$chosenIntervals );
-               }
-               else {
-                       $intervals = array(
-                               'years' => 31557600, // 86400 * 365.25
-                               'weeks' => 604800,
-                               'days' => 86400,
-                               'hours' => 3600,
-                               'minutes' => 60,
-                               'seconds' => 1,
-                       );
-
-                       if ( !empty( $chosenIntervals ) ) {
-                               $intervals = array_intersect_key( $intervals, 
array_flip( $chosenIntervals ) );
-                       }
-
-                       $segments = array();
-
-                       foreach ( $intervals as $name => $length ) {
-                               $value = floor( $seconds / $length );
-
-                               if ( $value > 0 || ( $name == 'seconds' && 
empty( $segments ) ) ) {
-                                       $seconds -= $value * $length;
-                                       $segments[] = $this->msg( 'duration-' . 
$name, array( $value ) )->escaped();
-                               }
-                       }
-
-                       return $this->getLanguage()->listToText( $segments );
-               }
-       }
-
-       /**
-        * Initializes the caching if not already done so.
-        * Should be called before any of the caching functionality is used.
-        *
-        * @since 0.1
-        */
-       protected function initCaching() {
-               if ( is_null( $this->hasCached ) ) {
-                       $cachedChunks = wfGetCache( CACHE_ANYTHING )->get( 
$this->getCacheKey() );
-
-                       $this->hasCached = is_array( $cachedChunks );
-                       $this->cachedChunks = $this->hasCached ? $cachedChunks 
: array();
-               }
-       }
-
-       /**
-        * Add some HTML to be cached.
-        * This is done by providing a callback function that should
-        * return the HTML to be added. It will only be called if the
-        * item is not in the cache yet or when the cache has been invalidated.
-        *
-        * @since 0.1
-        *
-        * @param {function} $callback
-        * @param array $args
-        * @param string|null $key
-        */
-       public function addCachedHTML( $callback, $args = array(), $key = null 
) {
-               $this->initCaching();
-
-               if ( $this->hasCached ) {
-                       $html = '';
-
-                       if ( is_null( $key ) ) {
-                               $itemKey = array_keys( array_slice( 
$this->cachedChunks, 0, 1 ) );
-                               $itemKey = array_shift( $itemKey );
-
-                               if ( !is_integer( $itemKey ) ) {
-                                       wfWarn( "Attempted to get item with 
non-numeric key while the next item in the queue has a key ($itemKey) in " . 
__METHOD__ );
-                               }
-                               elseif ( is_null( $itemKey ) ) {
-                                       wfWarn( "Attempted to get an item while 
the queue is empty in " . __METHOD__ );
-                               }
-                               else {
-                                       $html = array_shift( 
$this->cachedChunks );
-                               }
-                       }
-                       else {
-                               if ( array_key_exists( $key, 
$this->cachedChunks ) ) {
-                                       $html = $this->cachedChunks[$key];
-                                       unset( $this->cachedChunks[$key] );
-                               }
-                               else {
-                                       wfWarn( "There is no item with key 
'$key' in this->cachedChunks in " . __METHOD__ );
-                               }
-                       }
-               }
-               else {
-                       $html = call_user_func_array( $callback, $args );
-
-                       if ( is_null( $key ) ) {
-                               $this->cachedChunks[] = $html;
-                       }
-                       else {
-                               $this->cachedChunks[$key] = $html;
-                       }
-               }
-
-               $this->getOutput()->addHTML( $html );
-       }
-
-       /**
-        * Saves the HTML to the cache in case it got recomputed.
-        * Should be called after the last time anything is added via 
addCachedHTML.
-        *
-        * @since 0.1
-        */
-       public function saveCache() {
-               if ( $this->hasCached === false && !empty( $this->cachedChunks 
) ) {
-                       wfGetCache( CACHE_ANYTHING )->set( 
$this->getCacheKey(), $this->cachedChunks, $this->cacheExpiry );
-               }
-       }
-
-       /**
-        * Sets the time to live for the cache, in seconds or a unix timestamp 
indicating the point of expiry..
-        *
-        * @since 0.1
-        *
-        * @param integer $cacheExpiry
-        */
-       protected function setExpirey( $cacheExpiry ) {
-               $this->cacheExpiry = $cacheExpiry;
-       }
-
-       /**
-        * Returns the cache key to use to cache this page's HTML output.
-        * Is constructed from the special page name and language code.
-        *
-        * @since 0.1
-        *
-        * @return string
-        */
-       protected function getCacheKey() {
-               return wfMemcKey( $this->mName, $this->getLanguage()->getCode() 
);
-       }
-
-}


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to