r25518 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r25517‎ | r25518 | r25519 >
Date:03:39, 5 September 2007
Author:kim
Status:old
Tags:
Comment:
More minor refactors (tidied)
Modified paths:
  • /trunk/extensions/Wikidata/util/copy.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Wikidata/util/copy.php
@@ -39,6 +39,7 @@
4040 function getrow($dc, $table, $where) {
4141 $target_table=mysql_real_escape_string("${dc}_${table}");
4242 $query="SELECT * FROM $target_table ".$where;
 43+ print $query."<br>\n";
4344 return doquery($query);
4445 }
4546
@@ -240,68 +241,85 @@
241242 $relation["meaning2_mid"]=dup_defined_meaning($relation["meaning2_mid"],$dc1, $dc2);
242243 }
243244
244 -function read_defined_meaning($dc1,$dmid) {
245 - return getrow($dc1,"defined_meaning","where defined_meaning_id=$dmid");
246 -}
247245
 246+class defined_meaning_copier {
248247
249 -function dup_defined_meaning ($dmid, $dc1, $dc2){
 248+ protected $defined_meaning;
 249+ protected $save_meaning;
 250+ protected $dmid;
 251+ protected $dc1;
 252+ protected $dc2;
 253+
 254+ public function __construct ($dmid, $dc1, $dc2) {
 255+ $this->dmid=$dmid;
 256+ $this->dc1=$dc1;
 257+ $this->dc2=$dc2;
 258+ }
 259+
 260+ protected function read() {
 261+ $dmid=$this->dmid;
 262+ print "<".$dmid."-".$this->dc1.">";
 263+ $this->defined_meaning=getrow($this->dc1,"defined_meaning","where defined_meaning_id=$dmid");
 264+ return $this->defined_meaning; # for convenience
 265+ }
250266
251 - $defined_meaning=read_defined_meaning($dc1, $dmid);
252267
253 - # bit of exp here too (defnitely need to tidy)
254 - $defining_expression=expression($defined_meaning["expression_id"], $dc1);
255 - var_dump($defining_expression);
 268+ public function getDM() {
 269+ $dm=$this->defined_meaning;
 270+ if (is_null($dm)) {
 271+ $dm=$this->read();
 272+ }
 273+ return $this->defined_meaning;
 274+ }
256275
257 - $dm_target_table=mysql_real_escape_string("${dc2}_defined_meaning");
258 - $target_dmid=dupobject($defined_meaning["defined_meaning_id"], $dm_target_table, $dc1, $dc2);
259 - var_dump($target_dmid);
260 - $save_meaning=$defined_meaning;
261 - $save_meaning["defined_meaning_id"]=$target_dmid;
 276+ function dup (){
 277+ $dmid=$this->dmid;
 278+ $dc1=$this->dc1;
 279+ $dc2=$this->dc2;
262280
263 - # exp
264 - $target_table=mysql_real_escape_string("${dc2}_expression_ns");
265 - $target_expid1=dupobject($defining_expression["expression_id"], $target_table, $dc1, $dc2);
266 - var_dump($target_expid1);
267 - $save_expression=$defining_expression;
268 - $save_expression["expression_id"]=$target_expid1;
269 - mysql_insert_assoc($target_table,$save_expression);
270 - # and insert that info into the dm
271 - $save_meaning["expression_id"]=$target_expid1;
272 - $save_meaning["meaning_text_tcid"]=dup_translated_content($dc1, $dc2, $defined_meaning["meaning_text_tcid"]);
 281+ $this->read();
273282
274 - mysql_insert_assoc($dm_target_table, $save_meaning);
 283+ # bit of exp here too (defnitely need to tidy)
 284+ $defining_expression=expression($this->defined_meaning["expression_id"], $dc1);
 285+ $dm_target_table=mysql_real_escape_string("${dc2}_defined_meaning");
 286+ $target_dmid=dupobject($this->defined_meaning["defined_meaning_id"], $dm_target_table, $dc1, $dc2);
 287+ var_dump($target_dmid);
 288+ $this->save_meaning=$this->defined_meaning;
 289+ $this->save_meaning["defined_meaning_id"]=$target_dmid;
275290
276 - # the defining expression is also in syntrans,
277 - # so this might be redundant.
278 - dupsyntrans(
279 - $dc1,
280 - $dc2,
281 - $defined_meaning["defined_meaning_id"],
282 - $defining_expression["expression_id"],
283 - $save_meaning["defined_meaning_id"],
284 - $save_expression["expression_id"]
285 - );
 291+ # exp
 292+ $target_table=mysql_real_escape_string("${dc2}_expression_ns");
 293+ $target_expid1=dupobject($defining_expression["expression_id"], $target_table, $dc1, $dc2);
 294+ var_dump($target_expid1);
 295+ $save_expression=$defining_expression;
 296+ $save_expression["expression_id"]=$target_expid1;
 297+ mysql_insert_assoc($target_table,$save_expression);
 298+ # and insert that info into the dm
 299+ $this->save_meaning["expression_id"]=$target_expid1;
 300+ $this->save_meaning["meaning_text_tcid"]=dup_translated_content($dc1, $dc2, $this->defined_meaning["meaning_text_tcid"]);
286301
287 - $title_name=$defining_expression["spelling"];
288 - $title_number=$target_dmid;
289 - $title=str_replace(" ","_",$title_name)."_(".$title_number.")";
290 - $pagedata=array("page_namespace"=>24, "page_title"=>$title);
291 - mysql_insert_assoc("page",$pagedata);
 302+ mysql_insert_assoc($dm_target_table, $this->save_meaning);
292303
293 - $concepts=array(
294 - $dc1 => $defined_meaning["defined_meaning_id"],
295 - $dc2 => $save_meaning["defined_meaning_id"]
296 - );
297 - createConceptMapping($concepts);
 304+ $title_name=$defining_expression["spelling"];
 305+ $title_number=$target_dmid;
 306+ $title=str_replace(" ","_",$title_name)."_(".$title_number.")";
 307+ $pagedata=array("page_namespace"=>24, "page_title"=>$title);
 308+ mysql_insert_assoc("page",$pagedata);
298309
299 - dup_syntranses(
300 - $defined_meaning["defined_meaning_id"],
301 - $save_meaning["defined_meaning_id"],
302 - $dc1,
303 - $dc2
304 - );
 310+ $concepts=array(
 311+ $dc1 => $this->defined_meaning["defined_meaning_id"],
 312+ $dc2 => $this->save_meaning["defined_meaning_id"]
 313+ );
 314+ createConceptMapping($concepts);
305315
 316+ dup_syntranses(
 317+ $this->defined_meaning["defined_meaning_id"],
 318+ $this->save_meaning["defined_meaning_id"],
 319+ $dc1,
 320+ $dc2
 321+ );
 322+
 323+ }
306324 }
307325
308326
@@ -315,7 +333,8 @@
316334 $dc1=mysql_real_escape_string($dc1_dirty);
317335 $dc2=mysql_real_escape_string($dc2_dirty);
318336
319 -dup_defined_meaning($dmid, $dc1, $dc2);
 337+$dmc=new defined_meaning_copier($dmid, $dc1, $dc2); #sorry, not a [[delorean]]
 338+$dmc->dup();
320339
321340 echo"
322341 <hr>

Status & tagging log