r22550 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r22549‎ | r22550 | r22551 >
Date:03:11, 30 May 2007
Author:kim
Status:old
Tags:
Comment:
Special:ConceptMapping complete-ish (ui could use some polish still, perhaps)
I decided not to go for a search panel, since that seems overkill right now.

Also made a "link this id" link.

Possibly some work still needs to be done on permissions, i18n, and
minor details like that.
Modified paths:
  • /trunk/extensions/Wikidata/OmegaWiki/DefinedMeaning.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/SpecialConceptMapping.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/WikiDataAPI.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/Wikidata.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Wikidata/OmegaWiki/WikiDataAPI.php
@@ -943,6 +943,10 @@
944944 #wfDebug("Fallback language: $fallbackLanguageId\n");
945945 $dbr = & wfGetDB(DB_SLAVE);
946946
 947+ $definedMeaningId=$dbr->addQuotes($definedMeaningId);
 948+ $userLangaugeId=$dbr->addQuotes($userLangaugeId);
 949+ $fallbackLanguageId=$dbr->addQuotes($fallbackLanguageId);
 950+
947951 if($userLanguageId) {
948952 $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";
949953
@@ -1120,8 +1124,6 @@
11211125 member_mid=$dm_id,
11221126 add_transaction_id=$add_transaction_id
11231127 ";
1124 - global $wgOut;
1125 - $wgOut->addWikiText($sql);
11261128 $dbr->query($sql);
11271129 }
11281130
@@ -1150,11 +1152,9 @@
11511153 WHERE collection_id = $collection_id
11521154 AND internal_member_id=$concept_id
11531155 ";
1154 - wfDebug($query);
11551156 $queryResult = $dbr->query($query);
11561157 $row=$dbr->fetchObject($queryResult);
11571158 if (isset($row->member_mid)) {
1158 - wfDebug("do we have ".$row->member_mid."\n");
11591159 $map[$dc]=$row->member_mid;
11601160 }
11611161 }
@@ -1174,7 +1174,6 @@
11751175 WHERE member_mid=$dm
11761176 AND collection_id=$collection_id;
11771177 ";
1178 - wfDebug($query);
11791178 $queryResult = $dbr->query($query);
11801179 $row=$dbr->fetchObject($queryResult);
11811180 return isset($row->concept_id) ? $row->concept_id : null;
@@ -1183,7 +1182,6 @@
11841183 function &getAssociatedByConcept($dm, $dc) {
11851184 #$dbr = & wfGetDB(DB_SLAVE);
11861185 $concept_id=getConceptId($dm,$dc);
1187 - wfDebug("concept id:".$concept_id."\n");
11881186 return readConceptMapping($concept_id);
11891187 }
11901188
Index: trunk/extensions/Wikidata/OmegaWiki/Wikidata.php
@@ -446,6 +446,7 @@
447447 private $spelling=null;
448448 private $id=null;
449449 private $dataset=null;
 450+ private $title=null;
450451
451452 /** return spelling of associated expression in particular langauge
452453 * not nescesarily the correct langauge.
@@ -492,18 +493,119 @@
493494 $skin->makeLinkObj($title, $name , "dataset=$prefix");
494495 }
495496
 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) {
496503
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+ }
503514 return $title;
504515 }
505516
 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*/
506607 public function setId($id) {
507608 $this->id=$id;
 609+ $this->canonicalize();
508610 }
509611
510612 public function getId() {
@@ -515,6 +617,9 @@
516618 }
517619
518620 public function &getDataset() {
 621+ if ($this->dataset==null) {
 622+ $this->dataset=wdGetDataSetContext();
 623+ }
519624 return $this->dataset;
520625 }
521626
Index: trunk/extensions/Wikidata/OmegaWiki/SpecialConceptMapping.php
@@ -1,12 +1,13 @@
22 <?php
33 if (!defined('MEDIAWIKI')) die();
44 /**
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
67 * @addtogroup Extensions
78 *
89 * @author Erik Moeller <Eloquence@gmail.com>
910 * @author Kim Bruning <kim@bruning.xs4all.nl>
10 - * @license public domain
 11+ * @license public domain or GPL? (requesting info)
1112 */
1213
1314
@@ -66,6 +67,16 @@
6768 global $wgOut;
6869 require_once("forms.php");
6970
 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+
7081 $sets=wdGetDataSets();
7182 $options = array();
7283 $html="";
@@ -78,19 +89,33 @@
7990 $mappings=array();
8091 foreach ($sets as $key=>$set) {
8192 $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>');
87112 } else {
88 - $wgOut->addHTML("(not supplied)");
 113+ $wgOut->addHTML(' <span style="color:red">[not present or malformed]</span>');
89114 }
90115 $wgOut->addHTML("<br>\n");
91116 }
92117 if (sizeOf($mappings)>1) {
93118 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");
95120 } else {
96121 $wgOut->addHTML("Need to have at least two defined meanings before I can link them");
97122 }
Index: trunk/extensions/Wikidata/OmegaWiki/DefinedMeaning.php
@@ -111,6 +111,7 @@
112112 return $idStack;
113113 }
114114
 115+ /** @deprecated, use DefinedMeaningData.setTitle instead */
115116 protected function getDefinedMeaningIdFromTitle($title) {
116117 // get id from title: DefinedMeaning:expression (id)
117118 $bracketPosition = strrpos($title, "(");
@@ -160,11 +161,14 @@
161162 $slot = $active ? "$name" : $sk->makeLinkObj($dm->getTitle(),$name,"dataset=$prefix");
162163 $html.="<tr><td class=\"$class\">$slot</td></tr>";
163164 }
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";
166171 #$html="bla\n";
167172 return $html;
168173 }
169174 }
170 -
171175 ?>