Index: trunk/extensions/Wikidata/OmegaWiki/Wikidata.php |
— | — | @@ -419,7 +419,7 @@ |
420 | 420 | private $title=null; |
421 | 421 | |
422 | 422 | /** return spelling of associated expression in particular langauge |
423 | | - * not nescesarily the correct langauge. |
| 423 | + * not nescesarily the correct language. |
424 | 424 | */ |
425 | 425 | public function getSpelling() { |
426 | 426 | if ($this->spelling==null) { |
— | — | @@ -435,7 +435,6 @@ |
436 | 436 | $dataset=$this->getDataset(); |
437 | 437 | if ($dataset==null) |
438 | 438 | return null; |
439 | | - |
440 | 439 | $this->spelling=getSpellingForLanguage($id, $languageCode, "en", $dataset); |
441 | 440 | } |
442 | 441 | return $this->spelling; |
— | — | @@ -469,14 +468,13 @@ |
470 | 469 | public function getTitle() { |
471 | 470 | $title=$this->title; |
472 | 471 | if ($title==null) { |
473 | | - |
474 | 472 | $name=$this->getSpelling(); |
475 | 473 | $id=$this->getId(); |
476 | 474 | |
477 | | - if ($name==null or $id==null) |
| 475 | + if (is_null($name) or is_null($id)) |
478 | 476 | return null; |
479 | 477 | |
480 | | - $text="DefinedMeaning:$name ($id)"; |
| 478 | + $text="DefinedMeaning:".$name."_($id)"; |
481 | 479 | $title=Title::newFromText($text); |
482 | 480 | $this->title=$title; |
483 | 481 | } |
— | — | @@ -487,7 +485,10 @@ |
488 | 486 | * This is partially copied from DefinedMeaning.getDefinedMeaningIdFromTitle |
489 | 487 | * which is slightly less usable (and hence should be deprecated) |
490 | 488 | * |
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 |
492 | 493 | * updating. Canonicalize helps a bit. |
493 | 494 | * |
494 | 495 | * Will gladly eat invalid titles (in which case object state |
— | — | @@ -498,8 +499,7 @@ |
499 | 500 | $this->title=Title::newFromText($titleText); |
500 | 501 | $bracketPosition = strrpos($titleText, "("); |
501 | 502 | 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 |
504 | 504 | $definedMeaningId = substr($titleText, $bracketPosition + 1, strlen($titleText) - $bracketPosition - 2); |
505 | 505 | $this->setId($definedMeaningId); |
506 | 506 | } |
— | — | @@ -546,7 +546,7 @@ |
547 | 547 | * a horribly misformed title will work, as long as the id is correct :-P ) |
548 | 548 | */ |
549 | 549 | public function canonicalize(){ |
550 | | - $oldtitle=&$this->title; |
| 550 | + $oldtitle=$this->title; |
551 | 551 | $oldspelling=$this->spelling; |
552 | 552 | |
553 | 553 | $this->title=null; # } clear cached values to force db fetch. |
— | — | @@ -554,7 +554,7 @@ |
555 | 555 | $this->title=$this->getTitle(); # will fetch from db! |
556 | 556 | |
557 | 557 | if ($this->title==null) { # db lookup failure |
558 | | - $this->title=&$oldtitle; |
| 558 | + $this->title=$oldtitle; |
559 | 559 | $this->spelling=$oldspelling; |
560 | 560 | return false; |
561 | 561 | } |
Index: trunk/extensions/Wikidata/OmegaWiki/WikiDataAPI.php |
— | — | @@ -946,9 +946,7 @@ |
947 | 947 | |
948 | 948 | function getSpellingForLanguage($definedMeaningId, $languageCode, $fallbackLanguageCode='en', $dc=null) { |
949 | 949 | |
950 | | - if(is_null($dc)) { |
951 | | - $dc=wdGetDataSetContext(); |
952 | | - } |
| 950 | + $dc=wdGetDataSetContext($dc); |
953 | 951 | |
954 | 952 | $userLanguageId=getLanguageIdForCode($languageCode); |
955 | 953 | |
— | — | @@ -976,6 +974,11 @@ |
977 | 975 | $row=$dbr->fetchObject($res); |
978 | 976 | if(isset($row->spelling)) return $row->spelling; |
979 | 977 | |
| 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; |
980 | 983 | return null; |
981 | 984 | |
982 | 985 | } |
Index: trunk/extensions/Wikidata/README |
— | — | @@ -10,3 +10,4 @@ |
11 | 11 | OmegaWiki/ - the current main (only) application of the Wikidata framework |
12 | 12 | perl-tools/ - import/export tools written in Perl |
13 | 13 | php-tools/ - import/export tools written in PHP |
| 14 | +util/ - |
\ No newline at end of file |