http://www.mediawiki.org/wiki/Special:Code/MediaWiki/99762
Revision: 99762
Author: nikerabbit
Date: 2011-10-14 09:54:47 +0000 (Fri, 14 Oct 2011)
Log Message:
-----------
New API module: messagetranslations
Modified Paths:
--------------
trunk/extensions/Translate/README
trunk/extensions/Translate/Translate.php
trunk/extensions/Translate/_autoload.php
Added Paths:
-----------
trunk/extensions/Translate/api/ApiQueryMessageTranslations.php
Modified: trunk/extensions/Translate/README
===================================================================
--- trunk/extensions/Translate/README 2011-10-14 08:16:31 UTC (rev 99761)
+++ trunk/extensions/Translate/README 2011-10-14 09:54:47 UTC (rev 99762)
@@ -29,6 +29,8 @@
http://translatewiki.net/docs/Translate/html/
== Change log ==
+* 2011-10-14
+- New API module: messagetranslations
* 2011-10-12
- Multiple bug fixes and improvements to translatable page moving feature
* 2011-10-07
Modified: trunk/extensions/Translate/Translate.php
===================================================================
--- trunk/extensions/Translate/Translate.php 2011-10-14 08:16:31 UTC (rev
99761)
+++ trunk/extensions/Translate/Translate.php 2011-10-14 09:54:47 UTC (rev
99762)
@@ -84,6 +84,7 @@
// API
$wgAPIListModules['messagecollection'] = 'ApiQueryMessageCollection';
$wgAPIMetaModules['messagegroups'] = 'ApiQueryMessageGroups';
+$wgAPIMetaModules['messagetranslations'] = 'ApiQueryMessageTranslations';
// Register hooks.
$wgHooks['EditPage::showEditForm:initial'][] = 'TranslateEditAddons::addTools';
Modified: trunk/extensions/Translate/_autoload.php
===================================================================
--- trunk/extensions/Translate/_autoload.php 2011-10-14 08:16:31 UTC (rev
99761)
+++ trunk/extensions/Translate/_autoload.php 2011-10-14 09:54:47 UTC (rev
99762)
@@ -192,4 +192,5 @@
*/
$wgAutoloadClasses['ApiQueryMessageCollection'] = $dir .
'api/ApiQueryMessageCollection.php';
$wgAutoloadClasses['ApiQueryMessageGroups'] = $dir .
'api/ApiQueryMessageGroups.php';
+$wgAutoloadClasses['ApiQueryMessageTranslations'] = $dir .
'api/ApiQueryMessageTranslations.php';
/**@}*/
Added: trunk/extensions/Translate/api/ApiQueryMessageTranslations.php
===================================================================
--- trunk/extensions/Translate/api/ApiQueryMessageTranslations.php
(rev 0)
+++ trunk/extensions/Translate/api/ApiQueryMessageTranslations.php
2011-10-14 09:54:47 UTC (rev 99762)
@@ -0,0 +1,131 @@
+<?php
+/**
+ * Api module for querying message translations.
+ *
+ * @file
+ * @author Niklas Laxström
+ * @copyright Copyright © 2011, Niklas Laxström
+ * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
2.0 or later
+ */
+
+/**
+ * Api module for querying message translations.
+ *
+ * @ingroup API TranslateAPI
+ */
+class ApiQueryMessageTranslations extends ApiQueryBase {
+
+ public function __construct( $query, $moduleName ) {
+ parent::__construct( $query, $moduleName, 'mt' );
+ }
+
+ public function getCacheMode( $params ) {
+ return 'public';
+ }
+
+ public function execute() {
+ $params = $this->extractRequestParams();
+
+ $title = Title::newFromText( $params['title'] );
+ if ( !$title ) {
+ $this->dieUsage( 'Invalid title' );
+ }
+
+ $handle = new MessageHandle( $title );
+ if ( !$handle->isValid() ) {
+ $this->dieUsage( 'Title does not correspond to a
translatable message' );
+ }
+
+ $base = Title::makeTitle( $title->getNamespace(),
$handle->getKey() );
+ $namespace = $base->getNamespace();
+ $message = $base->getDBKey();
+
+ $dbr = wfGetDB( DB_SLAVE );
+
+ $res = $dbr->select( 'page',
+ array( 'page_namespace', 'page_title' ),
+ array(
+ 'page_namespace' => $namespace,
+ 'page_title ' . $dbr->buildLike( "$message/",
$dbr->anyString() ),
+ ),
+ __METHOD__,
+ array(
+ 'ORDER BY' => 'page_title',
+ 'USE INDEX' => 'name_title',
+ )
+ );
+
+ $titles = array();
+ foreach ( $res as $row ) {
+ $titles[] = $row->page_title;
+ }
+ $pageInfo = TranslateUtils::getContents( $titles, $namespace );
+
+ $result = $this->getResult();
+ $pages = array();
+ $count = 0;
+
+ foreach ( $pageInfo as $key => $info ) {
+
+ $tTitle = Title::makeTitle( $namespace, $key );
+ $tHandle = new MessageHandle( $tTitle );
+
+ $data = array(
+ 'title' => $tTitle->getPrefixedText(),
+ 'language' => $tHandle->getCode(),
+ 'lasttranslator' => $info[1],
+ );
+
+ $fuzzy = MessageHandle::hasFuzzyString( $info[0] ) ||
$tHandle->isFuzzy();
+
+ if ( $fuzzy ) {
+ $data['fuzzy'] = 'fuzzy';
+ }
+
+ $translation = str_replace( TRANSLATE_FUZZY, '',
$info[0] );
+ $result->setContent( $data, $translation );
+
+ $fit = $result->addValue( array( 'query',
$this->getModuleName() ), null, $data );
+ if ( !$fit ) {
+ $this->setContinueEnumParameter( 'offset',
$params['offset'] + $count - 1 );
+ break;
+ }
+
+ }
+
+ $result->setIndexedTagName_internal( array( 'query',
$this->getModuleName() ), 'message' );
+ }
+
+ public function getAllowedParams() {
+ return array(
+ 'title' => array(
+ ApiBase::PARAM_TYPE => 'string',
+ ApiBase::PARAM_REQUIRED => true,
+ ),
+ 'offset' => array(
+ ApiBase::PARAM_DFLT => 0,
+ ApiBase::PARAM_TYPE => 'integer',
+ ),
+ );
+ }
+
+ public function getParamDescription() {
+ return array(
+ 'title' => 'Full title of a known message',
+ );
+ }
+
+ public function getDescription() {
+ return 'Query all translations for a single message';
+ }
+
+ protected function getExamples() {
+ return array(
+
"api.php?action=query&meta=messagetranslations&title=MediaWiki:January List of
translations in the wiki for MediaWiki:January",
+ );
+ }
+
+ public function getVersion() {
+ return __CLASS__ . ': $Id$';
+ }
+}
Property changes on:
trunk/extensions/Translate/api/ApiQueryMessageTranslations.php
___________________________________________________________________
Added: svn:keywords
+ Id
Added: svn:eol-style
+ native
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs