r25300 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r25299‎ | r25300 | r25301 >
Date:01:43, 30 August 2007
Author:kim
Status:old
Tags:
Comment:
Copy functionality now does syntrans too
(This code was kindly submitted by Alan Smithee O:-) )
Modified paths:
  • /trunk/extensions/Wikidata/util/copy.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Wikidata/util/copy.php
@@ -1,4 +1,13 @@
22 <?php
 3+
 4+# (C) 2007 Alan Smithee (licensed under the GPL v. 3, or any later version, though you're not likely to care)
 5+# throwaway rapid prototype to copy defined meanings between tables.
 6+# I didn't write this, nobody saw me, you can't prove a thing!
 7+# Actually somewhat easier than fighting through multiple layers of
 8+# code in the recordsets for now.
 9+# probably will refactor this code into ulta-pretty helpers or
 10+# other recordset improvements.
 11+#
312 header("Content-type: text/html; charset=UTF-8");
413
514 define('MEDIAWIKI', true );
@@ -150,12 +159,62 @@
151160 writeSyntrans($syntrans, $newdmid, $newexpid, $dc2);
152161 }
153162
 163+function get_syntranses($dmid, $dc1) {
 164+ $syntranses=array();
 165+ $syntrans_table=mysql_real_escape_string("${dc1}_syntrans");
 166+ $query="SELECT * from $syntrans_table where defined_meaning_id=$dmid";
 167+ $result = mysql_query($query)or die ("error ".mysql_error());
 168+ var_dump($result);
 169+ while ($nextexp=mysql_fetch_assoc($result)) {
 170+ $syntranses[]=$nextexp;
 171+ }
 172+ return $syntranses;
 173+}
154174
 175+/* some coy&paste happening here, might want to tidy even before we
 176+* toss this throwaway code*/
 177+function write_expression($expression, $src_dmid, $dst_dmid, $dc1, $dc2) {
 178+ $target_table=mysql_real_escape_string("${dc2}_expression_ns");
 179+ $target_expid1=dupobject($expression["expression_id"], $target_table, $dc1, $dc2);
 180+ var_dump($target_expid1);
 181+ $save_expression=$expression;
 182+ $save_expression["expression_id"]=$target_expid1;
 183+ mysql_insert_assoc($target_table,$save_expression);
 184+ dupsyntrans(
 185+ $dc1,
 186+ $dc2,
 187+ $src_dmid,
 188+ $expression["expression_id"],
 189+ $dst_dmid,
 190+ $save_expression["expression_id"]
 191+ );
 192+
 193+}
 194+
 195+function write_syntranses($syntranses, $src_dmid, $dst_dmid, $dc1, $dc2) {
 196+ var_dump($syntranses);
 197+ print "<br>\nExpressions:";
 198+ foreach ($syntranses as $syntrans) {
 199+ $expression=expression($syntrans["expression_id"],$dc1);
 200+ print $expression["spelling"].";";
 201+ write_expression($expression, $src_dmid, $dst_dmid, $dc1, $dc2);
 202+ # ^- which incidentally also dups the syntrans
 203+ }
 204+}
 205+
 206+function dup_syntranses($src_dmid, $dst_dmid, $dc1, $dc2) {
 207+ $syntranses=get_syntranses($src_dmid, $dc1);
 208+ write_syntranses($syntranses, $src_dmid, $dst_dmid, $dc1, $dc2);
 209+}
 210+
155211 $start=stopwatch();
156212
157213 $dmid=$_REQUEST['dmid'];
158214 $dc1=$_REQUEST['dc1'];
159215 $dc2=$_REQUEST['dc2'];
 216+
 217+
 218+# dm
160219 $dmid_esc=mysql_real_escape_string($dmid);
161220
162221 echo $dmid_esc;
@@ -171,6 +230,7 @@
172231 $defined_meaning=mysql_fetch_assoc($result);
173232 var_dump($defined_meaning);
174233
 234+# bit of exp here too (defnitely need to tidy)
175235 $defining_expression=expression($defined_meaning["expression_id"], $dc1);
176236 var_dump($defining_expression);
177237
@@ -180,6 +240,7 @@
181241 $save_meaning=$defined_meaning;
182242 $save_meaning["defined_meaning_id"]=$target_dmid;
183243
 244+# exp
184245 $target_table=mysql_real_escape_string("${dc2}_expression_ns");
185246 $target_expid1=dupobject($defining_expression["expression_id"], $target_table, $dc1, $dc2);
186247 var_dump($target_expid1);
@@ -187,9 +248,12 @@
188249 $save_expression["expression_id"]=$target_expid1;
189250 mysql_insert_assoc($target_table,$save_expression);
190251
 252+# and insert that info into the dm +save it
191253 $save_meaning["expression_id"]=$target_expid1;
192254 mysql_insert_assoc($dm_target_table, $save_meaning);
193255
 256+# the defining expression is also in syntrans,
 257+# so this might be redundant.
194258 dupsyntrans(
195259 $dc1,
196260 $dc2,
@@ -211,6 +275,13 @@
212276 );
213277 createConceptMapping($concepts);
214278
 279+dup_syntranses(
 280+ $defined_meaning["defined_meaning_id"],
 281+ $save_meaning["defined_meaning_id"],
 282+ $dc1,
 283+ $dc2
 284+);
 285+
215286 echo"
216287 <hr>
217288 <div align=\"right\">

Status & tagging log