Hiong3-eng5 has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/68025


Change subject: API:Define add ability to include syntrans
......................................................................

API:Define add ability to include syntrans

Change-Id: I21fab0b3232e14910143b2db2513af86b3559c82
---
M includes/api/owDefine.php
1 file changed, 82 insertions(+), 12 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikiLexicalData 
refs/changes/25/68025/1

diff --git a/includes/api/owDefine.php b/includes/api/owDefine.php
index c38aedb..3d5bbc8 100644
--- a/includes/api/owDefine.php
+++ b/includes/api/owDefine.php
@@ -3,6 +3,8 @@
 /** O m e g a W i k i   A P I ' s   D e f i n e   c l a s s
  *
  * HISTORY
+ * - 2013-06-12: Add optional translation list option. &syntrans= (syn, trans 
or all)
+ *             added ability to add syntrans.
  * - 2013-06-05: Readjusted defining and definingByAnyLanguage functions into
  *             class Define. Express Class now extends Define Class.
  * - 2013-05-31: Readjusted the array produced. The Language Name added.
@@ -18,9 +20,9 @@
  * - 2013-03-14: Creation date ~he
  *
  * TODO
- * - Add optional translation list option. &trans=on. default off
- * - Add optional translation limit option. &transLang=nan-POJ|eng
- * - Add optional lang parameter. &lang=cmn-Hant
+ * - Add optional translation limit option. &trans_lang=385|85
+ * - Add optional translation limit option. &trans_lang_iso=nan-POJ|eng
+ * - Add optional lang parameter. &lang_iso=cmn-Hant
  *
  */
 
@@ -53,13 +55,50 @@
                }
 
                // Optional parameter
-               if ( $params['e'] ) {
-                       $options['e'] = $params['e'];
+               $options = array();
+               $part = 'off';
+
+               if ( isset( $params['syntrans'] ) ) {
+                       $part = $params['syntrans'];
                }
+
+               // error if $params['part'] is empty
+               if ( $part == '' ) {
+                       $this->dieUsage( 'parameter part for adding syntrans is 
empty', 'param part is empty' );
+               }
+
+               // get syntrans
+               // When returning synonyms or translation only
+               if ( $part == 'syn' or $part == 'trans' or $part == 'all' ) {
+                       if ( !isset( $params['lang'] ) ) {
+                               $this->dieUsage( 'parameter lang for adding 
syntrans is missing', 'param lang is missing' );
+                       }
+                       $options['part'] = $part;
+               }
+
+               if ( $params['e'] ) {
+                       $trueOrFalse = getExpressionId( $params['e'], 
$params['lang']);
+                       if ( $trueOrFalse == true ) {
+                               $options['e'] = $params['e'];
+                       }
+               }
+
+               if ( $params['e'] && !isset( $options['e'] ) ) {
+                       $this->dieUsage( 'parameter e for adding syntrans does 
not exist', 'param e does not exist' );
+               }
+
                if ( $params['lang'] ) {
-                       $this->languageId = $params['lang'];
-                       $defined = $this->defining( $params['dm'], 
$params['lang'], $options, $this->getModuleName() );
+                       $trueOrFalse = LanguageIdExist( $params['lang']);
+                       if ( $trueOrFalse == true ) {
+                               $options['lang'] = $params['lang'];
+                               $defined = $this->defining( $params['dm'], 
$params['lang'], $options, $this->getModuleName() );
+                       } else {
+                               $this->dieUsage( 'parameter lang for adding 
syntrans does not exist', 'param lang does not exist' );
+                       }
                } else {
+                       if ( $part == 'syn' or $part == 'trans' or $part == 
'all' ) {
+                               $this->dieUsage( 'parameter lang for adding 
syntrans is empty', 'param lang empty' );
+                       }
                        $defined = $this->definingForAnyLanguage( 
$params['dm'], $options, $this->getModuleName() );
                }
 
@@ -91,6 +130,9 @@
                        'e' => array (
                                ApiBase::PARAM_TYPE => 'string',
                        ),
+                       'syntrans' => array (
+                               ApiBase::PARAM_TYPE => 'string',
+                       ),
                );
        }
 
@@ -99,7 +141,8 @@
                return array(
                        'dm' => 'The defined meaning id to be defined',
                        'lang' => 'The language id to be defined',
-                       'e' => 'The expression to be defined'
+                       'e' => 'The expression to be defined',
+                       'syntrans' => 'include syntrans to the definition'
                );
        }
 
@@ -107,12 +150,30 @@
        public function getExamples() {
                return array(
                        'Get a definition from a defined meaning id only.',
-                       'api.php?action=ow_define&dm=8218&format=xml',
+                       'api.php?action=ow_define&dm=8218',
+                       '',
                        'Get a definition from a defined meaning id and a 
language id.',
-                       'api.php?action=ow_define&dm=8218&lang=87&format=xml' ,
+                       'api.php?action=ow_define&dm=8218&lang=87',
                        'When a definition is not available for a language id, 
',
                        'the definition will default to English',
-                       'api.php?action=ow_define&dm=8218&lang=107&format=xml'
+                       'api.php?action=ow_define&dm=8218&lang=107',
+                       '',
+                       'When you want to include synonyms',
+                       'api.php?action=ow_define&dm=8218&lang=87&syntrans=syn',
+                       'When you want to include translations',
+                       
'api.php?action=ow_define&dm=8218&lang=87&syntrans=trans',
+                       'When you want to include both synonyms and 
translations',
+                       'api.php?action=ow_define&dm=8218&lang=87&syntrans=all',
+                       '',
+                       'NOTE: You can not include syntrans without the 
language id.',
+                       '',
+                       'In case the expression is also given with the language 
id,',
+                       'the expression is excluded from the list of syntrans.',
+                       '',
+                       'Get the synonyms and translations of a defined meaning 
id with lang',
+                       
'api.php?action=ow_define&dm=8218&syntrans=all&e=字母&lang=107',
+                       'Get the synonyms of a defined meaning id',
+                       
'api.php?action=ow_define&dm=8218&syntrans=syn&e=aksara&lang=231',
                );
        }
 
@@ -120,6 +181,7 @@
         * Define expression when the language is not specified.
         */
        protected function defining( $definedMeaningId, $languageId, $options = 
array(), $moduleName = null ) {
+               $syntrans = array();
 
                if ( is_null( $moduleName ) ) {
                        $moduleName = 'ow_define';
@@ -149,6 +211,13 @@
                $definitionLanguage = getLanguageIdLanguageNameFromIds( 
$definitionLanguageId, $definitionLanguageId );
                $definitionSpelling = getSpellingForLanguageId( 
$definedMeaningId, $definitionLanguageId, WLD_ENGLISH_LANG_ID );
 
+               if ( isset( $options['part'] ) ) {
+                       if( $options['part'] == 'all' ) {
+                               $options['part'] = null;
+                       }
+                       $syntrans = $this->synTrans( $definedMeaningId, 
$options );
+               }
+
                return array(
                        $moduleName => array(
                                'dmid' => $definedMeaningId,
@@ -160,7 +229,8 @@
                                        'langid' => $definitionLanguageId,
                                        'lang' => $definitionLanguage,
                                        'text' => $text
-                               )
+                               ),
+                               'syntrans' => $syntrans
                        )
                );
 

-- 
To view, visit https://gerrit.wikimedia.org/r/68025
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I21fab0b3232e14910143b2db2513af86b3559c82
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikiLexicalData
Gerrit-Branch: master
Gerrit-Owner: Hiong3-eng5 <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to