Index: trunk/extensions/EducationProgram/specials/SpecialAmbassadorProfile.php |
— | — | @@ -13,16 +13,50 @@ |
14 | 14 | */ |
15 | 15 | abstract class SpecialAmbassadorProfile extends FormSpecialPage { |
16 | 16 | |
| 17 | + /** |
| 18 | + * Returns the name of the ambassador class. |
| 19 | + * |
| 20 | + * @since 0.1 |
| 21 | + * |
| 22 | + * @return string |
| 23 | + */ |
17 | 24 | protected abstract function getClassName(); |
18 | 25 | |
19 | 26 | /** |
| 27 | + * Returns if the user can access the page or not. |
| 28 | + * |
| 29 | + * @since 0.1 |
| 30 | + * |
| 31 | + * @return boolean |
| 32 | + */ |
| 33 | + protected abstract function userCanAccess(); |
| 34 | + |
| 35 | + /** |
| 36 | + * Returns if the special page should be listed on Special:SpecialPages and similar interfaces. |
| 37 | + * |
| 38 | + * @since 0.1 |
| 39 | + * |
| 40 | + * @return boolean |
| 41 | + */ |
| 42 | + public function isListed() { |
| 43 | + return $this->userCanAccess(); |
| 44 | + } |
| 45 | + |
| 46 | + /** |
20 | 47 | * Main method. |
21 | 48 | * |
22 | 49 | * @since 0.1 |
23 | 50 | * |
24 | 51 | * @param string $subPage |
| 52 | + * |
| 53 | + * @return string |
25 | 54 | */ |
26 | 55 | public function execute( $subPage ) { |
| 56 | + if ( !$this->userCanAccess() ) { |
| 57 | + $this->displayRestrictionError(); |
| 58 | + return ''; |
| 59 | + } |
| 60 | + |
27 | 61 | if ( $this->getRequest()->getSessionData( 'epprofilesaved' ) ) { |
28 | 62 | $messageKey = $this->getMsgPrefix() . 'profile-saved'; |
29 | 63 | $this->getOutput()->addHTML( |
Index: trunk/extensions/EducationProgram/specials/SpecialOAProfile.php |
— | — | @@ -19,7 +19,7 @@ |
20 | 20 | * @since 0.1 |
21 | 21 | */ |
22 | 22 | public function __construct() { |
23 | | - parent::__construct( 'OnlineAmbassadorProfile', 'ep-online', false ); |
| 23 | + parent::__construct( 'OnlineAmbassadorProfile' ); |
24 | 24 | } |
25 | 25 | |
26 | 26 | /** |
— | — | @@ -43,4 +43,15 @@ |
44 | 44 | return 'EPOA'; |
45 | 45 | } |
46 | 46 | |
| 47 | + /** |
| 48 | + * (non-PHPdoc) |
| 49 | + * @see SpecialAmbassadorProfile::userCanAccess() |
| 50 | + */ |
| 51 | + protected function userCanAccess() { |
| 52 | + $user = $this->getUser(); |
| 53 | + return $user->isAllowed( 'ep-online' ) |
| 54 | + || $user->isAllowed( 'ep-beonline' ) |
| 55 | + || EPOA::newFromUser( $user )->hasCourse(); |
| 56 | + } |
| 57 | + |
47 | 58 | } |
\ No newline at end of file |
Index: trunk/extensions/EducationProgram/specials/SpecialCAProfile.php |
— | — | @@ -19,7 +19,7 @@ |
20 | 20 | * @since 0.1 |
21 | 21 | */ |
22 | 22 | public function __construct() { |
23 | | - parent::__construct( 'CampusAmbassadorProfile', 'ep-campus', false ); |
| 23 | + parent::__construct( 'CampusAmbassadorProfile' ); |
24 | 24 | } |
25 | 25 | |
26 | 26 | /** |
— | — | @@ -43,4 +43,15 @@ |
44 | 44 | return 'EPCA'; |
45 | 45 | } |
46 | 46 | |
| 47 | + /** |
| 48 | + * (non-PHPdoc) |
| 49 | + * @see SpecialAmbassadorProfile::userCanAccess() |
| 50 | + */ |
| 51 | + protected function userCanAccess() { |
| 52 | + $user = $this->getUser(); |
| 53 | + return $user->isAllowed( 'ep-campus' ) |
| 54 | + || $user->isAllowed( 'ep-becampus' ) |
| 55 | + || EPCA::newFromUser( $user )->hasCourse(); |
| 56 | + } |
| 57 | + |
47 | 58 | } |
\ No newline at end of file |
Index: trunk/extensions/EducationProgram/includes/EPUtils.php |
— | — | @@ -208,11 +208,11 @@ |
209 | 209 | $items[wfMsg( 'ep-nav-mycourses' )] = SpecialPage::getTitleFor( 'MyCourses' ); |
210 | 210 | } |
211 | 211 | |
212 | | - if ( $user->isAllowed( 'ep-online' ) && EPOA::newFromUser( $user )->hasCourse() ) { |
| 212 | + if ( EPOA::newFromUser( $user )->hasCourse() ) { |
213 | 213 | $items[wfMsg( 'ep-nav-oaprofile' )] = SpecialPage::getTitleFor( 'OnlineAmbassadorProfile' ); |
214 | 214 | } |
215 | 215 | |
216 | | - if ( $user->isAllowed( 'ep-campus' ) && EPCA::newFromUser( $user )->hasCourse() ) { |
| 216 | + if ( EPCA::newFromUser( $user )->hasCourse() ) { |
217 | 217 | $items[wfMsg( 'ep-nav-caprofile' )] = SpecialPage::getTitleFor( 'CampusAmbassadorProfile' ); |
218 | 218 | } |
219 | 219 | |