r61470 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r61469‎ | r61470 | r61471 >
Date:18:31, 24 January 2010
Author:kipcool
Status:deferred
Tags:
Comment:
Adding the possibility to have language specific attributes for all attributes at syntrans level
Modified paths:
  • /trunk/extensions/Wikidata/OmegaWiki/Editor.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/SpecialSuggest.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/suggest.js (modified) (history)

Diff [purge]

Index: trunk/extensions/Wikidata/OmegaWiki/SpecialSuggest.php
@@ -10,7 +10,7 @@
1111 SpecialPage::SpecialPage( 'Suggest', 'UnlistedSpecialPage' );
1212
1313 }
14 -
 14+
1515 function execute( $par ) {
1616 global
1717 $wgOut, $IP;
@@ -57,6 +57,7 @@
5858 @$offset = $_GET['offset'];
5959 @$attributesLevel = $_GET['attributesLevel'];
6060 @$annotationAttributeId = $_GET['annotationAttributeId'];
 61+ $syntransId = $_GET["syntransId"];
6162
6263 $sql = '';
6364
@@ -74,19 +75,19 @@
7576 $sql = getSQLForClasses( $wgUser->getOption( 'language' ) );
7677 break;
7778 case "$wgDefinedMeaningAttributes":
78 - $sql = getSQLToSelectPossibleAttributes( $definedMeaningId, $attributesLevel, $annotationAttributeId, 'DM' );
 79+ $sql = getSQLToSelectPossibleAttributes( $definedMeaningId, $attributesLevel, $syntransId, $annotationAttributeId, 'DM' );
7980 break;
8081 case 'text-attribute':
81 - $sql = getSQLToSelectPossibleAttributes( $definedMeaningId, $attributesLevel, $annotationAttributeId, 'TEXT' );
 82+ $sql = getSQLToSelectPossibleAttributes( $definedMeaningId, $attributesLevel, $syntransId, $annotationAttributeId, 'TEXT' );
8283 break;
8384 case 'translated-text-attribute':
84 - $sql = getSQLToSelectPossibleAttributes( $definedMeaningId, $attributesLevel, $annotationAttributeId, 'TRNS' );
 85+ $sql = getSQLToSelectPossibleAttributes( $definedMeaningId, $attributesLevel, $syntransId, $annotationAttributeId, 'TRNS' );
8586 break;
8687 case "$wgLinkAttribute":
87 - $sql = getSQLToSelectPossibleAttributes( $definedMeaningId, $attributesLevel, $annotationAttributeId, 'URL' );
 88+ $sql = getSQLToSelectPossibleAttributes( $definedMeaningId, $attributesLevel, $syntransId, $annotationAttributeId, 'URL' );
8889 break;
8990 case "$wgOptionAttribute":
90 - $sql = getSQLToSelectPossibleAttributes( $definedMeaningId, $attributesLevel, $annotationAttributeId, 'OPTN' );
 91+ $sql = getSQLToSelectPossibleAttributes( $definedMeaningId, $attributesLevel, $syntransId, $annotationAttributeId, 'OPTN' );
9192 break;
9293 case 'language':
9394 require_once( 'languages.php' );
@@ -121,7 +122,7 @@
122123 " SUBSTRING(timestamp, 9, 2), ':', SUBSTRING(timestamp, 11, 2), ':', SUBSTRING(timestamp, 13, 2))";
123124 break;
124125 }
125 -
 126+
126127 if ( $search != '' ) {
127128 if ( $query == 'transaction' )
128129 $searchCondition = " AND $rowText LIKE " . $dbr->addQuotes( "%$search%" );
@@ -252,7 +253,7 @@
253254 * @param $language the 2 letter wikimedia code
254255 */
255256
256 -function getSQLToSelectPossibleAttributes( $definedMeaningId, $attributesLevel, $annotationAttributeId, $attributesType ) {
 257+function getSQLToSelectPossibleAttributes( $definedMeaningId, $attributesLevel, $syntransId, $annotationAttributeId, $attributesType ) {
257258
258259 global $wgDefaultClassMids, $wgUser;
259260
@@ -262,11 +263,38 @@
263264 $language = $wgUser->getOption( 'language' ) ;
264265 $lng = ' ( SELECT language_id FROM language WHERE wikimedia_key = ' . $dbr->addQuotes( $language ) . ' ) ';
265266
266 - if ( count( $wgDefaultClassMids ) > 0 )
267 - $defaultClassRestriction = " OR {$dc}_class_attributes.class_mid IN (" . join( $wgDefaultClassMids, ", " ) . ")";
 267+ $classMids = $wgDefaultClassMids ;
 268+
 269+ if ( $syntransId != 0 ) {
 270+ // find the language of the syntrans and add attributes of that language by adding the language DM to the list of default classes
 271+ // this first query returns the language_id
 272+ $sql = 'SELECT language_id' .
 273+ " FROM {$dc}_syntrans" .
 274+ " JOIN {$dc}_expression ON {$dc}_expression.expression_id = {$dc}_syntrans.expression_id" .
 275+ " WHERE {$dc}_syntrans.syntrans_sid = " . $syntransId .
 276+ ' AND ' . getLatestTransactionRestriction( "{$dc}_syntrans" ) .
 277+ ' AND ' . getLatestTransactionRestriction( "{$dc}_expression" );
 278+ $lang_res = $dbr->query( $sql );
 279+ $language_id = $dbr->fetchObject( $lang_res )->language_id;
 280+
 281+ // this second query finds the DM number for a given language_id
 282+ // 145264 is the collection_id of the "ISO 639-3 codes" collection
 283+ $sql = "SELECT member_mid FROM {$dc}_collection_contents, language" .
 284+ " WHERE language.language_id = $language_id" .
 285+ " AND {$dc}_collection_contents.collection_id = 145264" .
 286+ " AND language.iso639_3 = {$dc}_collection_contents.internal_member_id" .
 287+ ' AND ' . getLatestTransactionRestriction( "{$dc}_collection_contents" );
 288+ $lang_res = $dbr->query( $sql );
 289+ $language_dm_id = $dbr->fetchObject( $lang_res )->member_mid;
 290+
 291+ $classMids = array_merge ( $wgDefaultClassMids , array($language_dm_id) ) ;
 292+ }
 293+
 294+ if ( count( $classMids ) > 0 )
 295+ $defaultClassRestriction = " OR {$dc}_class_attributes.class_mid IN (" . join( $classMids, ", " ) . ")";
268296 else
269297 $defaultClassRestriction = "";
270 -
 298+
271299 $filteredAttributesRestriction = getFilteredAttributesRestriction( $annotationAttributeId );
272300
273301 $sql =
Index: trunk/extensions/Wikidata/OmegaWiki/suggest.js
@@ -52,6 +52,7 @@
5353
5454 var suggestAttributesLevel = document.getElementById(suggestPrefix + "parameter-level");
5555 var suggestDefinedMeaningId = document.getElementById(suggestPrefix + "parameter-definedMeaningId");
 56+ var suggestSyntransId = document.getElementById(suggestPrefix + "parameter-syntransId");
5657 var suggestAnnotationAttributeId = document.getElementById(suggestPrefix + "parameter-annotationAttributeId");
5758
5859 var URL = 'index.php';
@@ -73,6 +74,9 @@
7475 if (suggestDefinedMeaningId != null)
7576 URL = URL + '&definedMeaningId=' + encodeURI(suggestDefinedMeaningId.value);
7677
 78+ if (suggestSyntransId != null)
 79+ URL = URL + '&syntransId=' + encodeURI(suggestSyntransId.value);
 80+
7781 if (suggestAnnotationAttributeId != null)
7882 URL = URL + '&annotationAttributeId=' + encodeURI(suggestAnnotationAttributeId.value);
7983
Index: trunk/extensions/Wikidata/OmegaWiki/Editor.php
@@ -1303,8 +1303,7 @@
13041304 }
13051305
13061306 public function getInputValue( $id ) {
1307 - global
1308 - $wgRequest;
 1307+ global $wgRequest;
13091308
13101309 return trim( $wgRequest->getText( $id ) );
13111310 }
@@ -1368,12 +1367,16 @@
13691368
13701369 public function add( IdStack $idPath ) {
13711370 if ( $this->isAddField ) {
 1371+ $syntransId = $idPath->getKeyStack()->peek( 0 )->syntransId;
 1372+ if ( $syntransId == "" ) $syntransId = 0 ; // in the case of a DM option attribute, there is no syntrans in the PathId
 1373+
13721374 $parameters = array(
13731375 "level" => $this->attributesLevelName,
13741376 "definedMeaningId" => $idPath->getDefinedMeaningId(),
 1377+ "syntransId" => $syntransId,
13751378 "annotationAttributeId" => $idPath->getAnnotationAttribute()->getId()
13761379 );
1377 -
 1380+
13781381 return getSuggest( $this->addId( $idPath->getId() ), $this->suggestType(), $parameters );
13791382 }
13801383 else
@@ -1427,7 +1430,7 @@
14281431 if ( $this->isAddField ) {
14291432 $syntransId = $idPath->getKeyStack()->peek( 0 )->syntransId;
14301433 if ( ! $syntransId ) $syntransId = 0 ; // in the case of a DM option attribute, there is no syntrans in the PathId
1431 -
 1434+
14321435 $parameters = array(
14331436 "level" => $this->attributesLevelName,
14341437 "definedMeaningId" => $idPath->getDefinedMeaningId(),

Status & tagging log