Index: trunk/extensions/EducationProgram/EducationProgram.php |
— | — | @@ -523,6 +523,12 @@ |
524 | 524 | ), |
525 | 525 | ); |
526 | 526 | |
| 527 | +$wgResourceModules['ep.studentactivity'] = $moduleTemplate + array( |
| 528 | + 'styles' => array( |
| 529 | + 'ep.studentactivity.css', |
| 530 | + ), |
| 531 | +); |
| 532 | + |
527 | 533 | if ( array_key_exists( 'WikiEditorHooks', $GLOBALS['wgAutoloadClasses'] ) ) { |
528 | 534 | $wgResourceModules['ep.formpage']['dependencies'][] = 'ext.wikiEditor.toolbar'; |
529 | 535 | $wgResourceModules['ep.ambprofile']['dependencies'][] = 'ext.wikiEditor.toolbar'; |
Index: trunk/extensions/EducationProgram/specials/SpecialStudentActivity.php |
— | — | @@ -33,6 +33,8 @@ |
34 | 34 | public function execute( $subPage ) { |
35 | 35 | parent::execute( $subPage ); |
36 | 36 | |
| 37 | + $this->getOutput()->addModules( 'ep.studentactivity' ); |
| 38 | + |
37 | 39 | $this->displayNavigation(); |
38 | 40 | |
39 | 41 | $this->addCachedHTML( array( $this, 'displayCachedContent' ) ); |
— | — | @@ -40,15 +42,32 @@ |
41 | 43 | $this->saveCache(); |
42 | 44 | } |
43 | 45 | |
| 46 | + /** |
| 47 | + * Displays the content of the page that should be cached. |
| 48 | + * |
| 49 | + * @since 0.1 |
| 50 | + * |
| 51 | + * @return string |
| 52 | + */ |
44 | 53 | protected function displayCachedContent() { |
45 | 54 | $conds = array( 'last_active > ' . wfGetDB( DB_SLAVE )->addQuotes( |
46 | 55 | wfTimestamp( TS_MW, time() - ( EPSettings::get( 'recentActivityLimit' ) ) ) |
47 | 56 | ) ); |
48 | 57 | |
49 | 58 | return $this->displayStudentMeter( $conds ) . |
| 59 | + '<br />' . |
50 | 60 | $this->displayPager( $conds ); |
51 | 61 | } |
52 | 62 | |
| 63 | + /** |
| 64 | + * Returns the HTML for the pager. |
| 65 | + * |
| 66 | + * @since 0.1 |
| 67 | + * |
| 68 | + * @param array $conds |
| 69 | + * |
| 70 | + * @return string |
| 71 | + */ |
53 | 72 | public function displayPager( array $conds ) { |
54 | 73 | $pager = new EPStudentActivityPager( $this->getContext(), $conds ); |
55 | 74 | |
— | — | @@ -67,6 +86,15 @@ |
68 | 87 | } |
69 | 88 | } |
70 | 89 | |
| 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 | + */ |
71 | 99 | public function displayStudentMeter( array $conds ) { |
72 | 100 | $studentCount = EPStudents::singleton()->count( $conds ); |
73 | 101 | |
— | — | @@ -83,6 +111,7 @@ |
84 | 112 | 'src' => EPSettings::get( 'imageDir' ) . 'student-o-meter_morethan-' . $image . '.png', |
85 | 113 | 'alt' => $message, |
86 | 114 | 'title' => $message, |
| 115 | + 'class' => 'studentometer' |
87 | 116 | ) ); |
88 | 117 | } |
89 | 118 | |
Index: trunk/extensions/EducationProgram/specials/SpecialCachedPage.php |
— | — | @@ -3,6 +3,14 @@ |
4 | 4 | /** |
5 | 5 | * Abstract special page class with scaffolding for caching the HTML output. |
6 | 6 | * |
| 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 | + * |
7 | 15 | * @since 0.1 |
8 | 16 | * |
9 | 17 | * @file SpecialCachedPage.php |
— | — | @@ -45,7 +53,7 @@ |
46 | 54 | * |
47 | 55 | * @since 0.1 |
48 | 56 | * |
49 | | - * @param string $subPage |
| 57 | + * @param string|null $subPage |
50 | 58 | */ |
51 | 59 | public function execute( $subPage ) { |
52 | 60 | //parent::execute( $subPage ); |
— | — | @@ -63,25 +71,51 @@ |
64 | 72 | } |
65 | 73 | } |
66 | 74 | |
| 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 | + */ |
67 | 85 | protected function getCachedNotice( $subPage ) { |
68 | 86 | $refreshArgs = $_GET; |
69 | 87 | unset( $refreshArgs['title'] ); |
70 | 88 | $refreshArgs['action'] = 'purge'; |
71 | 89 | |
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', |
75 | 100 | $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; |
84 | 111 | } |
85 | 112 | |
| 113 | + /** |
| 114 | + * Returns a message with the time to live of the cache. |
| 115 | + * |
| 116 | + * @since 0.1 |
| 117 | + * |
| 118 | + * @return string |
| 119 | + */ |
86 | 120 | protected function getDurationText() { |
87 | 121 | return '5 minutes'; // TODO: generate and i18n |
88 | 122 | } |
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php |
— | — | @@ -783,8 +783,9 @@ |
784 | 784 | '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.', |
785 | 785 | |
786 | 786 | // 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.', |
789 | 790 | ); |
790 | 791 | |
791 | 792 | /** 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 | +} |