r93667 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r93666‎ | r93667 | r93668 >
Date:22:47, 1 August 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
added API module to query translation memories
Modified paths:
  • /trunk/extensions/LiveTranslate/LiveTranslate.php (modified) (history)
  • /trunk/extensions/LiveTranslate/LiveTranslate.sql (modified) (history)
  • /trunk/extensions/LiveTranslate/RELEASE-NOTES (modified) (history)
  • /trunk/extensions/LiveTranslate/api/ApiQueryLiveTranslate.php (modified) (history)
  • /trunk/extensions/LiveTranslate/api/ApiQueryTranslationMemories.php (added) (history)

Diff [purge]

Index: trunk/extensions/LiveTranslate/LiveTranslate.php
@@ -50,6 +50,7 @@
5151 $wgAutoloadClasses['ApiImportTranslationMemories'] = $egLiveTranslateIP . '/api/ApiImportTranslationMemories.php';
5252 $wgAutoloadClasses['ApiLiveTranslate'] = $egLiveTranslateIP . '/api/ApiLiveTranslate.php';
5353 $wgAutoloadClasses['ApiQueryLiveTranslate'] = $egLiveTranslateIP . '/api/ApiQueryLiveTranslate.php';
 54+$wgAutoloadClasses['ApiQueryTranslationMemories'] = $egLiveTranslateIP . '/api/ApiQueryTranslationMemories.php';
5455
5556 $incDirIP = $egLiveTranslateIP . '/includes/';
5657 $wgAutoloadClasses['LiveTranslateFunctions'] = $incDirIP . 'LiveTranslate_Functions.php';
@@ -69,6 +70,7 @@
7071 $wgAPIModules['importtms'] = 'ApiImportTranslationMemories';
7172 $wgAPIModules['livetranslate'] = 'ApiLiveTranslate';
7273 $wgAPIListModules['livetranslate'] = 'ApiQueryLiveTranslate';
 74+$wgAPIListModules['translationmemories'] = 'ApiQueryTranslationMemories';
7375
7476 $wgHooks['ArticleViewHeader'][] = 'LiveTranslateHooks::onArticleViewHeader';
7577 $wgHooks['LoadExtensionSchemaUpdates'][] = 'LiveTranslateHooks::onSchemaUpdate';
Index: trunk/extensions/LiveTranslate/RELEASE-NOTES
@@ -7,6 +7,7 @@
88 === Version 1.2 ===
99 2011-xx-xx
1010
 11+* Added API module to query translation memories.
1112 * Added i18n alias file.
1213 * Added TMX admin user rights group.
1314
Index: trunk/extensions/LiveTranslate/api/ApiQueryLiveTranslate.php
@@ -8,6 +8,7 @@
99 * @file ApiQueryLiveTranslate.php
1010 * @ingroup LiveTranslate
1111 *
 12+ * @licence GNU GPL v3+
1213 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1314 */
1415 class ApiQueryLiveTranslate extends ApiQueryBase {
Index: trunk/extensions/LiveTranslate/api/ApiQueryTranslationMemories.php
@@ -0,0 +1,152 @@
 2+<?php
 3+
 4+/**
 5+ * API module to get a list of translation memories.
 6+ *
 7+ * @since 1.2
 8+ *
 9+ * @file ApiQueryLiveTranslate.php
 10+ * @ingroup LiveTranslate
 11+ *
 12+ * @licence GNU GPL v3+
 13+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
 14+ */
 15+class ApiQueryTranslationMemories extends ApiQueryBase {
 16+
 17+ public function __construct( $main, $action ) {
 18+ parent :: __construct( $main, $action, 'qtm' );
 19+ }
 20+
 21+ /**
 22+ * Retrieve the specil words from the database.
 23+ */
 24+ public function execute() {
 25+ // Get the requests parameters.
 26+ $params = $this->extractRequestParams();
 27+
 28+ $this->addTables( 'live_translate_memories' );
 29+
 30+ foreach ( $params['props'] as &$prop ) {
 31+ $prop = "memory_$prop";
 32+ }
 33+
 34+ $this->addFields( $params['props'] );
 35+
 36+ if ( count( $params['ids'] ) > 0 ) {
 37+ $this->addWhere( array(
 38+ 'memory_id' => $params['ids']
 39+ ) );
 40+ }
 41+
 42+ if ( !is_null( $params['continue'] ) ) {
 43+ $dbr = wfGetDB( DB_SLAVE );
 44+ $this->addWhere( 'memory_id >= ' . $dbr->addQuotes( $params['continue'] ) );
 45+ }
 46+
 47+ $this->addOption( 'LIMIT', $params['limit'] + 1 );
 48+ $this->addOption( 'ORDER BY', 'memory_id ASC' );
 49+
 50+ $memories = $this->select( __METHOD__ );
 51+ $resultMemories = array();
 52+ $count = 0;
 53+
 54+ while ( $memory = $memories->fetchObject() ) {
 55+ if ( ++$count > $params['limit'] ) {
 56+ // We've reached the one extra which shows that
 57+ // there are additional pages to be had. Stop here...
 58+ $this->setContinueEnumParameter( 'continue', $memory->memory_id );
 59+ break;
 60+ }
 61+
 62+ $resultMemories[$memory->memory_id] = (array)$memory;
 63+ }
 64+
 65+ $this->getResult()->setIndexedTagName( $resultMemories, 'memory' );
 66+
 67+ $this->getResult()->addValue(
 68+ null,
 69+ 'memories',
 70+ $resultMemories
 71+ );
 72+ }
 73+
 74+ /**
 75+ * (non-PHPdoc)
 76+ * @see includes/api/ApiBase#getAllowedParams()
 77+ */
 78+ public function getAllowedParams() {
 79+ return array (
 80+ 'props' => array(
 81+ ApiBase::PARAM_DFLT => 'id|type|location|local|lang_count|tu_count|version_hash',
 82+ ApiBase::PARAM_ISMULTI => true,
 83+ ApiBase::PARAM_TYPE => array(
 84+ 'id',
 85+ 'type',
 86+ 'location',
 87+ 'local',
 88+ 'lang_count',
 89+ 'tu_count',
 90+ 'version_hash',
 91+ ),
 92+ ),
 93+ 'ids' => array(
 94+ ApiBase::PARAM_DFLT => '',
 95+ ApiBase::PARAM_ISMULTI => true,
 96+ ApiBase::PARAM_TYPE => 'integer',
 97+ ),
 98+ 'limit' => array(
 99+ ApiBase :: PARAM_DFLT => 500,
 100+ ApiBase :: PARAM_TYPE => 'limit',
 101+ ApiBase :: PARAM_MIN => 1,
 102+ ApiBase :: PARAM_MAX => ApiBase :: LIMIT_BIG1,
 103+ ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2
 104+ ),
 105+ 'continue' => null,
 106+ );
 107+ }
 108+
 109+ /**
 110+ * (non-PHPdoc)
 111+ * @see includes/api/ApiBase#getParamDescription()
 112+ */
 113+ public function getParamDescription() {
 114+ return array (
 115+ 'props' => 'Translation memory properties to query',
 116+ 'ids' => 'Limit the results to translation memories with an ID in this list',
 117+ 'continue' => 'Offset number from where to continue the query',
 118+ 'limit' => 'Max amount of words to return',
 119+ );
 120+ }
 121+
 122+ /**
 123+ * (non-PHPdoc)
 124+ * @see includes/api/ApiBase#getDescription()
 125+ */
 126+ public function getDescription() {
 127+ return 'This module returns all matching translation memories';
 128+ }
 129+
 130+ /**
 131+ * (non-PHPdoc)
 132+ * @see includes/api/ApiBase#getPossibleErrors()
 133+ */
 134+ public function getPossibleErrors() {
 135+ return array_merge( parent::getPossibleErrors(), array(
 136+ ) );
 137+ }
 138+
 139+ /**
 140+ * (non-PHPdoc)
 141+ * @see includes/api/ApiBase#getExamples()
 142+ */
 143+ protected function getExamples() {
 144+ return array (
 145+ 'api.php?action=query&list=translationmemories',
 146+ );
 147+ }
 148+
 149+ public function getVersion() {
 150+ return __CLASS__ . ': $Id: $';
 151+ }
 152+
 153+}
Property changes on: trunk/extensions/LiveTranslate/api/ApiQueryTranslationMemories.php
___________________________________________________________________
Added: svn:eol-style
1154 + native
Index: trunk/extensions/LiveTranslate/LiveTranslate.sql
@@ -15,7 +15,7 @@
1616 CREATE TABLE IF NOT EXISTS /*$wgDBprefix*/live_translate_memories (
1717 memory_id INT(4) unsigned NOT NULL auto_increment PRIMARY KEY,
1818 memory_type INT(2) unsigned NOT NULL,
19 - memory_location VARCHAR(255) NOT NULL,
 19+ memory_location VARCHAR(255) NOT NULL,
2020 memory_local INT(1) unsigned NOT NULL,
2121 memory_lang_count INT(2) unsigned NOT NULL,
2222 memory_tu_count INT(8) unsigned NOT NULL,

Status & tagging log