Esempio n. 1
0
 public static function display($perm, $formName, $title)
 {
     $html = '';
     $sql = new SQLStore(wfGetDB(DB_SLAVE));
     if ($formName == 'edit') {
         $titleArray = explode(':', $title);
         $ontAbbr = $titleArray[0];
         $termID = str_replace(' ', '_', $titleArray[1]);
         $magic = $sql->getAnnotationMagicWords($ontAbbr);
         $ontology = new OntologyData($ontAbbr);
         $term = $ontology->parseTermByID($termID);
         $html .= self::printEditForm($perm, $ontAbbr, $term, $magic);
         wfDebugLog('OntoKiWi', 'OKW\\Display\\FormDisplayPrinter:: display: edit form');
     } else {
         if ($formName == 'create') {
             $sql = new SQLStore(wfGetDB(DB_SLAVE));
             $ontologies = $sql->getOntologies();
             $magic = $sql->getAnnotationMagicWords();
             $html .= self::printCreateForm($perm, $ontAbbr, $title, $ontologies, $magic);
             wfDebugLog('OntoKiWi', 'OKW\\Display\\FormDisplayPrinter:: display: create form');
         } else {
             #TODO: Throw Exception
         }
     }
     return $html;
 }
Esempio n. 2
0
 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);
 }
Esempio n. 3
0
    public static function reformatWikiText($wikiText, $validAnnotation = null)
    {
        $sql = new SQLStore(wfGetDB(DB_SLAVE));
        $magic = $sql->getAnnotationMagicWords();
        $dictMagicIRI = array();
        foreach ($magic as $name => $value) {
            $dictMagicIRI[$value['iri']] = $name;
        }
        $text = '';
        $output = array();
        preg_match_all('/{{\\s*[#]?Annotation\\s*:[\\s]*[^|]([^}]*)}}/', $wikiText, $matches, PREG_SET_ORDER);
        $options = array();
        $valids = array();
        $invalids = array();
        if (!empty($matches) || !is_null($validAnnotation)) {
            foreach ($matches as $match) {
                preg_match_all('/[\\s]*[|]([^|]*)/', $match[1], $params, PREG_PATTERN_ORDER);
                list($option, $valid, $invalid) = self::extractAnnotation($params[1], $magic);
                $options = array_merge($options, $option);
                $valids = array_merge($valids, $valid);
                $invalids = array_merge($invalids, $invalid);
            }
            if (!is_null($validAnnotation)) {
                $output = array();
                foreach ($validAnnotation as $iri => $value) {
                    $output[$iri]['name'] = $dictMagicIRI[$iri];
                    $output[$iri]['value'] = $value;
                }
            } else {
                foreach ($valids as $index => $term) {
                    if (!array_key_exists($term['iri'], $output)) {
                        $output[$term['iri']]['name'] = $term['name'];
                        if ($term['type'] == 'unique') {
                            $output[$term['iri']]['value'] = array($term['value']);
                        } else {
                            $output[$term['iri']]['value'] = $term['value'];
                        }
                    } else {
                        if ($term['type'] == 'unique') {
                            $output[$term['iri']]['value'] = array($term['value']);
                        } else {
                            $output[$term['iri']]['value'] = array_merge($output[$term['iri']]['value'], $term['value']);
                        }
                    }
                }
            }
            $text .= <<<END
{{ #Annotation: <!-- Auto formatted ontology annnotation wikitext -->
END;
            foreach ($output as $iri => $term) {
                $value = $term['value'];
                $name = $term['name'];
                foreach ($value as $annote) {
                    $text .= <<<END

| {$name} = {$annote}
END;
                }
            }
            foreach ($invalids as $index => $error) {
                $msg = self::getErrorMessage($error);
                if (sizeof($options[$index]) == 1) {
                    $param = $options[$index][0];
                    $text .= <<<END

| {$msg} {$param}
END;
                } else {
                    $name = $options[$index][0];
                    $value = $options[$index][1];
                    $text .= <<<END

| {$msg} {$name} = {$value}
END;
                }
            }
            $text .= <<<END
\t\t\t
}}


END;
            $text .= preg_replace('/([\\s]?{{\\s*[#]?Annotation\\s*:[\\s]*[^|][^}]*}}[\\s]?)/', '', $wikiText);
        } else {
            $text = $wikiText;
        }
        foreach ($dictMagicIRI as $iri => $name) {
            if (!array_key_exists($iri, $output)) {
                $output[$iri]['value'] = null;
            }
        }
        return array($text, $output);
    }