r23692 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23691‎ | r23692 | r23693 >
Date:01:52, 4 July 2007
Author:kim
Status:old
Tags:
Comment:
* Somewhat dirty save mechanism now _written_,
not yet tested (will test after getting some sleep),
will need some work to make robust.
* Mechanism is mostly separate from normal code, so everthing
still runs as normal AFAICT from my (admittedly brief)
tests.
Modified paths:
  • /trunk/extensions/Wikidata/OmegaWiki/DefinedMeaningModel.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/Record.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/SaveDM.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/Skel.php (added) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/WikiDataAPI.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Wikidata/OmegaWiki/Skel.php
@@ -0,0 +1,25 @@
 2+<?php
 3+# A very simple skeleton Wikidata script.
 4+
 5+define('MEDIAWIKI', true );
 6+
 7+require_once("../../../../StartProfiler.php");
 8+require_once("../../../../LocalSettings.php");
 9+require_once("../../php-tools/ProgressBar.php");
 10+require_once("DatabaseUtilities.php");
 11+require_once("Setup.php");
 12+
 13+
 14+global
 15+$beginTime, $wgCommandLineMode;
 16+
 17+$beginTime = time();
 18+$wgCommandLineMode = true;
 19+$dc = "uw";
 20+
 21+/* insert code here */
 22+
 23+$endTime = time();
 24+echo("\n\nTime elapsed: " . durationToString($endTime - $beginTime));
 25+
 26+?>
Index: trunk/extensions/Wikidata/OmegaWiki/DefinedMeaningModel.php
@@ -14,6 +14,7 @@
1515
1616 protected $record=null;
1717 protected $definedMeaningID=null;
 18+ protected $viewInformation=null;
1819
1920 /**
2021 *Construct a new DefinedMeaningModel for a particular defined meaning
@@ -37,6 +38,7 @@
3839 $viewInformation->queryTransactionInformation= new QueryLatestTransactionInformation();
3940 }
4041
 42+ $this->viewInformation=$viewInformation;
4143 #wfDebug("definedMeaningId:$definedMeaningId, filterLanguageId:$viewInformation->filterLanguageId, possiblySynonymousRelationTypeId:$viewInformation->possiblySynonymousRelationTypeId, queryTransactionInformation:$viewInformation->queryTransactionInformation\n");
4244 $this->setDefinedMeaningID($definedMeaningId);
4345 $record = new ArrayRecord($definedMeaningAttribute->type);
@@ -66,13 +68,31 @@
6769 /* Sorry, don't know what horrible cannibalised hacks are. Therefore I cannot update code properly.
6870 * Please check if it still works correctly. Peter-Jan Roes.
6971 */
70 - /* :-D */
 72+ /* You are a wise man! :-D */
7173 public function save() {
7274 initializeOmegaWikiAttributes($this->viewInformation);
7375 initializeObjectAttributeEditors($this->viewInformation);
7476
75 - $definedMeaningId = $this->getDefinedMeaningID();
 77+ # Nice try sherlock, but we really need to get our DMID from elsewhere
 78+ #$definedMeaningId = $this->getDefinedMeaningID();
7679
 80+ #Need 3 steps: copy defining expression, create new dm, then update
 81+
 82+ $expression=$this->dupDefiningExpression();
 83+ # to make the expression really work, we may need to call
 84+ # more here?
 85+
 86+ # shouldn't this stuff be protected?
 87+ $expressionId=$expression->id;
 88+ $languageId=$expression->languageId;
 89+ $text="Copied Defined Meaning"; // this might work for now
 90+ // but where to get useful
 91+ // text?
 92+
 93+ #here we assume the DM is not there yet.. not entirely wise
 94+ #in the long run.
 95+ $definedMeaningId=createNewDefinedMeaning($expressionId, $langaugeId, $text);
 96+
7797 getDefinedMeaningEditor($this->viewInformation)->save(
7898 $this->getIdStack($definedMeaningId),
7999 $this->getRecord()
@@ -95,6 +115,7 @@
96116 }
97117
98118 /*horrible cannibalised hack. Use at own risk*/
 119+ /* this particular function doesn't actually work yet */
99120 public function saveWithinTransaction() {
100121 global
101122 $wgTitle, $wgUser, $wgRequest;
@@ -126,6 +147,19 @@
127148 public function getDefinedMeaningID() {
128149 return $this->definedMeaningID;
129150 }
 151+
 152+ /** Attempts to save defining expression if it does not exist "here"
 153+ * (This works right now because we override the datasetcontext in
 154+ * SaveDM.php . dc should be handled more solidly) */
 155+ protected function dupDefiningExpression() {
130156
 157+ $record=$this->getRecord();
 158+ $expression=$record->getValue("defined-meaning-full-defining-expression");
 159+
 160+ $spelling=$expression->getValue("defined-meaning-defining-expression");
 161+ $language=$expression->getValue("language");
 162+ return findOrCreateExpression($spelling, $language);
 163+ }
 164+
131165 }
132166
Index: trunk/extensions/Wikidata/OmegaWiki/Record.php
@@ -28,6 +28,15 @@
2929 return @$this->values[$attribute->id];
3030 }
3131
 32+ /**
 33+ * Obtains a value based on the provided key.
 34+ * In future, this should check against an attributes global with string
 35+ * lookup, and might even be smart.
 36+ * For now, this just does a direct lookup.
 37+ */
 38+ public function getValue ($key) {
 39+ return @$this->values[$key];
 40+ }
3241
3342 public function project(Structure $structure) {
3443 $result = project($this, $structure);
@@ -72,11 +81,12 @@
7382 $str=$this->getStructure();
7483 $type=$str->getStructureType();
7584 $rv.="$key:ArrayRecord(..., $type) {";
76 - $rv2=$rv;
 85+ $comma=$rv;
7786 foreach ($this->values as $key=>$value) {
78 - $rv=$rv2;
 87+ $rv=$comma;
 88+ $repr="$key:$value";
 89+ #Duck typing (should refactor this to a has_attr() function);
7990 $methods=get_class_methods(get_class($value));
80 - $repr="$key:$value";
8191 if (!is_null($methods)) {
8292 if (in_array("tostring_indent",$methods)) {
8393 $repr=$value->tostring_indent($depth+1,$key);
@@ -84,8 +94,8 @@
8595 }
8696 $rv.=$repr;
8797
88 - $rv2=$rv;
89 - $rv2.=", ";
 98+ $comma=$rv;
 99+ $comma.=", ";
90100 }
91101 $rv.="}";
92102 return $rv;
Index: trunk/extensions/Wikidata/OmegaWiki/SaveDM.php
@@ -51,8 +51,15 @@
5252
5353 $record=$model->getRecord();
5454 echo $record;
55 -echo $record->getAttributeValue(new Attribute("defined-meaning-full-defining-expression"));
 55+$defexp=$record->getValue("defined-meaning-full-defining-expression");
 56+echo $defexp."\n";
 57+#$expid=$record->getAttributeValue(new Attribute("expression-id"));
 58+$id=$defexp->getValue("expression-id");
 59+$spelling=$defexp->getValue("defined-meaning-defining-expression");
 60+$language=$defexp->getValue("language");
5661
 62+echo "id: $id, spelling:$spelling, language:$language";
 63+
5764 $endTime = time();
5865 echo("\n\nTime elapsed: " . durationToString($endTime - $beginTime));
5966
Index: trunk/extensions/Wikidata/OmegaWiki/WikiDataAPI.php
@@ -154,10 +154,7 @@
155155 }
156156
157157 function findExpression($spelling, $languageId) {
158 - wfDebug( "findExpression $spelling" );
159158 if ($expressionId = getExpressionId($spelling, $languageId)){
160 - //wfDebug( "expression $spelling found in database" );
161 - //exit();
162159 return new Expression($expressionId, $spelling, $languageId);
163160 }
164161 else{
@@ -178,6 +175,8 @@
179176 return createExpression($spelling, $languageId);
180177 }
181178
 179+
 180+
182181 function getSynonymId($definedMeaningId, $expressionId) {
183182 $dc=wdGetDataSetContext();
184183 $dbr =& wfGetDB(DB_SLAVE);

Status & tagging log