Index: trunk/extensions/Translate/Translate.php |
— | — | @@ -85,6 +85,8 @@ |
86 | 86 | $wgAPIListModules['messagecollection'] = 'ApiQueryMessageCollection'; |
87 | 87 | $wgAPIMetaModules['messagegroups'] = 'ApiQueryMessageGroups'; |
88 | 88 | $wgAPIMetaModules['messagetranslations'] = 'ApiQueryMessageTranslations'; |
| 89 | +$wgAPIModules['translationreview'] = 'ApiTranslationReview'; |
| 90 | +$wgHooks['APIQueryInfoTokens'][] = 'ApiTranslationReview::injectTokenFunction'; |
89 | 91 | |
90 | 92 | // Register hooks. |
91 | 93 | $wgHooks['EditPage::showEditForm:initial'][] = 'TranslateEditAddons::addTools'; |
Index: trunk/extensions/Translate/_autoload.php |
— | — | @@ -193,4 +193,5 @@ |
194 | 194 | $wgAutoloadClasses['ApiQueryMessageCollection'] = $dir . 'api/ApiQueryMessageCollection.php'; |
195 | 195 | $wgAutoloadClasses['ApiQueryMessageGroups'] = $dir . 'api/ApiQueryMessageGroups.php'; |
196 | 196 | $wgAutoloadClasses['ApiQueryMessageTranslations'] = $dir . 'api/ApiQueryMessageTranslations.php'; |
| 197 | +$wgAutoloadClasses['ApiTranslationReview'] = $dir . 'api/ApiTranslationReview.php'; |
197 | 198 | /**@}*/ |
Index: trunk/extensions/Translate/api/ApiTranslationReview.php |
— | — | @@ -0,0 +1,132 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * API module for marking translations as reviewed |
| 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 marking translations as reviewed |
| 13 | + * |
| 14 | + * @ingroup API TranslateAPI |
| 15 | + */ |
| 16 | +class ApiTranslationReview extends ApiBase { |
| 17 | + |
| 18 | + public function execute() { |
| 19 | + global $wgUser; |
| 20 | + if ( !$wgUser->isallowed( 'translate-messagereview' ) ) { |
| 21 | + $this->dieUsageMsg( 'permissiondenied' ); |
| 22 | + } |
| 23 | + |
| 24 | + $params = $this->extractRequestParams(); |
| 25 | + |
| 26 | + $revision = Revision::newFromId( $params['revision'] ); |
| 27 | + if ( !$revision ) { |
| 28 | + $this->dieUsage( 'You made me sad :(', 'invalidrevision' ); |
| 29 | + } |
| 30 | + |
| 31 | + $title = $revision->getTitle(); |
| 32 | + $handle = new MessageHandle( $title ); |
| 33 | + if ( !$handle->isValid() ) { |
| 34 | + $this->dieUsage( 'You made me confused :X', 'unknownmessage' ); |
| 35 | + } |
| 36 | + |
| 37 | + $dbw = wfGetDB( DB_MASTER ); |
| 38 | + $table = 'translate_reviews'; |
| 39 | + $row = array( |
| 40 | + 'trr_user' => $wgUser->getId(), |
| 41 | + 'trr_page' => $revision->getPage(), |
| 42 | + 'trr_revision' => $revision->getId(), |
| 43 | + ); |
| 44 | + $options = array( 'IGNORE' ); |
| 45 | + $res = $dbw->insert( $table, $row, __METHOD__, $options ); |
| 46 | + if ( !$dbw->affectedRows() ) { |
| 47 | + $this->setWarning( 'Already marked as reviewed by you' ); |
| 48 | + } |
| 49 | + |
| 50 | + $output = array( 'review' => array( |
| 51 | + 'title' => $title->getPrefixedText(), |
| 52 | + 'pageid' => $revision->getPage(), |
| 53 | + 'revision' => $revision->getId() |
| 54 | + ) ); |
| 55 | + |
| 56 | + $this->getResult()->addValue( null, $this->getModuleName(), $output ); |
| 57 | + } |
| 58 | + |
| 59 | + public function isWriteMode() { |
| 60 | + return true; |
| 61 | + } |
| 62 | + |
| 63 | + public function needsToken() { |
| 64 | + return true; |
| 65 | + } |
| 66 | + |
| 67 | + public function getTokenSalt() { |
| 68 | + return 'translate-messagereview'; |
| 69 | + } |
| 70 | + |
| 71 | + public function getAllowedParams() { |
| 72 | + return array( |
| 73 | + 'revision' => array( |
| 74 | + ApiBase::PARAM_TYPE => 'integer', |
| 75 | + ApiBase::PARAM_REQUIRED => true, |
| 76 | + ), |
| 77 | + 'token' => array( |
| 78 | + ApiBase::PARAM_TYPE => 'string', |
| 79 | + ApiBase::PARAM_REQUIRED => true, |
| 80 | + ), |
| 81 | + ); |
| 82 | + } |
| 83 | + |
| 84 | + public function getParamDescription() { |
| 85 | + return array( |
| 86 | + 'revision' => 'The revision number to review', |
| 87 | + 'token' => 'A token previously acquired with prop=token&intoken=translationreview', |
| 88 | + ); |
| 89 | + } |
| 90 | + |
| 91 | + public function getDescription() { |
| 92 | + return 'Mark translations reviewed'; |
| 93 | + } |
| 94 | + |
| 95 | + public function getPossibleErrors() { |
| 96 | + return array_merge( parent::getPossibleErrors(), array( |
| 97 | + array( 'code' => 'permissiondenied', 'info' => 'You must have translate-messagereview right' ), |
| 98 | + array( 'code' => 'unknownmessage', 'info' => 'Title $1 does not belong to a message group' ), |
| 99 | + array( 'code' => 'invalidrevision', 'info' => 'Revision $1 is invalid' ), |
| 100 | + ) ); |
| 101 | + } |
| 102 | + |
| 103 | + public function getExamples() { |
| 104 | + return array( |
| 105 | + 'api.php?action=translationreview&revision=1&token=foo', |
| 106 | + ); |
| 107 | + } |
| 108 | + |
| 109 | + public function getVersion() { |
| 110 | + return __CLASS__ . ': $Id$'; |
| 111 | + } |
| 112 | + |
| 113 | + public static function getToken( $pageid, $title ) { |
| 114 | + global $wgUser; |
| 115 | + if ( !$wgUser->isAllowed( 'translate-messagereview' ) ) { |
| 116 | + return false; |
| 117 | + } |
| 118 | + |
| 119 | + static $cachedToken = null; |
| 120 | + if ( !is_null( $cachedToken ) ) { |
| 121 | + return $cachedToken; |
| 122 | + } |
| 123 | + |
| 124 | + $cachedToken = $wgUser->editToken( 'translate-messagereview' ); |
| 125 | + return $cachedToken; |
| 126 | + } |
| 127 | + |
| 128 | + public static function injectTokenFunction( &$list ) { |
| 129 | + $list['translationreview'] = array( __CLASS__, 'getToken' ); |
| 130 | + return true; // Hooks must return bool |
| 131 | + } |
| 132 | + |
| 133 | +} |
Property changes on: trunk/extensions/Translate/api/ApiTranslationReview.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 134 | + native |
Added: svn:keywords |
2 | 135 | + Id |