https://www.mediawiki.org/wiki/Special:Code/MediaWiki/114027
Revision: 114027
Author: jeroendedauw
Date: 2012-03-16 18:33:43 +0000 (Fri, 16 Mar 2012)
Log Message:
-----------
some work on caching special:studentactivity and fixed image display
Modified Paths:
--------------
trunk/extensions/EducationProgram/EducationProgram.settings.php
trunk/extensions/EducationProgram/includes/EPStudentActivityPager.php
trunk/extensions/EducationProgram/specials/SpecialStudentActivity.php
Modified: trunk/extensions/EducationProgram/EducationProgram.settings.php
===================================================================
--- trunk/extensions/EducationProgram/EducationProgram.settings.php
2012-03-16 17:58:45 UTC (rev 114026)
+++ trunk/extensions/EducationProgram/EducationProgram.settings.php
2012-03-16 18:33:43 UTC (rev 114027)
@@ -40,7 +40,7 @@
'ambassadorCommonsUrl' =>
'https://commons.wikimedia.org/wiki/Special:UploadWizard',
'citylessCountries' => array( 'BT', 'BV', 'IO', 'VG',
'TD', 'CX', 'CC', 'KM', 'DJ', 'GQ', 'FK', 'FX', 'TF', 'GW', 'HM', 'KI', 'YT',
'MS', 'NR', 'NU', 'NF', 'PN', 'SH', 'PM', 'WS', 'SC', 'GS', 'SJ', 'TK', 'TP',
'TV', 'UM', 'VU', 'EH' ),
'ambassadorImgWidth' => 140,
- 'recentActivityLimit' => 17 * 60 * 60,
+ 'recentActivityLimit' => 24 * 60 * 60,
'resourceDir' => $resourceDir,
'imageDir' => $resourceDir . 'images/',
);
Modified: trunk/extensions/EducationProgram/includes/EPStudentActivityPager.php
===================================================================
--- trunk/extensions/EducationProgram/includes/EPStudentActivityPager.php
2012-03-16 17:58:45 UTC (rev 114026)
+++ trunk/extensions/EducationProgram/includes/EPStudentActivityPager.php
2012-03-16 18:33:43 UTC (rev 114027)
@@ -113,7 +113,8 @@
$value =
EPCourses::singleton()->getLinkFor( $this->courseNames[$value] );
}
else {
- wfWarn( 'Course id not in
$this->courseNames in ' . __METHOD__ );
+ // TODO: enable
+ //wfWarn( 'Course id not in
$this->courseNames in ' . __METHOD__ );
}
break;
case 'org_id':
@@ -130,7 +131,8 @@
}
}
else {
- wfWarn( 'Course id not in
$this->courseOrgs in ' . __METHOD__ );
+ // TODO: enable
+ //wfWarn( 'Course id not in
$this->courseOrgs in ' . __METHOD__ );
}
break;
}
Modified: trunk/extensions/EducationProgram/specials/SpecialStudentActivity.php
===================================================================
--- trunk/extensions/EducationProgram/specials/SpecialStudentActivity.php
2012-03-16 17:58:45 UTC (rev 114026)
+++ trunk/extensions/EducationProgram/specials/SpecialStudentActivity.php
2012-03-16 18:33:43 UTC (rev 114027)
@@ -32,14 +32,35 @@
public function execute( $subPage ) {
parent::execute( $subPage );
+ $cache = wfGetCache( CACHE_ANYTHING );
+ $cacheKey = wfMemcKey( get_class( $this ),
$this->getLanguage()->getCode() );
+ $cachedHTML = $cache->get( $cacheKey );
+
+ $out = $this->getOutput();
+
+ if ( $this->getRequest()->getText( 'action' ) !== 'purge' &&
is_string( $cachedHTML ) ) {
+ $html = $cachedHTML;
+ }
+ else {
+ $conds = array( 'last_active > ' . wfGetDB( DB_SLAVE
)->addQuotes(
+ wfTimestamp( TS_MW, time() - ( EPSettings::get(
'recentActivityLimit' ) ) )
+ ) );
+
+ $this->displayStudentMeter( $conds );
+ $this->displayPager( $conds );
+
+ $html = $out->getHTML();
+ $cache->set( $cacheKey, $html, 3600 );
+ }
+
+ $out->clearHTML();
+
$this->displayNavigation();
- $conds = array( 'last_active > ' . wfGetDB( DB_SLAVE
)->addQuotes(
- wfTimestamp( TS_MW, time() - ( EPSettings::get(
'recentActivityLimit' ) ) )
- ) );
+ $out->addHTML( $html );
+ }
- $this->showStudentMeter( $conds );
-
+ public function displayPager( array $conds ) {
$out = $this->getOutput();
$pager = new EPStudentActivityPager( $this->getContext(),
$conds );
@@ -59,14 +80,14 @@
}
}
- public function showStudentMeter( array $conds ) {
+ public function displayStudentMeter( array $conds ) {
$studentCount = EPStudents::singleton()->count( $conds );
if ( $studentCount < 10 ) {
$image = $studentCount < 5 ? 0 : 5;
}
else {
- $image = floor( $studentCount / 10 );
+ $image = min( round( $studentCount / 10 ) * 10, 60 );
}
$message = $this->msg( 'ep-studentactivity-count',
$studentCount )->escaped();
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs