r65759 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r65758‎ | r65759 | r65760 >
Date:19:26, 1 May 2010
Author:ashley
Status:ok
Tags:
Comment:
CodeReview: coding style tweaks for API modules
Modified paths:
  • /trunk/extensions/CodeReview/api/ApiCodeComments.php (modified) (history)
  • /trunk/extensions/CodeReview/api/ApiCodeDiff.php (modified) (history)
  • /trunk/extensions/CodeReview/api/ApiCodeTestUpload.php (modified) (history)
  • /trunk/extensions/CodeReview/api/ApiCodeUpdate.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CodeReview/api/ApiCodeTestUpload.php
@@ -9,7 +9,7 @@
1010 $this->dieUsage( 'You don\'t have permission to upload test results', 'permissiondenied' );
1111 }
1212 $params = $this->extractRequestParams();
13 -
 13+
1414 $this->validateParams( $params );
1515 $this->validateHmac( $params );
1616
@@ -17,16 +17,16 @@
1818 if ( !$repo ) {
1919 $this->dieUsage( "Invalid repo ``{$params['repo']}''", 'invalidrepo' );
2020 }
21 -
 21+
2222 $suite = $repo->getTestSuite( $params['suite'] );
2323 if ( !$suite ) {
2424 $this->dieUsage( "Invalid test suite ``{$params['suite']}''", 'invalidsuite' );
2525 }
26 -
 26+
2727 // Note that we might be testing a revision that hasn't gotten slurped in yet,
2828 // so we won't reject data for revisions we don't know about yet.
2929 $revId = intval( $params['rev'] );
30 -
 30+
3131 $status = $params['status'];
3232 if ( $status == 'running' || $status == 'aborted' ) {
3333 // Set the 'tests running' flag so we can mark it...
@@ -35,12 +35,12 @@
3636 // Save data and mark running test as completed.
3737 $results = json_decode( $params['results'], true );
3838 if ( !is_array( $results ) ) {
39 - $this->dieUsage( "Invalid test result data", 'invalidresults' );
 39+ $this->dieUsage( 'Invalid test result data', 'invalidresults' );
4040 }
4141 $suite->saveResults( $revId, $results );
4242 }
4343 }
44 -
 44+
4545 protected function validateParams( $params ) {
4646 $required = array( 'repo', 'suite', 'rev', 'status', 'hmac' );
4747 if ( isset( $params['status'] ) && $params['status'] == 'complete' ) {
@@ -52,10 +52,10 @@
5353 }
5454 }
5555 }
56 -
 56+
5757 protected function validateHmac( $params ) {
5858 global $wgCodeReviewSharedSecret;
59 -
 59+
6060 // Generate a hash MAC to validate our credentials
6161 $message = array(
6262 $params['repo'],
@@ -63,10 +63,10 @@
6464 $params['rev'],
6565 $params['status'],
6666 );
67 - if ( $params['status'] == "complete" ) {
 67+ if ( $params['status'] == 'complete' ) {
6868 $message[] = $params['results'];
6969 }
70 - $hmac = hash_hmac( "sha1", implode( "|", $message ), $wgCodeReviewSharedSecret );
 70+ $hmac = hash_hmac( 'sha1', implode( '|', $message ), $wgCodeReviewSharedSecret );
7171 if ( $hmac != $params['hmac'] ) {
7272 $this->dieUsageMsg( array( 'invalidhmac', $params['hmac'] ) );
7373 }
@@ -76,7 +76,7 @@
7777 // Discourage casual browsing :)
7878 return true;
7979 }
80 -
 80+
8181 public function isWriteMode() {
8282 return true;
8383 }
@@ -107,7 +107,7 @@
108108 'results' => 'JSON-encoded map of test names to success results, for status "complete"',
109109 );
110110 }
111 -
 111+
112112 public function getPossibleErrors() {
113113 return array_merge( parent::getPossibleErrors(), array(
114114 array( 'code' => 'permissiondenied', 'info' => 'You don\'t have permission to upload test results' ),
Index: trunk/extensions/CodeReview/api/ApiCodeComments.php
@@ -1,11 +1,11 @@
22 <?php
33
4 -/*
 4+/**
55 * Created on Oct 29, 2008
66 *
77 * API for MediaWiki 1.8+
88 *
9 - * Copyright (C) 2008 Bryan Tong Minh <Bryan.TongMinh@Gmail.com>
 9+ * Copyright © 2008 Bryan Tong Minh <Bryan.TongMinh@Gmail.com>
1010 *
1111 * This program is free software; you can redistribute it and/or modify
1212 * it under the terms of the GNU General Public License as published by
@@ -35,19 +35,23 @@
3636 $this->dieUsage( 'You don\'t have permission to view code comments', 'permissiondenied' );
3737 }
3838 $params = $this->extractRequestParams();
39 - if ( is_null( $params['repo'] ) )
 39+ if ( is_null( $params['repo'] ) ) {
4040 $this->dieUsageMsg( array( 'missingparam', 'repo' ) );
 41+ }
4142 $this->props = array_flip( $params['prop'] );
42 - if ( isset( $this->props['revision'] ) )
 43+ if ( isset( $this->props['revision'] ) ) {
4344 $this->setWarning( 'ccprop=revision has been deprecated in favor of ccprop=status' );
 45+ }
4446
4547 $listview = new CodeCommentsListView( $params['repo'] );
46 - if ( is_null( $listview->getRepo() ) )
 48+ if ( is_null( $listview->getRepo() ) ) {
4749 $this->dieUsage( "Invalid repo ``{$params['repo']}''", 'invalidrepo' );
 50+ }
4851 $pager = $listview->getPager();
4952
50 - if ( !is_null( $params['start'] ) )
 53+ if ( !is_null( $params['start'] ) ) {
5154 $pager->setOffset( $this->getDB()->timestamp( $params['start'] ) );
 55+ }
5256 $limit = $params['limit'];
5357 $pager->setLimit( $limit );
5458
@@ -78,36 +82,41 @@
7983
8084 private function formatRow( $row ) {
8185 $item = array();
82 - if ( isset( $this->props['revid'] ) )
 86+ if ( isset( $this->props['revid'] ) ) {
8387 $item['revid'] = $row->cc_rev_id;
84 - if ( isset( $this->props['timestamp'] ) )
 88+ }
 89+ if ( isset( $this->props['timestamp'] ) ) {
8590 $item['timestamp'] = wfTimestamp( TS_ISO_8601, $row->cc_timestamp );
86 - if ( isset( $this->props['user'] ) )
 91+ }
 92+ if ( isset( $this->props['user'] ) ) {
8793 $item['user'] = $row->cc_user_text;
88 - if ( isset( $this->props['revision'] ) || isset( $this->props['status'] ) )
 94+ }
 95+ if ( isset( $this->props['revision'] ) || isset( $this->props['status'] ) ) {
8996 $item['status'] = $row->cr_status;
90 - if ( isset( $this->props['text'] ) )
 97+ }
 98+ if ( isset( $this->props['text'] ) ) {
9199 ApiResult::setContent( $item, $row->cc_text );
 100+ }
92101 return $item;
93102 }
94103
95104 public function getAllowedParams() {
96 - return array (
 105+ return array(
97106 'repo' => null,
98 - 'limit' => array (
99 - ApiBase :: PARAM_DFLT => 10,
100 - ApiBase :: PARAM_TYPE => 'limit',
101 - ApiBase :: PARAM_MIN => 1,
102 - ApiBase :: PARAM_MAX => ApiBase :: LIMIT_BIG1,
103 - ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2
 107+ 'limit' => array(
 108+ ApiBase::PARAM_DFLT => 10,
 109+ ApiBase::PARAM_TYPE => 'limit',
 110+ ApiBase::PARAM_MIN => 1,
 111+ ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
 112+ ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
104113 ),
105114 'start' => array(
106 - ApiBase :: PARAM_TYPE => 'timestamp'
 115+ ApiBase::PARAM_TYPE => 'timestamp'
107116 ),
108 - 'prop' => array (
109 - ApiBase :: PARAM_ISMULTI => true,
110 - ApiBase :: PARAM_DFLT => 'timestamp|user|status|revid',
111 - ApiBase :: PARAM_TYPE => array (
 117+ 'prop' => array(
 118+ ApiBase::PARAM_ISMULTI => true,
 119+ ApiBase::PARAM_DFLT => 'timestamp|user|status|revid',
 120+ ApiBase::PARAM_TYPE => array(
112121 'timestamp',
113122 'user',
114123 'status',
@@ -131,7 +140,7 @@
132141 public function getDescription() {
133142 return 'List comments on revisions in CodeReview';
134143 }
135 -
 144+
136145 public function getPossibleErrors() {
137146 return array_merge( parent::getPossibleErrors(), array(
138147 array( 'missingparam', 'repo' ),
Index: trunk/extensions/CodeReview/api/ApiCodeDiff.php
@@ -69,7 +69,7 @@
7070 return array(
7171 'Fetch formatted diff from CodeReview\'s backing revision control system.' );
7272 }
73 -
 73+
7474 public function getPossibleErrors() {
7575 return array_merge( parent::getPossibleErrors(), array(
7676 array( 'code' => 'permissiondenied', 'info' => 'You don\'t have permission to view code diffs' ),
Index: trunk/extensions/CodeReview/api/ApiCodeUpdate.php
@@ -37,7 +37,7 @@
3838 if ( !$log ) {
3939 // FIXME: When and how often does this happen?
4040 // Should we use dieUsage() here instead?
41 - ApiBase::dieDebug( __METHOD__, "Something awry..." );
 41+ ApiBase::dieDebug( __METHOD__, 'Something awry...' );
4242 }
4343
4444 $result = array();
@@ -68,7 +68,7 @@
6969 // Discourage casual browsing :)
7070 return true;
7171 }
72 -
 72+
7373 public function isWriteMode() {
7474 return true;
7575 }
@@ -93,7 +93,7 @@
9494 return array(
9595 'Update CodeReview repository data from master revision control system.' );
9696 }
97 -
 97+
9898 public function getPossibleErrors() {
9999 return array_merge( parent::getPossibleErrors(), array(
100100 array( 'code' => 'permissiondenied', 'info' => 'You don\'t have permission update code' ),

Status & tagging log