Index: trunk/extensions/EducationProgram/EducationProgram.php |
— | — | @@ -57,8 +57,10 @@ |
58 | 58 | $wgAutoloadClasses['EPHooks'] = dirname( __FILE__ ) . '/EducationProgram.hooks.php'; |
59 | 59 | $wgAutoloadClasses['EPSettings'] = dirname( __FILE__ ) . '/EducationProgram.settings.php'; |
60 | 60 | |
| 61 | +$wgAutoloadClasses['ApiAddInstructor'] = dirname( __FILE__ ) . '/api/ApiAddInstructor.php'; |
61 | 62 | $wgAutoloadClasses['ApiDeleteEducation'] = dirname( __FILE__ ) . '/api/ApiDeleteEducation.php'; |
62 | 63 | $wgAutoloadClasses['ApiRefreshEducation'] = dirname( __FILE__ ) . '/api/ApiRefreshEducation.php'; |
| 64 | +$wgAutoloadClasses['ApiRemoveInstructor'] = dirname( __FILE__ ) . '/api/ApiRemoveInstructor.php'; |
63 | 65 | |
64 | 66 | $wgAutoloadClasses['EPCourse'] = dirname( __FILE__ ) . '/includes/EPCourse.php'; |
65 | 67 | $wgAutoloadClasses['EPCoursePager'] = dirname( __FILE__ ) . '/includes/EPCoursePager.php'; |
— | — | @@ -139,8 +141,10 @@ |
140 | 142 | $egEPDBObjects[] = array( 'table' => 'ep_mentors_per_org', 'prefix' => 'mpo_' ); |
141 | 143 | |
142 | 144 | // API |
| 145 | +$wgAPIModules['addinstructor'] = 'ApiAddInstructor'; |
143 | 146 | $wgAPIModules['deleteeducation'] = 'ApiDeleteEducation'; |
144 | 147 | $wgAPIModules['refresheducation'] = 'ApiRefreshEducation'; |
| 148 | +$wgAPIModules['removeinstructor'] = 'ApiRemoveInstructor'; |
145 | 149 | |
146 | 150 | // Hooks |
147 | 151 | $wgHooks['LoadExtensionSchemaUpdates'][] = 'EPHooks::onSchemaUpdate'; |
Index: trunk/extensions/EducationProgram/api/ApiAddInstructor.php |
— | — | @@ -0,0 +1,105 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * API module to associate users as instructor for a course. |
| 6 | + * |
| 7 | + * @since 0.1 |
| 8 | + * |
| 9 | + * @file ApiAddInstructor.php |
| 10 | + * @ingroup Education Program |
| 11 | + * @ingroup API |
| 12 | + * |
| 13 | + * @licence GNU GPL v3+ |
| 14 | + * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
| 15 | + */ |
| 16 | +class ApiAddInstructor extends ApiBase { |
| 17 | + |
| 18 | + public function execute() { |
| 19 | + $params = $this->extractRequestParams(); |
| 20 | + |
| 21 | + if ( !( isset( $params['username'] ) XOR isset( $params['userid'] ) ) ) { |
| 22 | + $this->dieUsage( wfMsgExt( 'ep-addinstructor-invalid-user-arg' ), 'username-xor-userid' ); |
| 23 | + } |
| 24 | + |
| 25 | + $everythingOk = true; |
| 26 | + |
| 27 | + // TODO |
| 28 | + |
| 29 | + $this->getResult()->addValue( |
| 30 | + null, |
| 31 | + 'success', |
| 32 | + $everythingOk |
| 33 | + ); |
| 34 | + } |
| 35 | + |
| 36 | + /** |
| 37 | + * Get the User being used for this instance. |
| 38 | + * ApiBase extends ContextSource as of 1.19. |
| 39 | + * |
| 40 | + * @since 0.1 |
| 41 | + * |
| 42 | + * @return User |
| 43 | + */ |
| 44 | + public function getUser() { |
| 45 | + return method_exists( 'ApiBase', 'getUser' ) ? parent::getUser() : $GLOBALS['wgUser']; |
| 46 | + } |
| 47 | + |
| 48 | + public function needsToken() { |
| 49 | + return true; |
| 50 | + } |
| 51 | + |
| 52 | + public function mustBePosted() { |
| 53 | + return true; |
| 54 | + } |
| 55 | + |
| 56 | + public function getAllowedParams() { |
| 57 | + return array( |
| 58 | + 'username' => array( |
| 59 | + ApiBase::PARAM_TYPE => 'string', |
| 60 | + ApiBase::PARAM_REQUIRED => false, |
| 61 | + ), |
| 62 | + 'userid' => array( |
| 63 | + ApiBase::PARAM_TYPE => 'integer', |
| 64 | + ApiBase::PARAM_REQUIRED => false, |
| 65 | + ), |
| 66 | + 'courseid' => array( |
| 67 | + ApiBase::PARAM_TYPE => 'integer', |
| 68 | + ApiBase::PARAM_REQUIRED => true, |
| 69 | + ), |
| 70 | + 'token' => null, |
| 71 | + ); |
| 72 | + } |
| 73 | + |
| 74 | + public function getParamDescription() { |
| 75 | + return array( |
| 76 | + 'courseid' => 'The ID of the course to which the instructor should be added', |
| 77 | + 'username' => 'Name of the user to associate as instructor', |
| 78 | + 'userid' => 'Id of the user to associate as instructor', |
| 79 | + 'token' => 'Edit token. You can get one of these through prop=info.', |
| 80 | + ); |
| 81 | + } |
| 82 | + |
| 83 | + public function getDescription() { |
| 84 | + return array( |
| 85 | + 'API module for associating a user as instructor with a course.' |
| 86 | + ); |
| 87 | + } |
| 88 | + |
| 89 | + public function getPossibleErrors() { |
| 90 | + return array_merge( parent::getPossibleErrors(), array( |
| 91 | + array( 'code' => 'username-xor-userid', 'info' => 'You need to either provide the username or the userid parameter' ), |
| 92 | + ) ); |
| 93 | + } |
| 94 | + |
| 95 | + protected function getExamples() { |
| 96 | + return array( |
| 97 | + 'api.php?action=addinstructor&courseid=42&userid=9001', |
| 98 | + 'api.php?action=addinstructor&courseid=42&username=Jeroen%20De%20Dauw', |
| 99 | + ); |
| 100 | + } |
| 101 | + |
| 102 | + public function getVersion() { |
| 103 | + return __CLASS__ . ': $Id$'; |
| 104 | + } |
| 105 | + |
| 106 | +} |
Property changes on: trunk/extensions/EducationProgram/api/ApiAddInstructor.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 107 | + native |
Added: svn:keywords |
2 | 108 | + Id |
Index: trunk/extensions/EducationProgram/api/ApiRemoveInstructor.php |
— | — | @@ -0,0 +1,105 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * API module to disassociate users as instructor from a course. |
| 6 | + * |
| 7 | + * @since 0.1 |
| 8 | + * |
| 9 | + * @file ApiRemoveInstructor.php |
| 10 | + * @ingroup Education Program |
| 11 | + * @ingroup API |
| 12 | + * |
| 13 | + * @licence GNU GPL v3+ |
| 14 | + * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
| 15 | + */ |
| 16 | +class ApiRemoveInstructor extends ApiBase { |
| 17 | + |
| 18 | + public function execute() { |
| 19 | + $params = $this->extractRequestParams(); |
| 20 | + |
| 21 | + if ( !( isset( $params['username'] ) XOR isset( $params['userid'] ) ) ) { |
| 22 | + $this->dieUsage( wfMsgExt( 'ep-addinstructor-invalid-user-arg' ), 'username-xor-userid' ); |
| 23 | + } |
| 24 | + |
| 25 | + $everythingOk = true; |
| 26 | + |
| 27 | + // TODO |
| 28 | + |
| 29 | + $this->getResult()->addValue( |
| 30 | + null, |
| 31 | + 'success', |
| 32 | + $everythingOk |
| 33 | + ); |
| 34 | + } |
| 35 | + |
| 36 | + /** |
| 37 | + * Get the User being used for this instance. |
| 38 | + * ApiBase extends ContextSource as of 1.19. |
| 39 | + * |
| 40 | + * @since 0.1 |
| 41 | + * |
| 42 | + * @return User |
| 43 | + */ |
| 44 | + public function getUser() { |
| 45 | + return method_exists( 'ApiBase', 'getUser' ) ? parent::getUser() : $GLOBALS['wgUser']; |
| 46 | + } |
| 47 | + |
| 48 | + public function needsToken() { |
| 49 | + return true; |
| 50 | + } |
| 51 | + |
| 52 | + public function mustBePosted() { |
| 53 | + return true; |
| 54 | + } |
| 55 | + |
| 56 | + public function getAllowedParams() { |
| 57 | + return array( |
| 58 | + 'username' => array( |
| 59 | + ApiBase::PARAM_TYPE => 'string', |
| 60 | + ApiBase::PARAM_REQUIRED => false, |
| 61 | + ), |
| 62 | + 'userid' => array( |
| 63 | + ApiBase::PARAM_TYPE => 'integer', |
| 64 | + ApiBase::PARAM_REQUIRED => false, |
| 65 | + ), |
| 66 | + 'courseid' => array( |
| 67 | + ApiBase::PARAM_TYPE => 'integer', |
| 68 | + ApiBase::PARAM_REQUIRED => true, |
| 69 | + ), |
| 70 | + 'token' => null, |
| 71 | + ); |
| 72 | + } |
| 73 | + |
| 74 | + public function getParamDescription() { |
| 75 | + return array( |
| 76 | + 'courseid' => 'The ID of the course from which the instructor should be remove', |
| 77 | + 'username' => 'Name of the user to disassociate as instructor', |
| 78 | + 'userid' => 'Id of the user to disassociate as instructor', |
| 79 | + 'token' => 'Edit token. You can get one of these through prop=info.', |
| 80 | + ); |
| 81 | + } |
| 82 | + |
| 83 | + public function getDescription() { |
| 84 | + return array( |
| 85 | + 'API module for disassociating a user as instructor from a course.' |
| 86 | + ); |
| 87 | + } |
| 88 | + |
| 89 | + public function getPossibleErrors() { |
| 90 | + return array_merge( parent::getPossibleErrors(), array( |
| 91 | + array( 'code' => 'username-xor-userid', 'info' => 'You need to either provide the username or the userid parameter' ), |
| 92 | + ) ); |
| 93 | + } |
| 94 | + |
| 95 | + protected function getExamples() { |
| 96 | + return array( |
| 97 | + 'api.php?action=removeinstructor&courseid=42&userid=9001', |
| 98 | + 'api.php?action=removeinstructor&courseid=42&username=Jeroen%20De%20Dauw', |
| 99 | + ); |
| 100 | + } |
| 101 | + |
| 102 | + public function getVersion() { |
| 103 | + return __CLASS__ . ': $Id$'; |
| 104 | + } |
| 105 | + |
| 106 | +} |
Property changes on: trunk/extensions/EducationProgram/api/ApiRemoveInstructor.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 107 | + native |
Added: svn:keywords |
2 | 108 | + Id |