r109008 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r109007‎ | r109008 | r109009 >
Date:22:26, 15 January 2012
Author:jeroendedauw
Status:deferred
Tags:
Comment:
base for api modules to add and remove instructors from courses
Modified paths:
  • /trunk/extensions/EducationProgram/EducationProgram.php (modified) (history)
  • /trunk/extensions/EducationProgram/api/ApiAddInstructor.php (added) (history)
  • /trunk/extensions/EducationProgram/api/ApiRemoveInstructor.php (added) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/EducationProgram.php
@@ -57,8 +57,10 @@
5858 $wgAutoloadClasses['EPHooks'] = dirname( __FILE__ ) . '/EducationProgram.hooks.php';
5959 $wgAutoloadClasses['EPSettings'] = dirname( __FILE__ ) . '/EducationProgram.settings.php';
6060
 61+$wgAutoloadClasses['ApiAddInstructor'] = dirname( __FILE__ ) . '/api/ApiAddInstructor.php';
6162 $wgAutoloadClasses['ApiDeleteEducation'] = dirname( __FILE__ ) . '/api/ApiDeleteEducation.php';
6263 $wgAutoloadClasses['ApiRefreshEducation'] = dirname( __FILE__ ) . '/api/ApiRefreshEducation.php';
 64+$wgAutoloadClasses['ApiRemoveInstructor'] = dirname( __FILE__ ) . '/api/ApiRemoveInstructor.php';
6365
6466 $wgAutoloadClasses['EPCourse'] = dirname( __FILE__ ) . '/includes/EPCourse.php';
6567 $wgAutoloadClasses['EPCoursePager'] = dirname( __FILE__ ) . '/includes/EPCoursePager.php';
@@ -139,8 +141,10 @@
140142 $egEPDBObjects[] = array( 'table' => 'ep_mentors_per_org', 'prefix' => 'mpo_' );
141143
142144 // API
 145+$wgAPIModules['addinstructor'] = 'ApiAddInstructor';
143146 $wgAPIModules['deleteeducation'] = 'ApiDeleteEducation';
144147 $wgAPIModules['refresheducation'] = 'ApiRefreshEducation';
 148+$wgAPIModules['removeinstructor'] = 'ApiRemoveInstructor';
145149
146150 // Hooks
147151 $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
1107 + native
Added: svn:keywords
2108 + 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
1107 + native
Added: svn:keywords
2108 + Id

Status & tagging log