r101613 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r101612‎ | r101613 | r101614 >
Date:10:59, 2 November 2011
Author:nikerabbit
Status:ok
Tags:
Comment:
Api module for group review
Internationalization/#174
Modified paths:
  • /trunk/extensions/Translate/Translate.php (modified) (history)
  • /trunk/extensions/Translate/_autoload.php (modified) (history)
  • /trunk/extensions/Translate/api/ApiGroupReview.php (added) (history)

Diff [purge]

Index: trunk/extensions/Translate/Translate.php
@@ -86,7 +86,9 @@
8787 $wgAPIMetaModules['messagegroups'] = 'ApiQueryMessageGroups';
8888 $wgAPIMetaModules['messagetranslations'] = 'ApiQueryMessageTranslations';
8989 $wgAPIModules['translationreview'] = 'ApiTranslationReview';
 90+$wgAPIModules['groupreview'] = 'ApiGroupReview';
9091 $wgHooks['APIQueryInfoTokens'][] = 'ApiTranslationReview::injectTokenFunction';
 92+$wgHooks['APIQueryInfoTokens'][] = 'ApiGroupReview::injectTokenFunction';
9193
9294 // Register hooks.
9395 $wgHooks['EditPage::showEditForm:initial'][] = 'TranslateEditAddons::addTools';
Index: trunk/extensions/Translate/_autoload.php
@@ -194,4 +194,5 @@
195195 $wgAutoloadClasses['ApiQueryMessageGroups'] = $dir . 'api/ApiQueryMessageGroups.php';
196196 $wgAutoloadClasses['ApiQueryMessageTranslations'] = $dir . 'api/ApiQueryMessageTranslations.php';
197197 $wgAutoloadClasses['ApiTranslationReview'] = $dir . 'api/ApiTranslationReview.php';
 198+$wgAutoloadClasses['ApiGroupReview'] = $dir . 'api/ApiGroupReview.php';
198199 /**@}*/
Index: trunk/extensions/Translate/api/ApiGroupReview.php
@@ -0,0 +1,154 @@
 2+<?php
 3+/**
 4+ * API module for switching workflow states for message groups
 5+ * @file
 6+ * @author Niklas Laxström
 7+ * @copyright Copyright © 2011, Niklas Laxström
 8+ * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
 9+ */
 10+
 11+/**
 12+ * API module for switching workflow states for message groups
 13+ *
 14+ * @ingroup API TranslateAPI
 15+ */
 16+class ApiGroupReview extends ApiBase {
 17+ protected static $right = 'translate-groupreview';
 18+
 19+ public function execute() {
 20+ global $wgUser, $wgTranslateWorkflowStates;
 21+ if ( !count( $wgTranslateWorkflowStates ) ) {
 22+ $this->dieUsage( 'Message group review not in use', 'disabled' );
 23+ }
 24+
 25+ if ( !$wgUser->isallowed( self::$right ) ) {
 26+ $this->dieUsage( 'Permission denied', 'permissiondenied' );
 27+ }
 28+
 29+ $params = $this->extractRequestParams();
 30+
 31+ $group = MessageGroups::getGroup( $params['group'] );
 32+ if ( !$group ) {
 33+ $this->dieUsageMsg( array( 'missingparam', 'group' ) );
 34+ }
 35+
 36+ $languages = Language::getLanguageNames( false );
 37+ if ( !isset( $languages[$params['language']] ) ) {
 38+ $this->dieUsageMsg( array( 'missingparam', 'language' ) );
 39+ }
 40+
 41+ $dbw = wfGetDB( DB_MASTER );
 42+ $table = 'translate_groupreviews';
 43+ $row = array(
 44+ 'tgr_group' => $group->getId(),
 45+ 'tgr_lang' => $params['language'],
 46+ 'tgr_state' => $params['state'],
 47+ );
 48+ $index = array( 'tgr_group', 'tgr_language' );
 49+ $res = $dbw->replace( $table, array( $index ), $row, __METHOD__ );
 50+
 51+ /* Will be implemented later
 52+ $logger = new LogPage( 'translationreview' );
 53+ $params = array( $revision->getId() );
 54+ $logger->addEntry( 'group', $title, null, $params, $wgUser );
 55+ */
 56+
 57+ $output = array( 'review' => array(
 58+ 'group' => $group->getId(),
 59+ 'language' => $params['language'],
 60+ 'state' => $params['state'],
 61+ ) );
 62+
 63+ $this->getResult()->addValue( null, $this->getModuleName(), $output );
 64+ }
 65+
 66+ public function isWriteMode() {
 67+ return true;
 68+ }
 69+
 70+ public function needsToken() {
 71+ return true;
 72+ }
 73+
 74+ public function getTokenSalt() {
 75+ return 'translate-groupreview';
 76+ }
 77+
 78+ public function getAllowedParams() {
 79+ global $wgTranslateWorkflowStates;
 80+ return array(
 81+ 'group' => array(
 82+ ApiBase::PARAM_TYPE => array_keys( MessageGroups::getAllGroups() ),
 83+ ApiBase::PARAM_REQUIRED => true,
 84+ ),
 85+ 'language' => array(
 86+ ApiBase::PARAM_TYPE => 'string',
 87+ ApiBase::PARAM_DFLT => 'en',
 88+ ),
 89+ 'state' => array(
 90+ ApiBase::PARAM_TYPE => array_values( $wgTranslateWorkflowStates ),
 91+ ApiBase::PARAM_REQUIRED => true,
 92+ ),
 93+ 'token' => array(
 94+ ApiBase::PARAM_TYPE => 'string',
 95+ ApiBase::PARAM_REQUIRED => true,
 96+ ),
 97+ );
 98+ }
 99+
 100+ public function getParamDescription() {
 101+ return array(
 102+ 'group' => 'Message group',
 103+ 'language' => 'Language code',
 104+ 'state' => 'The new state for the group',
 105+ 'token' => 'A token previously acquired with action=query&prop=info&intoken=groupreview',
 106+ );
 107+ }
 108+
 109+ public function getDescription() {
 110+ return 'Set message group workflow states';
 111+ }
 112+
 113+ public function getPossibleErrors() {
 114+ $right = self::$right;
 115+ return array_merge( parent::getPossibleErrors(), array(
 116+ array( 'code' => 'permissiondenied', 'info' => "You must have $right right" ),
 117+ array( 'code' => 'disabled', 'info' => "Message group workflows are not in use" ),
 118+ ) );
 119+ }
 120+
 121+ public function getExamples() {
 122+ global $wgTranslateWorkflowStates;
 123+ $groups = MessageGroups::getAllGroups();
 124+ $group = key( $groups );
 125+ $state = current( $wgTranslateWorkflowStates );
 126+ return array(
 127+ "api.php?action=groupreview&group=$group&language=de&state=$state",
 128+ );
 129+ }
 130+
 131+ public function getVersion() {
 132+ return __CLASS__ . ': $Id: $';
 133+ }
 134+
 135+ public static function getToken( $pageid, $title ) {
 136+ global $wgUser;
 137+ if ( !$wgUser->isAllowed( self::$right ) ) {
 138+ return false;
 139+ }
 140+
 141+ static $cachedToken = null;
 142+ if ( !is_null( $cachedToken ) ) {
 143+ return $cachedToken;
 144+ }
 145+
 146+ $cachedToken = $wgUser->editToken( $this->getTokenSalt() );
 147+ return $cachedToken;
 148+ }
 149+
 150+ public static function injectTokenFunction( &$list ) {
 151+ $list['groupreview'] = array( __CLASS__, 'getToken' );
 152+ return true; // Hooks must return bool
 153+ }
 154+
 155+}
Property changes on: trunk/extensions/Translate/api/ApiGroupReview.php
___________________________________________________________________
Added: svn:eol-style
1156 + native

Follow-up revisions

RevisionCommit summaryAuthorDate
r101622Fix fatal errors in r101612 and r101613nikerabbit13:15, 2 November 2011

Status & tagging log