Index: trunk/extensions/EducationProgram/EducationProgram.php |
— | — | @@ -116,6 +116,7 @@ |
117 | 117 | $wgAutoloadClasses['SpecialOA'] = dirname( __FILE__ ) . '/specials/SpecialOA.php'; |
118 | 118 | $wgAutoloadClasses['SpecialOAProfile'] = dirname( __FILE__ ) . '/specials/SpecialOAProfile.php'; |
119 | 119 | $wgAutoloadClasses['SpecialCAProfile'] = dirname( __FILE__ ) . '/specials/SpecialCAProfile.php'; |
| 120 | +$wgAutoloadClasses['SpecialAmbassadorProfile'] = dirname( __FILE__ ) . '/specials/SpecialAmbassadorProfile.php'; |
120 | 121 | |
121 | 122 | // Special pages |
122 | 123 | $wgSpecialPages['MyCourses'] = 'SpecialMyCourses'; |
Index: trunk/extensions/EducationProgram/specials/SpecialAmbassadorProfile.php |
— | — | @@ -0,0 +1,124 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Abstract profile page for ambassadors. |
| 6 | + * |
| 7 | + * @since 0.1 |
| 8 | + * |
| 9 | + * @file SpecialOAProfile.php |
| 10 | + * @ingroup EducationProgram |
| 11 | + * |
| 12 | + * @licence GNU GPL v3 or later |
| 13 | + * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
| 14 | + */ |
| 15 | +abstract class SpecialAmbassadorProfile extends FormSpecialPage { |
| 16 | + |
| 17 | + protected abstract function getClassName(); |
| 18 | + |
| 19 | + /** |
| 20 | + * Main method. |
| 21 | + * |
| 22 | + * @since 0.1 |
| 23 | + * |
| 24 | + * @param string $subPage |
| 25 | + */ |
| 26 | + public function execute( $subPage ) { |
| 27 | + if ( $this->getRequest()->getSessionData( 'epprofilesaved' ) ) { |
| 28 | + $messageKey = $this->getMsgPrefix() . 'profile-saved'; |
| 29 | + $this->getOutput()->addHTML( |
| 30 | + '<div class="successbox"><strong><p>' . wfMsgHtml( $messageKey ) . '</p></strong></div>' |
| 31 | + . '<hr style="display: block; clear: both; visibility: hidden;" />' |
| 32 | + ); |
| 33 | + $this->getRequest()->setSessionData( 'epprofilesaved', false ); |
| 34 | + } |
| 35 | + |
| 36 | + parent::execute( $subPage ); |
| 37 | + } |
| 38 | + |
| 39 | + protected function getMsgPrefix() { |
| 40 | + return strtolower( $this->getClassName() ) . '-'; |
| 41 | + } |
| 42 | + |
| 43 | + /** |
| 44 | + * (non-PHPdoc) |
| 45 | + * @see FormSpecialPage::getFormFields() |
| 46 | + * @return array |
| 47 | + */ |
| 48 | + protected function getFormFields() { |
| 49 | + $fields = array(); |
| 50 | + |
| 51 | + $class = $this->getClassName(); |
| 52 | + $ambassador = $class::newFromUser( $this->getUser() ); |
| 53 | + |
| 54 | + $fields['bio'] = array( |
| 55 | + 'type' => 'textarea', |
| 56 | + 'label-message' => $this->getMsgPrefix() . 'profile-bio', |
| 57 | + 'required' => true, |
| 58 | + 'validation-callback' => function ( $value, array $alldata = null ) { |
| 59 | + return strlen( $value ) < 10 ? wfMsgExt( $this->getMsgPrefix() . 'profile-invalid-bio', 'parsemag', 10 ) : true; |
| 60 | + }, |
| 61 | + 'rows' => 10, |
| 62 | + 'id' => 'wpTextbox1', |
| 63 | + 'default' => $ambassador->getField( 'bio' ), |
| 64 | + ); |
| 65 | + |
| 66 | + $lang = $this->getLanguage(); |
| 67 | + |
| 68 | + $prefix = $this->getMsgPrefix(); |
| 69 | + $fields['photo'] = array( |
| 70 | + 'type' => 'text', |
| 71 | + 'label-message' => $this->getMsgPrefix() . 'profile-photo', |
| 72 | + 'validation-callback' => function ( $value, array $alldata = null ) use ( $lang, $prefix ) { |
| 73 | + if ( trim( $value ) === '' ) { |
| 74 | + return true; |
| 75 | + } |
| 76 | + |
| 77 | + $domains = EPSettings::get( 'ambassadorPictureDomains' ); |
| 78 | + |
| 79 | + foreach ( $domains as $domain ) { |
| 80 | + $pattern = '@^https?://(([a-z0-9]+)\.)?' . str_replace( '.', '\.', $domain ) . '/.*$@i'; |
| 81 | + |
| 82 | + if ( preg_match( $pattern, $value ) ) { |
| 83 | + return true; |
| 84 | + } |
| 85 | + } |
| 86 | + |
| 87 | + return wfMsgExt( |
| 88 | + $prefix . 'profile-invalid-photo', |
| 89 | + 'parsemag', |
| 90 | + $lang->listToText( $domains ), |
| 91 | + count( $domains ) |
| 92 | + ); |
| 93 | + }, |
| 94 | + 'default' => $ambassador->getField( 'photo' ), |
| 95 | + ); |
| 96 | + |
| 97 | + return $fields; |
| 98 | + } |
| 99 | + |
| 100 | + /** |
| 101 | + * Gets called after the form is saved. |
| 102 | + * |
| 103 | + * @since 0.1 |
| 104 | + */ |
| 105 | + public function onSuccess() { |
| 106 | + $this->getRequest()->setSessionData( 'epprofilesaved', true ); |
| 107 | + $this->getOutput()->redirect( $this->getTitle()->getLocalURL() ); |
| 108 | + } |
| 109 | + |
| 110 | + /** |
| 111 | + * Process the form. At this point we know that the user passes all the criteria in |
| 112 | + * userCanExecute(). |
| 113 | + * |
| 114 | + * @param array $data |
| 115 | + * |
| 116 | + * @return Bool|Array |
| 117 | + */ |
| 118 | + public function onSubmit( array $data ) { |
| 119 | + $class = $this->getClassName(); |
| 120 | + $ambassador = $class::newFromUser( $this->getUser() ); |
| 121 | + $ambassador->setFields( $data ); |
| 122 | + return $ambassador->save() ? true : array(); |
| 123 | + } |
| 124 | + |
| 125 | +} |
\ No newline at end of file |
Index: trunk/extensions/EducationProgram/specials/SpecialOAProfile.php |
— | — | @@ -11,7 +11,7 @@ |
12 | 12 | * @licence GNU GPL v3 or later |
13 | 13 | * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
14 | 14 | */ |
15 | | -class SpecialOAProfile extends FormSpecialPage { |
| 15 | +class SpecialOAProfile extends SpecialAmbassadorProfile { |
16 | 16 | |
17 | 17 | /** |
18 | 18 | * Constructor. |
— | — | @@ -23,75 +23,24 @@ |
24 | 24 | } |
25 | 25 | |
26 | 26 | /** |
27 | | - * Main method. |
28 | | - * |
29 | | - * @since 0.1 |
30 | | - * |
31 | | - * @param string $subPage |
32 | | - */ |
33 | | - public function execute( $subPage ) { |
34 | | - parent::execute( $subPage ); |
35 | | - } |
36 | | - |
37 | | - /** |
38 | 27 | * (non-PHPdoc) |
39 | 28 | * @see FormSpecialPage::getFormFields() |
40 | 29 | * @return array |
41 | 30 | */ |
42 | 31 | protected function getFormFields() { |
43 | | - $fields = array(); |
| 32 | + $fields = parent::getFormFields(); |
44 | 33 | |
45 | | - $fields['bio'] = array( |
46 | | - 'type' => 'textarea', |
47 | | - 'label-message' => 'ep-oa-profile-bio', |
48 | | - 'required' => true, |
49 | | - 'validation-callback' => function ( $value, array $alldata = null ) { |
50 | | - return strlen( $value ) < 10 ? wfMsgExt( 'ep-oa-profile-invalid-bio', 'parsemag', 10 ) : true; |
51 | | - }, |
52 | | - 'rows' => 10, |
53 | | - 'id' => 'wpTextbox1', |
54 | | - ); |
55 | 34 | |
56 | | - $lang = $this->getLanguage(); |
57 | 35 | |
58 | | - $fields['photo'] = array( |
59 | | - 'type' => 'text', |
60 | | - 'label-message' => 'ep-oa-profile-photo', |
61 | | - 'validation-callback' => function ( $value, array $alldata = null ) use ( $lang ) { |
62 | | - foreach ( EPSettings::get( 'ambassadorPictureDomains' ) as $domain ) { |
63 | | - $pattern = '@^https?://(([a-z0-9]+)\.)?' . str_replace( '.', '\.', $domain ) . '/.*$@i'; |
64 | | - |
65 | | - if ( preg_match( $pattern, $value ) ) { |
66 | | - return true; |
67 | | - } |
68 | | - } |
69 | | - |
70 | | - return wfMsgExt( 'ep-oa-profile-invalid-photo', 'parsemag', $lang->listToText( $domain ) ); |
71 | | - }, |
72 | | - ); |
73 | | - |
74 | 36 | return $fields; |
75 | 37 | } |
76 | 38 | |
77 | 39 | /** |
78 | | - * Gets called after the form is saved. |
79 | | - * |
80 | | - * @since 0.1 |
| 40 | + * (non-PHPdoc) |
| 41 | + * @see FormSpecialPage::getClassName() |
81 | 42 | */ |
82 | | - public function onSuccess() { |
83 | | - // $this->getOutput()->redirect( $this->getReturnToTitle( true )->getLocalURL() ); |
| 43 | + protected function getClassName() { |
| 44 | + return 'EPOA'; |
84 | 45 | } |
85 | 46 | |
86 | | - /** |
87 | | - * Process the form. At this point we know that the user passes all the criteria in |
88 | | - * userCanExecute(). |
89 | | - * |
90 | | - * @param array $data |
91 | | - * |
92 | | - * @return Bool|Array |
93 | | - */ |
94 | | - public function onSubmit( array $data ) { |
95 | | - |
96 | | - } |
97 | | - |
98 | 47 | } |
\ No newline at end of file |
Index: trunk/extensions/EducationProgram/specials/SpecialCAProfile.php |
— | — | @@ -11,7 +11,7 @@ |
12 | 12 | * @licence GNU GPL v3 or later |
13 | 13 | * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
14 | 14 | */ |
15 | | -class SpecialCAProfile extends SpecialEPPage { |
| 15 | +class SpecialCAProfile extends SpecialAmbassadorProfile { |
16 | 16 | |
17 | 17 | /** |
18 | 18 | * Constructor. |
— | — | @@ -23,17 +23,24 @@ |
24 | 24 | } |
25 | 25 | |
26 | 26 | /** |
27 | | - * Main method. |
28 | | - * |
29 | | - * @since 0.1 |
30 | | - * |
31 | | - * @param string $subPage |
| 27 | + * (non-PHPdoc) |
| 28 | + * @see FormSpecialPage::getFormFields() |
| 29 | + * @return array |
32 | 30 | */ |
33 | | - public function execute( $subPage ) { |
34 | | - parent::execute( $subPage ); |
| 31 | + protected function getFormFields() { |
| 32 | + $fields = parent::getFormFields(); |
35 | 33 | |
36 | 34 | |
37 | 35 | |
| 36 | + return $fields; |
38 | 37 | } |
39 | 38 | |
| 39 | + /** |
| 40 | + * (non-PHPdoc) |
| 41 | + * @see FormSpecialPage::getClassName() |
| 42 | + */ |
| 43 | + protected function getClassName() { |
| 44 | + return 'EPCA'; |
| 45 | + } |
| 46 | + |
40 | 47 | } |
\ No newline at end of file |
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php |
— | — | @@ -485,6 +485,24 @@ |
486 | 486 | 'ep-enlist-invalid-user-args' => 'You need to either provide the username or the userid parameter', |
487 | 487 | 'ep-enlist-invalid-user' => 'The provided user id or name is not valid and can therefore not be associated as instrucor or ambassador with the specified course', |
488 | 488 | 'ep-enlist-invalid-course' => 'There is no course with the provided ID', |
| 489 | + |
| 490 | + // Special:OnlineAmbassadorProfile |
| 491 | + 'onlineambassadorprofile' => 'Online Ambassador profile', |
| 492 | + 'onlineambassadorprofile-legend' => 'My Online Ambassador profile', |
| 493 | + 'onlineambassadorprofile-text' => 'Your Online Ambassador profile is what students get to see when they browse available ambassadors.', |
| 494 | + 'epoa-profile-invalid-photo' => 'The photo must be located on {{PLURAL:$2|this website: $1|one of these websites: $1}}', |
| 495 | + 'epoa-profile-bio' => 'Short bio', |
| 496 | + 'epoa-profile-photo' => 'Profile photo', |
| 497 | + 'epoa-profile-saved' => 'Your profile has been saved', |
| 498 | + |
| 499 | + // Special:CampusAmbassadorProfile |
| 500 | + 'campusambassadorprofile' => 'Campus Ambassador profile', |
| 501 | + 'campusambassadorprofile-legend' => 'My Campus Ambassador profile', |
| 502 | + 'campusambassadorprofile-text' => 'Your Campus Ambassador profile is what students get to see when they browse available ambassadors.', |
| 503 | + 'epca-profile-invalid-photo' => 'The photo must be located on {{PLURAL:$2|this website: $1|one of these websites: $1}}', |
| 504 | + 'epca-profile-bio' => 'Short bio', |
| 505 | + 'epca-profile-photo' => 'Profile photo', |
| 506 | + 'epca-profile-saved' => 'Your profile has been saved', |
489 | 507 | ); |
490 | 508 | |
491 | 509 | /** Message documentation (Message documentation) |