https://www.mediawiki.org/wiki/Special:Code/MediaWiki/115792
Revision: 115792
Author: kipcool
Date: 2012-12-19 13:19:27 +0000 (Wed, 19 Dec 2012)
Log Message:
-----------
Changed the identical meaning checkbox to a combobox
Modified Paths:
--------------
trunk/extensions/Wikidata/OmegaWiki/Editor.php
trunk/extensions/Wikidata/OmegaWiki/OmegaWikiAttributes.php
trunk/extensions/Wikidata/OmegaWiki/OmegaWikiEditors.php
trunk/extensions/Wikidata/OmegaWiki/WikiDataAPI.php
trunk/extensions/Wikidata/OmegaWiki/resources/tables.css
trunk/extensions/Wikidata/OmegaWiki/type.php
Modified: trunk/extensions/Wikidata/OmegaWiki/Editor.php
===================================================================
--- trunk/extensions/Wikidata/OmegaWiki/Editor.php 2012-12-19 13:15:22 UTC
(rev 115791)
+++ trunk/extensions/Wikidata/OmegaWiki/Editor.php 2012-12-19 13:19:27 UTC
(rev 115792)
@@ -235,18 +235,23 @@
}
}
-/* XXX: Basic Editor class. */
+/**
+ * Basic Editor class.
+ */
abstract class DefaultEditor implements Editor {
protected $editors;
protected $attributeEditorMap;
protected $attribute;
protected $isCollapsible;
+ protected $displayHeader;
public function __construct( Attribute $attribute = null ) {
$this->attribute = $attribute;
$this->editors = array();
$this->attributeEditorMap = new AttributeEditorMap();
$this->isCollapsible = true;
+ // show header by default
+ $this->displayHeader = true;
}
public function addEditor( Editor $editor ) {
@@ -282,6 +287,15 @@
$this->isCollapsible = $value;
}
+ public function setDisplayHeader( $value ) {
+ $this->displayHeader = $value;
+ }
+
+ public function getDisplayHeader() {
+ return $this->displayHeader;
+ }
+
+
public function getExpansionPrefix( $class, $elementId ) {
if ( ! $this->isCollapsible ) {
return '';
@@ -522,13 +536,13 @@
public function getUpdateRecord( IdStack $idPath, Structure $structure,
$editors ) {
$result = new ArrayRecord( $structure );
- foreach ( $editors as $editor )
+ foreach ( $editors as $editor ) {
if ( $attribute = $editor->getUpdateAttribute() ) {
$idPath->pushAttribute( $attribute );
$result->setAttributeValue( $attribute,
$editor->getUpdateValue( $idPath ) );
$idPath->popAttribute();
}
-
+ }
return $result;
}
@@ -1390,15 +1404,15 @@
}
public function add( IdStack $idPath ) {
- if ( $this->isAddField )
+ if ( $this->isAddField ) {
return getTextBox( $this->addId( $idPath->getId() ),
"", $this->onChangeHandler );
- else
+ } else {
return "";
+ }
}
public function getInputValue( $id ) {
- global
- $wgRequest;
+ global $wgRequest;
return trim( $wgRequest->getText( $id ) );
}
@@ -1415,9 +1429,9 @@
$label = htmlspecialchars( $value->linkLabel );
$url = htmlspecialchars( $value->linkURL );
- if ( $label == "" )
+ if ( $label == "" ) {
$label = $url;
-
+ }
return
'<a href="' . $url . '">' . $label . '</a>' . EOL;
}
@@ -1447,10 +1461,11 @@
}
public function add( IdStack $idPath ) {
- if ( $this->isAddField )
+ if ( $this->isAddField ) {
return getCheckBox( $this->addId( $idPath->getId() ),
$this->defaultValue );
- else
+ } else {
return "";
+ }
}
public function getInputValue( $id ) {
@@ -1460,12 +1475,69 @@
}
}
+/*
+* IdenticalMeaningEditor
+* in view mode, shows either = or ≈
+* in edit mode, shows a combobox to choose.
+* for html we use strings "true" and "false" instead of "0" and "1"
+* to be sure that an undefined value will not be considered as a "0".
+*/
+class IdenticalMeaningEditor extends ScalarEditor {
+ protected $defaultValue;
+ // textValues is an array of "value" => "how the value is displayed"
+ // e.g. array( "true" => "=", "false" => "≈" );
+ protected $textValues;
+
+ public function __construct( Attribute $attribute = null,
PermissionController $permissionController, $isAddField ) {
+ parent::__construct( $attribute, $permissionController,
$isAddField );
+
+ $this->defaultValue = "true";
+ $this->textValues = array( "true" => "=", "false" => "≈" );
+ }
+
+ public function getViewHTML( IdStack $idPath, $value ) {
+ // $value is what is returned from the database, i.e. an
integer, 0 or 1
+ if ( $value == 0 ) return $this->textValues["false"];
+ if ( $value == 1 ) return $this->textValues["true"];
+ return "undefined"; // should not happen
+ }
+
+ public function getEditHTML( IdStack $idPath, $value ) {
+ // $value is what is returned from the database, i.e. an
integer, 0 or 1
+ if ( $value == 0 ) {
+ return getSelect( $this->updateId( $idPath->getId() ),
$this->textValues, "false" );
+ }
+ if ( $value == 1 ) {
+ return getSelect( $this->updateId( $idPath->getId() ),
$this->textValues, "true" );
+ }
+
+ // if no $value is not 0 and not 1, should not happen
+ return "undefined";
+ }
+
+ public function add( IdStack $idPath ) {
+ if ( $this->isAddField ) {
+ return getSelect( $this->addId( $idPath->getId() ),
$this->textValues, $this->defaultValue);
+ } else {
+ return "";
+ }
+ }
+
+ public function getInputValue( $id ) {
+ global $wgRequest;
+ $inputvalue = trim( $wgRequest->getText( $id ) );
+ return $inputvalue;
+ }
+}
+
+
abstract class SuggestEditor extends ScalarEditor {
public function add( IdStack $idPath ) {
- if ( $this->isAddField )
+ if ( $this->isAddField ) {
return getSuggest( $this->addId( $idPath->getId() ),
$this->suggestType() );
- else
+ } else {
return "";
+ }
}
protected abstract function suggestType();
@@ -1730,22 +1802,25 @@
$class = $idPath->getClass();
$attributeId = $idPath->getId();
$attributeValue = $value->getAttributeValue( $attribute
);
-
+
if ( $editor->showsData( $attributeValue ) ) {
- if ( !$compress )
- $result .=
- '<' . $htmlTag . '>' .
- $this->childHeader( $editor,
$attribute, $class, $attributeId );
-
+ if ( !$compress ) {
+ $result .= Html::openElement( $htmlTag,
array('class' => $class )) ;
+
+ if ( $editor->getDisplayHeader() ) {
+ $result .= $this->childHeader(
$editor, $attribute, $class, $attributeId );
+ }
+ }
$result .= $this->viewChild( $editor, $idPath,
$value, $attribute, $class, $attributeId );
-
- if ( !$compress )
- $result .= '</' . $htmlTag . '>';
+
+ if ( !$compress ) {
+ $result .= Html::closeElement( $htmlTag
);
+ }
}
$idPath->popAttribute();
- }
-
+ } // foreach editors
+
return $result;
}
@@ -1785,17 +1860,21 @@
$class = $idPath->getClass();
$attributeId = $idPath->getId();
- if ( !$compress )
- $result .=
- '<' . $htmlTag . '>' .
- $this->childHeader(
$editor, $attribute, $class, $attributeId );
-
- $result .= $this->editChild( $editor, $idPath,
$value, $attribute, $class, $attributeId );
-
- if ( !$compress )
- $result .= '</' . $htmlTag . '>';
+ if ( !$compress ) {
+ $result .= Html::openElement( $htmlTag,
array('class' => $class )) ;
+
+ if ( $editor->getDisplayHeader() ) {
+ $result .= $this->childHeader(
$editor, $attribute, $class, $attributeId );
+ }
+ }
+
+ $result .= $this->editChild( $editor, $idPath,
$value, $attribute, $class, $attributeId );
+
+ if ( !$compress ) {
+ $result .= Html::closeElement( $htmlTag
);
+ }
}
-
+
$idPath->popAttribute();
}
@@ -1877,7 +1956,9 @@
public function view( IdStack $idPath, $value ) {
$editors = $this->getEditors();
- $compress = $this->shouldCompressOnView( $idPath, $value,
$editors );
+//
+// $compress = $this->shouldCompressOnView( $idPath, $value,
$editors );
+ $compress = false ;
$result = $this->viewEditors( $idPath, $value, $editors,
$this->htmlTag, $compress );
if ( !$compress )
@@ -2662,35 +2743,6 @@
}
}
-/*
-Don't know what it is, but obviously only used for SwissProt
-cf. GoToSourceTemplate.php
-*/
-class GotoSourceEditor extends Viewer {
- public function view( IdStack $idPath, $value ) {
- global $wgGotoSourceTemplates;
- if ( count( $wgGotoSourceTemplates ) <= 1 ) return "" ;
-
- $collectionId = $value->collectionId;
- $sourceIdentifier = $value->sourceIdentifier;
-
- $gotoSourceTemplate = $wgGotoSourceTemplates[$collectionId];
-
- if ( $gotoSourceTemplate != null ) {
- $url = $gotoSourceTemplate->getURL( $sourceIdentifier );
- return '<a href="' . htmlspecialchars( $url ) . '">Go
to source</a>' . EOL;
- }
- else
- return "";
-
- }
-
- public function showsData( $value ) {
- return true;
- }
-}
-
-
class DefinedMeaningContextEditor extends WrappingEditor {
public function view( IdStack $idPath, $value ) {
$definedMeaningId = (int) $value->definedMeaningId;
Modified: trunk/extensions/Wikidata/OmegaWiki/OmegaWikiAttributes.php
===================================================================
--- trunk/extensions/Wikidata/OmegaWiki/OmegaWikiAttributes.php 2012-12-19
13:15:22 UTC (rev 115791)
+++ trunk/extensions/Wikidata/OmegaWiki/OmegaWikiAttributes.php 2012-12-19
13:19:27 UTC (rev 115792)
@@ -96,7 +96,8 @@
$t->definedMeaningAttributes = new Attribute(
WD_DEFINED_MEANING_ATTRIBUTES, wfMsgSc( "DefinedMeaningAttributes" ),
"will-be-specified-below" );
$t->objectAttributes = new Attribute( WD_OBJECT_ATTRIBUTES,
wfMsgSc( "Annotation" ), "will-be-specified-below" );
$t->expressionId = new Attribute( "expression-id", "Expression
Id", "expression-id" );
- $t->identicalMeaning = new Attribute( "identMeaning", wfMsgSc(
"IdenticalMeaning" ), "boolean" );
+ // instead of " ", could be wfMsgSc( "IdenticalMeaning" ), but
then the header is too long
+ $t->identicalMeaning = new Attribute( WD_IDENTICAL_MEANING, "
", "combobox" );
if ( $viewInformation->filterOnLanguage() ) {
$t->expression = new Attribute( WD_EXPRESSION, wfMsgSc(
"Spelling" ), "spelling" );
@@ -161,13 +162,15 @@
$t->alternativeDefinitionsStructure = new Structure(
WD_ALTERNATIVE_DEFINITIONS, $t->definitionId, $t->alternativeDefinition,
$t->source );
$t->alternativeDefinitions = new Attribute( null, wfMsgSc(
"AlternativeDefinitions" ), $t->alternativeDefinitionsStructure );
- if ( $viewInformation->filterOnLanguage() )
+ if ( $viewInformation->filterOnLanguage() ) {
$synonymsAndTranslationsCaption = wfMsgSc( "Synonyms" );
- else
+ } else {
$synonymsAndTranslationsCaption = wfMsgSc(
"SynonymsAndTranslations" );
+ }
$t->syntransId = new Attribute( "syntrans-id",
"$synonymsAndTranslationsCaption identifier", "integer" );
- $t->synonymsTranslationsStructure = new Structure(
WD_SYNONYMS_TRANSLATIONS, $t->syntransId, $t->expression, $t->identicalMeaning
);
+// $t->synonymsTranslationsStructure = new Structure(
WD_SYNONYMS_TRANSLATIONS, $t->syntransId, $t->expression, $t->identicalMeaning
);
+ $t->synonymsTranslationsStructure = new Structure(
WD_SYNONYMS_TRANSLATIONS, $t->identicalMeaning, $t->syntransId, $t->expression
);
$t->synonymsAndTranslations = new Attribute( null,
"$synonymsAndTranslationsCaption", $t->synonymsTranslationsStructure );
$t->translatedTextAttributeId = new Attribute(
"translated-text-attribute-id", "Attribute identifier", "object-id" );
$t->translatedTextAttribute = new Attribute(
"translated-text-attribute", wfMsgSc( "TranslatedTextAttribute" ),
$definedMeaningReferenceType );
Modified: trunk/extensions/Wikidata/OmegaWiki/OmegaWikiEditors.php
===================================================================
--- trunk/extensions/Wikidata/OmegaWiki/OmegaWikiEditors.php 2012-12-19
13:15:22 UTC (rev 115791)
+++ trunk/extensions/Wikidata/OmegaWiki/OmegaWikiEditors.php 2012-12-19
13:19:27 UTC (rev 115792)
@@ -5,7 +5,6 @@
require_once( "WikiDataBootstrappedMeanings.php" );
require_once( "ContextFetcher.php" );
require_once( "WikiDataGlobals.php" );
-// require_once( "GotoSourceTemplate.php" ); // not used, disabled
require_once( "ViewInformation.php" );
class DummyViewer extends Viewer {
@@ -537,6 +536,7 @@
$o = OmegaWikiAttributes::getInstance();
+ // defining the language + expression editor (syntrans)
$tableEditor = new RecordSetTableEditor(
$o->synonymsAndTranslations,
new SimplePermissionController( true ),
@@ -546,10 +546,21 @@
false,
new SynonymTranslationController(
$viewInformation->filterLanguageId )
);
-
+
+
+ // defining the identicalMeaning Editor
+ $attribute = $o->identicalMeaning ;
+ $permissionController = new SimplePermissionController( true ) ;
+ $isAddField = true ;
+ $identicalMeaningEditor = new IdenticalMeaningEditor(
+ $attribute, $permissionController, $isAddField
+ );
+ $tableEditor->addEditor( $identicalMeaningEditor );
+
+ // expression Editor
$tableEditor->addEditor( getExpressionTableCellEditor( $o->expression,
$viewInformation ) );
- $tableEditor->addEditor( new BooleanEditor( $o->identicalMeaning, new
SimplePermissionController( true ), true, true ) );
-
+
+ // not sure what this does
addPropertyToColumnFilterEditors( $tableEditor, $viewInformation,
$o->syntransId, $synTransMeaningName );
// Add annotation editor on the rightmost column.
@@ -623,17 +634,12 @@
}
function getDefinedMeaningCollectionMembershipEditor( ViewInformation
$viewInformation ) {
- global $wgGotoSourceTemplates;
-
$o = OmegaWikiAttributes::getInstance();
$editor = new RecordSetTableEditor( $o->collectionMembership, new
SimplePermissionController( true ), new ShowEditFieldChecker( true ), new
AllowAddController( true ), true, false, new
DefinedMeaningCollectionController() );
$editor->addEditor( new CollectionReferenceEditor(
$o->collectionMeaning, new SimplePermissionController( false ), true ) );
$editor->addEditor( new ShortTextEditor( $o->sourceIdentifier, new
SimplePermissionController( false ), true ) );
- if ( count( $wgGotoSourceTemplates ) > 1 )
- $editor->addEditor( new GotoSourceEditor( $o->gotoSource, new
SimplePermissionController( true ), true ) );
-
addTableMetadataEditors( $editor, $viewInformation );
return $editor;
@@ -757,10 +763,15 @@
function getExpressionsEditor( $spelling, ViewInformation $viewInformation ) {
$o = OmegaWikiAttributes::getInstance();
- $expressionMeaningsRecordEditor = new RecordUnorderedListEditor(
$o->expressionMeanings, 3 );
+ $headerLevel = 3 ;
+ $expressionMeaningsRecordEditor = new RecordUnorderedListEditor(
$o->expressionMeanings, $headerLevel );
- $exactMeaningsEditor = getExpressionMeaningsEditor(
$o->expressionExactMeanings, true, $viewInformation );
+ $allowAdd = true;
+ $exactMeaningsEditor = getExpressionMeaningsEditor(
$o->expressionExactMeanings, $allowAdd, $viewInformation );
+ $exactMeaningsEditor->setDisplayHeader(false);
$expressionMeaningsRecordEditor->addEditor( $exactMeaningsEditor );
+
+// add an approximate meaning editor (identicalMeaning = 0):
$approximateMeaningsEditor = getExpressionMeaningsEditor(
$o->expressionApproximateMeanings, false, $viewInformation ) ;
$expressionMeaningsRecordEditor->addEditor( $approximateMeaningsEditor
);
Modified: trunk/extensions/Wikidata/OmegaWiki/WikiDataAPI.php
===================================================================
--- trunk/extensions/Wikidata/OmegaWiki/WikiDataAPI.php 2012-12-19 13:15:22 UTC
(rev 115791)
+++ trunk/extensions/Wikidata/OmegaWiki/WikiDataAPI.php 2012-12-19 13:19:27 UTC
(rev 115792)
@@ -42,23 +42,12 @@
}
function assureIsBoundToDefinedMeaning( $definedMeaningId,
$identicalMeaning ) {
- if ( !$this->isBoundToDefinedMeaning( $definedMeaningId ) )
+ if ( !$this->isBoundToDefinedMeaning( $definedMeaningId ) ) {
$this->bindToDefinedMeaning( $definedMeaningId,
$identicalMeaning );
- }
-
- function fetchMeaningIds() {
-
- $dbr = wfGetDB( DB_SLAVE );
- $dc = $this->dataset;
- $id = $this->id;
- $queryResult = $dbr->query( "SELECT * FROM {$dc}_syntrans where
expression_id=$id AND " . getLatestTransactionRestriction( "{$dc}_syntrans" ) );
- while ( $syntransRecord = $dbr->fetchObject( $queryResult ) ) {
- $this->meaningIds[] =
$syntransRecord->defined_meaning_id;
}
- $dbr->freeResult( $queryResult ) ;
}
-
}
+
function getExpression( $expressionId, $dc = null ) {
if ( is_null( $dc ) ) {
$dc = wdGetDataSetContext();
@@ -208,13 +197,14 @@
"WHERE
defined_meaning_id=$definedMeaningId AND expression_id=$expressionId " .
' AND ' .
getLatestTransactionRestriction( "{$dc}_syntrans" ) . " LIMIT 1" );
- if ( $synonym = $dbr->fetchObject( $queryResult ) )
+ if ( $synonym = $dbr->fetchObject( $queryResult ) ) {
return $synonym->syntrans_sid;
- else
- return 0;
+ }
+ // else
+ return 0;
}
-function createSynonymOrTranslation( $definedMeaningId, $expressionId,
$identicalMeaning = 1 ) {
+function createSynonymOrTranslation( $definedMeaningId, $expressionId,
$identicalMeaning = "true" ) {
$dc = wdGetDataSetContext();
$synonymId = getSynonymId( $definedMeaningId, $expressionId );
@@ -224,9 +214,15 @@
}
$dbw = wfGetDB( DB_MASTER );
- $identicalMeaningInteger = (int) $identicalMeaning;
+ if ( $identicalMeaning == "true" ) {
+ $identicalMeaningInteger = 1;
+ } else {
+ // if ( $identicalMeaning == "false" )
+ $identicalMeaningInteger = 0;
+ }
$sql = "insert into {$dc}_syntrans(syntrans_sid, defined_meaning_id,
expression_id, identical_meaning, add_transaction_id) " .
"values($synonymId, $definedMeaningId, $expressionId,
$identicalMeaningInteger, " . getUpdateTransactionId() . ")";
+
$queryResult = $dbw->query( $sql );
}
@@ -249,7 +245,7 @@
$expression = findOrCreateExpression( $spelling, $languageId );
$expression->assureIsBoundToDefinedMeaning( $definedMeaningId,
$identicalMeaning );
}
-
+
function getMaximum( $field, $table ) {
$dbr = wfGetDB( DB_SLAVE );
$sql = "select max($field) as maximum from $table";
@@ -526,15 +522,29 @@
createSynonymOrTranslation( $definedMeaningId, $expressionId,
$identicalMeaning );
}
-function updateSynonymOrTranslationWithId( $syntransId, $identicalMeaning ) {
+function updateSynonymOrTranslationWithId( $syntransId, $identicalMeaningInput
) {
$dc = wdGetDataSetContext();
$dbr = wfGetDB( DB_SLAVE );
- $queryResult = $dbr->query( "SELECT defined_meaning_id, expression_id" .
+
+ // check that $identicalMeaningInput has the correct form
+ if ( $identicalMeaningInput != "true" && $identicalMeaningInput !=
"false" ) {
+ // unknown value, no update possible
+ return;
+ }
+
+ $queryResult = $dbr->query( "SELECT defined_meaning_id, expression_id,
identical_meaning" .
" FROM
{$dc}_syntrans" .
" WHERE
syntrans_sid=$syntransId AND remove_transaction_id IS NULL LIMIT 1" );
if ( $syntrans = $dbr->fetchObject( $queryResult ) ) {
- updateSynonymOrTranslation( $syntrans->defined_meaning_id,
$syntrans->expression_id, $identicalMeaning );
+ // transform the identical_meaning value into the string form
used in the html form
+ $identicalMeaningDB = ( $syntrans->identical_meaning == 1 ) ?
"true" : "false" ;
+
+ // check if the "identicalMeaning" value of the database is
different
+ // from the value provided as an input in the html form.
+ if ( $identicalMeaningInput != $identicalMeaningDB ) {
+ updateSynonymOrTranslation(
$syntrans->defined_meaning_id, $syntrans->expression_id, $identicalMeaningInput
);
+ }
}
}
@@ -609,8 +619,9 @@
}
function addTranslatedTextIfNotPresent( $translatedContentId, $languageId,
$text ) {
- if ( !translatedTextExists( $translatedContentId, $languageId ) )
+ if ( !translatedTextExists( $translatedContentId, $languageId ) ) {
addTranslatedText( $translatedContentId, $languageId, $text );
+ }
}
function getDefinedMeaningDefinitionId( $definedMeaningId ) {
@@ -750,7 +761,7 @@
function bootstrapCollection( $collection, $languageId, $collectionType ) {
$expression = findOrCreateExpression( $collection, $languageId );
$definedMeaningId = addDefinedMeaning( $expression->id );
- $expression->assureIsBoundToDefinedMeaning( $definedMeaningId, true );
+ $expression->assureIsBoundToDefinedMeaning( $definedMeaningId, "true" );
addDefinedMeaningDefinition( $definedMeaningId, $languageId,
$collection );
return addCollection( $definedMeaningId, $collectionType );
}
@@ -789,12 +800,12 @@
$definedMeaningId = newObjectId( "{$dc}_defined_meaning" );
- // wfDebug( "addDefinedMeaning(): $definedMeaningId has to be inserted
to the database $dc" );
$dbw = wfGetDB( DB_MASTER );
- $dbw->query( "INSERT INTO {$dc}_defined_meaning(defined_meaning_id,
expression_id, add_transaction_id) values($definedMeaningId,
$definingExpressionId, " . getUpdateTransactionId() . ")" );
-
- // wfDebug( "addDefinedMeaning(): after $definedMeaningId has been
inserted in the database" );
+ $insertquery = "INSERT INTO {$dc}_defined_meaning(defined_meaning_id,
expression_id, add_transaction_id) "
+ . "values($definedMeaningId, $definingExpressionId, " .
getUpdateTransactionId() . ")" ;
+ $dbw->query( $insertquery );
+
$expression = getExpression( $definingExpressionId );
$pageId = createPage( NS_DEFINEDMEANING, getPageTitle(
"$expression->spelling ($definedMeaningId)" ) );
createInitialRevisionForPage( $pageId, 'Created by adding defined
meaning' );
@@ -804,9 +815,9 @@
function createNewDefinedMeaning( $definingExpressionId, $languageId, $text ) {
$definedMeaningId = addDefinedMeaning( $definingExpressionId );
- createSynonymOrTranslation( $definedMeaningId, $definingExpressionId,
true );
+ createSynonymOrTranslation( $definedMeaningId, $definingExpressionId,
"true" );
addDefinedMeaningDefiningDefinition( $definedMeaningId, $languageId,
$text );
-
+
return $definedMeaningId;
}
@@ -1118,6 +1129,13 @@
}
+/**
+* returns one of the possible translations of
+* a given DefinedMeaning ( $definedMeaningId )
+* preferably in a given language ( $languageCode )
+* or in English otherwise.
+* null if not found
+*/
function getSpellingForLanguage( $definedMeaningId, $languageCode,
$fallbackLanguageCode = 'en', $dc = null ) {
$dc = wdGetDataSetContext( $dc );
@@ -1134,7 +1152,13 @@
$userLanguageId = $dbr->addQuotes( $userLanguageId );
if ( $userLanguageId ) {
- $actual_query = "select spelling from
{$dc}_syntrans,{$dc}_expression where
{$dc}_syntrans.defined_meaning_id=$definedMeaningId and
{$dc}_expression.expression_id={$dc}_syntrans.expression_id and
language_id=$userLanguageId and {$dc}_expression.remove_transaction_id is NULL
LIMIT 1";
+ $actual_query =
+ "select spelling from {$dc}_syntrans,{$dc}_expression "
.
+ " where
{$dc}_syntrans.defined_meaning_id=$definedMeaningId " .
+ " and
{$dc}_expression.expression_id={$dc}_syntrans.expression_id " .
+ " and language_id=$userLanguageId " .
+ " and {$dc}_expression.remove_transaction_id is NULL " .
+ " LIMIT 1";
$res = $dbr->query( $actual_query );
$row = $dbr->fetchObject( $res );
@@ -1144,7 +1168,13 @@
}
$fallbackLanguageId = $dbr->addQuotes( $fallbackLanguageId );
- $fallback_query = "select spelling from {$dc}_syntrans,{$dc}_expression
where {$dc}_syntrans.defined_meaning_id=$definedMeaningId and
{$dc}_expression.expression_id={$dc}_syntrans.expression_id and
language_id=$fallbackLanguageId and {$dc}_expression.remove_transaction_id is
NULL LIMIT 1";
+ $fallback_query =
+ "select spelling from {$dc}_syntrans,{$dc}_expression " .
+ " where {$dc}_syntrans.defined_meaning_id=$definedMeaningId " .
+ " and
{$dc}_expression.expression_id={$dc}_syntrans.expression_id " .
+ " and language_id=$fallbackLanguageId " .
+ " and {$dc}_expression.remove_transaction_id is NULL " .
+ " LIMIT 1";
$res = $dbr->query( $fallback_query );
$row = $dbr->fetchObject( $res );
@@ -1152,7 +1182,12 @@
return $row->spelling;
}
- $final_fallback = "select spelling from {$dc}_syntrans,{$dc}_expression
where {$dc}_syntrans.defined_meaning_id=$definedMeaningId and
{$dc}_expression.expression_id={$dc}_syntrans.expression_id and
{$dc}_expression.remove_transaction_id is NULL LIMIT 1";
+ $final_fallback =
+ "select spelling from {$dc}_syntrans,{$dc}_expression " .
+ " where {$dc}_syntrans.defined_meaning_id=$definedMeaningId " .
+ " and
{$dc}_expression.expression_id={$dc}_syntrans.expression_id " .
+ " and {$dc}_expression.remove_transaction_id is NULL " .
+ " LIMIT 1";
$res = $dbr->query( $final_fallback );
$row = $dbr->fetchObject( $res );
@@ -1287,18 +1322,18 @@
}
function getExpressionMeaningIds( $spelling, $dc = null ) {
- if ( is_null( $dc ) ) {
- $dc = wdGetDataSetContext();
- }
- $dbr = & wfGetDB( DB_SLAVE );
- $queryResult = $dbr->query(
+ if ( is_null( $dc ) ) {
+ $dc = wdGetDataSetContext();
+ }
+ $dbr = & wfGetDB( DB_SLAVE );
+ $queryResult = $dbr->query(
"SELECT defined_meaning_id" .
" FROM {$dc}_expression, {$dc}_syntrans " .
- " WHERE spelling=" . $dbr->addQuotes( $spelling ) .
- " AND {$dc}_expression.expression_id={$dc}_syntrans.expression_id" .
- " AND " . getLatestTransactionRestriction( "{$dc}_syntrans" ) .
- " AND " . getLatestTransactionRestriction( "{$dc}_expression" )
- );
+ " WHERE spelling=" . $dbr->addQuotes( $spelling ) .
+ " AND
{$dc}_expression.expression_id={$dc}_syntrans.expression_id" .
+ " AND " . getLatestTransactionRestriction( "{$dc}_syntrans" ) .
+ " AND " . getLatestTransactionRestriction( "{$dc}_expression" )
+ );
$result = array();
@@ -1311,18 +1346,18 @@
}
function getExpressionMeaningIdsForLanguages( $spelling, $languageIds, $dc =
null ) {
- if ( is_null( $dc ) ) {
- $dc = wdGetDataSetContext();
- }
- $dbr = & wfGetDB( DB_SLAVE );
- $queryResult = $dbr->query(
+ if ( is_null( $dc ) ) {
+ $dc = wdGetDataSetContext();
+ }
+ $dbr = & wfGetDB( DB_SLAVE );
+ $queryResult = $dbr->query(
"SELECT defined_meaning_id, language_id" .
" FROM {$dc}_expression, {$dc}_syntrans " .
- " WHERE spelling=" . $dbr->addQuotes( $spelling ) .
- " AND {$dc}_expression.expression_id={$dc}_syntrans.expression_id" .
- " AND " . getLatestTransactionRestriction( "{$dc}_syntrans" ) .
- " AND " . getLatestTransactionRestriction( "{$dc}_expression" )
- );
+ " WHERE spelling=" . $dbr->addQuotes( $spelling ) .
+ " AND
{$dc}_expression.expression_id={$dc}_syntrans.expression_id" .
+ " AND " . getLatestTransactionRestriction( "{$dc}_syntrans" ) .
+ " AND " . getLatestTransactionRestriction( "{$dc}_expression" )
+ );
$result = array();
@@ -1688,81 +1723,6 @@
}
-/**
- * Returns the definitions and translations of the given defined meaning in
the
- * given languages in an associative array.
- * @param $dmid the defined meaning id.
- * @param $languages an aray of language id's.
- * @return array an associative array with two entries per language: def_lid
and trans_lid
- * (where lid is the language id); def_lid contains the definition in the
language,
- * trans_lid contains the translations in a single string separated by the |
character.
- */
-function getDefinitionsAndTranslationsForLanguages( $dmid, $languages, $dc =
null ) {
- if ( is_null( $dc ) ) {
- $dc = wdGetDataSetContext();
- }
- $dbr = wfGetDB( DB_SLAVE );
-
- // First we'll fill an associative array with the definitions and
- // translations. Then we'll use the isoCodes array to put them in the
- // proper order.
-
- // the associative array holding the definitions and translations
- $data = array();
-
- // ****************************
- // query to get the definitions
- // ****************************
- $qry = 'SELECT txt.text_text, trans.language_id ';
- $qry .= "FROM {$dc}_text txt, {$dc}_translated_content trans,
{$dc}_defined_meaning dm ";
- $qry .= 'WHERE txt.text_id = trans.text_id ';
- $qry .= 'AND trans.translated_content_id = dm.meaning_text_tcid ';
- $qry .= "AND dm.defined_meaning_id = $dmid ";
- $qry .= 'AND trans.language_id IN (' . implode( ',', $languages ) . ')
';
- $qry .= 'AND ' . getLatestTransactionRestriction( 'trans' );
- $qry .= 'AND ' . getLatestTransactionRestriction( 'dm' );
-
-
- $definitions = $dbr->query( $qry );
- while ( $row = $dbr->fetchRow( $definitions ) ) {
- // $key becomes something like def_23
- $key = 'def_' . $row['language_id'];
- $data[$key] = $row['text_text'];
- }
- $dbr->freeResult( $definitions );
-
- // *****************************
- // query to get the translations
- // *****************************
- $qry = "SELECT exp.spelling, exp.language_id ";
- $qry .= "FROM {$dc}_expression exp ";
- $qry .= "INNER JOIN {$dc}_syntrans trans ON
exp.expression_id=trans.expression_id ";
- $qry .= "WHERE trans.defined_meaning_id=$dmid ";
- $qry .= "AND " . getLatestTransactionRestriction( "exp" );
- $qry .= "AND " . getLatestTransactionRestriction( "trans" );
-
- $translations = $dbr->query( $qry );
- while ( $row = $dbr->fetchRow( $translations ) ) {
- // qry gets all languages, we filter them here. Saves an order
- // of magnitude execution time.
- if ( in_array( $row['language_id'], $languages ) ) {
- // $key becomes something like trans_23
- $key = 'trans_' . $row['language_id'];
- if ( !isset( $data[$key] ) ) {
- $data[$key] = $row['spelling'];
- } else {
- $data[$key] = $data[$key] . '|' .
$row['spelling'];
- }
- }
- }
- $dbr->freeResult( $translations );
-
- return $data;
-
-}
-
-
-
class ClassAttribute {
public $attributeId;
public $levelName;
Modified: trunk/extensions/Wikidata/OmegaWiki/resources/tables.css
===================================================================
--- trunk/extensions/Wikidata/OmegaWiki/resources/tables.css 2012-12-19
13:15:22 UTC (rev 115791)
+++ trunk/extensions/Wikidata/OmegaWiki/resources/tables.css 2012-12-19
13:19:27 UTC (rev 115792)
@@ -148,7 +148,6 @@
.level3 {
font-size:120% ;
- font-weight: bold;
background-color: #e0ffff;
margin-top:10px;
padding:5px;
@@ -165,6 +164,19 @@
padding:5px;
}
+li.exp-meanings-exact div.level3 {
+ font-weight: bold;
+}
+
+li.exp-meanings-exact>div>ul {
+ margin: 0px;
+}
+
+li.exp-meanings-approx {
+ font-weight: normal;
+ font-style: italic;
+}
+
td.add {
text-align: center;
}
Modified: trunk/extensions/Wikidata/OmegaWiki/type.php
===================================================================
--- trunk/extensions/Wikidata/OmegaWiki/type.php 2012-12-19 13:15:22 UTC
(rev 115791)
+++ trunk/extensions/Wikidata/OmegaWiki/type.php 2012-12-19 13:19:27 UTC
(rev 115792)
@@ -9,18 +9,20 @@
require_once( 'Wikidata.php' );
require_once( 'WikiDataGlobals.php' );
-function booleanAsText( $value ) {
- if ( $value )
- return "Yes";
- else
- return "No";
+function booleanAsText( $boolValue, $textValues = array("true" => "Yes",
"false" => "No") ) {
+ if ( $boolValue ) {
+ return $textValues["true"];
+ } else {
+ return $textValues["false"];
+ }
}
function booleanAsHTML( $value ) {
- if ( $value )
+ if ( $value ) {
return '<input type="checkbox" checked="checked"
disabled="disabled"/>';
- else
+ } else {
return '<input type="checkbox" disabled="disabled"/>';
+ }
}
function pageAsURL( $nameSpace, $title, $usedc = true ) {
@@ -117,6 +119,8 @@
function collectionAsLink( $collectionId ) {
return definedMeaningAsLink( getCollectionMeaningId( $collectionId ) );
}
+/*
+useless?
function convertToHTML( $value, $type ) {
switch( $type ) {
@@ -166,4 +170,4 @@
}
}
-
+*/
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits