Index: trunk/extensions/Wikidata/OmegaWiki/WikiDataAPI.php |
— | — | @@ -943,6 +943,10 @@ |
944 | 944 | #wfDebug("Fallback language: $fallbackLanguageId\n"); |
945 | 945 | $dbr = & wfGetDB(DB_SLAVE); |
946 | 946 | |
| 947 | + $definedMeaningId=$dbr->addQuotes($definedMeaningId); |
| 948 | + $userLangaugeId=$dbr->addQuotes($userLangaugeId); |
| 949 | + $fallbackLanguageId=$dbr->addQuotes($fallbackLanguageId); |
| 950 | + |
947 | 951 | if($userLanguageId) { |
948 | 952 | $actual_query="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 language_id=$userLanguageId and {$dc}_expression_ns.remove_transaction_id is NULL"; |
949 | 953 | |
— | — | @@ -1120,8 +1124,6 @@ |
1121 | 1125 | member_mid=$dm_id, |
1122 | 1126 | add_transaction_id=$add_transaction_id |
1123 | 1127 | "; |
1124 | | - global $wgOut; |
1125 | | - $wgOut->addWikiText($sql); |
1126 | 1128 | $dbr->query($sql); |
1127 | 1129 | } |
1128 | 1130 | |
— | — | @@ -1150,11 +1152,9 @@ |
1151 | 1153 | WHERE collection_id = $collection_id |
1152 | 1154 | AND internal_member_id=$concept_id |
1153 | 1155 | "; |
1154 | | - wfDebug($query); |
1155 | 1156 | $queryResult = $dbr->query($query); |
1156 | 1157 | $row=$dbr->fetchObject($queryResult); |
1157 | 1158 | if (isset($row->member_mid)) { |
1158 | | - wfDebug("do we have ".$row->member_mid."\n"); |
1159 | 1159 | $map[$dc]=$row->member_mid; |
1160 | 1160 | } |
1161 | 1161 | } |
— | — | @@ -1174,7 +1174,6 @@ |
1175 | 1175 | WHERE member_mid=$dm |
1176 | 1176 | AND collection_id=$collection_id; |
1177 | 1177 | "; |
1178 | | - wfDebug($query); |
1179 | 1178 | $queryResult = $dbr->query($query); |
1180 | 1179 | $row=$dbr->fetchObject($queryResult); |
1181 | 1180 | return isset($row->concept_id) ? $row->concept_id : null; |
— | — | @@ -1183,7 +1182,6 @@ |
1184 | 1183 | function &getAssociatedByConcept($dm, $dc) { |
1185 | 1184 | #$dbr = & wfGetDB(DB_SLAVE); |
1186 | 1185 | $concept_id=getConceptId($dm,$dc); |
1187 | | - wfDebug("concept id:".$concept_id."\n"); |
1188 | 1186 | return readConceptMapping($concept_id); |
1189 | 1187 | } |
1190 | 1188 | |
Index: trunk/extensions/Wikidata/OmegaWiki/Wikidata.php |
— | — | @@ -446,6 +446,7 @@ |
447 | 447 | private $spelling=null; |
448 | 448 | private $id=null; |
449 | 449 | private $dataset=null; |
| 450 | + private $title=null; |
450 | 451 | |
451 | 452 | /** return spelling of associated expression in particular langauge |
452 | 453 | * not nescesarily the correct langauge. |
— | — | @@ -492,18 +493,119 @@ |
493 | 494 | $skin->makeLinkObj($title, $name , "dataset=$prefix"); |
494 | 495 | } |
495 | 496 | |
| 497 | + /** returns the page title associated with this defined meaning (as a Title object) |
| 498 | + * First time from db lookup. Subsequently from cache |
| 499 | + */ |
| 500 | + public function &getTitle() { |
| 501 | + $title=&$this->title; |
| 502 | + if ($title==null) { |
496 | 503 | |
497 | | - public function &getTitle() { |
498 | | - $name=$this->getSpelling(); |
499 | | - $id=$this->getId(); |
500 | | - $text="DefinedMeaning:$name ($id)"; |
501 | | - wfDebug($text); |
502 | | - $title=Title::newFromText($text); |
| 504 | + $name=$this->getSpelling(); |
| 505 | + $id=$this->getId(); |
| 506 | + |
| 507 | + if ($name==null or $id==null) |
| 508 | + return null; |
| 509 | + |
| 510 | + $text="DefinedMeaning:$name ($id)"; |
| 511 | + $title=Title::newFromText($text); |
| 512 | + $this->title=$title; |
| 513 | + } |
503 | 514 | return $title; |
504 | 515 | } |
505 | 516 | |
| 517 | + /** set the title (and associated ID) from text representation |
| 518 | + * This is partially copied from DefinedMeaning.getDefinedMeaningIdFromTitle |
| 519 | + * which is slightly less usable (and hence should be deprecated) |
| 520 | + * |
| 521 | + * Also note the traditionally very weak error-checking, this may need |
| 522 | + * updating. Canonicalize helps a bit. |
| 523 | + * |
| 524 | + * Will gladly eat invalid titles (in which case object state |
| 525 | + * may become somewhat undefined) |
| 526 | + */ |
| 527 | + public function setTitleText($titleText){ |
| 528 | + // get id from title: DefinedMeaning:expression (id) |
| 529 | + $this->title=Title::newFromText($titleText); |
| 530 | + $bracketPosition = strrpos($titleText, "("); |
| 531 | + if ($bracketPosition==false) |
| 532 | + return; # we accept that we may have a somewhat broken |
| 533 | + # title string. |
| 534 | + $definedMeaningId = substr($titleText, $bracketPosition + 1, strlen($titleText) - $bracketPosition - 2); |
| 535 | + $this->setId($definedMeaningId); |
| 536 | + } |
| 537 | + |
| 538 | + /**set the title (and associated ID) from mediawiki Title object*/ |
| 539 | + public function setTitle(&$title){ |
| 540 | + $this->setTitleText($title->getFullText()); |
| 541 | + } |
| 542 | + |
| 543 | + /**retturn full text representation of title*/ |
| 544 | + public function getTitleText(){ |
| 545 | + $title=$this->getTitle(); |
| 546 | + return $title->getFullText(); |
| 547 | + } |
| 548 | + /** |
| 549 | + * Look up defined meaning id in db, |
| 550 | + * and attempt to get defined meaning into |
| 551 | + * canonical form, with correct spelling, etc. |
| 552 | + * |
| 553 | + * use canonicalize anytime you take user input. |
| 554 | + * note that the defined meaning must already |
| 555 | + * be in the database for this to work. |
| 556 | + * |
| 557 | + * example(s): |
| 558 | + * For any user supplied defined meaning, |
| 559 | + * "traditionally" we have only looked at the part |
| 560 | + * between parens. |
| 561 | + * For instance, for |
| 562 | + * DefinedMeaning:Jump (6684) |
| 563 | + * |
| 564 | + * We only really look at (6684), and discard the rest. |
| 565 | + * This can lead to funny situations... |
| 566 | + * |
| 567 | + * If a user were to look for DefinedMeaning:YellowBus (6684) |
| 568 | + * they would get a page back with that title, but with |
| 569 | + * the contents of DefinedMeaning:Jump (6684)... very confusing! |
| 570 | + * |
| 571 | + * This kind of odd behaviour (and anything else we might come across later) |
| 572 | + * gets corrected here. |
| 573 | + * |
| 574 | + * @return true on success (page (already) exists in db, title now updated); |
| 575 | + * false on failure (page not (yet?) in db, or id was never set, |
| 576 | + * or not enough info to perform lookup (need at least id or something with id in it: |
| 577 | + * a horribly misformed title will work, as long as the id is correct :-P ) |
| 578 | + */ |
| 579 | + public function canonicalize(){ |
| 580 | + $oldtitle=&$this->title; |
| 581 | + $oldspelling=$this->spelling; |
| 582 | + |
| 583 | + $this->title=null; # } clear cached values to force db fetch. |
| 584 | + $this->spelling=null; # } |
| 585 | + $this->title=$this->getTitle(); # will fetch from db! |
| 586 | + |
| 587 | + if ($this->title==null) { # db lookup failure |
| 588 | + $this->title=&$oldtitle; |
| 589 | + $this->spelling=$oldspelling; |
| 590 | + return false; |
| 591 | + } |
| 592 | + |
| 593 | + return true; |
| 594 | + } |
| 595 | + |
| 596 | + /** returns true if a database entry already exists for this dmid, and an expression is present in this langauge in this dataset, otherwise returns false. */ |
| 597 | + public function exists() { |
| 598 | + /*reusing getSpelling for now as a hack. Probably better |
| 599 | + *to write a dedicated exists in WikiDataAPI, or here |
| 600 | + */ |
| 601 | + if ($this->getSpelling()!=null) |
| 602 | + return true; |
| 603 | + return false; |
| 604 | + } |
| 605 | + |
| 606 | + /** sets id*/ |
506 | 607 | public function setId($id) { |
507 | 608 | $this->id=$id; |
| 609 | + $this->canonicalize(); |
508 | 610 | } |
509 | 611 | |
510 | 612 | public function getId() { |
— | — | @@ -515,6 +617,9 @@ |
516 | 618 | } |
517 | 619 | |
518 | 620 | public function &getDataset() { |
| 621 | + if ($this->dataset==null) { |
| 622 | + $this->dataset=wdGetDataSetContext(); |
| 623 | + } |
519 | 624 | return $this->dataset; |
520 | 625 | } |
521 | 626 | |
Index: trunk/extensions/Wikidata/OmegaWiki/SpecialConceptMapping.php |
— | — | @@ -1,12 +1,13 @@ |
2 | 2 | <?php |
3 | 3 | if (!defined('MEDIAWIKI')) die(); |
4 | 4 | /** |
5 | | - * A Special Page extension to add languages, runnable by users with the 'addlanguage' right. |
| 5 | + * A Special Page extension to create concept-mappings |
| 6 | + * also provides a web-api. Minimal documentation is available by calling with &action=help, as a parameter |
6 | 7 | * @addtogroup Extensions |
7 | 8 | * |
8 | 9 | * @author Erik Moeller <Eloquence@gmail.com> |
9 | 10 | * @author Kim Bruning <kim@bruning.xs4all.nl> |
10 | | - * @license public domain |
| 11 | + * @license public domain or GPL? (requesting info) |
11 | 12 | */ |
12 | 13 | |
13 | 14 | |
— | — | @@ -66,6 +67,16 @@ |
67 | 68 | global $wgOut; |
68 | 69 | require_once("forms.php"); |
69 | 70 | |
| 71 | + $wgOut->addHTML(" |
| 72 | + <p>Concept Mapping allows you to identify |
| 73 | + which defined meaning in one dataset is identical |
| 74 | + to defined meanings in other datasets.</p>\n |
| 75 | + <p>Please enter or cut and paste the defined |
| 76 | + meanings (with id), or simply the defined meaning ids |
| 77 | + which are identical.</p>\n |
| 78 | + <p> For example, you could paste <code>DefinedMeaning:Boat (7774)</code> |
| 79 | + or simply type <code>7774</code>.</p>\n"); |
| 80 | + |
70 | 81 | $sets=wdGetDataSets(); |
71 | 82 | $options = array(); |
72 | 83 | $html=""; |
— | — | @@ -78,19 +89,33 @@ |
79 | 90 | $mappings=array(); |
80 | 91 | foreach ($sets as $key=>$set) { |
81 | 92 | $rq=$wgRequest->getText("set_".$key); |
82 | | - $rq=ltrim($rq); |
83 | | - $wgOut->addHTML("$key: $rq"); |
84 | | - if ($rq!=null and $rq!="") { |
85 | | - $mappings[$key]=$rq; |
86 | | - $wgOut->addHTML(" (will insert)"); |
| 93 | + $rq=trim($rq); |
| 94 | + $dmData=new DefinedMeaningData(); |
| 95 | + $dmData->setDataset($set); |
| 96 | + $dmData->setTitleText($rq); #is $rq a page title? |
| 97 | + if ($dmData->getId()==null) { #guess not |
| 98 | + $dmData->setId($rq); # maybe it's a defined meaning id? |
| 99 | + } |
| 100 | + $dmData->canonicalize(); |
| 101 | + $id=null; |
| 102 | + $title=null; |
| 103 | + if ($dmData->exists()) { |
| 104 | + $id=$dmData->getId(); |
| 105 | + $title=$dmData->getTitleText(); |
| 106 | + } |
| 107 | + |
| 108 | + $wgOut->addHTML("$key: $rq ($title)"); |
| 109 | + if ($id!=null) { |
| 110 | + $mappings[$key]=$id; |
| 111 | + $wgOut->addHTML(' <span style="color:green">[OK]</span>'); |
87 | 112 | } else { |
88 | | - $wgOut->addHTML("(not supplied)"); |
| 113 | + $wgOut->addHTML(' <span style="color:red">[not present or malformed]</span>'); |
89 | 114 | } |
90 | 115 | $wgOut->addHTML("<br>\n"); |
91 | 116 | } |
92 | 117 | if (sizeOf($mappings)>1) { |
93 | 118 | createConceptMapping($mappings); |
94 | | - $wgOut->addHTML("Mapped all fields marked with (will insert)<br>\n"); |
| 119 | + $wgOut->addHTML("Mapped all fields marked with [OK]<br>\n"); |
95 | 120 | } else { |
96 | 121 | $wgOut->addHTML("Need to have at least two defined meanings before I can link them"); |
97 | 122 | } |
Index: trunk/extensions/Wikidata/OmegaWiki/DefinedMeaning.php |
— | — | @@ -111,6 +111,7 @@ |
112 | 112 | return $idStack; |
113 | 113 | } |
114 | 114 | |
| 115 | + /** @deprecated, use DefinedMeaningData.setTitle instead */ |
115 | 116 | protected function getDefinedMeaningIdFromTitle($title) { |
116 | 117 | // get id from title: DefinedMeaning:expression (id) |
117 | 118 | $bracketPosition = strrpos($title, "("); |
— | — | @@ -160,11 +161,14 @@ |
161 | 162 | $slot = $active ? "$name" : $sk->makeLinkObj($dm->getTitle(),$name,"dataset=$prefix"); |
162 | 163 | $html.="<tr><td class=\"$class\">$slot</td></tr>"; |
163 | 164 | } |
164 | | - $html.="</table>"; |
165 | | - $html.="</div>"; |
| 165 | + $cmtitle=Title::newFromText("Special:ConceptMapping"); |
| 166 | + $titleText=$wgTitle->getPrefixedURL(); |
| 167 | + $cmlink=$sk->makeLinkObj($cmtitle,"<small>link to other concepts</small>","set_$dc=$titleText"); |
| 168 | + $html.="<tr><td>$cmlink</td></tr>\n"; |
| 169 | + $html.="</table>\n"; |
| 170 | + $html.="</div>\n"; |
166 | 171 | #$html="bla\n"; |
167 | 172 | return $html; |
168 | 173 | } |
169 | 174 | } |
170 | | - |
171 | 175 | ?> |