$box->box_uid = $box_uid; $box->template = $data['table_template']; $box->set_from_DB(); $rows = get_wikibox_rows($box, $uid, $data['metadata']); if (count($rows) == 0) { $row = $box->insert_row('', $uid); $rows[] = $row->row_index; echo "adding new row row_index = " . $row->row_index . "\n"; $row->db_save_row(); } #print_r($rows); # usually this should only happen once, but it comes as an array. foreach ($rows as $index => $row_index) { $box->rows[$row_index]->row_data = $data['row_data']; $box->rows[$row_index]->db_save_row(); insert_row_metadata($box->rows[$row_index], $data['metadata']); } #print_r($box->rows); if ($box) { $tableEdit = new TableEdit(); $title = Title::newFromID($box->page_uid); $tableEdit->save_to_page($title, $box); unset($box); } } # end else - page already exists } # end while loop reading infile echo "done!\n"; # ============ functions ========================= function parse_line($line)
function make_box($page_name, $template = '', $data, $fill = 1) { global $db; $uid = 0; if (isset($data['owner'])) { $uid = $data['owner']; } $metadata = ''; if (isset($data['metadata'])) { $metadata = $data['metadata']; } # identify the box $box_id = get_wikibox_id($page_name, $template); # echo "\nbox_id:$box_id\n"; $box_uid = get_wikibox_uid($box_id); # echo "box_uid:$box_uid\n"; $box = new wikiBox(); $box->box_uid = $box_uid; $box->template = $template; $box->set_from_DB(); # if fill != 1, then we aren't filling a new row. We just want the box from the database, even if it's empty. if ($fill == 1) { $rows = get_wikibox_rows($box, $uid, $metadata); # echo "found rows owned by $uid and matching $metadata\n"; print_r($rows);#print_r($box->rows);echo "\n"; if (count($rows) == 0) { $row = $box->insert_row('', $uid); $rows[] = $row->row_index; #echo "adding new row row_index = ".$row->row_index."\n"; } # print_r($box); # print_r($rows); foreach ($rows as $row_index) { $function = "do_" . $template; $row_data = $box->rows[$row_index]->row_data; if ($box->rows[$row_index]->owner_uid == $uid) { $row_data = $data['row_data']; } $box->rows[$row_index]->row_data = $row_data; if ($box->box_id > 0) { $box->rows[$row_index]->row_id = insert_wikibox_row($box->rows[$row_index]); insert_row_metadata($box->rows[$row_index], $metadata); } } } # print_r($box->rows); $tableEdit = new TableEdit(); $table = str_replace("\\'", "'", $tableEdit->make_wikibox($box)); return str_replace('\\n', "\n", $table); }