r114059 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r114058‎ | r114059 | r114060 >
Date:19:04, 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.settings.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPOAPager.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPStudentActivityPager.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialCachedPage.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialStudentActivity.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/EducationProgram.settings.php
@@ -40,9 +40,16 @@
4141 'ambassadorCommonsUrl' => 'https://commons.wikimedia.org/wiki/Special:UploadWizard',
4242 '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' ),
4343 'ambassadorImgWidth' => 140,
 44+ 'ambassadorImgHeight' => 140,
4445 'recentActivityLimit' => 24 * 60 * 60,
4546 'resourceDir' => $resourceDir,
4647 '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',
4754 );
4855 }
4956
Index: trunk/extensions/EducationProgram/specials/SpecialStudentActivity.php
@@ -19,8 +19,8 @@
2020 * @since 0.1
2121 */
2222 public function __construct() {
 23+ $this->cacheExpiry = 60;
2324 parent::__construct( 'StudentActivity' );
24 - $this->cacheExpiry = 600;
2525 }
2626
2727 /**
Index: trunk/extensions/EducationProgram/specials/SpecialCachedPage.php
@@ -19,7 +19,7 @@
2020 * @since 0.1
2121 * @var integer|null
2222 */
23 - protected $cacheExpiry = 300;
 23+ protected $cacheExpiry = null;
2424
2525 /**
2626 * List of HTML chunks to be cached (if !hasCached) or that where cashed (of hasCached).
@@ -53,20 +53,52 @@
5454 if ( $this->getRequest()->getText( 'action' ) === 'purge' ) {
5555 $this->hasCached = false;
5656 }
 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+ }
5765 }
5866
 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+
5990 /**
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.
6393 *
6494 * @since 0.1
6595 */
6696 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() );
6899
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+ }
71103 }
72104
73105 /**
@@ -82,9 +114,7 @@
83115 * @param string|null $key
84116 */
85117 public function addCachedHTML( $callback, $args = array(), $key = null ) {
86 - if ( is_null( $this->hasCached ) ) {
87 - $this->initCaching();
88 - }
 118+ $this->initCaching();
89119
90120 if ( $this->hasCached ) {
91121 $html = '';
Index: trunk/extensions/EducationProgram/includes/EPOAPager.php
@@ -87,7 +87,10 @@
8888 $value = '';
8989
9090 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+ ) );
9295
9396 if ( $thumb && !$thumb->isError() ) {
9497 $value = $thumb->toHtml();
Index: trunk/extensions/EducationProgram/includes/EPStudentActivityPager.php
@@ -42,13 +42,13 @@
4343 protected $courseOrgs = array();
4444
4545 /**
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 )
4848 *
4949 * @since 0.1
5050 * @var array
5151 */
52 - protected $orgNames = array();
 52+ protected $orgData = array();
5353
5454 /**
5555 * Constructor.
@@ -113,8 +113,7 @@
114114 $value = EPCourses::singleton()->getLinkFor( $this->courseNames[$value] );
115115 }
116116 else {
117 - // TODO: enable
118 - //wfWarn( 'Course id not in $this->courseNames in ' . __METHOD__ );
 117+ wfWarn( 'Course id not in $this->courseNames in ' . __METHOD__ );
119118 }
120119 break;
121120 case 'org_id':
@@ -123,16 +122,16 @@
124123 if ( array_key_exists( $courseId, $this->courseOrgs ) ) {
125124 $orgId = $this->courseOrgs[$courseId];
126125
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'] );
129129 }
130130 else {
131131 wfWarn( 'Org id not in $this->orgNames in ' . __METHOD__ );
132132 }
133133 }
134134 else {
135 - // TODO: enable
136 - //wfWarn( 'Course id not in $this->courseOrgs in ' . __METHOD__ );
 135+ wfWarn( 'Course id not in $this->courseOrgs in ' . __METHOD__ );
137136 }
138137 break;
139138 }
@@ -223,13 +222,54 @@
224223 $this->courseOrgs[$courseData['id']] = $courseData['org_id'];
225224 }
226225
227 - $this->orgNames = EPOrgs::singleton()->selectFields(
228 - array( 'id', 'name' ),
 226+ $orgs = EPOrgs::singleton()->selectFields(
 227+ array( 'id', 'name', 'country' ),
229228 array( 'id' => array_unique( $orgIds ) )
230229 );
 230+
 231+ foreach ( $orgs as $org ) {
 232+ $this->orgData[$org['id']] = array(
 233+ 'name' => $org['name'],
 234+ 'flag' => $this->getFlagHtml( $org['country'] ),
 235+ );
 236+ }
231237 }
232238 }
233239
 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+
234274 /**
235275 * (non-PHPdoc)
236276 * @see EPPager::getMsg()
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php
@@ -781,6 +781,10 @@
782782
783783 You can find a full list of students on [[Special:Students|the student list]].',
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.',
 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.',
785789 );
786790
787791 /** Message documentation (Message documentation)

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r114023work on special:studentactivity and adding frank his imagesjeroendedauw16:59, 16 March 2012

Comments

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

Cannot review without message documentation.

#Comment by 😂 (talk | contribs)   03:05, 21 March 2012

Rather than using $_GET directly, you can use WebRequest's getQueryValues().

#Comment by Jeroen De Dauw (talk | contribs)   18:50, 21 March 2012

Right, this was already remarked somewhere else and been fixed in the meanwhile :)

Status & tagging log