r76922 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r76921‎ | r76922 | r76923 >
Date:00:00, 18 November 2010
Author:reedy
Status:ok (Comments)
Tags:
Comment:
bug 25940 Add API module(s) to add comments/set revision status

:D
Modified paths:
  • /trunk/extensions/CodeReview/CodeReview.php (modified) (history)
  • /trunk/extensions/CodeReview/api/ApiRevisionUpdate.php (added) (history)

Diff [purge]

Index: trunk/extensions/CodeReview/CodeReview.php
@@ -39,6 +39,7 @@
4040
4141 $wgAutoloadClasses['ApiCodeUpdate'] = $dir . 'api/ApiCodeUpdate.php';
4242 $wgAutoloadClasses['ApiCodeDiff'] = $dir . 'api/ApiCodeDiff.php';
 43+$wgAutoloadClasses['ApiRevisionUpdate'] = $dir . 'api/ApiRevisionUpdate.php';
4344 $wgAutoloadClasses['ApiQueryCodeComments'] = $dir . 'api/ApiQueryCodeComments.php';
4445 $wgAutoloadClasses['ApiQueryCodeRevisions'] = $dir . 'api/ApiQueryCodeRevisions.php';
4546 $wgAutoloadClasses['CodeRevisionCommitterApi'] = $dir . 'api/CodeRevisionCommitterApi.php';
@@ -83,6 +84,7 @@
8485
8586 $wgAPIModules['codeupdate'] = 'ApiCodeUpdate';
8687 $wgAPIModules['codediff'] = 'ApiCodeDiff';
 88+$wgAPIModules['updaterev'] ='ApiRevisionUpdate';
8789 $wgAPIListModules['codecomments'] = 'ApiQueryCodeComments';
8890 $wgAPIListModules['coderevisions'] = 'ApiQueryCodeRevisions';
8991
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
1111 + native
Added: svn:keywords
2112 + Id

Follow-up revisions

RevisionCommit summaryAuthorDate
r76930bug 25940 Add API module(s) to add comments/set revision status...reedy00:42, 18 November 2010
r76942Followup r76922, fix capitalisation, change api module reference to updaterevreedy10:55, 18 November 2010
r77103Followup r76922, return comment id if there is onereedy12:49, 22 November 2010

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r76905Prequisite to bug 25940 (Add API module(s) to add comments/set revision status)...reedy21:01, 17 November 2010
r76912More for bug 25940 (Add API module(s) to add comments/set revision status)...reedy22:45, 17 November 2010

Comments

#Comment by Bryan (talk | contribs)   09:08, 18 November 2010

The name updaterev is ambigious: it could either mean update an SVN revision or it could mean update a page revision. I would add code to distinguish the two: codeupdaterev or updatecoderev. And while we're at the naming, in general I don't like abbreviations, I would prefer coderevisionupdate.

+			$params['removeTags'],

Wrong capitalization.

+	    	$params['comment']
+		);

Indentation.

#Comment by Reedy (talk | contribs)   10:53, 18 November 2010

Status & tagging log