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

Revision: 114070
Author:   jeroendedauw
Date:     2012-03-17 21:07:37 +0000 (Sat, 17 Mar 2012)
Log Message:
-----------
follow up to r114067 and changed special:educationprogram to use new caching 
stuff

Modified Paths:
--------------
    trunk/extensions/EducationProgram/EducationProgram.i18n.php
    trunk/extensions/EducationProgram/specials/SpecialCachedPage.php
    trunk/extensions/EducationProgram/specials/SpecialEducationProgram.php

Modified: trunk/extensions/EducationProgram/EducationProgram.i18n.php
===================================================================
--- trunk/extensions/EducationProgram/EducationProgram.i18n.php 2012-03-17 
21:05:27 UTC (rev 114069)
+++ trunk/extensions/EducationProgram/EducationProgram.i18n.php 2012-03-17 
21:07:37 UTC (rev 114070)
@@ -787,7 +787,7 @@
        'cachedspecial-viewing-cached-ts' => 'You are viewing a cached version 
of this page, which might not be completely actual.',
        'cachedspecial-refresh-now' => 'View latest.',
 
-       // Durations
+       // Durations, back compat for MW < 1.20
        'duration-seconds' => '$1 {{PLURAL:$1|second|seconds}}',
        'duration-minutes' => '$1 {{PLURAL:$1|minute|minutes}}',
        'duration-hours' => '$1 {{PLURAL:$1|hour|hours}}',

Modified: trunk/extensions/EducationProgram/specials/SpecialCachedPage.php
===================================================================
--- trunk/extensions/EducationProgram/specials/SpecialCachedPage.php    
2012-03-17 21:05:27 UTC (rev 114069)
+++ trunk/extensions/EducationProgram/specials/SpecialCachedPage.php    
2012-03-17 21:07:37 UTC (rev 114070)
@@ -110,6 +110,7 @@
 
        /**
         * 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
         *
@@ -119,31 +120,36 @@
         * @return string
         */
        protected function getDurationText( $seconds, array $chosenIntervals = 
array( 'years', 'days', 'hours', 'minutes', 'seconds' ) ) {
-               $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 ) );
+               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,
+                       );
 
-               $segments = array();
+                       if ( !empty( $chosenIntervals ) ) {
+                               $intervals = array_intersect_key( $intervals, 
array_flip( $chosenIntervals ) );
+                       }
 
-               foreach ( $intervals as $name => $length ) {
-                       $value = floor( $seconds / $length );
+                       $segments = array();
 
-                       if ( $value > 0 || ( $name == 'seconds' && empty( 
$segments ) ) ) {
-                               $seconds -= $value * $length;
-                               $segments[] = wfMsgExt( 'duration-' . $name, 
'parsemag', $value );
+                       foreach ( $intervals as $name => $length ) {
+                               $value = floor( $seconds / $length );
+
+                               if ( $value > 0 || ( $name == 'seconds' && 
empty( $segments ) ) ) {
+                                       $seconds -= $value * $length;
+                                       $segments[] = wfMsgExt( 'duration-' . 
$name, 'parsemag', $value );
+                               }
                        }
+
+                       return $this->getLanguage()->listToText( $segments );
                }
-
-               return $this->getLanguage()->listToText( $segments );
        }
 
        /**

Modified: trunk/extensions/EducationProgram/specials/SpecialEducationProgram.php
===================================================================
--- trunk/extensions/EducationProgram/specials/SpecialEducationProgram.php      
2012-03-17 21:05:27 UTC (rev 114069)
+++ trunk/extensions/EducationProgram/specials/SpecialEducationProgram.php      
2012-03-17 21:07:37 UTC (rev 114070)
@@ -19,6 +19,7 @@
         * @since 0.1
         */
        public function __construct() {
+               $this->cacheExpiry = 3600;
                parent::__construct( 'EducationProgram' );
        }
 
@@ -32,53 +33,48 @@
        public function execute( $subPage ) {
                parent::execute( $subPage );
 
-               $cache = wfGetCache( CACHE_ANYTHING );
-               $cacheKey = wfMemcKey( get_class( $this ), 
$this->getLanguage()->getCode() );
-               $cachedHTML = $cache->get( $cacheKey );
+               $this->displayNavigation();
 
-               $out = $this->getOutput();
+               $this->addCachedHTML( array( $this, 'displaySummaryTable' ) );
 
-               if ( $this->getRequest()->getText( 'action' ) !== 'purge' && 
is_string( $cachedHTML ) ) {
-                       $out->clearHTML();
-                       $out->addHTML( $cachedHTML );
-               }
-               else {
-                       $this->displaySummaryTable();
-                       $cache->set( $cacheKey, $out->getHTML(), 3600 );
-               }
+               $this->saveCache();
        }
 
        /**
+        * Display a table with a basic summary of what the extension is 
handling.
+        *
         * @since 0.1
+        *
+        * @return string
         */
        protected function displaySummaryTable() {
-               $out = $this->getOutput();
+               $html = Html::openElement( 'table', array( 'class' => 
'wikitable ep-summary' ) );
 
-               $out->addHTML( Html::openElement( 'table', array( 'class' => 
'wikitable ep-summary' ) ) );
+               $html .= '<tr>' . Html::element( 'th', array( 'colspan' => 2 ), 
wfMsg( 'ep-summary-table-header' ) ) . '</tr>';
 
-               $out->addHTML( '<tr>' . Html::element( 'th', array( 'colspan' 
=> 2 ), wfMsg( 'ep-summary-table-header' ) ) . '</tr>' );
-
                $summaryData = $this->getSummaryInfo();
 
                foreach ( $summaryData as $stat => $value ) {
-                       $out->addHTML( '<tr>' );
+                       $html .= '<tr>';
 
-                       $out->addHtml( Html::rawElement(
+                       $html .=  Html::rawElement(
                                'th',
                                array( 'class' => 'ep-summary-name' ),
                                wfMsgExt( strtolower( get_called_class() ) . 
'-summary-' . $stat, 'parseinline' )
-                       ) );
+                       );
 
-                       $out->addHTML( Html::rawElement(
+                       $html .=  Html::rawElement(
                                'td',
                                array( 'class' => 'ep-summary-value' ),
                                $value
-                       ) );
+                       );
 
-                       $out->addHTML( '</tr>' );
+                       $html .= '</tr>';
                }
 
-               $out->addHTML( Html::closeElement( 'table' ) );
+               $html .= Html::closeElement( 'table' );
+
+               return $html;
        }
 
        protected function getSummaryInfo() {


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

Reply via email to