private function exportTerm() { $this->getOutput()->disable(); wfResetOutputBuffers(); $request = $this->getRequest(); $config = $this->getConfig(); $request->response()->header("Content-type: application/xml; charset=utf-8"); if ($request->getCheck('downloadTerm')) { $filename = urlencode($config->get('Sitename') . '-' . wfTimestamp() . '.xml'); $request->response()->header("Content-disposition: attachment; filename={$filename}"); } $pages = explode("\n", $request->getVal('pages')); $pageSet = array(); foreach ($pages as $title) { $title = trim($title); if (OntologyValidator::isExistTitleText($title)) { $titleArray = explode(':', $title); $ontAbbr = $titleArray[0]; $termID = str_replace(' ', '_', $titleArray[1]); if (!array_key_exists($ontAbbr, $pageSet)) { $pageSet[$ontAbbr][] = $termID; } else { if (!in_array($termID, $pageSet[$ontAbbr])) { $pageSet[$ontAbbr][] = $termID; } } } } $export = ''; $initial = true; foreach ($pageSet as $ontAbbr => $terms) { $ontology = new OntologyData($ontAbbr); $iris = array(); foreach ($terms as $term) { $iris[] = $ontology->getPrefix() . $term; } $rdf = $ontology->getRDF(); $xml = $rdf->exportDescribe($ontology->getGraph(), $iris); if ($initial) { $initial = false; } else { $xml = preg_replace('/^<\\?xml[^?>]*\\?>[\\s]?/', '', $xml); $xml = preg_replace('/<rdf\\:RDF[\\s]?xmlns\\:rdf[^\\s>]*[\\s]?xmlns:rdfs[^\\s>]*[\\s]?>[\\s]?/', '', $xml); } $xml = preg_replace('/<\\/rdf\\:RDF>/', '', $xml); $export .= $xml; } $export .= '</rdf:RDF>'; wfDebugLog('OntoKiWi', 'OKW\\Special\\ExportOntology: output term RDF/XML generated'); print $export; }
public static function extractSupClass($params, $ontology) { $options = array(); $valids = array(); $invalids = array(); $supClasses = array(); foreach ($params as $param) { $index = uniqid(); $pair = explode('=', $param, 2); if (count($pair) == 2) { $name = $pair[0]; $name = preg_replace('/[\\s]*(<!--.*?(?=-->)-->)[\\s]*/', '', $name); $name = strtolower(trim($name)); $value = $pair[1]; $value = preg_replace('/[\\s]*(<!--.*?(?=-->)-->)[\\s]*/', '', $value); $value = trim($value); $options[$index][] = $name; $options[$index][] = $value; if ($name == 'subclassof') { if (strtolower($value) == 'thing') { $supClassIRI = $GLOBALS['okwRDFConfig']['Thing']; $valids[$index]['iri'] = $supClassIRI; $valids[$index]['id'] = DisplayHelper::getShortTerm($supClassIRI); $valids[$index]['title'] = DisplayHelper::getShortTerm($supClassIRI); } else { $supClassIRI = $ontology->convertToIRI($value); $term = $ontology->parseTermByIRI($supClassIRI); if (!is_null($term)) { $title = $ontology->getOntAbbr() . ':' . $term->id; if (OntologyValidator::isExistTitleText($title)) { $valids[$index]['iri'] = $supClassIRI; $valids[$index]['id'] = $ontology->convertToID($supClassIRI); $valids[$index]['title'] = $ontology->convertToTitle($supClassIRI); } else { $invalids[$index] = self::ERROR_INVALID_TERM; } } else { $invalids[$index] = self::ERROR_INVALID_TERM; } } } else { $invalids[$index] = self::ERROR_INVALID_MAGICWORD; } } else { $options[$index][] = $param; $invalids[$index] = self::ERROR_EXCESS_INPUT; } } return array($options, $valids, $invalids); }
/** * Function * * onBeforePageDisplay * * @param OutputPage $out * @param Skin $skin * @return boolean */ public static function onBeforePageDisplay(OutputPage &$out, Skin &$skin) { # Modify OutputPage HTML base on WebRequest's action switch ($GLOBALS['wgRequest']->getVal('action')) { # If purge page, do nothing case 'purge': break; # If OntoKiWi edit ontology with form, change displayed title and load form resources # If OntoKiWi edit ontology with form, change displayed title and load form resources case 'formedit': $title = $out->getPageTitle(); $title = str_replace(' ', '_', $title); $out->mPagetitle = $title; $out->addModules(array('ext.okw.form.js', 'ext.okw.form.css')); break; # If delete page, check if page has ontology data, and: # 1) change displayed title # 2) add "Delete Ontology Data" checkbox # If delete page, check if page has ontology data, and: # 1) change displayed title # 2) add "Delete Ontology Data" checkbox case 'delete': global $wgRequest; if (OntologyValidator::isExistTitleText($wgRequest->getVal('title'))) { $title = $out->getPageTitle(); $title = str_replace(' ', '_', $title); $html = preg_replace('/(<input[^>]*name=[\'"]wpWatch[\'"].+?(?=<div>))/', '${1} <input name="okwDelete" type="checkbox" value="1" id="wpWatch" checked/> ' . '<label for="okwDelete">Delete Ontology Data</label>', $out->getHTML()); $out->clearHTML(); $out->addHTML($html); } break; # Default display to check if page has ontology data, and: # 1) Change displayed title # 2) Call PageDisplayPrinter::display # 3) Load page resources # 4) Redirect if only ID is provided and is valid # Default display to check if page has ontology data, and: # 1) Change displayed title # 2) Call PageDisplayPrinter::display # 3) Load page resources # 4) Redirect if only ID is provided and is valid default: $title = $out->getPageTitle(); $titleName = str_replace(' ', '_', $title); if (OntologyValidator::isExistOutputPage($out)) { $out->mPagetitle = $titleName; $html = $out->getHTML(); $out->clearHTML(); $html = PageDisplayPrinter::display($titleName) . $html; $out->addHTML($html); $out->addModules(array('ext.okw.page.js', 'ext.okw.page.css')); } else { if (preg_match_all('/([a-zA-Z]+)[:_]([a-zA-Z]*)[:_]?(\\d+)/', $titleName, $matches, PREG_SET_ORDER)) { if ($matches[0][2] == '') { $title = Title::newFromText($matches[0][1] . ':' . $matches[0][1] . '_' . $matches[0][3]); if (OntologyValidator::isExistTitle($title)) { $out->redirect($title->getFullURL()); $out->output(); } } } } break; } return true; }
private static function checkClass($termIRI, $ontology, $newWiki) { $term = $ontology->parseTermByIRI($termIRI); if (!is_null($term)) { $title = $ontology->getOntAbbr() . ':' . $term->id; if ($newWiki) { return OntologyValidator::isValidTitleText($title); } else { return OntologyValidator::isExistTitleText($title); } } else { return false; } }