Index: trunk/extensions/EducationProgram/EducationProgram.settings.php |
— | — | @@ -29,6 +29,9 @@ |
30 | 30 | protected static function getDefaultSettings() { |
31 | 31 | return array( |
32 | 32 | 'enableTopLink' => true, |
| 33 | + 'ambassadorPictureDomains' => array( |
| 34 | + 'wikimedia.org' |
| 35 | + ), |
33 | 36 | ); |
34 | 37 | } |
35 | 38 | |
Index: trunk/extensions/EducationProgram/actions/ViewCourseAction.php |
— | — | @@ -18,56 +18,35 @@ |
19 | 19 | return 'viewcourse'; |
20 | 20 | } |
21 | 21 | |
22 | | - /** |
23 | | - * |
24 | | - * |
25 | | - * @return String HTML |
26 | | - */ |
27 | | - public function onView() { |
28 | | - $out = $this->getOutput(); |
29 | | - |
30 | | - $name = $this->getTitle()->getText(); |
31 | | - |
32 | | - $course = EPCourse::get( $name ); |
| 22 | + protected function getItemClass() { |
| 23 | + return 'EPCourse'; |
| 24 | + } |
33 | 25 | |
34 | | - if ( $course === false ) { |
35 | | - $this->displayNavigation(); |
| 26 | + protected function displayPage( EPDBObject $course ) { |
| 27 | + parent::displayPage( $course ); |
36 | 28 | |
37 | | - if ( $this->getUser()->isAllowed( 'ep-course' ) ) { |
38 | | - $out->redirect( $this->getTitle()->getLocalURL( array( 'action' => 'edit' ) ) ); |
39 | | - } |
40 | | - else { |
41 | | - $out->addWikiMsg( 'ep-course-none', $name ); |
42 | | - } |
43 | | - } |
44 | | - else { |
45 | | - $this->displayNavigation(); |
| 29 | + $out = $this->getOutput(); |
46 | 30 | |
47 | | - $this->displaySummary( $course ); |
| 31 | + $out->addHTML( Html::element( 'h2', array(), wfMsg( 'ep-course-description' ) ) ); |
48 | 32 | |
49 | | - $out->addHTML( Html::element( 'h2', array(), wfMsg( 'ep-course-description' ) ) ); |
| 33 | + $out->addHTML( $this->getOutput()->parse( $course->getField( 'description' ) ) ); |
50 | 34 | |
51 | | - $out->addHTML( $this->getOutput()->parse( $course->getField( 'description' ) ) ); |
| 35 | + $studentIds = array_map( |
| 36 | + function( EPStudent $student ) { |
| 37 | + return $student->getId(); |
| 38 | + }, |
| 39 | + $course->getStudents( 'id' ) |
| 40 | + ); |
52 | 41 | |
53 | | - $studentIds = array_map( |
54 | | - function( EPStudent $student ) { |
55 | | - return $student->getId(); |
56 | | - }, |
57 | | - $course->getStudents( 'id' ) |
58 | | - ); |
59 | | - |
60 | | - if ( count( $studentIds ) > 0 ) { |
61 | | - $out->addHTML( Html::element( 'h2', array(), wfMsg( 'ep-course-students' ) ) ); |
62 | | - EPStudent::displayPager( $this->getContext(), array( 'id' => $studentIds ) ); |
63 | | - } |
64 | | - else { |
65 | | - // TODO |
66 | | - } |
| 42 | + if ( count( $studentIds ) > 0 ) { |
| 43 | + $out->addHTML( Html::element( 'h2', array(), wfMsg( 'ep-course-students' ) ) ); |
| 44 | + EPStudent::displayPager( $this->getContext(), array( 'id' => $studentIds ) ); |
67 | 45 | } |
68 | | - |
69 | | - return ''; |
| 46 | + else { |
| 47 | + // TODO |
| 48 | + } |
70 | 49 | } |
71 | | - |
| 50 | + |
72 | 51 | /** |
73 | 52 | * Gets the summary data. |
74 | 53 | * |
Index: trunk/extensions/EducationProgram/actions/EPViewAction.php |
— | — | @@ -19,6 +19,97 @@ |
20 | 20 | } |
21 | 21 | |
22 | 22 | /** |
| 23 | + * Returns the class name of the EPDBObject this action handles. |
| 24 | + * |
| 25 | + * @since 0.1 |
| 26 | + * |
| 27 | + * @return string |
| 28 | + */ |
| 29 | + protected abstract function getItemClass(); |
| 30 | + |
| 31 | + /** |
| 32 | + * |
| 33 | + * |
| 34 | + * @return String HTML |
| 35 | + */ |
| 36 | + public function onView() { |
| 37 | + $out = $this->getOutput(); |
| 38 | + $name = $this->getTitle()->getText(); |
| 39 | + $class = $this->getItemClass(); |
| 40 | + |
| 41 | + $object = false; |
| 42 | + |
| 43 | + if ( $this->getRequest()->getCheck( 'revid' ) ) { |
| 44 | + $currentObject = $class::get( $name, 'id' ); |
| 45 | + |
| 46 | + if ( $currentObject !== false ) { |
| 47 | + $rev = EPRevision::selectRow( null, array( |
| 48 | + 'id' => $this->getRequest()->getInt( 'revid' ), |
| 49 | + 'object_id' => $currentObject->getField( 'id' ) |
| 50 | + ) ); |
| 51 | + |
| 52 | + if ( $rev === false ) { |
| 53 | + // TODO |
| 54 | + } |
| 55 | + else { |
| 56 | + $object = $rev->getObject(); |
| 57 | + |
| 58 | + $lang = $this->getLanguage(); |
| 59 | + |
| 60 | + $current = false; // TODO |
| 61 | + $td = $lang->timeanddate( $rev->getField( 'time' ), true ); |
| 62 | + $tddate = $lang->date( $rev->getField( 'time' ), true ); |
| 63 | + $tdtime = $lang->time( $rev->getField( 'time' ), true ); |
| 64 | + |
| 65 | + $userToolLinks = Linker::userLink( $rev->getUser()->getId(), $rev->getUser()->getName() ) |
| 66 | + . Linker::userToolLinks( $rev->getUser()->getId(), $rev->getUser()->getName() ); |
| 67 | + |
| 68 | + $infomsg = $current && !wfMessage( 'revision-info-current' )->isDisabled() |
| 69 | + ? 'revision-info-current' |
| 70 | + : 'revision-info'; |
| 71 | + |
| 72 | + $out->setSubtitle( |
| 73 | + "<div id=\"mw-{$infomsg}\">" . |
| 74 | + wfMessage( $infomsg, $td )->rawParams( $userToolLinks )->params( |
| 75 | + $rev->getId(), |
| 76 | + $tddate, |
| 77 | + $tdtime, |
| 78 | + $rev->getUser() |
| 79 | + )->parse() . |
| 80 | + "</div>" |
| 81 | + ); |
| 82 | + } |
| 83 | + } |
| 84 | + } |
| 85 | + |
| 86 | + if ( $object === false ) { |
| 87 | + $object = $class::get( $name ); |
| 88 | + } |
| 89 | + |
| 90 | + if ( $object === false ) { |
| 91 | + $this->displayNavigation(); |
| 92 | + |
| 93 | + if ( $this->getUser()->isAllowed( $class::getEditRight() ) ) { |
| 94 | + $out->redirect( $this->getTitle()->getLocalURL( array( 'action' => 'edit' ) ) ); |
| 95 | + } |
| 96 | + else { |
| 97 | + $out->addWikiMsg( strtolower( get_called_class() ) . '-none', $name ); |
| 98 | + } |
| 99 | + } |
| 100 | + else { |
| 101 | + $this->displayPage( $object ); |
| 102 | + } |
| 103 | + |
| 104 | + return ''; |
| 105 | + } |
| 106 | + |
| 107 | + protected function displayPage( EPDBObject $object ) { |
| 108 | + $this->displayNavigation(); |
| 109 | + |
| 110 | + $this->displaySummary( $object ); |
| 111 | + } |
| 112 | + |
| 113 | + /** |
23 | 114 | * Adds a navigation menu with the provided links. |
24 | 115 | * Links should be provided in an array with: |
25 | 116 | * label => Title (object) |
Index: trunk/extensions/EducationProgram/actions/ViewOrgAction.php |
— | — | @@ -18,47 +18,26 @@ |
19 | 19 | return 'vieworg'; |
20 | 20 | } |
21 | 21 | |
22 | | - /** |
23 | | - * |
24 | | - * |
25 | | - * @return String HTML |
26 | | - */ |
27 | | - public function onView() { |
28 | | - $out = $this->getOutput(); |
29 | | - |
30 | | - $name = $this->getTitle()->getText(); |
31 | | - |
32 | | - $out->setPageTitle( wfMsgExt( 'ep-institution-title', 'parsemag', $name ) ); |
| 22 | + protected function getItemClass() { |
| 23 | + return 'EPOrg'; |
| 24 | + } |
33 | 25 | |
34 | | - $org = EPOrg::get( $name ); |
| 26 | + protected function displayPage( EPDBObject $org ) { |
| 27 | + parent::displayPage( $org ); |
35 | 28 | |
36 | | - if ( $org === false ) { |
37 | | - if ( $this->getUser()->isAllowed( 'ep-org' ) ) { |
38 | | - $out->redirect( $this->getTitle()->getLocalURL( array( 'action' => 'edit' ) ) ); |
39 | | - } |
40 | | - else { |
41 | | - $out->addWikiMsg( 'ep-institution-none', $name ); |
42 | | - } |
43 | | - } |
44 | | - else { |
45 | | - $this->displayNavigation(); |
| 29 | + $out = $this->getOutput(); |
46 | 30 | |
47 | | - $this->displaySummary( $org ); |
| 31 | + $out->addHTML( Html::element( 'h2', array(), wfMsg( 'ep-institution-courses' ) ) ); |
48 | 32 | |
49 | | - $out->addHTML( Html::element( 'h2', array(), wfMsg( 'ep-institution-courses' ) ) ); |
| 33 | + EPCourse::displayPager( $this->getContext(), array( 'org_id' => $org->getId() ) ); |
50 | 34 | |
51 | | - EPCourse::displayPager( $this->getContext(), array( 'org_id' => $org->getId() ) ); |
| 35 | + if ( $this->getUser()->isAllowed( 'ep-course' ) ) { |
| 36 | + $out->addHTML( Html::element( 'h2', array(), wfMsg( 'ep-institution-add-course' ) ) ); |
52 | 37 | |
53 | | - if ( $this->getUser()->isAllowed( 'ep-course' ) ) { |
54 | | - $out->addHTML( Html::element( 'h2', array(), wfMsg( 'ep-institution-add-course' ) ) ); |
55 | | - |
56 | | - EPCourse::displayAddNewControl( $this->getContext(), array( 'org' => $org->getId() ) ); |
57 | | - } |
| 38 | + EPCourse::displayAddNewControl( $this->getContext(), array( 'org' => $org->getId() ) ); |
58 | 39 | } |
59 | | - |
60 | | - return ''; |
61 | 40 | } |
62 | | - |
| 41 | + |
63 | 42 | /** |
64 | 43 | * Gets the summary data. |
65 | 44 | * |
Index: trunk/extensions/EducationProgram/actions/EPEditAction.php |
— | — | @@ -166,6 +166,8 @@ |
167 | 167 | else { |
168 | 168 | $data['name'] = $this->getTitle()->getText(); |
169 | 169 | } |
| 170 | + |
| 171 | + $data['name'] = $this->getLanguage()->ucfirst( $data['name'] ); |
170 | 172 | |
171 | 173 | return $data; |
172 | 174 | } |
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 SpecialEPPage { |
| 15 | +class SpecialOAProfile extends FormSpecialPage { |
16 | 16 | |
17 | 17 | /** |
18 | 18 | * Constructor. |
— | — | @@ -31,9 +31,67 @@ |
32 | 32 | */ |
33 | 33 | public function execute( $subPage ) { |
34 | 34 | parent::execute( $subPage ); |
| 35 | + } |
35 | 36 | |
| 37 | + /** |
| 38 | + * (non-PHPdoc) |
| 39 | + * @see FormSpecialPage::getFormFields() |
| 40 | + * @return array |
| 41 | + */ |
| 42 | + protected function getFormFields() { |
| 43 | + $fields = array(); |
36 | 44 | |
| 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 | + ); |
37 | 55 | |
| 56 | + $lang = $this->getLanguage(); |
| 57 | + |
| 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 | + return $fields; |
38 | 75 | } |
39 | 76 | |
| 77 | + /** |
| 78 | + * Gets called after the form is saved. |
| 79 | + * |
| 80 | + * @since 0.1 |
| 81 | + */ |
| 82 | + public function onSuccess() { |
| 83 | + // $this->getOutput()->redirect( $this->getReturnToTitle( true )->getLocalURL() ); |
| 84 | + } |
| 85 | + |
| 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 | + |
40 | 98 | } |
\ No newline at end of file |
Index: trunk/extensions/EducationProgram/specials/SpecialEPPage.php |
— | — | @@ -113,7 +113,7 @@ |
114 | 114 | |
115 | 115 | /** |
116 | 116 | * Get the Language being used for this instance. |
117 | | - * getLang was deprecated in 1.19, getLanguage was introduces in the same version. |
| 117 | + * getLang was deprecated in 1.19, getLanguage was introduced in the same version. |
118 | 118 | * |
119 | 119 | * @since 0.1 |
120 | 120 | * |
Index: trunk/extensions/EducationProgram/includes/EPOrg.php |
— | — | @@ -170,6 +170,18 @@ |
171 | 171 | } |
172 | 172 | |
173 | 173 | /** |
| 174 | + * (non-PHPdoc) |
| 175 | + * @see EPDBObject::writeToDB() |
| 176 | + */ |
| 177 | + public function writeToDB() { |
| 178 | + if ( $this->hasField( 'name' ) ) { |
| 179 | + $this->setField( 'name', $GLOBALS['wgLang']->ucfirst( $this->getField( 'name' ) ) ); |
| 180 | + } |
| 181 | + |
| 182 | + return parent::writeToDB(); |
| 183 | + } |
| 184 | + |
| 185 | + /** |
174 | 186 | * Returns a list of orgs in an array that can be fed to select inputs. |
175 | 187 | * |
176 | 188 | * @since 0.1 |
Index: trunk/extensions/EducationProgram/includes/EPRevision.php |
— | — | @@ -14,6 +14,15 @@ |
15 | 15 | class EPRevision extends EPDBObject { |
16 | 16 | |
17 | 17 | /** |
| 18 | + * Cached user object for this revision. |
| 19 | + * |
| 20 | + * @since 0.1 |
| 21 | + * @var User|false |
| 22 | + */ |
| 23 | + protected $user = false; |
| 24 | + |
| 25 | + |
| 26 | + /** |
18 | 27 | * @see parent::__construct |
19 | 28 | * |
20 | 29 | * @since 0.1 |
— | — | @@ -76,5 +85,61 @@ |
77 | 86 | return new static( $fields ); |
78 | 87 | } |
79 | 88 | |
| 89 | + /** |
| 90 | + * Return the object as it was at this revision. |
| 91 | + * |
| 92 | + * @since 0,1 |
| 93 | + * |
| 94 | + * @return EPDBObject |
| 95 | + */ |
| 96 | + public function getObject() { |
| 97 | + $class = $this->getField( 'type' ); |
| 98 | + return $class::newFromArray( $this->getField( 'data' ) ); |
| 99 | + } |
80 | 100 | |
| 101 | + /** |
| 102 | + * Returns the the object stored in the revision with the provided id, |
| 103 | + * or false if there is no matching object. |
| 104 | + * |
| 105 | + * @since 0.1 |
| 106 | + * |
| 107 | + * @param integer $revId |
| 108 | + * @param integer|null $objectId |
| 109 | + * |
| 110 | + * @return EPDBObject|false |
| 111 | + */ |
| 112 | + public static function getObjectFromRevId( $revId, $objectId = null ) { |
| 113 | + $conditions = array( |
| 114 | + 'id' => $revId |
| 115 | + ); |
| 116 | + |
| 117 | + if ( !is_null( $objectId ) ) { |
| 118 | + $conditions['object_id'] = $objectId; |
| 119 | + } |
| 120 | + |
| 121 | + $rev = EPRevision::selectRow( array( 'type', 'data' ), $conditions ); |
| 122 | + |
| 123 | + if ( $rev === false ) { |
| 124 | + return false; |
| 125 | + } |
| 126 | + else { |
| 127 | + return $rev->getDataObject(); |
| 128 | + } |
| 129 | + } |
| 130 | + |
| 131 | + /** |
| 132 | + * Returns the user that authored this revision. |
| 133 | + * |
| 134 | + * @since 0.1 |
| 135 | + * |
| 136 | + * @return User |
| 137 | + */ |
| 138 | + public function getUser() { |
| 139 | + if ( $this->user === false ) { |
| 140 | + $this->user = User::newFromId( $this->loadAndGetField( 'user_id' ) ); |
| 141 | + } |
| 142 | + |
| 143 | + return $this->user; |
| 144 | + } |
| 145 | + |
81 | 146 | } |
Index: trunk/extensions/EducationProgram/includes/EPCourse.php |
— | — | @@ -270,6 +270,18 @@ |
271 | 271 | } |
272 | 272 | |
273 | 273 | /** |
| 274 | + * (non-PHPdoc) |
| 275 | + * @see EPDBObject::writeToDB() |
| 276 | + */ |
| 277 | + public function writeToDB() { |
| 278 | + if ( $this->hasField( 'name' ) ) { |
| 279 | + $this->setField( 'name', $GLOBALS['wgLang']->ucfirst( $this->getField( 'name' ) ) ); |
| 280 | + } |
| 281 | + |
| 282 | + return parent::writeToDB(); |
| 283 | + } |
| 284 | + |
| 285 | + /** |
274 | 286 | * Returns the org associated with this term. |
275 | 287 | * |
276 | 288 | * @since 0.1 |
Index: trunk/extensions/EducationProgram/EducationProgram.hooks.php |
— | — | @@ -253,7 +253,7 @@ |
254 | 254 | if ( array_key_exists( $title->getNamespace(), $classes ) ) { |
255 | 255 | $links['views'] = array(); |
256 | 256 | $links['actions'] = array(); |
257 | | - |
| 257 | + |
258 | 258 | $user = $sktemplate->getUser(); |
259 | 259 | $class = $classes[$title->getNamespace()]; |
260 | 260 | $exists = $class::hasIdentifier( $title->getText() ); |