Index: branches/wmf/1.18wmf1/extensions/Translate/MessageCollection.php |
— | — | @@ -188,11 +188,13 @@ |
189 | 189 | |
190 | 190 | /** |
191 | 191 | * Loads all message data. Must be called before accessing the messages |
192 | | - * with ArrayAccess or iteration. |
| 192 | + * with ArrayAccess or iteration. Must be called before filtering for |
| 193 | + * $dbtype to have an effect. |
| 194 | + * @param $dbtype One of DB_* constants. |
193 | 195 | */ |
194 | | - public function loadTranslations() { |
195 | | - $this->loadData( $this->keys ); |
196 | | - $this->loadInfo( $this->keys ); |
| 196 | + public function loadTranslations( $dbtype = DB_SLAVE ) { |
| 197 | + $this->loadData( $this->keys, $dbtype ); |
| 198 | + $this->loadInfo( $this->keys, $dbtype ); |
197 | 199 | $this->initMessages(); |
198 | 200 | } |
199 | 201 | |
— | — | @@ -476,8 +478,9 @@ |
477 | 479 | /** |
478 | 480 | * Loads existence and fuzzy state for given list of keys. |
479 | 481 | * @param $keys \list{String} List of keys in database format. |
| 482 | + * @param $dbtype One of DB_* constants. |
480 | 483 | */ |
481 | | - protected function loadInfo( array $keys ) { |
| 484 | + protected function loadInfo( array $keys, $dbtype = DB_SLAVE ) { |
482 | 485 | if ( $this->dbInfo !== null ) { |
483 | 486 | return; |
484 | 487 | } |
— | — | @@ -488,7 +491,7 @@ |
489 | 492 | return; |
490 | 493 | } |
491 | 494 | |
492 | | - $dbr = wfGetDB( DB_SLAVE ); |
| 495 | + $dbr = wfGetDB( $dbtype ); |
493 | 496 | |
494 | 497 | $tables = array( 'page', 'revtag' ); |
495 | 498 | $fields = array( 'page_title', 'rt_type' ); |
— | — | @@ -509,8 +512,9 @@ |
510 | 513 | /** |
511 | 514 | * Loads translation for given list of keys. |
512 | 515 | * @param $keys \list{String} List of keys in database format. |
| 516 | + * @param $dbtype One of DB_* constants. |
513 | 517 | */ |
514 | | - protected function loadData( $keys ) { |
| 518 | + protected function loadData( $keys, $dbtype = DB_SLAVE ) { |
515 | 519 | if ( $this->dbData !== null ) { |
516 | 520 | return; |
517 | 521 | } |
— | — | @@ -521,7 +525,7 @@ |
522 | 526 | return; |
523 | 527 | } |
524 | 528 | |
525 | | - $dbr = wfGetDB( DB_SLAVE ); |
| 529 | + $dbr = wfGetDB( $dbtype ); |
526 | 530 | |
527 | 531 | $tables = array( 'page', 'revision', 'text' ); |
528 | 532 | $fields = array( 'page_title', 'rev_user_text', 'old_flags', 'old_text' ); |
Index: branches/wmf/1.18wmf1/extensions/Translate/tag/RenderJob.php |
— | — | @@ -51,6 +51,7 @@ |
52 | 52 | |
53 | 53 | $group = $page->getMessageGroup(); |
54 | 54 | $collection = $group->initCollection( $code ); |
| 55 | + $collection->loadTranslations( DB_MASTER ); |
55 | 56 | |
56 | 57 | $text = $page->getParse()->getTranslationPageText( $collection ); |
57 | 58 | |
Index: branches/wmf/1.18wmf1/extensions/Translate/tag/TPParse.php |
— | — | @@ -177,7 +177,7 @@ |
178 | 178 | // For finding the messages |
179 | 179 | $prefix = $this->title->getPrefixedDBKey() . '/'; |
180 | 180 | |
181 | | - if ( $collection instanceOf MessageCollection ) { |
| 181 | + if ( $collection instanceof MessageCollection ) { |
182 | 182 | $collection->filter( 'hastranslation', false ); |
183 | 183 | $collection->loadTranslations(); |
184 | 184 | } |
Index: branches/wmf/1.18wmf1/extensions/Translate/Translate.php |
— | — | @@ -84,6 +84,7 @@ |
85 | 85 | // API |
86 | 86 | $wgAPIListModules['messagecollection'] = 'ApiQueryMessageCollection'; |
87 | 87 | $wgAPIMetaModules['messagegroups'] = 'ApiQueryMessageGroups'; |
| 88 | +$wgAPIMetaModules['messagetranslations'] = 'ApiQueryMessageTranslations'; |
88 | 89 | |
89 | 90 | // Register hooks. |
90 | 91 | $wgHooks['EditPage::showEditForm:initial'][] = 'TranslateEditAddons::addTools'; |
Index: branches/wmf/1.18wmf1/extensions/Translate/_autoload.php |
— | — | @@ -192,4 +192,5 @@ |
193 | 193 | */ |
194 | 194 | $wgAutoloadClasses['ApiQueryMessageCollection'] = $dir . 'api/ApiQueryMessageCollection.php'; |
195 | 195 | $wgAutoloadClasses['ApiQueryMessageGroups'] = $dir . 'api/ApiQueryMessageGroups.php'; |
| 196 | +$wgAutoloadClasses['ApiQueryMessageTranslations'] = $dir . 'api/ApiQueryMessageTranslations.php'; |
196 | 197 | /**@}*/ |
Index: branches/wmf/1.18wmf1/extensions/Translate/api/ApiQueryMessageTranslations.php |
— | — | @@ -0,0 +1,134 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Api module for querying message translations. |
| 5 | + * |
| 6 | + * @file |
| 7 | + * @author Niklas Laxström |
| 8 | + * @copyright Copyright © 2011, Niklas Laxström |
| 9 | + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
| 10 | + */ |
| 11 | + |
| 12 | +/** |
| 13 | + * Api module for querying message translations. |
| 14 | + * |
| 15 | + * @ingroup API TranslateAPI |
| 16 | + */ |
| 17 | +class ApiQueryMessageTranslations extends ApiQueryBase { |
| 18 | + |
| 19 | + public function __construct( $query, $moduleName ) { |
| 20 | + parent::__construct( $query, $moduleName, 'mt' ); |
| 21 | + } |
| 22 | + |
| 23 | + public function getCacheMode( $params ) { |
| 24 | + return 'public'; |
| 25 | + } |
| 26 | + |
| 27 | + public function execute() { |
| 28 | + $params = $this->extractRequestParams(); |
| 29 | + |
| 30 | + $title = Title::newFromText( $params['title'] ); |
| 31 | + if ( !$title ) { |
| 32 | + $this->dieUsage( 'Invalid title' ); |
| 33 | + } |
| 34 | + |
| 35 | + $handle = new MessageHandle( $title ); |
| 36 | + if ( !$handle->isValid() ) { |
| 37 | + $this->dieUsage( 'Title does not correspond to a translatable message' ); |
| 38 | + } |
| 39 | + |
| 40 | + $base = Title::makeTitle( $title->getNamespace(), $handle->getKey() ); |
| 41 | + $namespace = $base->getNamespace(); |
| 42 | + $message = $base->getDBKey(); |
| 43 | + |
| 44 | + $dbr = wfGetDB( DB_SLAVE ); |
| 45 | + |
| 46 | + $res = $dbr->select( 'page', |
| 47 | + array( 'page_namespace', 'page_title' ), |
| 48 | + array( |
| 49 | + 'page_namespace' => $namespace, |
| 50 | + 'page_title ' . $dbr->buildLike( "$message/", $dbr->anyString() ), |
| 51 | + ), |
| 52 | + __METHOD__, |
| 53 | + array( |
| 54 | + 'ORDER BY' => 'page_title', |
| 55 | + 'USE INDEX' => 'name_title', |
| 56 | + ) |
| 57 | + ); |
| 58 | + |
| 59 | + $titles = array(); |
| 60 | + foreach ( $res as $row ) { |
| 61 | + $titles[] = $row->page_title; |
| 62 | + } |
| 63 | + $pageInfo = TranslateUtils::getContents( $titles, $namespace ); |
| 64 | + |
| 65 | + $result = $this->getResult(); |
| 66 | + $pages = array(); |
| 67 | + $count = 0; |
| 68 | + |
| 69 | + foreach ( $pageInfo as $key => $info ) { |
| 70 | + if ( ++$count <= $params['offset'] ) { |
| 71 | + continue; |
| 72 | + } |
| 73 | + |
| 74 | + $tTitle = Title::makeTitle( $namespace, $key ); |
| 75 | + $tHandle = new MessageHandle( $tTitle ); |
| 76 | + |
| 77 | + $data = array( |
| 78 | + 'title' => $tTitle->getPrefixedText(), |
| 79 | + 'language' => $tHandle->getCode(), |
| 80 | + 'lasttranslator' => $info[1], |
| 81 | + ); |
| 82 | + |
| 83 | + $fuzzy = MessageHandle::hasFuzzyString( $info[0] ) || $tHandle->isFuzzy(); |
| 84 | + |
| 85 | + if ( $fuzzy ) { |
| 86 | + $data['fuzzy'] = 'fuzzy'; |
| 87 | + } |
| 88 | + |
| 89 | + $translation = str_replace( TRANSLATE_FUZZY, '', $info[0] ); |
| 90 | + $result->setContent( $data, $translation ); |
| 91 | + |
| 92 | + $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $data ); |
| 93 | + if ( !$fit ) { |
| 94 | + $this->setContinueEnumParameter( 'offset', $count ); |
| 95 | + break; |
| 96 | + } |
| 97 | + |
| 98 | + } |
| 99 | + |
| 100 | + $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'message' ); |
| 101 | + } |
| 102 | + |
| 103 | + public function getAllowedParams() { |
| 104 | + return array( |
| 105 | + 'title' => array( |
| 106 | + ApiBase::PARAM_TYPE => 'string', |
| 107 | + ApiBase::PARAM_REQUIRED => true, |
| 108 | + ), |
| 109 | + 'offset' => array( |
| 110 | + ApiBase::PARAM_DFLT => 0, |
| 111 | + ApiBase::PARAM_TYPE => 'integer', |
| 112 | + ), |
| 113 | + ); |
| 114 | + } |
| 115 | + |
| 116 | + public function getParamDescription() { |
| 117 | + return array( |
| 118 | + 'title' => 'Full title of a known message', |
| 119 | + ); |
| 120 | + } |
| 121 | + |
| 122 | + public function getDescription() { |
| 123 | + return 'Query all translations for a single message'; |
| 124 | + } |
| 125 | + |
| 126 | + protected function getExamples() { |
| 127 | + return array( |
| 128 | + "api.php?action=query&meta=messagetranslations&mttitle=MediaWiki:January List of translations in the wiki for MediaWiki:January", |
| 129 | + ); |
| 130 | + } |
| 131 | + |
| 132 | + public function getVersion() { |
| 133 | + return __CLASS__ . ': $Id$'; |
| 134 | + } |
| 135 | +} |
Property changes on: branches/wmf/1.18wmf1/extensions/Translate/api/ApiQueryMessageTranslations.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 136 | + native |
Added: svn:keywords |
2 | 137 | + Id |
Property changes on: branches/wmf/1.18wmf1/extensions/Translate |
___________________________________________________________________ |
Modified: svn:mergeinfo |
3 | 138 | Merged /trunk/translatewiki:r99673,99762-99764 |