r23014 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23013‎ | r23014 | r23015 >
Date:17:35, 15 June 2007
Author:erik
Status:old
Tags:
Comment:
fix dataset problem & bug in getspelling
Modified paths:
  • /trunk/extensions/Wikidata/OmegaWiki/WikiDataAPI.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/Wikidata.php (modified) (history)
  • /trunk/extensions/Wikidata/README (modified) (history)

Diff [purge]

Index: trunk/extensions/Wikidata/OmegaWiki/Wikidata.php
@@ -419,7 +419,7 @@
420420 private $title=null;
421421
422422 /** return spelling of associated expression in particular langauge
423 - * not nescesarily the correct langauge.
 423+ * not nescesarily the correct language.
424424 */
425425 public function getSpelling() {
426426 if ($this->spelling==null) {
@@ -435,7 +435,6 @@
436436 $dataset=$this->getDataset();
437437 if ($dataset==null)
438438 return null;
439 -
440439 $this->spelling=getSpellingForLanguage($id, $languageCode, "en", $dataset);
441440 }
442441 return $this->spelling;
@@ -469,14 +468,13 @@
470469 public function getTitle() {
471470 $title=$this->title;
472471 if ($title==null) {
473 -
474472 $name=$this->getSpelling();
475473 $id=$this->getId();
476474
477 - if ($name==null or $id==null)
 475+ if (is_null($name) or is_null($id))
478476 return null;
479477
480 - $text="DefinedMeaning:$name ($id)";
 478+ $text="DefinedMeaning:".$name."_($id)";
481479 $title=Title::newFromText($text);
482480 $this->title=$title;
483481 }
@@ -487,7 +485,10 @@
488486 * This is partially copied from DefinedMeaning.getDefinedMeaningIdFromTitle
489487 * which is slightly less usable (and hence should be deprecated)
490488 *
491 - * Also note the traditionally very weak error-checking, this may need
 489+ * Also note the traditionally very weak error-checking, th$this->title=Title::newFromText($titleText);
 490+ $bracketPosition = strrpos($titleText, "(");
 491+ if ($bracketPosition==false)
 492+ return; # we accept that we may have a someis may need
492493 * updating. Canonicalize helps a bit.
493494 *
494495 * Will gladly eat invalid titles (in which case object state
@@ -498,8 +499,7 @@
499500 $this->title=Title::newFromText($titleText);
500501 $bracketPosition = strrpos($titleText, "(");
501502 if ($bracketPosition==false)
502 - return; # we accept that we may have a somewhat broken
503 - # title string.
 503+ return; # Defined Meaning ID is missing from title string
504504 $definedMeaningId = substr($titleText, $bracketPosition + 1, strlen($titleText) - $bracketPosition - 2);
505505 $this->setId($definedMeaningId);
506506 }
@@ -546,7 +546,7 @@
547547 * a horribly misformed title will work, as long as the id is correct :-P )
548548 */
549549 public function canonicalize(){
550 - $oldtitle=&$this->title;
 550+ $oldtitle=$this->title;
551551 $oldspelling=$this->spelling;
552552
553553 $this->title=null; # } clear cached values to force db fetch.
@@ -554,7 +554,7 @@
555555 $this->title=$this->getTitle(); # will fetch from db!
556556
557557 if ($this->title==null) { # db lookup failure
558 - $this->title=&$oldtitle;
 558+ $this->title=$oldtitle;
559559 $this->spelling=$oldspelling;
560560 return false;
561561 }
Index: trunk/extensions/Wikidata/OmegaWiki/WikiDataAPI.php
@@ -946,9 +946,7 @@
947947
948948 function getSpellingForLanguage($definedMeaningId, $languageCode, $fallbackLanguageCode='en', $dc=null) {
949949
950 - if(is_null($dc)) {
951 - $dc=wdGetDataSetContext();
952 - }
 950+ $dc=wdGetDataSetContext($dc);
953951
954952 $userLanguageId=getLanguageIdForCode($languageCode);
955953
@@ -976,6 +974,11 @@
977975 $row=$dbr->fetchObject($res);
978976 if(isset($row->spelling)) return $row->spelling;
979977
 978+ $final_fallback="select spelling from {$dc}_syntrans,{$dc}_expression_ns where {$dc}_syntrans.defined_meaning_id=$definedMeaningId and {$dc}_expression_ns.expression_id={$dc}_syntrans.expression_id and {$dc}_expression_ns.remove_transaction_id is NULL LIMIT 1";
 979+
 980+ $res=$dbr->query($final_fallback);
 981+ $row=$dbr->fetchObject($res);
 982+ if(isset($row->spelling)) return $row->spelling;
980983 return null;
981984
982985 }
Index: trunk/extensions/Wikidata/README
@@ -10,3 +10,4 @@
1111 OmegaWiki/ - the current main (only) application of the Wikidata framework
1212 perl-tools/ - import/export tools written in Perl
1313 php-tools/ - import/export tools written in PHP
 14+util/ -
\ No newline at end of file

Status & tagging log