Index: trunk/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: trunk/extensions/Translate/README |
— | — | @@ -29,6 +29,8 @@ |
30 | 30 | http://translatewiki.net/docs/Translate/html/ |
31 | 31 | |
32 | 32 | == Change log == |
| 33 | +* 2011-10-14 |
| 34 | +- New API module: messagetranslations |
33 | 35 | * 2011-10-12 |
34 | 36 | - Multiple bug fixes and improvements to translatable page moving feature |
35 | 37 | * 2011-10-07 |
Index: trunk/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: trunk/extensions/Translate/api/ApiQueryMessageTranslations.php |
— | — | @@ -0,0 +1,131 @@ |
| 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 | + |
| 71 | + $tTitle = Title::makeTitle( $namespace, $key ); |
| 72 | + $tHandle = new MessageHandle( $tTitle ); |
| 73 | + |
| 74 | + $data = array( |
| 75 | + 'title' => $tTitle->getPrefixedText(), |
| 76 | + 'language' => $tHandle->getCode(), |
| 77 | + 'lasttranslator' => $info[1], |
| 78 | + ); |
| 79 | + |
| 80 | + $fuzzy = MessageHandle::hasFuzzyString( $info[0] ) || $tHandle->isFuzzy(); |
| 81 | + |
| 82 | + if ( $fuzzy ) { |
| 83 | + $data['fuzzy'] = 'fuzzy'; |
| 84 | + } |
| 85 | + |
| 86 | + $translation = str_replace( TRANSLATE_FUZZY, '', $info[0] ); |
| 87 | + $result->setContent( $data, $translation ); |
| 88 | + |
| 89 | + $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $data ); |
| 90 | + if ( !$fit ) { |
| 91 | + $this->setContinueEnumParameter( 'offset', $params['offset'] + $count - 1 ); |
| 92 | + break; |
| 93 | + } |
| 94 | + |
| 95 | + } |
| 96 | + |
| 97 | + $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), 'message' ); |
| 98 | + } |
| 99 | + |
| 100 | + public function getAllowedParams() { |
| 101 | + return array( |
| 102 | + 'title' => array( |
| 103 | + ApiBase::PARAM_TYPE => 'string', |
| 104 | + ApiBase::PARAM_REQUIRED => true, |
| 105 | + ), |
| 106 | + 'offset' => array( |
| 107 | + ApiBase::PARAM_DFLT => 0, |
| 108 | + ApiBase::PARAM_TYPE => 'integer', |
| 109 | + ), |
| 110 | + ); |
| 111 | + } |
| 112 | + |
| 113 | + public function getParamDescription() { |
| 114 | + return array( |
| 115 | + 'title' => 'Full title of a known message', |
| 116 | + ); |
| 117 | + } |
| 118 | + |
| 119 | + public function getDescription() { |
| 120 | + return 'Query all translations for a single message'; |
| 121 | + } |
| 122 | + |
| 123 | + protected function getExamples() { |
| 124 | + return array( |
| 125 | + "api.php?action=query&meta=messagetranslations&title=MediaWiki:January List of translations in the wiki for MediaWiki:January", |
| 126 | + ); |
| 127 | + } |
| 128 | + |
| 129 | + public function getVersion() { |
| 130 | + return __CLASS__ . ': $Id$'; |
| 131 | + } |
| 132 | +} |
Property changes on: trunk/extensions/Translate/api/ApiQueryMessageTranslations.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 133 | + native |
Added: svn:keywords |
2 | 134 | + Id |