https://www.mediawiki.org/wiki/Special:Code/MediaWiki/113081
Revision: 113081 Author: jeroendedauw Date: 2012-03-05 20:42:08 +0000 (Mon, 05 Mar 2012) Log Message: ----------- address http://education.wmflabs.org/index.php/Thread:MW_1.18_talk:Community_portal/Ambassadors_can't_join_a_class_or_edit_a_profile_about_themselves Modified Paths: -------------- trunk/extensions/EducationProgram/includes/EPUtils.php trunk/extensions/EducationProgram/specials/SpecialAmbassadorProfile.php trunk/extensions/EducationProgram/specials/SpecialCAProfile.php trunk/extensions/EducationProgram/specials/SpecialOAProfile.php Modified: trunk/extensions/EducationProgram/includes/EPUtils.php =================================================================== --- trunk/extensions/EducationProgram/includes/EPUtils.php 2012-03-05 20:40:13 UTC (rev 113080) +++ trunk/extensions/EducationProgram/includes/EPUtils.php 2012-03-05 20:42:08 UTC (rev 113081) @@ -208,11 +208,11 @@ $items[wfMsg( 'ep-nav-mycourses' )] = SpecialPage::getTitleFor( 'MyCourses' ); } - if ( $user->isAllowed( 'ep-online' ) && EPOA::newFromUser( $user )->hasCourse() ) { + if ( EPOA::newFromUser( $user )->hasCourse() ) { $items[wfMsg( 'ep-nav-oaprofile' )] = SpecialPage::getTitleFor( 'OnlineAmbassadorProfile' ); } - if ( $user->isAllowed( 'ep-campus' ) && EPCA::newFromUser( $user )->hasCourse() ) { + if ( EPCA::newFromUser( $user )->hasCourse() ) { $items[wfMsg( 'ep-nav-caprofile' )] = SpecialPage::getTitleFor( 'CampusAmbassadorProfile' ); } Modified: trunk/extensions/EducationProgram/specials/SpecialAmbassadorProfile.php =================================================================== --- trunk/extensions/EducationProgram/specials/SpecialAmbassadorProfile.php 2012-03-05 20:40:13 UTC (rev 113080) +++ trunk/extensions/EducationProgram/specials/SpecialAmbassadorProfile.php 2012-03-05 20:42:08 UTC (rev 113081) @@ -13,16 +13,50 @@ */ abstract class SpecialAmbassadorProfile extends FormSpecialPage { + /** + * Returns the name of the ambassador class. + * + * @since 0.1 + * + * @return string + */ protected abstract function getClassName(); /** + * Returns if the user can access the page or not. + * + * @since 0.1 + * + * @return boolean + */ + protected abstract function userCanAccess(); + + /** + * Returns if the special page should be listed on Special:SpecialPages and similar interfaces. + * + * @since 0.1 + * + * @return boolean + */ + public function isListed() { + return $this->userCanAccess(); + } + + /** * Main method. * * @since 0.1 * * @param string $subPage + * + * @return string */ public function execute( $subPage ) { + if ( !$this->userCanAccess() ) { + $this->displayRestrictionError(); + return ''; + } + if ( $this->getRequest()->getSessionData( 'epprofilesaved' ) ) { $messageKey = $this->getMsgPrefix() . 'profile-saved'; $this->getOutput()->addHTML( Modified: trunk/extensions/EducationProgram/specials/SpecialCAProfile.php =================================================================== --- trunk/extensions/EducationProgram/specials/SpecialCAProfile.php 2012-03-05 20:40:13 UTC (rev 113080) +++ trunk/extensions/EducationProgram/specials/SpecialCAProfile.php 2012-03-05 20:42:08 UTC (rev 113081) @@ -19,7 +19,7 @@ * @since 0.1 */ public function __construct() { - parent::__construct( 'CampusAmbassadorProfile', 'ep-campus', false ); + parent::__construct( 'CampusAmbassadorProfile' ); } /** @@ -43,4 +43,15 @@ return 'EPCA'; } + /** + * (non-PHPdoc) + * @see SpecialAmbassadorProfile::userCanAccess() + */ + protected function userCanAccess() { + $user = $this->getUser(); + return $user->isAllowed( 'ep-campus' ) + || $user->isAllowed( 'ep-becampus' ) + || EPCA::newFromUser( $user )->hasCourse(); + } + } \ No newline at end of file Modified: trunk/extensions/EducationProgram/specials/SpecialOAProfile.php =================================================================== --- trunk/extensions/EducationProgram/specials/SpecialOAProfile.php 2012-03-05 20:40:13 UTC (rev 113080) +++ trunk/extensions/EducationProgram/specials/SpecialOAProfile.php 2012-03-05 20:42:08 UTC (rev 113081) @@ -19,7 +19,7 @@ * @since 0.1 */ public function __construct() { - parent::__construct( 'OnlineAmbassadorProfile', 'ep-online', false ); + parent::__construct( 'OnlineAmbassadorProfile' ); } /** @@ -43,4 +43,15 @@ return 'EPOA'; } + /** + * (non-PHPdoc) + * @see SpecialAmbassadorProfile::userCanAccess() + */ + protected function userCanAccess() { + $user = $this->getUser(); + return $user->isAllowed( 'ep-online' ) + || $user->isAllowed( 'ep-beonline' ) + || EPOA::newFromUser( $user )->hasCourse(); + } + } \ No newline at end of file _______________________________________________ MediaWiki-CVS mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs
