protected function doSave() { global $wgUser; $action = $this; $article = $this->page; $title = $article->getTitle(); $output = $action->getOutput(); $titleArray = explode(':', $title->getText()); $ontAbbr = $titleArray[0]; $termID = str_replace(' ', '_', $titleArray[1]); $update = new OntologyUpdate($ontAbbr, $termID); if ($title->exists()) { $wikiText = $article->getPage()->getContent()->getWikitextForTransclusion(); } else { $wikiText = ''; } /* if ( $title->exists() ) { if ( $this->perm >= self::ONTOLOGY_MANAGER ) { #$update->updateSubClassOf( $this->options['subclassof'] ); } else if ( $this->perm == self::ONTOLOGY_MASTER ) { $update->updateIRI( $this->options['term-iri'] ); $update->updateType( $this->options['term-type'] ); } } else { if ( $this->perm >= self::ONTOLOGY_PUBLIC ) { #$update->updateSubClassOf( $this->options['subclassof'] ); $update->updateType( $this->options['term-type'] ); } } $update->updateLabel( $this->options['term-label'] ); if ( key_exists( 'annotation-type', $this->options ) && key_exists( 'annotation-text', $this->options ) ) { $newWikiText = ActionHelper::changeOntologyAnnotation( $oldWikiText, $this->options['annotation-type'], $this->options['annotation-text'] ); } */ if ($this->perm >= self::ONTOLOGY_USER) { if ($this->perm == self::ONTOLOGY_MASTER) { if ($title->exists()) { $update->updateIRI($this->options['term-iri']); $update->updateType($this->options['term-type']); } else { $update->updateType($this->options['term-type']); } wfDebugLog('OntoKiWi', sprintf('OKW\\Action\\FormEditAction: %s is allowed {ontology_master}: updated restricted information about the term [[%s]]', $wgUser->getName(), $title->getText())); } $common['label'] = $this->options['term-label']; list($wikiText, $common) = CommonParser::reformatWikiText($wikiText, $common); wfDebugLog('OntoKiWi', sprintf('OKW\\Action\\FormEditAction: reformatted common information wikitext of the term [[%s]]', $title->getText())); $update->updateLabel($common['label']); wfDebugLog('OntoKiWi', sprintf('OKW\\Action\\FormEditAction: updated common information about the term [[%s]]', $title->getText())); if (array_key_exists('annotation-type', $this->options) && array_key_exists('annotation-text', $this->options)) { if (sizeof($this->options['annotation-type']) != sizeof($this->options['annotation-text'])) { #TODO: Throw Exception } $sql = new SQLStore(wfGetDB(DB_SLAVE)); $magic = $sql->getAnnotationMagicWords(); $annotations = array(); foreach ($this->options['annotation-type'] as $index => $name) { $iri = $magic[$name]['iri']; $text = $this->options['annotation-text'][$index]; $annotations[$iri][] = $text; } list($wikiText, $annotations) = AnnotationParser::reformatWikiText($wikiText, $annotations); wfDebugLog('OntoKiWi', sprintf('OKW\\Action\\FormEditAction: reformatted annotation wikitext of the term [[%s]]', $title->getText())); $update->updateAnnotations($annotations); wfDebugLog('OntoKiWi', sprintf('OKW\\Action\\FormEditAction: updated annotation of the term [[%s]]', $title->getText())); } if (array_key_exists('subclassof', $this->options)) { list($wikiText, $supClasses) = HierarchyParser::reformatWikiText($ontAbbr, $wikiText, $this->options['subclassof']); wfDebugLog('OntoKiWi', sprintf('OKW\\Action\\FormEditAction: reformatted hierarchy wikitext of the term [[%s]]', $title->getText())); } if (array_key_exists('axiom-type', $this->options) && array_key_exists('axiom-text', $this->options)) { if (sizeof($this->options['axiom-type']) != sizeof($this->options['axiom-text'])) { #TODO: Throw Exception } $axioms = array(); foreach ($this->options['axiom-type'] as $index => $type) { $axioms[$index]['type'] = $type; $axioms[$index]['text'] = $this->options['axiom-text'][$index]; } list($wikiText, $axioms) = AxiomParser::reformatWikiText($ontAbbr, $wikiText, $axioms); wfDebugLog('OntoKiWi', sprintf('OKW\\Action\\FormEditAction: reformatted axiom wikitext of the term [[%s]]', $title->getText())); } $update->updateSubClassOf($supClasses, $axioms['subclassof']); wfDebugLog('OntoKiWi', sprintf('OKW\\Action\\FormEditAction: updated hierarchy of the term [[%s]]', $title->getText())); #TODO: Equivalent update wfDebugLog('OntoKiWi', sprintf('OKW\\Action\\FormEditAction: updated axiom of the term [[%s]]', $title->getText())); } $editor = $this->setupEditPage($wikiText); return $this->doMWStore($output, $title, $editor); }
/** * Function * * @param WikiPage $article * @param User $user * @param string $reason * @param unknown $id * @param Content $content * @param unknown $logEntry * * Delete corresponding RDF data of the deleting page if "Delete Ontology Data" option is selected */ public static function onArticleDeleteComplete(WikiPage &$article, User &$user, $reason, $id, $content, $logEntry) { global $wgRequest; if ($wgRequest->getVal('okwDelete')) { $title = $article->getTitle(); if ($title->userCan('ontology_master')) { $titleArray = explode(':', $title->getText()); $ontAbbr = $titleArray[0]; $termID = str_replace(' ', '_', $titleArray[1]); $update = new OntologyUpdate($ontAbbr, $termID); $update->deleteTerm(); } } }