Kipcool has uploaded a new change for review.

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


Change subject: DefinedMeaningHeaderEditor * avoid translation from same 
language where a synonym is randomly fetched and used in the header. This is 
confusing. * added alternative layout that can be activated in the user 
preferences. * Expression class moved to its own 
......................................................................

DefinedMeaningHeaderEditor
* avoid translation from same language where a synonym is randomly
fetched and used in the header. This is confusing.
* added alternative layout that can be activated in the user preferences.
* Expression class moved to its own file

Change-Id: Icf58fe44da31add3cfa4ad4f91e0aba4bc5cf8dd
---
M OmegaWiki/Editor.php
A OmegaWiki/Expression.php
M OmegaWiki/OmegaWikiEditors.php
M OmegaWiki/ViewInformation.php
M OmegaWiki/WikiDataAPI.php
M Wikidata.hooks.php
6 files changed, 120 insertions(+), 62 deletions(-)


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

diff --git a/OmegaWiki/Editor.php b/OmegaWiki/Editor.php
index c822812..9cc2a4c 100644
--- a/OmegaWiki/Editor.php
+++ b/OmegaWiki/Editor.php
@@ -1261,47 +1261,95 @@
 
 
 class DefinedMeaningHeaderEditor extends ScalarEditor {
-       protected $truncate;
+
+       /** Integer type
+        * indicates where the definition should be truncated. 0 for no 
truncation
+        */
        protected $truncateAt;
        protected $addText = "";
 
-       public function __construct( $attribute, $permissionController, 
$truncate = false, $truncateAt = 0 ) {
-               parent::__construct( $attribute, $permissionController, false );
+       public function __construct( $attribute, $truncateAt = 0 ) {
+               parent::__construct( $attribute, new 
SimplePermissionController( false ), false );
 
-               $this->truncate = $truncate;
                $this->truncateAt = $truncateAt;
        }
 
-       public function getViewHTML( IdStack $idPath, $value ) {
-               global $wgOut;
+       public function getViewHTML( IdStack $idPath, $definedMeaningId ) {
+               global $wgOut, $wgLang, $wgUser;
+
+               /**
+                * the first definition will be used as a meta descriptor for 
search engines
+                * then isMetaDescSet is set to one, to indicate that the meta 
descriptor is already set
+                */
                static $isMetaDescSet = 0 ;
 
-               $definition = getDefinedMeaningDefinition( $value );
-               $definedMeaningAsLink = definedMeaningAsLink( $value );
+               $output = "";
+
+               $userLanguageId = getLanguageIdForCode( $wgLang->getCode() ) ;
+               $definition = getDefinedMeaningDefinition( $definedMeaningId );
+               $definingExpression = definingExpression( $definedMeaningId );
+
+               // word being currently viewed (typically title of page 
"Expression:word")
+               // the "peek(1)" part is a bit of a mystery
+               $expressionId = $idPath->getKeyStack()->peek( 1 )->expressionId;
+               $expression = getExpression( $expressionId );
+
+               // getting the truncated definition
                $escapedDefinition = htmlspecialchars( $definition );
-               if ( $this->truncate && strlen( $definition ) > 
$this->truncateAt ) {
+               if ( ( $this->truncateAt > 0 ) && ( strlen( $definition ) > 
$this->truncateAt ) ) {
                        $spancontent = htmlspecialchars( mb_substr( 
$definition, 0, $this->truncateAt ) ) . wfMessage( 'ellipsis' )->text();
                        $escapedDefinition = Html::element( 'span', array( 
'title' => $escapedDefinition ), $spancontent );
                }
 
+               // setting the definition as meta description for the page
                if ( $isMetaDescSet == 0 ) {
-                       $expression = definedMeaningExpression ( $value ) ;
-                       $wgOut->addMeta( 'Description', $expression . ": " . 
$definition );
+                       $wgOut->addMeta( 'Description', $definition );
                        $isMetaDescSet = 1 ;
                }
 
-               $DMPageName = definingExpression( $value ) . " (" . $value . 
")" ;
+               // creating the link to edit the DM directly, that will be 
displayed on the right
+               $DMPageName = $definingExpression . " (" . $definedMeaningId . 
")" ;
                $DMTitle = Title::makeTitle( NS_DEFINEDMEANING , $DMPageName );
                $editURL = $DMTitle->getLocalURL( 'action=edit' ) ;
-               $editLink = Html::openElement( 'span', array( 'class' => 
'dm_edit_link' ) )
-                       . Html::rawElement( 'sup', array(), '['. createLink( 
$editURL , wfMessage( 'edit')->text() ) . ']' )
-                       . Html::closeElement( 'span' );
+               $editLink = Html::openElement( 'span', array( 'class' => 
'dm_edit_link' ) );
+               $editLink .= Html::rawElement( 'sup', array(), '['. createLink( 
$editURL , wfMessage( 'edit')->text() ) . ']' );
+               $editLink .= Html::closeElement( 'span' );
 
-               $output = $editLink . $definedMeaningAsLink . ": " . 
$escapedDefinition ;
+               if ( $wgUser->getOption( 'ow_alt_layout' ) ) {
+                       // EXPERIMENTAL LAYOUT:
+                       // DMlink (expression of page) : translation \n 
definition
+                       $translation = "";
+                       $definedMeaningAsLink = definedMeaningReferenceAsLink( 
$definedMeaningId, $definingExpression, $expression->spelling );
+
+                       if ( ( $userLanguageId != $expression->languageId ) && 
( $userLanguageId > 0 )) {
+                               // find a translation in the user language if 
exists
+                               // returns "" if not found
+                               $translation = 
definedMeaningExpressionForLanguage( $definedMeaningId, $userLanguageId );
+                       }
+                       $output = $editLink ;
+                       $output .= $definedMeaningAsLink;
+                       if ( $translation != "" ) {
+                               $output .= " : " . $translation;
+                       }
+                       $output .= Html::element('br') . $escapedDefinition ;
+
+               } else {
+                       // STANDARD CLASSIC LAYOUT:
+                       // DMlink (translated if possible) : definition
+                       if ( $userLanguageId == $expression->languageId ) {
+                               // no translation needed
+                               $definedMeaningAsLink = 
definedMeaningReferenceAsLink( $definedMeaningId, $definingExpression, 
$expression->spelling );
+                       } else {
+                               // try to get a translation
+                               $definedMeaningAsLink = definedMeaningAsLink( 
$definedMeaningId );
+                       }
+                       $output = $editLink . $definedMeaningAsLink . ": " . 
$escapedDefinition ;
+               }
+
                return $output ;
        }
 
-       public function getEditHTML( IdStack $idPath, $value ) {
+       public function getEditHTML( IdStack $idPath, $definedMeaningId ) {
                return "";
        }
 
diff --git a/OmegaWiki/Expression.php b/OmegaWiki/Expression.php
new file mode 100644
index 0000000..c199301
--- /dev/null
+++ b/OmegaWiki/Expression.php
@@ -0,0 +1,47 @@
+<?php
+
+require_once( 'WikiDataGlobals.php' );
+require_once( 'WikiDataAPI.php' );
+
+class Expression {
+       public $id;
+       public $spelling;
+       public $languageId;
+       public $pageId;
+       public $meaningIds = array();
+       public $dataset;
+
+       function __construct( $id, $spelling, $languageId, $dc = null ) {
+               $this->id = $id;
+               $this->spelling = $spelling;
+               $this->languageId = $languageId;
+               if ( is_null( $dc ) ) {
+                       $this->dataset = wdGetDataSetContext();
+               } else {
+                       $this->dataset = $dc;
+               }
+       }
+
+       function createNewInDatabase() {
+               $this->pageId = $this->createPage();
+               createInitialRevisionForPage( $this->pageId, 'Created by adding 
expression' );
+       }
+
+       function createPage() {
+               return createPage( NS_EXPRESSION, getPageTitle( $this->spelling 
) );
+       }
+
+       function isBoundToDefinedMeaning( $definedMeaningId ) {
+               return expressionIsBoundToDefinedMeaning( $definedMeaningId, 
$this->id );
+       }
+
+       function bindToDefinedMeaning( $definedMeaningId, $identicalMeaning ) {
+               createSynonymOrTranslation( $definedMeaningId, $this->id, 
$identicalMeaning );
+       }
+
+       function assureIsBoundToDefinedMeaning( $definedMeaningId, 
$identicalMeaning ) {
+               if ( !$this->isBoundToDefinedMeaning( $definedMeaningId ) ) {
+                       $this->bindToDefinedMeaning( $definedMeaningId, 
$identicalMeaning );
+               }
+       }
+}
diff --git a/OmegaWiki/OmegaWikiEditors.php b/OmegaWiki/OmegaWikiEditors.php
index 0d84955..413de33 100644
--- a/OmegaWiki/OmegaWikiEditors.php
+++ b/OmegaWiki/OmegaWikiEditors.php
@@ -815,7 +815,7 @@
        $insideExpression = true;
        $definedMeaningEditor = getDefinedMeaningEditor( $viewInformation, 
$insideExpression );
 
-       $definedMeaningCaptionEditor = new DefinedMeaningHeaderEditor( 
$o->definedMeaningId, new SimplePermissionController( false ), false, 75 );
+       $definedMeaningCaptionEditor = new DefinedMeaningHeaderEditor( 
$o->definedMeaningId, 75 );
        $definedMeaningCaptionEditor->setAddText( wfMessage( 
'ow_NewExactMeaning' )->text() );
 
        $expressionMeaningsEditor = new RecordSetListEditor( $attribute, new 
SimplePermissionController( true ), new ShowEditFieldChecker( true ), new 
AllowAddController( $allowAdd ), false, $allowAdd, new 
ExpressionMeaningController( ), 3, false );
diff --git a/OmegaWiki/ViewInformation.php b/OmegaWiki/ViewInformation.php
index 73608c0..227caca 100644
--- a/OmegaWiki/ViewInformation.php
+++ b/OmegaWiki/ViewInformation.php
@@ -21,8 +21,7 @@
        public $filterLanguageList;
 
        /**
-       * The language of the expression being displayed in the Expression: 
namespace
-       * i.e. the word being consulted
+       * The language of the expression to display, according to the url 
&explang=...
        */
        public $expressionLanguageId;
 
diff --git a/OmegaWiki/WikiDataAPI.php b/OmegaWiki/WikiDataAPI.php
index bcd2313..434c39d 100644
--- a/OmegaWiki/WikiDataAPI.php
+++ b/OmegaWiki/WikiDataAPI.php
@@ -1,50 +1,9 @@
 <?php
 
+require_once( 'Expression.php' );
 require_once( 'Transaction.php' );
 require_once( 'WikiDataGlobals.php' );
 
-class Expression {
-       public $id;
-       public $spelling;
-       public $languageId;
-       public $pageId;
-       public $meaningIds = array();
-       public $dataset;
-
-       function __construct( $id, $spelling, $languageId, $dc = null ) {
-               $this->id = $id;
-               $this->spelling = $spelling;
-               $this->languageId = $languageId;
-               if ( is_null( $dc ) ) {
-                       $this->dataset = wdGetDataSetContext();
-               } else {
-                       $this->dataset = $dc;
-               }
-       }
-
-       function createNewInDatabase() {
-               $this->pageId = $this->createPage();
-               createInitialRevisionForPage( $this->pageId, 'Created by adding 
expression' );
-       }
-
-       function createPage() {
-               return createPage( NS_EXPRESSION, getPageTitle( $this->spelling 
) );
-       }
-
-       function isBoundToDefinedMeaning( $definedMeaningId ) {
-               return expressionIsBoundToDefinedMeaning( $definedMeaningId, 
$this->id );
-       }
-
-       function bindToDefinedMeaning( $definedMeaningId, $identicalMeaning ) {
-               createSynonymOrTranslation( $definedMeaningId, $this->id, 
$identicalMeaning );
-       }
-
-       function assureIsBoundToDefinedMeaning( $definedMeaningId, 
$identicalMeaning ) {
-               if ( !$this->isBoundToDefinedMeaning( $definedMeaningId ) ) {
-                       $this->bindToDefinedMeaning( $definedMeaningId, 
$identicalMeaning );
-               }
-       }
-}
 
 function getExpression( $expressionId, $dc = null ) {
        if ( is_null( $dc ) ) {
diff --git a/Wikidata.hooks.php b/Wikidata.hooks.php
index b540927..f653181 100644
--- a/Wikidata.hooks.php
+++ b/Wikidata.hooks.php
@@ -45,6 +45,11 @@
                );
 */
                // allow the user to select the languages to display
+               $preferences['ow_alt_layout'] = array(
+                       'type' => 'check',
+                       'label' => 'Alternative layout',
+                       'section' => 'omegawiki',
+               );
                $preferences['ow_language_filter'] = array(
                        'type' => 'check',
                        'label' => '<b>' . wfMessage( 'ow_pref_lang_switch' 
)->text() . '</b>',

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

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

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

Reply via email to