Index: trunk/extensions/LiveTranslate/LiveTranslate.php |
— | — | @@ -50,6 +50,7 @@ |
51 | 51 | $wgAutoloadClasses['ApiImportTranslationMemories'] = $egLiveTranslateIP . '/api/ApiImportTranslationMemories.php'; |
52 | 52 | $wgAutoloadClasses['ApiLiveTranslate'] = $egLiveTranslateIP . '/api/ApiLiveTranslate.php'; |
53 | 53 | $wgAutoloadClasses['ApiQueryLiveTranslate'] = $egLiveTranslateIP . '/api/ApiQueryLiveTranslate.php'; |
| 54 | +$wgAutoloadClasses['ApiQueryTranslationMemories'] = $egLiveTranslateIP . '/api/ApiQueryTranslationMemories.php'; |
54 | 55 | |
55 | 56 | $incDirIP = $egLiveTranslateIP . '/includes/'; |
56 | 57 | $wgAutoloadClasses['LiveTranslateFunctions'] = $incDirIP . 'LiveTranslate_Functions.php'; |
— | — | @@ -69,6 +70,7 @@ |
70 | 71 | $wgAPIModules['importtms'] = 'ApiImportTranslationMemories'; |
71 | 72 | $wgAPIModules['livetranslate'] = 'ApiLiveTranslate'; |
72 | 73 | $wgAPIListModules['livetranslate'] = 'ApiQueryLiveTranslate'; |
| 74 | +$wgAPIListModules['translationmemories'] = 'ApiQueryTranslationMemories'; |
73 | 75 | |
74 | 76 | $wgHooks['ArticleViewHeader'][] = 'LiveTranslateHooks::onArticleViewHeader'; |
75 | 77 | $wgHooks['LoadExtensionSchemaUpdates'][] = 'LiveTranslateHooks::onSchemaUpdate'; |
Index: trunk/extensions/LiveTranslate/RELEASE-NOTES |
— | — | @@ -7,6 +7,7 @@ |
8 | 8 | === Version 1.2 === |
9 | 9 | 2011-xx-xx |
10 | 10 | |
| 11 | +* Added API module to query translation memories. |
11 | 12 | * Added i18n alias file. |
12 | 13 | * Added TMX admin user rights group. |
13 | 14 | |
Index: trunk/extensions/LiveTranslate/api/ApiQueryLiveTranslate.php |
— | — | @@ -8,6 +8,7 @@ |
9 | 9 | * @file ApiQueryLiveTranslate.php |
10 | 10 | * @ingroup LiveTranslate |
11 | 11 | * |
| 12 | + * @licence GNU GPL v3+ |
12 | 13 | * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
13 | 14 | */ |
14 | 15 | 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 |
1 | 154 | + native |
Index: trunk/extensions/LiveTranslate/LiveTranslate.sql |
— | — | @@ -15,7 +15,7 @@ |
16 | 16 | CREATE TABLE IF NOT EXISTS /*$wgDBprefix*/live_translate_memories ( |
17 | 17 | memory_id INT(4) unsigned NOT NULL auto_increment PRIMARY KEY, |
18 | 18 | memory_type INT(2) unsigned NOT NULL, |
19 | | - memory_location VARCHAR(255) NOT NULL, |
| 19 | + memory_location VARCHAR(255) NOT NULL, |
20 | 20 | memory_local INT(1) unsigned NOT NULL, |
21 | 21 | memory_lang_count INT(2) unsigned NOT NULL, |
22 | 22 | memory_tu_count INT(8) unsigned NOT NULL, |