Index: trunk/extensions/Wikidata/App.php |
— | — | @@ -133,12 +133,12 @@ |
134 | 134 | "DefinedMeaningReference" => "Defined meaning", |
135 | 135 | "ExactMeanings" => "Exact meanings", |
136 | 136 | "Expression" => "Expression", |
137 | | - "ExpressionMeanings" => "Expression meanings", |
| 137 | + "ExpressionMeanings" => "Expression meanings", |
138 | 138 | "Expressions" => "Expressions", |
139 | 139 | "IdenticalMeaning" => "Identical meaning?", |
140 | 140 | "IncomingRelations" => "Incoming relations", |
141 | 141 | "GotoSource" => "Go to source", |
142 | | - "Language" => "Language", |
| 142 | + "language" => "Language", |
143 | 143 | "LevelAnnotation" => "Annotation", |
144 | 144 | "OptionAttribute" => "Property", |
145 | 145 | "OptionAttributeOption" => "Option", |
— | — | @@ -150,13 +150,13 @@ |
151 | 151 | "PossiblySynonymous" => "Possibly synonymous", |
152 | 152 | "Relations" => "Relations", |
153 | 153 | "RelationType" => "Relation type", |
154 | | - "Spelling" => "Spelling", |
| 154 | + "spelling" => "Spelling", |
155 | 155 | "Synonyms" => "Synonyms", |
156 | 156 | "SynonymsAndTranslations" => "Synonyms and translations", |
157 | 157 | "Source" => "Source", |
158 | 158 | "SourceIdentifier" => "Source identifier", |
159 | 159 | "TextAttribute" => "Property", |
160 | | - "Text" => "Text", |
| 160 | + "text" => "Text", |
161 | 161 | "TextAttributeValues" => "String properties", |
162 | 162 | "TranslatedTextAttribute" => "Property", |
163 | 163 | "TranslatedText" => "Translated text", |
Index: trunk/extensions/Wikidata/OmegaWiki/DefinedMeaning.php |
— | — | @@ -27,13 +27,34 @@ |
28 | 28 | $definedMeaningModel->copyTo($copyTo); |
29 | 29 | } |
30 | 30 | |
31 | | - if(!empty($dmInfo["expression"])) |
32 | | - $definedMeaningModel->setDefiningExpression($dmInfo["expression"]); |
| 31 | + if(!empty($dmInfo["expression"])) { |
| 32 | + $definedMeaningModel->setDefiningExpression($dmInfo["expression"]); |
| 33 | + } |
33 | 34 | |
34 | 35 | // Search for this DM in all data-sets, beginning with the current one. |
35 | 36 | // Switch dataset context if found elsewhere. |
36 | 37 | $match=$definedMeaningModel->checkExistence(true, true); |
37 | 38 | |
| 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! :-( |
38 | 59 | if(is_null($match)) { |
39 | 60 | $wgOut->showErrorPage('errorpagetitle','ow_dm_missing'); |
40 | 61 | return false; |
Index: trunk/extensions/Wikidata/OmegaWiki/DefinedMeaningModel.php |
— | — | @@ -379,12 +379,17 @@ |
380 | 380 | */ |
381 | 381 | public static function splitTitleText($titleText) { |
382 | 382 | $bracketPosition = strrpos($titleText, "("); |
383 | | - if ($bracketPosition==false) |
| 383 | + if ($bracketPosition===false) |
384 | 384 | return null; # Defined Meaning ID is missing from title string |
385 | 385 | $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 | + } |
388 | 392 | $definedMeaningId = substr($titleText, $bracketPosition + 1, strlen($titleText) - $bracketPosition - 2); |
| 393 | + |
389 | 394 | $rv["expression"]=$definingExpression; |
390 | 395 | $rv["id"]=(int)$definedMeaningId; |
391 | 396 | return $rv; |
— | — | @@ -417,6 +422,15 @@ |
418 | 423 | return $this->definingExpression; |
419 | 424 | } |
420 | 425 | |
| 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 | + |
421 | 435 | public function setDefiningExpression($definingExpression) { |
422 | 436 | $this->definingExpression=$definingExpression; |
423 | 437 | } |