https://www.mediawiki.org/wiki/Special:Code/MediaWiki/114060
Revision: 114060
Author: jeroendedauw
Date: 2012-03-17 19:45:06 +0000 (Sat, 17 Mar 2012)
Log Message:
-----------
work on special:studentactivity
Modified Paths:
--------------
trunk/extensions/EducationProgram/EducationProgram.i18n.php
trunk/extensions/EducationProgram/EducationProgram.php
trunk/extensions/EducationProgram/specials/SpecialCachedPage.php
trunk/extensions/EducationProgram/specials/SpecialStudentActivity.php
Added Paths:
-----------
trunk/extensions/EducationProgram/resources/ep.studentactivity.css
Modified: trunk/extensions/EducationProgram/EducationProgram.i18n.php
===================================================================
--- trunk/extensions/EducationProgram/EducationProgram.i18n.php 2012-03-17
19:04:03 UTC (rev 114059)
+++ trunk/extensions/EducationProgram/EducationProgram.i18n.php 2012-03-17
19:45:06 UTC (rev 114060)
@@ -783,8 +783,9 @@
'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
- 'cachedspecial-viewing-cached' => 'You are viewing a cached version of
this page, which can be up to $1 old.',
- 'cachedspecial-refresh-now' => 'Refresh now.',
+ '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.',
);
/** Message documentation (Message documentation)
Modified: trunk/extensions/EducationProgram/EducationProgram.php
===================================================================
--- trunk/extensions/EducationProgram/EducationProgram.php 2012-03-17
19:04:03 UTC (rev 114059)
+++ trunk/extensions/EducationProgram/EducationProgram.php 2012-03-17
19:45:06 UTC (rev 114060)
@@ -523,6 +523,12 @@
),
);
+$wgResourceModules['ep.studentactivity'] = $moduleTemplate + array(
+ 'styles' => array(
+ 'ep.studentactivity.css',
+ ),
+);
+
if ( array_key_exists( 'WikiEditorHooks', $GLOBALS['wgAutoloadClasses'] ) ) {
$wgResourceModules['ep.formpage']['dependencies'][] =
'ext.wikiEditor.toolbar';
$wgResourceModules['ep.ambprofile']['dependencies'][] =
'ext.wikiEditor.toolbar';
Added: trunk/extensions/EducationProgram/resources/ep.studentactivity.css
===================================================================
--- trunk/extensions/EducationProgram/resources/ep.studentactivity.css
(rev 0)
+++ trunk/extensions/EducationProgram/resources/ep.studentactivity.css
2012-03-17 19:45:06 UTC (rev 114060)
@@ -0,0 +1,16 @@
+/**
+ * CSS for the Education Program MediaWiki extension.
+ * @see https://www.mediawiki.org/wiki/Extension:Education_Program
+ *
+ * @licence GNU GPL v3 or later
+ * @author Jeroen De Dauw <jeroendedauw at gmail dot com>
+ */
+
+img.studentometer, table.ep-studentactivity {
+ margin-left: auto;
+ margin-right: auto;
+}
+
+img.studentometer {
+ display: block;
+}
Modified: trunk/extensions/EducationProgram/specials/SpecialCachedPage.php
===================================================================
--- trunk/extensions/EducationProgram/specials/SpecialCachedPage.php
2012-03-17 19:04:03 UTC (rev 114059)
+++ trunk/extensions/EducationProgram/specials/SpecialCachedPage.php
2012-03-17 19:45:06 UTC (rev 114060)
@@ -3,6 +3,14 @@
/**
* 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
@@ -45,7 +53,7 @@
*
* @since 0.1
*
- * @param string $subPage
+ * @param string|null $subPage
*/
public function execute( $subPage ) {
//parent::execute( $subPage );
@@ -63,25 +71,51 @@
}
}
+ /**
+ * 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';
- return
- $this->msg(
- 'cachedspecial-viewing-cached',
+ $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()
- )->escaped() .
- ' ' .
- Linker::link(
- $this->getTitle( $subPage ),
- $this->msg( 'cachedspecial-refresh-now'
)->escaped(),
- array(),
- $refreshArgs
- );
+ )->escaped();
+ }
+ else {
+ $message = $this->msg(
+ 'cachedspecial-viewing-cached-ts',
+ $this->getDurationText()
+ )->escaped();
+ }
+
+ return $message . ' ' . $refreshLink;
}
+ /**
+ * Returns a message with the time to live of the cache.
+ *
+ * @since 0.1
+ *
+ * @return string
+ */
protected function getDurationText() {
return '5 minutes'; // TODO: generate and i18n
}
Modified: trunk/extensions/EducationProgram/specials/SpecialStudentActivity.php
===================================================================
--- trunk/extensions/EducationProgram/specials/SpecialStudentActivity.php
2012-03-17 19:04:03 UTC (rev 114059)
+++ trunk/extensions/EducationProgram/specials/SpecialStudentActivity.php
2012-03-17 19:45:06 UTC (rev 114060)
@@ -33,6 +33,8 @@
public function execute( $subPage ) {
parent::execute( $subPage );
+ $this->getOutput()->addModules( 'ep.studentactivity' );
+
$this->displayNavigation();
$this->addCachedHTML( array( $this, 'displayCachedContent' ) );
@@ -40,15 +42,32 @@
$this->saveCache();
}
+ /**
+ * Displays the content of the page that should be cached.
+ *
+ * @since 0.1
+ *
+ * @return string
+ */
protected function displayCachedContent() {
$conds = array( 'last_active > ' . wfGetDB( DB_SLAVE
)->addQuotes(
wfTimestamp( TS_MW, time() - ( EPSettings::get(
'recentActivityLimit' ) ) )
) );
return $this->displayStudentMeter( $conds ) .
+ '<br />' .
$this->displayPager( $conds );
}
+ /**
+ * Returns the HTML for the pager.
+ *
+ * @since 0.1
+ *
+ * @param array $conds
+ *
+ * @return string
+ */
public function displayPager( array $conds ) {
$pager = new EPStudentActivityPager( $this->getContext(),
$conds );
@@ -67,6 +86,15 @@
}
}
+ /**
+ * Returns the HTML for the student activity meter.
+ *
+ * @since 0.1
+ *
+ * @param array $conds
+ *
+ * @return string
+ */
public function displayStudentMeter( array $conds ) {
$studentCount = EPStudents::singleton()->count( $conds );
@@ -83,6 +111,7 @@
'src' => EPSettings::get( 'imageDir' ) .
'student-o-meter_morethan-' . $image . '.png',
'alt' => $message,
'title' => $message,
+ 'class' => 'studentometer'
) );
}
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs