https://www.mediawiki.org/wiki/Special:Code/MediaWiki/114059

Revision: 114059
Author:   jeroendedauw
Date:     2012-03-17 19:04:03 +0000 (Sat, 17 Mar 2012)
Log Message:
-----------
work on special:studentactivity

Modified Paths:
--------------
    trunk/extensions/EducationProgram/EducationProgram.i18n.php
    trunk/extensions/EducationProgram/EducationProgram.settings.php
    trunk/extensions/EducationProgram/includes/EPOAPager.php
    trunk/extensions/EducationProgram/includes/EPStudentActivityPager.php
    trunk/extensions/EducationProgram/specials/SpecialCachedPage.php
    trunk/extensions/EducationProgram/specials/SpecialStudentActivity.php

Modified: trunk/extensions/EducationProgram/EducationProgram.i18n.php
===================================================================
--- trunk/extensions/EducationProgram/EducationProgram.i18n.php 2012-03-17 
17:22:39 UTC (rev 114058)
+++ trunk/extensions/EducationProgram/EducationProgram.i18n.php 2012-03-17 
19:04:03 UTC (rev 114059)
@@ -781,6 +781,10 @@
 
 You can find a full list of students on [[Special:Students|the student 
list]].',
        '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.',
 );
 
 /** Message documentation (Message documentation)

Modified: trunk/extensions/EducationProgram/EducationProgram.settings.php
===================================================================
--- trunk/extensions/EducationProgram/EducationProgram.settings.php     
2012-03-17 17:22:39 UTC (rev 114058)
+++ trunk/extensions/EducationProgram/EducationProgram.settings.php     
2012-03-17 19:04:03 UTC (rev 114059)
@@ -40,9 +40,16 @@
                        'ambassadorCommonsUrl' => 
'https://commons.wikimedia.org/wiki/Special:UploadWizard',
                        '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' ),
                        'ambassadorImgWidth' => 140,
+                       'ambassadorImgHeight' => 140,
                        'recentActivityLimit' => 24 * 60 * 60,
                        'resourceDir' => $resourceDir,
                        'imageDir' => $resourceDir . 'images/',
+                       'flagWidth' => 25,
+                       'flagHeight' => 25,
+                       'countryFlags' => array(
+                               'US' => 'Flag_of_the_United_States.svg',
+                       ),
+                       'fallbackFlag' => 'Nuvola unknown flag.svg',
                );
        }
 

Modified: trunk/extensions/EducationProgram/includes/EPOAPager.php
===================================================================
--- trunk/extensions/EducationProgram/includes/EPOAPager.php    2012-03-17 
17:22:39 UTC (rev 114058)
+++ trunk/extensions/EducationProgram/includes/EPOAPager.php    2012-03-17 
19:04:03 UTC (rev 114059)
@@ -87,7 +87,10 @@
                                $value = '';
 
                                if ( $file !== false ) {
-                                       $thumb = $file->transform( array( 
'width' => EPSettings::get( 'ambassadorImgWidth' ) ) );
+                                       $thumb = $file->transform( array(
+                                               'width' => EPSettings::get( 
'ambassadorImgWidth' ),
+                                               'height' => EPSettings::get( 
'ambassadorImgHeight' ),
+                                       ) );
 
                                        if ( $thumb && !$thumb->isError() ) {
                                                $value = $thumb->toHtml();

Modified: trunk/extensions/EducationProgram/includes/EPStudentActivityPager.php
===================================================================
--- trunk/extensions/EducationProgram/includes/EPStudentActivityPager.php       
2012-03-17 17:22:39 UTC (rev 114058)
+++ trunk/extensions/EducationProgram/includes/EPStudentActivityPager.php       
2012-03-17 19:04:03 UTC (rev 114059)
@@ -42,13 +42,13 @@
        protected $courseOrgs = array();
 
        /**
-        * List of org ids mapped to their title names.
-        * org id => org name
+        * List of org ids mapped with their associated names and countries.
+        * org id => array( 'name' => org name, 'country' => country code )
         *
         * @since 0.1
         * @var array
         */
-       protected $orgNames = array();
+       protected $orgData = array();
 
        /**
         * Constructor.
@@ -113,8 +113,7 @@
                                        $value = 
EPCourses::singleton()->getLinkFor( $this->courseNames[$value] );
                                }
                                else {
-                                       // TODO: enable
-                                       //wfWarn( 'Course id not in 
$this->courseNames in ' . __METHOD__ );
+                                       wfWarn( 'Course id not in 
$this->courseNames in ' . __METHOD__ );
                                }
                                break;
                        case 'org_id':
@@ -123,16 +122,16 @@
                                if ( array_key_exists( $courseId, 
$this->courseOrgs ) ) {
                                        $orgId = $this->courseOrgs[$courseId];
 
-                                       if ( array_key_exists( $orgId, 
$this->orgNames ) ) {
-                                               $value = 
EPOrgs::singleton()->getLinkFor( $this->orgNames[$orgId] );
+                                       if ( array_key_exists( $orgId, 
$this->orgData ) ) {
+                                               $value = 
$this->orgData[$orgId]['flag'];
+                                               $value .= 
EPOrgs::singleton()->getLinkFor( $this->orgData[$orgId]['name'] );
                                        }
                                        else {
                                                wfWarn( 'Org id not in 
$this->orgNames in ' . __METHOD__ );
                                        }
                                }
                                else {
-                                       // TODO: enable
-                                       //wfWarn( 'Course id not in 
$this->courseOrgs in ' . __METHOD__ );
+                                       wfWarn( 'Course id not in 
$this->courseOrgs in ' . __METHOD__ );
                                }
                                break;
                }
@@ -223,13 +222,54 @@
                                $this->courseOrgs[$courseData['id']] = 
$courseData['org_id'];
                        }
 
-                       $this->orgNames = EPOrgs::singleton()->selectFields(
-                               array( 'id', 'name' ),
+                       $orgs = EPOrgs::singleton()->selectFields(
+                               array( 'id', 'name', 'country' ),
                                array( 'id' => array_unique( $orgIds ) )
                        );
+
+                       foreach ( $orgs as $org ) {
+                               $this->orgData[$org['id']] = array(
+                                       'name' => $org['name'],
+                                       'flag' => $this->getFlagHtml( 
$org['country'] ),
+                               );
+                       }
                }
        }
 
+       protected function getFlagHtml( $country ) {
+               $file = false;
+               $countryFlags = EPSettings::get( 'countryFlags' );
+
+               if ( array_key_exists( $country, $countryFlags )  ) {
+                       $file = wfFindFile( $countryFlags[$country] );
+               }
+
+               if ( $file === false ) {
+                       $file = wfFindFile( EPSettings::get( 'fallbackFlag' ) );
+               }
+
+               if ( $file === false ) {
+                       wfWarn( 'Could not find fallback flag in ' . __METHOD__ 
);
+                       $flag = '';
+               }
+               else {
+                       $thumb = $file->transform( array(
+                               'width' => EPSettings::get( 'flagWidth' ),
+                               'height' => EPSettings::get( 'flagHeight' ),
+                       ) );
+
+                       if ( $thumb && !$thumb->isError() ) {
+                               $flag = $thumb->toHtml() . ' ';
+                       }
+                       else {
+                               wfWarn( 'Thumb error in ' . __METHOD__ );
+                               $flag = '';
+                       }
+               }
+
+               return $flag;
+       }
+
        /**
         * (non-PHPdoc)
         * @see EPPager::getMsg()

Modified: trunk/extensions/EducationProgram/specials/SpecialCachedPage.php
===================================================================
--- trunk/extensions/EducationProgram/specials/SpecialCachedPage.php    
2012-03-17 17:22:39 UTC (rev 114058)
+++ trunk/extensions/EducationProgram/specials/SpecialCachedPage.php    
2012-03-17 19:04:03 UTC (rev 114059)
@@ -19,7 +19,7 @@
         * @since 0.1
         * @var integer|null
         */
-       protected $cacheExpiry = 300;
+       protected $cacheExpiry = null;
 
        /**
         * List of HTML chunks to be cached (if !hasCached) or that where 
cashed (of hasCached).
@@ -53,20 +53,52 @@
                if ( $this->getRequest()->getText( 'action' ) === 'purge' ) {
                        $this->hasCached = false;
                }
+
+               if ( !is_null( $this->cacheExpiry ) ) {
+                       $this->initCaching();
+
+                       if ( $this->hasCached === true ) {
+                               $this->getOutput()->setSubtitle( 
$this->getCachedNotice( $subPage ) );
+                       }
+               }
        }
 
+       protected function getCachedNotice( $subPage ) {
+               $refreshArgs = $_GET;
+               unset( $refreshArgs['title'] );
+               $refreshArgs['action'] = 'purge';
+
+               return
+                       $this->msg(
+                               'cachedspecial-viewing-cached',
+                               $this->getDurationText()
+                       )->escaped() .
+                       ' ' .
+                       Linker::link(
+                               $this->getTitle( $subPage ),
+                               $this->msg( 'cachedspecial-refresh-now' 
)->escaped(),
+                               array(),
+                               $refreshArgs
+                       );
+       }
+
+       protected function getDurationText() {
+               return '5 minutes'; // TODO: generate and i18n
+       }
+
        /**
-        * Initializes the caching.
-        * Should be called ONCE before any of the caching functionality is 
used,
-        * only when $this->hasCached is null.
+        * Initializes the caching if not already done so.
+        * Should be called before any of the caching functionality is used.
         *
         * @since 0.1
         */
        protected function initCaching() {
-               $cachedChunks = wfGetCache( CACHE_ANYTHING )->get( 
$this->getCacheKey() );
+               if ( is_null( $this->hasCached ) ) {
+                       $cachedChunks = wfGetCache( CACHE_ANYTHING )->get( 
$this->getCacheKey() );
 
-               $this->hasCached = is_array( $cachedChunks );
-               $this->cachedChunks = $this->hasCached ? $cachedChunks : 
array();
+                       $this->hasCached = is_array( $cachedChunks );
+                       $this->cachedChunks = $this->hasCached ? $cachedChunks 
: array();
+               }
        }
 
        /**
@@ -82,9 +114,7 @@
         * @param string|null $key
         */
        public function addCachedHTML( $callback, $args = array(), $key = null 
) {
-               if ( is_null( $this->hasCached ) ) {
-                       $this->initCaching();
-               }
+               $this->initCaching();
 
                if ( $this->hasCached ) {
                        $html = '';

Modified: trunk/extensions/EducationProgram/specials/SpecialStudentActivity.php
===================================================================
--- trunk/extensions/EducationProgram/specials/SpecialStudentActivity.php       
2012-03-17 17:22:39 UTC (rev 114058)
+++ trunk/extensions/EducationProgram/specials/SpecialStudentActivity.php       
2012-03-17 19:04:03 UTC (rev 114059)
@@ -19,8 +19,8 @@
         * @since 0.1
         */
        public function __construct() {
+               $this->cacheExpiry = 60;
                parent::__construct( 'StudentActivity' );
-               $this->cacheExpiry = 600;
        }
 
        /**


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to