r114060 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r114059‎ | r114060 | r114061 >
Date:19:45, 17 March 2012
Author:jeroendedauw
Status:deferred (Comments)
Tags:
Comment:
work on special:studentactivity
Modified paths:
  • /trunk/extensions/EducationProgram/EducationProgram.i18n.php (modified) (history)
  • /trunk/extensions/EducationProgram/EducationProgram.php (modified) (history)
  • /trunk/extensions/EducationProgram/resources/ep.studentactivity.css (added) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialCachedPage.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialStudentActivity.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/EducationProgram.php
@@ -523,6 +523,12 @@
524524 ),
525525 );
526526
 527+$wgResourceModules['ep.studentactivity'] = $moduleTemplate + array(
 528+ 'styles' => array(
 529+ 'ep.studentactivity.css',
 530+ ),
 531+);
 532+
527533 if ( array_key_exists( 'WikiEditorHooks', $GLOBALS['wgAutoloadClasses'] ) ) {
528534 $wgResourceModules['ep.formpage']['dependencies'][] = 'ext.wikiEditor.toolbar';
529535 $wgResourceModules['ep.ambprofile']['dependencies'][] = 'ext.wikiEditor.toolbar';
Index: trunk/extensions/EducationProgram/specials/SpecialStudentActivity.php
@@ -33,6 +33,8 @@
3434 public function execute( $subPage ) {
3535 parent::execute( $subPage );
3636
 37+ $this->getOutput()->addModules( 'ep.studentactivity' );
 38+
3739 $this->displayNavigation();
3840
3941 $this->addCachedHTML( array( $this, 'displayCachedContent' ) );
@@ -40,15 +42,32 @@
4143 $this->saveCache();
4244 }
4345
 46+ /**
 47+ * Displays the content of the page that should be cached.
 48+ *
 49+ * @since 0.1
 50+ *
 51+ * @return string
 52+ */
4453 protected function displayCachedContent() {
4554 $conds = array( 'last_active > ' . wfGetDB( DB_SLAVE )->addQuotes(
4655 wfTimestamp( TS_MW, time() - ( EPSettings::get( 'recentActivityLimit' ) ) )
4756 ) );
4857
4958 return $this->displayStudentMeter( $conds ) .
 59+ '<br />' .
5060 $this->displayPager( $conds );
5161 }
5262
 63+ /**
 64+ * Returns the HTML for the pager.
 65+ *
 66+ * @since 0.1
 67+ *
 68+ * @param array $conds
 69+ *
 70+ * @return string
 71+ */
5372 public function displayPager( array $conds ) {
5473 $pager = new EPStudentActivityPager( $this->getContext(), $conds );
5574
@@ -67,6 +86,15 @@
6887 }
6988 }
7089
 90+ /**
 91+ * Returns the HTML for the student activity meter.
 92+ *
 93+ * @since 0.1
 94+ *
 95+ * @param array $conds
 96+ *
 97+ * @return string
 98+ */
7199 public function displayStudentMeter( array $conds ) {
72100 $studentCount = EPStudents::singleton()->count( $conds );
73101
@@ -83,6 +111,7 @@
84112 'src' => EPSettings::get( 'imageDir' ) . 'student-o-meter_morethan-' . $image . '.png',
85113 'alt' => $message,
86114 'title' => $message,
 115+ 'class' => 'studentometer'
87116 ) );
88117 }
89118
Index: trunk/extensions/EducationProgram/specials/SpecialCachedPage.php
@@ -3,6 +3,14 @@
44 /**
55 * Abstract special page class with scaffolding for caching the HTML output.
66 *
 7+ * To enable the caching functionality, the cacheExpiry field should be set
 8+ * in the constructor.
 9+ *
 10+ * To add HTML that should be cached, use addCachedHTML like this:
 11+ * $this->addCachedHTML( array( $this, 'displayCachedContent' ) );
 12+ *
 13+ * After adding the last HTML that should be cached, call $this->saveCache();
 14+ *
715 * @since 0.1
816 *
917 * @file SpecialCachedPage.php
@@ -45,7 +53,7 @@
4654 *
4755 * @since 0.1
4856 *
49 - * @param string $subPage
 57+ * @param string|null $subPage
5058 */
5159 public function execute( $subPage ) {
5260 //parent::execute( $subPage );
@@ -63,25 +71,51 @@
6472 }
6573 }
6674
 75+ /**
 76+ * Returns a message that notifies the user he/she is looking at
 77+ * a cached version of the page, including a refresh link.
 78+ *
 79+ * @since 0.1
 80+ *
 81+ * @param string|null $subPage
 82+ *
 83+ * @return string
 84+ */
6785 protected function getCachedNotice( $subPage ) {
6886 $refreshArgs = $_GET;
6987 unset( $refreshArgs['title'] );
7088 $refreshArgs['action'] = 'purge';
7189
72 - return
73 - $this->msg(
74 - 'cachedspecial-viewing-cached',
 90+ $refreshLink = Linker::link(
 91+ $this->getTitle( $subPage ),
 92+ $this->msg( 'cachedspecial-refresh-now' )->escaped(),
 93+ array(),
 94+ $refreshArgs
 95+ );
 96+
 97+ if ( $this->cacheExpiry < 1000000000 ) {
 98+ $message = $this->msg(
 99+ 'cachedspecial-viewing-cached-ttl',
75100 $this->getDurationText()
76 - )->escaped() .
77 - ' ' .
78 - Linker::link(
79 - $this->getTitle( $subPage ),
80 - $this->msg( 'cachedspecial-refresh-now' )->escaped(),
81 - array(),
82 - $refreshArgs
83 - );
 101+ )->escaped();
 102+ }
 103+ else {
 104+ $message = $this->msg(
 105+ 'cachedspecial-viewing-cached-ts',
 106+ $this->getDurationText()
 107+ )->escaped();
 108+ }
 109+
 110+ return $message . ' ' . $refreshLink;
84111 }
85112
 113+ /**
 114+ * Returns a message with the time to live of the cache.
 115+ *
 116+ * @since 0.1
 117+ *
 118+ * @return string
 119+ */
86120 protected function getDurationText() {
87121 return '5 minutes'; // TODO: generate and i18n
88122 }
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php
@@ -783,8 +783,9 @@
784784 '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.',
785785
786786 // Cached special page
787 - 'cachedspecial-viewing-cached' => 'You are viewing a cached version of this page, which can be up to $1 old.',
788 - 'cachedspecial-refresh-now' => 'Refresh now.',
 787+ 'cachedspecial-viewing-cached-ttl' => 'You are viewing a cached version of this page, which can be up to $1 old.',
 788+ 'cachedspecial-viewing-cached-ts' => 'You are viewing a cached version of this page, which might not be completely actual.',
 789+ 'cachedspecial-refresh-now' => 'View latest.',
789790 );
790791
791792 /** Message documentation (Message documentation)
Index: trunk/extensions/EducationProgram/resources/ep.studentactivity.css
@@ -0,0 +1,16 @@
 2+/**
 3+ * CSS for the Education Program MediaWiki extension.
 4+ * @see https://www.mediawiki.org/wiki/Extension:Education_Program
 5+ *
 6+ * @licence GNU GPL v3 or later
 7+ * @author Jeroen De Dauw <jeroendedauw at gmail dot com>
 8+ */
 9+
 10+img.studentometer, table.ep-studentactivity {
 11+ margin-left: auto;
 12+ margin-right: auto;
 13+}
 14+
 15+img.studentometer {
 16+ display: block;
 17+}

Comments

#Comment by Nikerabbit (talk | contribs)   07:36, 19 March 2012

Cannot review without message documentation.

Status & tagging log