r110679 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r110678‎ | r110679 | r110680 >
Date:19:36, 3 February 2012
Author:jeroendedauw
Status:deferred
Tags:
Comment:
work on ambassador profiles
Modified paths:
  • /trunk/extensions/EducationProgram/EducationProgram.i18n.php (modified) (history)
  • /trunk/extensions/EducationProgram/EducationProgram.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialAmbassadorProfile.php (added) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialCAProfile.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialOAProfile.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/EducationProgram.php
@@ -116,6 +116,7 @@
117117 $wgAutoloadClasses['SpecialOA'] = dirname( __FILE__ ) . '/specials/SpecialOA.php';
118118 $wgAutoloadClasses['SpecialOAProfile'] = dirname( __FILE__ ) . '/specials/SpecialOAProfile.php';
119119 $wgAutoloadClasses['SpecialCAProfile'] = dirname( __FILE__ ) . '/specials/SpecialCAProfile.php';
 120+$wgAutoloadClasses['SpecialAmbassadorProfile'] = dirname( __FILE__ ) . '/specials/SpecialAmbassadorProfile.php';
120121
121122 // Special pages
122123 $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 @@
1212 * @licence GNU GPL v3 or later
1313 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1414 */
15 -class SpecialOAProfile extends FormSpecialPage {
 15+class SpecialOAProfile extends SpecialAmbassadorProfile {
1616
1717 /**
1818 * Constructor.
@@ -23,75 +23,24 @@
2424 }
2525
2626 /**
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 - /**
3827 * (non-PHPdoc)
3928 * @see FormSpecialPage::getFormFields()
4029 * @return array
4130 */
4231 protected function getFormFields() {
43 - $fields = array();
 32+ $fields = parent::getFormFields();
4433
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 - );
5534
56 - $lang = $this->getLanguage();
5735
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 -
7436 return $fields;
7537 }
7638
7739 /**
78 - * Gets called after the form is saved.
79 - *
80 - * @since 0.1
 40+ * (non-PHPdoc)
 41+ * @see FormSpecialPage::getClassName()
8142 */
82 - public function onSuccess() {
83 - // $this->getOutput()->redirect( $this->getReturnToTitle( true )->getLocalURL() );
 43+ protected function getClassName() {
 44+ return 'EPOA';
8445 }
8546
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 -
9847 }
\ No newline at end of file
Index: trunk/extensions/EducationProgram/specials/SpecialCAProfile.php
@@ -11,7 +11,7 @@
1212 * @licence GNU GPL v3 or later
1313 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1414 */
15 -class SpecialCAProfile extends SpecialEPPage {
 15+class SpecialCAProfile extends SpecialAmbassadorProfile {
1616
1717 /**
1818 * Constructor.
@@ -23,17 +23,24 @@
2424 }
2525
2626 /**
27 - * Main method.
28 - *
29 - * @since 0.1
30 - *
31 - * @param string $subPage
 27+ * (non-PHPdoc)
 28+ * @see FormSpecialPage::getFormFields()
 29+ * @return array
3230 */
33 - public function execute( $subPage ) {
34 - parent::execute( $subPage );
 31+ protected function getFormFields() {
 32+ $fields = parent::getFormFields();
3533
3634
3735
 36+ return $fields;
3837 }
3938
 39+ /**
 40+ * (non-PHPdoc)
 41+ * @see FormSpecialPage::getClassName()
 42+ */
 43+ protected function getClassName() {
 44+ return 'EPCA';
 45+ }
 46+
4047 }
\ No newline at end of file
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php
@@ -485,6 +485,24 @@
486486 'ep-enlist-invalid-user-args' => 'You need to either provide the username or the userid parameter',
487487 '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',
488488 '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',
489507 );
490508
491509 /** Message documentation (Message documentation)

Status & tagging log