Index: trunk/extensions/EducationProgram/EducationProgram.settings.php |
— | — | @@ -40,9 +40,16 @@ |
41 | 41 | 'ambassadorCommonsUrl' => 'https://commons.wikimedia.org/wiki/Special:UploadWizard', |
42 | 42 | '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' ), |
43 | 43 | 'ambassadorImgWidth' => 140, |
| 44 | + 'ambassadorImgHeight' => 140, |
44 | 45 | 'recentActivityLimit' => 24 * 60 * 60, |
45 | 46 | 'resourceDir' => $resourceDir, |
46 | 47 | 'imageDir' => $resourceDir . 'images/', |
| 48 | + 'flagWidth' => 25, |
| 49 | + 'flagHeight' => 25, |
| 50 | + 'countryFlags' => array( |
| 51 | + 'US' => 'Flag_of_the_United_States.svg', |
| 52 | + ), |
| 53 | + 'fallbackFlag' => 'Nuvola unknown flag.svg', |
47 | 54 | ); |
48 | 55 | } |
49 | 56 | |
Index: trunk/extensions/EducationProgram/specials/SpecialStudentActivity.php |
— | — | @@ -19,8 +19,8 @@ |
20 | 20 | * @since 0.1 |
21 | 21 | */ |
22 | 22 | public function __construct() { |
| 23 | + $this->cacheExpiry = 60; |
23 | 24 | parent::__construct( 'StudentActivity' ); |
24 | | - $this->cacheExpiry = 600; |
25 | 25 | } |
26 | 26 | |
27 | 27 | /** |
Index: trunk/extensions/EducationProgram/specials/SpecialCachedPage.php |
— | — | @@ -19,7 +19,7 @@ |
20 | 20 | * @since 0.1 |
21 | 21 | * @var integer|null |
22 | 22 | */ |
23 | | - protected $cacheExpiry = 300; |
| 23 | + protected $cacheExpiry = null; |
24 | 24 | |
25 | 25 | /** |
26 | 26 | * List of HTML chunks to be cached (if !hasCached) or that where cashed (of hasCached). |
— | — | @@ -53,20 +53,52 @@ |
54 | 54 | if ( $this->getRequest()->getText( 'action' ) === 'purge' ) { |
55 | 55 | $this->hasCached = false; |
56 | 56 | } |
| 57 | + |
| 58 | + if ( !is_null( $this->cacheExpiry ) ) { |
| 59 | + $this->initCaching(); |
| 60 | + |
| 61 | + if ( $this->hasCached === true ) { |
| 62 | + $this->getOutput()->setSubtitle( $this->getCachedNotice( $subPage ) ); |
| 63 | + } |
| 64 | + } |
57 | 65 | } |
58 | 66 | |
| 67 | + protected function getCachedNotice( $subPage ) { |
| 68 | + $refreshArgs = $_GET; |
| 69 | + unset( $refreshArgs['title'] ); |
| 70 | + $refreshArgs['action'] = 'purge'; |
| 71 | + |
| 72 | + return |
| 73 | + $this->msg( |
| 74 | + 'cachedspecial-viewing-cached', |
| 75 | + $this->getDurationText() |
| 76 | + )->escaped() . |
| 77 | + ' ' . |
| 78 | + Linker::link( |
| 79 | + $this->getTitle( $subPage ), |
| 80 | + $this->msg( 'cachedspecial-refresh-now' )->escaped(), |
| 81 | + array(), |
| 82 | + $refreshArgs |
| 83 | + ); |
| 84 | + } |
| 85 | + |
| 86 | + protected function getDurationText() { |
| 87 | + return '5 minutes'; // TODO: generate and i18n |
| 88 | + } |
| 89 | + |
59 | 90 | /** |
60 | | - * Initializes the caching. |
61 | | - * Should be called ONCE before any of the caching functionality is used, |
62 | | - * only when $this->hasCached is null. |
| 91 | + * Initializes the caching if not already done so. |
| 92 | + * Should be called before any of the caching functionality is used. |
63 | 93 | * |
64 | 94 | * @since 0.1 |
65 | 95 | */ |
66 | 96 | protected function initCaching() { |
67 | | - $cachedChunks = wfGetCache( CACHE_ANYTHING )->get( $this->getCacheKey() ); |
| 97 | + if ( is_null( $this->hasCached ) ) { |
| 98 | + $cachedChunks = wfGetCache( CACHE_ANYTHING )->get( $this->getCacheKey() ); |
68 | 99 | |
69 | | - $this->hasCached = is_array( $cachedChunks ); |
70 | | - $this->cachedChunks = $this->hasCached ? $cachedChunks : array(); |
| 100 | + $this->hasCached = is_array( $cachedChunks ); |
| 101 | + $this->cachedChunks = $this->hasCached ? $cachedChunks : array(); |
| 102 | + } |
71 | 103 | } |
72 | 104 | |
73 | 105 | /** |
— | — | @@ -82,9 +114,7 @@ |
83 | 115 | * @param string|null $key |
84 | 116 | */ |
85 | 117 | public function addCachedHTML( $callback, $args = array(), $key = null ) { |
86 | | - if ( is_null( $this->hasCached ) ) { |
87 | | - $this->initCaching(); |
88 | | - } |
| 118 | + $this->initCaching(); |
89 | 119 | |
90 | 120 | if ( $this->hasCached ) { |
91 | 121 | $html = ''; |
Index: trunk/extensions/EducationProgram/includes/EPOAPager.php |
— | — | @@ -87,7 +87,10 @@ |
88 | 88 | $value = ''; |
89 | 89 | |
90 | 90 | if ( $file !== false ) { |
91 | | - $thumb = $file->transform( array( 'width' => EPSettings::get( 'ambassadorImgWidth' ) ) ); |
| 91 | + $thumb = $file->transform( array( |
| 92 | + 'width' => EPSettings::get( 'ambassadorImgWidth' ), |
| 93 | + 'height' => EPSettings::get( 'ambassadorImgHeight' ), |
| 94 | + ) ); |
92 | 95 | |
93 | 96 | if ( $thumb && !$thumb->isError() ) { |
94 | 97 | $value = $thumb->toHtml(); |
Index: trunk/extensions/EducationProgram/includes/EPStudentActivityPager.php |
— | — | @@ -42,13 +42,13 @@ |
43 | 43 | protected $courseOrgs = array(); |
44 | 44 | |
45 | 45 | /** |
46 | | - * List of org ids mapped to their title names. |
47 | | - * org id => org name |
| 46 | + * List of org ids mapped with their associated names and countries. |
| 47 | + * org id => array( 'name' => org name, 'country' => country code ) |
48 | 48 | * |
49 | 49 | * @since 0.1 |
50 | 50 | * @var array |
51 | 51 | */ |
52 | | - protected $orgNames = array(); |
| 52 | + protected $orgData = array(); |
53 | 53 | |
54 | 54 | /** |
55 | 55 | * Constructor. |
— | — | @@ -113,8 +113,7 @@ |
114 | 114 | $value = EPCourses::singleton()->getLinkFor( $this->courseNames[$value] ); |
115 | 115 | } |
116 | 116 | else { |
117 | | - // TODO: enable |
118 | | - //wfWarn( 'Course id not in $this->courseNames in ' . __METHOD__ ); |
| 117 | + wfWarn( 'Course id not in $this->courseNames in ' . __METHOD__ ); |
119 | 118 | } |
120 | 119 | break; |
121 | 120 | case 'org_id': |
— | — | @@ -123,16 +122,16 @@ |
124 | 123 | if ( array_key_exists( $courseId, $this->courseOrgs ) ) { |
125 | 124 | $orgId = $this->courseOrgs[$courseId]; |
126 | 125 | |
127 | | - if ( array_key_exists( $orgId, $this->orgNames ) ) { |
128 | | - $value = EPOrgs::singleton()->getLinkFor( $this->orgNames[$orgId] ); |
| 126 | + if ( array_key_exists( $orgId, $this->orgData ) ) { |
| 127 | + $value = $this->orgData[$orgId]['flag']; |
| 128 | + $value .= EPOrgs::singleton()->getLinkFor( $this->orgData[$orgId]['name'] ); |
129 | 129 | } |
130 | 130 | else { |
131 | 131 | wfWarn( 'Org id not in $this->orgNames in ' . __METHOD__ ); |
132 | 132 | } |
133 | 133 | } |
134 | 134 | else { |
135 | | - // TODO: enable |
136 | | - //wfWarn( 'Course id not in $this->courseOrgs in ' . __METHOD__ ); |
| 135 | + wfWarn( 'Course id not in $this->courseOrgs in ' . __METHOD__ ); |
137 | 136 | } |
138 | 137 | break; |
139 | 138 | } |
— | — | @@ -223,13 +222,54 @@ |
224 | 223 | $this->courseOrgs[$courseData['id']] = $courseData['org_id']; |
225 | 224 | } |
226 | 225 | |
227 | | - $this->orgNames = EPOrgs::singleton()->selectFields( |
228 | | - array( 'id', 'name' ), |
| 226 | + $orgs = EPOrgs::singleton()->selectFields( |
| 227 | + array( 'id', 'name', 'country' ), |
229 | 228 | array( 'id' => array_unique( $orgIds ) ) |
230 | 229 | ); |
| 230 | + |
| 231 | + foreach ( $orgs as $org ) { |
| 232 | + $this->orgData[$org['id']] = array( |
| 233 | + 'name' => $org['name'], |
| 234 | + 'flag' => $this->getFlagHtml( $org['country'] ), |
| 235 | + ); |
| 236 | + } |
231 | 237 | } |
232 | 238 | } |
233 | 239 | |
| 240 | + protected function getFlagHtml( $country ) { |
| 241 | + $file = false; |
| 242 | + $countryFlags = EPSettings::get( 'countryFlags' ); |
| 243 | + |
| 244 | + if ( array_key_exists( $country, $countryFlags ) ) { |
| 245 | + $file = wfFindFile( $countryFlags[$country] ); |
| 246 | + } |
| 247 | + |
| 248 | + if ( $file === false ) { |
| 249 | + $file = wfFindFile( EPSettings::get( 'fallbackFlag' ) ); |
| 250 | + } |
| 251 | + |
| 252 | + if ( $file === false ) { |
| 253 | + wfWarn( 'Could not find fallback flag in ' . __METHOD__ ); |
| 254 | + $flag = ''; |
| 255 | + } |
| 256 | + else { |
| 257 | + $thumb = $file->transform( array( |
| 258 | + 'width' => EPSettings::get( 'flagWidth' ), |
| 259 | + 'height' => EPSettings::get( 'flagHeight' ), |
| 260 | + ) ); |
| 261 | + |
| 262 | + if ( $thumb && !$thumb->isError() ) { |
| 263 | + $flag = $thumb->toHtml() . ' '; |
| 264 | + } |
| 265 | + else { |
| 266 | + wfWarn( 'Thumb error in ' . __METHOD__ ); |
| 267 | + $flag = ''; |
| 268 | + } |
| 269 | + } |
| 270 | + |
| 271 | + return $flag; |
| 272 | + } |
| 273 | + |
234 | 274 | /** |
235 | 275 | * (non-PHPdoc) |
236 | 276 | * @see EPPager::getMsg() |
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php |
— | — | @@ -781,6 +781,10 @@ |
782 | 782 | |
783 | 783 | You can find a full list of students on [[Special:Students|the student list]].', |
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 | + |
| 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.', |
785 | 789 | ); |
786 | 790 | |
787 | 791 | /** Message documentation (Message documentation) |