Index: trunk/extensions/CodeReview/CodeReview.php |
— | — | @@ -39,6 +39,7 @@ |
40 | 40 | |
41 | 41 | $wgAutoloadClasses['ApiCodeUpdate'] = $dir . 'api/ApiCodeUpdate.php'; |
42 | 42 | $wgAutoloadClasses['ApiCodeDiff'] = $dir . 'api/ApiCodeDiff.php'; |
| 43 | +$wgAutoloadClasses['ApiRevisionUpdate'] = $dir . 'api/ApiRevisionUpdate.php'; |
43 | 44 | $wgAutoloadClasses['ApiQueryCodeComments'] = $dir . 'api/ApiQueryCodeComments.php'; |
44 | 45 | $wgAutoloadClasses['ApiQueryCodeRevisions'] = $dir . 'api/ApiQueryCodeRevisions.php'; |
45 | 46 | $wgAutoloadClasses['CodeRevisionCommitterApi'] = $dir . 'api/CodeRevisionCommitterApi.php'; |
— | — | @@ -83,6 +84,7 @@ |
84 | 85 | |
85 | 86 | $wgAPIModules['codeupdate'] = 'ApiCodeUpdate'; |
86 | 87 | $wgAPIModules['codediff'] = 'ApiCodeDiff'; |
| 88 | +$wgAPIModules['updaterev'] ='ApiRevisionUpdate'; |
87 | 89 | $wgAPIListModules['codecomments'] = 'ApiQueryCodeComments'; |
88 | 90 | $wgAPIListModules['coderevisions'] = 'ApiQueryCodeRevisions'; |
89 | 91 | |
Index: trunk/extensions/CodeReview/api/ApiRevisionUpdate.php |
— | — | @@ -0,0 +1,109 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +class ApiRevisionUpdate extends ApiBase { |
| 5 | + |
| 6 | + public function execute() { |
| 7 | + global $wgUser; |
| 8 | + // Before doing anything at all, let's check permissions |
| 9 | + if ( !$wgUser->isAllowed( 'codereview-use' ) ) { |
| 10 | + $this->dieUsage( 'You don\'t have permission to update code', 'permissiondenied' ); |
| 11 | + } |
| 12 | + |
| 13 | + $params = $this->extractRequestParams(); |
| 14 | + |
| 15 | + $repo = CodeRepository::newFromName( $params['repo'] ); |
| 16 | + if ( !$repo ) { |
| 17 | + $this->dieUsage( "Invalid repo ``{$params['repo']}''", 'invalidrepo' ); |
| 18 | + } |
| 19 | + |
| 20 | + $rev = $repo->getRevision( $params['rev'] ); |
| 21 | + |
| 22 | + if ( !$rev ) { |
| 23 | + $this->dieUsage( "There is no revision with ID {$params['rev']}", 'nosuchrev' ); |
| 24 | + } |
| 25 | + |
| 26 | + $revisionCommitter = new CodeRevisionCommitterApi( $repo, $rev ); |
| 27 | + |
| 28 | + $revisionCommitter->doRevisionUpdate( |
| 29 | + $params['status'], |
| 30 | + $params['addtags'], |
| 31 | + $params['removeTags'], |
| 32 | + array(), //Signoff Flags to be done/exposed at later date |
| 33 | + $params['comment'] |
| 34 | + ); |
| 35 | + |
| 36 | + $r = array( 'result' => 'Success' ); |
| 37 | + $this->getResult()->addValue( null, $this->getModuleName(), $r ); |
| 38 | + } |
| 39 | + |
| 40 | + public function mustBePosted() { |
| 41 | + return true; |
| 42 | + } |
| 43 | + |
| 44 | + public function isWriteMode() { |
| 45 | + return true; |
| 46 | + } |
| 47 | + |
| 48 | + public function getAllowedParams() { |
| 49 | + return array( |
| 50 | + 'repo' => array( |
| 51 | + ApiBase::PARAM_TYPE => 'string', |
| 52 | + ApiBase::PARAM_REQUIRED => true, |
| 53 | + ), |
| 54 | + 'rev' => array( |
| 55 | + ApiBase::PARAM_TYPE => 'integer', |
| 56 | + ApiBase::PARAM_MIN => 1, |
| 57 | + ApiBase::PARAM_REQUIRED => true, |
| 58 | + ), |
| 59 | + 'comment' => null, |
| 60 | + 'status' => array( |
| 61 | + ApiBase::PARAM_TYPE => CodeRevision::getPossibleStates() |
| 62 | + ), |
| 63 | + 'addtags' => array( |
| 64 | + ApiBase::PARAM_TYPE => 'string', |
| 65 | + ApiBase::PARAM_ISMULTI => true, |
| 66 | + ), |
| 67 | + 'removetags' => array( |
| 68 | + ApiBase::PARAM_TYPE => 'string', |
| 69 | + ApiBase::PARAM_ISMULTI => true, |
| 70 | + ), |
| 71 | + ); |
| 72 | + } |
| 73 | + |
| 74 | + public function getParamDescription() { |
| 75 | + return array( |
| 76 | + 'repo' => 'Name of repository', |
| 77 | + 'rev' => 'Revision ID number', |
| 78 | + 'comment' => 'Comment to add to the revision', |
| 79 | + 'status' => 'Status to set the revision to', |
| 80 | + 'addtags' => 'Tags to be added to the revision', |
| 81 | + 'removetags' => 'Tags to be removed from the revision', |
| 82 | + ); |
| 83 | + } |
| 84 | + |
| 85 | + public function getDescription() { |
| 86 | + return array( |
| 87 | + 'Submit comments, new status and tags to a revision' |
| 88 | + ); |
| 89 | + } |
| 90 | + |
| 91 | + public function getPossibleErrors() { |
| 92 | + return array_merge( parent::getPossibleErrors(), array( |
| 93 | + array( 'code' => 'permissiondenied', 'info' => 'You don\'t have permission to update code' ), |
| 94 | + array( 'code' => 'invalidrepo', 'info' => "Invalid repo ``repo''" ), |
| 95 | + array( 'code' => 'nosuchrev', 'info' => 'There is no revision with ID \'rev\'' ), |
| 96 | + array( 'missingparam', 'repo' ), |
| 97 | + array( 'missingparam', 'rev' ), |
| 98 | + ) ); |
| 99 | + } |
| 100 | + |
| 101 | + public function getExamples() { |
| 102 | + return array( |
| 103 | + 'api.php?action=updaterev&repo=MediaWiki&rev=1&status=fixme', |
| 104 | + ); |
| 105 | + } |
| 106 | + |
| 107 | + public function getVersion() { |
| 108 | + return __CLASS__ . ': $Id$'; |
| 109 | + } |
| 110 | +} |
Property changes on: trunk/extensions/CodeReview/api/ApiRevisionUpdate.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 111 | + native |
Added: svn:keywords |
2 | 112 | + Id |