https://www.mediawiki.org/wiki/Special:Code/MediaWiki/114045
Revision: 114045
Author: jeroendedauw
Date: 2012-03-17 01:23:53 +0000 (Sat, 17 Mar 2012)
Log Message:
-----------
Follow up to r114044; decided upon an approach for the caching stuff and got
rid of the rest
Modified Paths:
--------------
trunk/extensions/EducationProgram/EducationProgram.i18n.php
trunk/extensions/EducationProgram/specials/SpecialCachedPage.php
trunk/extensions/EducationProgram/specials/SpecialStudentActivity.php
Modified: trunk/extensions/EducationProgram/EducationProgram.i18n.php
===================================================================
--- trunk/extensions/EducationProgram/EducationProgram.i18n.php 2012-03-17
00:51:25 UTC (rev 114044)
+++ trunk/extensions/EducationProgram/EducationProgram.i18n.php 2012-03-17
01:23:53 UTC (rev 114045)
@@ -777,6 +777,9 @@
'epca-visible' => 'Publicly list me as Campus Ambassador',
// Special:StudentActivity
+ 'ep-studentactivity-noresults' => 'There are no students that where
active in the last 24 hours :(
+
+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.',
);
Modified: trunk/extensions/EducationProgram/specials/SpecialCachedPage.php
===================================================================
--- trunk/extensions/EducationProgram/specials/SpecialCachedPage.php
2012-03-17 00:51:25 UTC (rev 114044)
+++ trunk/extensions/EducationProgram/specials/SpecialCachedPage.php
2012-03-17 01:23:53 UTC (rev 114045)
@@ -1,29 +1,45 @@
<?php
-class CachedOutput {
+/**
+ * Abstract special page class with scaffolding for caching the HTML output.
+ *
+ * @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
+ * @var integer|null
*/
- protected $cacheExpiry = 3600;
+ protected $cacheExpiry = 300;
protected $cachedChunks;
protected $hasCached = null;
- protected $out;
+ /**
+ * Main method.
+ *
+ * @since 0.1
+ *
+ * @param string $subPage
+ */
+ public function execute( $subPage ) {
+ //parent::execute( $subPage );
- public function __construct( OutputPage $out ) {
- $this->out = $out;
+ if ( $this->getRequest()->getText( 'action' ) === 'purge' ) {
+ $this->hasCached = false;
+ }
}
- public function invalidateCache() {
- $this->hasCached = false;
- }
-
/**
* Initializes the caching.
* Should be called ONCE before any of the caching functionality is
used,
@@ -59,17 +75,17 @@
$html = '';
if ( is_null( $key ) ) {
- $itemKey = array_flip( array_slice(
$this->cachedChunks, 0, 1 ) );
+ $itemKey = array_keys( array_slice(
$this->cachedChunks, 0, 1 ) );
$itemKey = array_shift( $itemKey );
- if ( is_integer( $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( $key );
+ $html = array_shift(
$this->cachedChunks );
}
}
else {
@@ -93,13 +109,9 @@
}
}
- $this->addHTML( $html );
+ $this->getOutput()->addHTML( $html );
}
- public function addHTML( $html ) {
- $this->out->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.
@@ -136,116 +148,3 @@
}
}
-
-/**
- * Abstract special page class with scaffolding for caching the HTML output.
- *
- * @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;
-
- protected $cachedOutput = null;
-
- /**
- * Main method.
- *
- * @since 0.1
- *
- * @param string $subPage
- */
- public function execute( $subPage ) {
- //parent::execute( $subPage );
-
- if ( !is_null( $this->cacheExpiry ) ) {
- $cache = wfGetCache( CACHE_ANYTHING );
- $cacheKey = $this->getCacheKey();
- $cachedHTML = $cache->get( $cacheKey );
-
- $out = $this->getOutput();
-
- if ( $this->getRequest()->getText( 'action' ) !==
'purge' && is_string( $cachedHTML ) ) {
- $html = $cachedHTML;
- }
- else {
- $this->displayCachedContent();
-
- $html = $out->getHTML();
- $cache->set( $cacheKey, $html,
$this->cacheExpiry );
- }
-
- $out->clearHTML();
-
- $this->displayBeforeCached();
- $out->addHTML( $html );
- $this->displayAfterCached();
- }
- }
-
- /**
- * 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()
);
- }
-
- /**
- * Display the cached content. Everything added to the output here
- * will be cached.
- *
- * @since 0.1
- */
- protected function displayCachedContent() {
-
- }
-
- /**
- * Display non-cached content that will be added to the final output
- * before the cached HTML.
- *
- * @since 0.1
- */
- protected function displayBeforeCached() {
-
- }
-
- /**
- * Display non-cached content that will be added to the final output
- * after the cached HTML.
- *
- * @since 0.1
- */
- protected function displayAfterCached() {
-
- }
-
-}
Modified: trunk/extensions/EducationProgram/specials/SpecialStudentActivity.php
===================================================================
--- trunk/extensions/EducationProgram/specials/SpecialStudentActivity.php
2012-03-17 00:51:25 UTC (rev 114044)
+++ trunk/extensions/EducationProgram/specials/SpecialStudentActivity.php
2012-03-17 01:23:53 UTC (rev 114045)
@@ -23,6 +23,8 @@
$this->cacheExpiry = 600;
}
+ protected $cachedOut;
+
/**
* Main method.
*
@@ -31,31 +33,13 @@
* @param string $subPage
*/
public function execute( $subPage ) {
- //parent::execute( $subPage );
+ parent::execute( $subPage );
- if ( !is_null( $this->cacheExpiry ) ) {
- $cache = wfGetCache( CACHE_ANYTHING );
- $cacheKey = $this->getCacheKey();
- $cachedHTML = $cache->get( $cacheKey );
+ $this->displayNavigation();
- $out = $this->getOutput();
+ $this->addCachedHTML( array( $this, 'displayCachedContent' ) );
- if ( $this->getRequest()->getText( 'action' ) !==
'purge' && is_string( $cachedHTML ) ) {
- $html = $cachedHTML;
- }
- else {
- $this->displayCachedContent();
-
- $html = $out->getHTML();
- $cache->set( $cacheKey, $html,
$this->cacheExpiry );
- }
-
- $out->clearHTML();
-
- $this->displayBeforeCached();
- $out->addHTML( $html );
- $this->displayAfterCached();
- }
+ $this->saveCache();
}
protected function displayCachedContent() {
@@ -63,27 +47,25 @@
wfTimestamp( TS_MW, time() - ( EPSettings::get(
'recentActivityLimit' ) ) )
) );
- $this->displayStudentMeter( $conds );
- $this->displayPager( $conds );
+ return $this->displayStudentMeter( $conds ) .
+ $this->displayPager( $conds );
}
public function displayPager( array $conds ) {
- $out = $this->getOutput();
-
$pager = new EPStudentActivityPager( $this->getContext(),
$conds );
if ( $pager->getNumRows() ) {
- $out->addHTML(
+ return
$pager->getFilterControl() .
$pager->getNavigationBar() .
$pager->getBody() .
$pager->getNavigationBar() .
- $pager->getMultipleItemControl()
- );
+ $pager->getMultipleItemControl();
}
else {
- $out->addHTML( $pager->getFilterControl( true ) );
- $out->addWikiMsg( 'ep-studentactivity-noresults' );
+ return $pager->getFilterControl( true )
+ . '<br />'
+ . wfMsgExt( 'ep-studentactivity-noresults',
'parseinline' );
}
}
@@ -99,7 +81,7 @@
$message = $this->msg( 'ep-studentactivity-count',
$studentCount )->escaped();
- $this->getOutput()->addElement( 'img', array(
+ return Html::element( 'img', array(
'src' => EPSettings::get( 'imageDir' ) .
'student-o-meter_morethan-' . $image . '.png',
'alt' => $message,
'title' => $message,
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs