r25274 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r25273‎ | r25274 | r25275 >
Date:10:03, 29 August 2007
Author:kim
Status:old
Tags:
Comment:
Adding some futt bugly copy code. Only advantage is that
it isn't obscured by multiple layers of anything else,
so hopefully easier to work with for now.
Modified paths:
  • /trunk/extensions/Wikidata/OmegaWiki/DefinedMeaning.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/SpecialTransaction.php (modified) (history)
  • /trunk/extensions/Wikidata/util/copy.php (added) (history)

Diff [purge]

Index: trunk/extensions/Wikidata/OmegaWiki/DefinedMeaning.php
@@ -6,6 +6,7 @@
77 require_once('DefinedMeaningModel.php');
88
99 class DefinedMeaning extends DefaultWikidataApplication {
 10+ protected $definedMeaningModel;
1011 public function view() {
1112 global
1213 $wgOut, $wgTitle, $wgRequest, $wdCurrentContext;
@@ -21,6 +22,7 @@
2223 }
2324 parent::view();
2425 $definedMeaningModel = new DefinedMeaningModel($dmInfo["id"], $this->viewInformation);
 26+ $this->definedMeaningModel=$definedMeaningModel; #TODO if I wasn't so sleepy I'd make this consistent
2527
2628 $copyTo=$wgRequest->getText('CopyTo');
2729 if ($copyTo) {
@@ -244,7 +246,28 @@
245247 $html= getOptionPanel( array (
246248 'Copy to' => getSelect('CopyTo', $datasetarray)
247249 ));
 250+ $html.=$this->getCopyPanel2();
248251 return $html;
249252 }
 253+
 254+ /** links to futt bugly alternate copy mechanism, the
 255+ * latter being something that actually is somewhat
 256+ * understandable (though not yet refactored into
 257+ * something purdy and maintainable)
 258+ */
 259+ protected function getCopyPanel2() {
 260+ $html="Copy to (approach B):<br>\n";
 261+ $datasets=wdGetDatasets();
 262+ $dmid=$this->definedMeaningModel->getId();
 263+ $dc1=$this->definedMeaningModel->getDataSet();
 264+ foreach($datasets as $datasetid=>$dataset) {
 265+ $name=$dataset->fetchName();
 266+ $dc2=$datasetid;
 267+ $html.="<a href='extended/Wikidata/util/copy.php?dmid=$dmid&dc1=$dc1&dc2=$dc2'>$name</a><br>\n";
 268+ }
 269+
 270+ return $html;
 271+ }
 272+
250273 }
251274
Index: trunk/extensions/Wikidata/OmegaWiki/SpecialTransaction.php
@@ -995,8 +995,6 @@
996996
997997 $o=OmegaWikiAttributes::getInstance();
998998
999 - $o=OmegaWikiAttributes::getInstance();
1000 -
1001999 $editor = createTableViewer($attribute);
10021000
10031001 if ($showRollBackOptions) {
Index: trunk/extensions/Wikidata/util/copy.php
@@ -0,0 +1,178 @@
 2+<?php
 3+header("Content-type: text/html; charset=UTF-8");
 4+
 5+define('MEDIAWIKI', true );
 6+include_once("../../../LocalSettings.php");
 7+global $wgDBserver, $wgDBuser, $wgDBpassword, $wgDBname;
 8+
 9+$db1=$wgDBserver; # hostname
 10+$db2=$wgDBuser; # user
 11+$db3=$wgDBpassword; # pass
 12+$db4=$wgDBname; # db-name
 13+
 14+$connection=MySQL_connect($db1,$db2,$db3);
 15+if (!$connection)die("Cannot connect to SQL server. Try again later.");
 16+MySQL_select_db($db4)or die("Cannot open database");
 17+mysql_query("SET NAMES 'utf8'");
 18+
 19+
 20+function stopwatch(){
 21+ list($usec, $sec) = explode(" ", microtime());
 22+ return ((float)$usec + (float)$sec);
 23+}
 24+
 25+function expression($expression_id, $dc1) {
 26+ $expression=mysql_real_escape_string("${dc1}_expression_ns");
 27+ $query=
 28+ "SELECT *
 29+ FROM $expression
 30+ WHERE expression_id=$expression_id";
 31+ echo $query;
 32+
 33+ $result = mysql_query($query)or die ("error ".mysql_error());
 34+
 35+ $dmdata= mysql_fetch_assoc($result);
 36+ return $dmdata;
 37+}
 38+
 39+/**@deprecated , use dupobject*/
 40+function new_dm_id($dc2) {
 41+ $defined_meaning=mysql_real_escape_string("${dc2}_defined_meaning");
 42+ $query="SELECT max(defined_meaning_id) as maxdm from $defined_meaning";
 43+ echo "$query\n";
 44+ $result = mysql_query($query)or die ("error ".mysql_error());
 45+ echo "bla\n";
 46+ $data= mysql_fetch_assoc($result);
 47+ var_dump($data);
 48+ return $data["maxdm"]+1;
 49+}
 50+
 51+/**@deprecated , use dupobject*/
 52+function new_exp_id($dc2) {
 53+ $expression_ns=mysql_real_escape_string("${dc2}_expression_ns");
 54+ $query="SELECT max(expression_id) as maxexp from $expression_ns";
 55+ $result = mysql_query($query)or die ("error ".mysql_error());
 56+ $data= mysql_fetch_assoc($result);
 57+ var_dump($data);
 58+ return $data["maxexp"]+1;
 59+}
 60+
 61+function readobject($id, $dc1) {
 62+ $objects=mysql_real_escape_string("${dc1}_objects");
 63+ $query="SELECT * from $objects where object_id=$id";
 64+ $result = mysql_query($query)or die ("error ".mysql_error());
 65+ $data= mysql_fetch_assoc($result);
 66+ var_dump($data);
 67+ return $data;
 68+}
 69+
 70+function writeobject($object,$dc2,$table) {
 71+ $objects=mysql_real_escape_string("${dc2}_objects");
 72+ unset($object["object_id"]);
 73+ $object["table"]=$table;
 74+ mysql_insert_assoc($objects,$object);
 75+ return mysql_insert_id();
 76+}
 77+
 78+function dupobject($id, $table, $dc1, $dc2) {
 79+ $object=readobject($id, $dc1);
 80+ $newid=writeobject($object,$dc2, $table);
 81+ return $newid;
 82+}
 83+
 84+
 85+/**
 86+ * inverse of mysql_fetch_assoc
 87+/* see: http://www.php.net/mysql_fetch_assoc (Comment by R. Bradly, 14-Sep-2006)
 88+ */
 89+ function mysql_insert_assoc ($my_table, $my_array) {
 90+
 91+ // Find all the keys (column names) from the array $my_array
 92+
 93+ // We compose the query
 94+ $sql = "insert into `$my_table` set";
 95+ // implode the column names, inserting "\", \"" between each (but not after the last one)
 96+ // we add the enclosing quotes at the same time
 97+ $sql_comma=$sql;
 98+ foreach($my_array as $key=>$value) {
 99+ $sql=$sql_comma;
 100+ if (is_null($value)) {
 101+ $value="DEFAULT";
 102+ } else {
 103+ $value="\"$value\"";
 104+ }
 105+ $sql.=" `$key`=$value";
 106+ $sql_comma=$sql.",";
 107+ }
 108+ // Same with the values
 109+ echo $sql."; <br>\n";
 110+ $result = mysql_query($sql);
 111+
 112+ if ($result)
 113+ {
 114+ echo "The row was added sucessfully";
 115+ return true;
 116+ }
 117+ else
 118+ {
 119+ echo ("The row was not added<br>The error was" . mysql_error());
 120+ return false;
 121+ }
 122+ }
 123+
 124+
 125+
 126+$start=stopwatch();
 127+
 128+$dmid=$_REQUEST['dmid'];
 129+$dc1=$_REQUEST['dc1'];
 130+$dc2=$_REQUEST['dc2'];
 131+$dmid_esc=mysql_real_escape_string($dmid);
 132+
 133+echo $dmid_esc;
 134+$defined_meaning=mysql_real_escape_string("${dc1}_defined_meaning");
 135+
 136+$query=
 137+"SELECT *
 138+FROM $defined_meaning
 139+WHERE defined_meaning_id=$dmid_esc";
 140+echo $query;
 141+
 142+$result = mysql_query($query)or die ("error ".mysql_error());
 143+$defined_meaning=mysql_fetch_assoc($result);
 144+var_dump($defined_meaning);
 145+
 146+$defining_expression=expression($defined_meaning["expression_id"], $dc1);
 147+var_dump($defining_expression);
 148+
 149+$dm_target_table=mysql_real_escape_string("${dc2}_defined_meaning");
 150+$target_dmid=dupobject($defined_meaning["defined_meaning_id"], $dm_target_table, $dc1, $dc2);
 151+var_dump($target_dmid);
 152+$save_meaning=$defined_meaning;
 153+$save_meaning["defined_meaning_id"]=$target_dmid;
 154+
 155+$target_table=mysql_real_escape_string("${dc2}_expression_ns");
 156+$target_expid1=dupobject($defining_expression["expression_id"], $target_table, $dc1, $dc2);
 157+var_dump($target_expid1);
 158+$save_expression=$defining_expression;
 159+$save_expression["expression_id"]=$target_expid1;
 160+mysql_insert_assoc($target_table,$save_expression);
 161+
 162+$save_meaning["expression_id"]=$target_expid1;
 163+mysql_insert_assoc($dm_target_table, $save_meaning);
 164+
 165+$title_name=$defining_expression["spelling"];
 166+$title_number=$target_dmid;
 167+$title=str_replace(" ","_",$title_name)."_(".$title_number.")";
 168+$pagedata=array("page_namespace"=>24, "page_title"=>$title);
 169+mysql_insert_assoc("page",$pagedata);
 170+
 171+
 172+echo"
 173+<hr>
 174+<div align=\"right\">
 175+<small>Page time: ".substr((stopwatch()-$start),0,5)." seconds</small>
 176+</div>
 177+";
 178+
 179+?>
Property changes on: trunk/extensions/Wikidata/util/copy.php
___________________________________________________________________
Added: svn:executable
1180 + *

Status & tagging log