r24398 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r24397‎ | r24398 | r24399 >
Date:21:43, 26 July 2007
Author:erik
Status:old
Tags:
Comment:
safe fallback strategy on dm lookup
Modified paths:
  • /trunk/extensions/Wikidata/App.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/DefinedMeaning.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/DefinedMeaningModel.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Wikidata/App.php
@@ -133,12 +133,12 @@
134134 "DefinedMeaningReference" => "Defined meaning",
135135 "ExactMeanings" => "Exact meanings",
136136 "Expression" => "Expression",
137 - "ExpressionMeanings" => "Expression meanings",
 137+ "ExpressionMeanings" => "Expression meanings",
138138 "Expressions" => "Expressions",
139139 "IdenticalMeaning" => "Identical meaning?",
140140 "IncomingRelations" => "Incoming relations",
141141 "GotoSource" => "Go to source",
142 - "Language" => "Language",
 142+ "language" => "Language",
143143 "LevelAnnotation" => "Annotation",
144144 "OptionAttribute" => "Property",
145145 "OptionAttributeOption" => "Option",
@@ -150,13 +150,13 @@
151151 "PossiblySynonymous" => "Possibly synonymous",
152152 "Relations" => "Relations",
153153 "RelationType" => "Relation type",
154 - "Spelling" => "Spelling",
 154+ "spelling" => "Spelling",
155155 "Synonyms" => "Synonyms",
156156 "SynonymsAndTranslations" => "Synonyms and translations",
157157 "Source" => "Source",
158158 "SourceIdentifier" => "Source identifier",
159159 "TextAttribute" => "Property",
160 - "Text" => "Text",
 160+ "text" => "Text",
161161 "TextAttributeValues" => "String properties",
162162 "TranslatedTextAttribute" => "Property",
163163 "TranslatedText" => "Translated text",
Index: trunk/extensions/Wikidata/OmegaWiki/DefinedMeaning.php
@@ -27,13 +27,34 @@
2828 $definedMeaningModel->copyTo($copyTo);
2929 }
3030
31 - if(!empty($dmInfo["expression"]))
32 - $definedMeaningModel->setDefiningExpression($dmInfo["expression"]);
 31+ if(!empty($dmInfo["expression"])) {
 32+ $definedMeaningModel->setDefiningExpression($dmInfo["expression"]);
 33+ }
3334
3435 // Search for this DM in all data-sets, beginning with the current one.
3536 // Switch dataset context if found elsewhere.
3637 $match=$definedMeaningModel->checkExistence(true, true);
3738
 39+ // The defining expression is likely incorrect for some reason. Let's just
 40+ // try looking up the number.
 41+ if(is_null($match) && !empty($dmInfo["expression"])) {
 42+ $definedMeaningModel->setDefiningExpression(null);
 43+ $dmInfo["expression"]=null;
 44+ $match=$definedMeaningModel->checkExistence(true, true);
 45+ }
 46+
 47+ // The defining expression is either bad or missing. Let's redirect
 48+ // to the correct URL.
 49+ if(empty($dmInfo["expression"]) && !is_null($match)) {
 50+ $definedMeaningModel->loadRecord();
 51+ $title=Title::newFromText($definedMeaningModel->getWikiTitle());
 52+ $url=$title->getFullURL();
 53+ $wgOut->disable();
 54+ header("Location: $url");
 55+ return false;
 56+ }
 57+
 58+ // Bad defining expression AND bad ID! :-(
3859 if(is_null($match)) {
3960 $wgOut->showErrorPage('errorpagetitle','ow_dm_missing');
4061 return false;
Index: trunk/extensions/Wikidata/OmegaWiki/DefinedMeaningModel.php
@@ -379,12 +379,17 @@
380380 */
381381 public static function splitTitleText($titleText) {
382382 $bracketPosition = strrpos($titleText, "(");
383 - if ($bracketPosition==false)
 383+ if ($bracketPosition===false)
384384 return null; # Defined Meaning ID is missing from title string
385385 $rv=array();
386 - $definingExpression = substr($titleText, 0, $bracketPosition -1);
387 - $definingExpression = str_replace("_"," ",$definingExpression);
 386+ if($bracketPosition>0) {
 387+ $definingExpression = substr($titleText, 0, $bracketPosition -1);
 388+ $definingExpression = str_replace("_"," ",$definingExpression);
 389+ } else {
 390+ $definingExpression = null;
 391+ }
388392 $definedMeaningId = substr($titleText, $bracketPosition + 1, strlen($titleText) - $bracketPosition - 2);
 393+
389394 $rv["expression"]=$definingExpression;
390395 $rv["id"]=(int)$definedMeaningId;
391396 return $rv;
@@ -417,6 +422,15 @@
418423 return $this->definingExpression;
419424 }
420425
 426+ public function getWikiTitle() {
 427+ $dmEx=$this->getDefiningExpression();
 428+ $dmId=$this->getId();
 429+ $dmTitle="DefinedMeaning:$dmEx ($dmId)";
 430+ $dmTitle=str_replace(" ", "_", $dmTitle);
 431+ return $dmTitle;
 432+
 433+ }
 434+
421435 public function setDefiningExpression($definingExpression) {
422436 $this->definingExpression=$definingExpression;
423437 }

Status & tagging log