Пример #1
0
 public static function validateDataEditFilter($editor, $text, $section, &$error, $summary)
 {
     // I can't remember if jsondataobj needs to be a singleton/global, but
     // will chance calling a new instance here.
     $title = $editor->getTitle();
     $ns = $title->getNamespace();
     if (!JsonData::isJsonDataNeeded($ns)) {
         return true;
     }
     $jsondataobj = new JsonData($title);
     $json = JsonData::stripOuterTagsFromText($text);
     try {
         $schematext = $jsondataobj->getSchemaText();
     } catch (JsonDataException $e) {
         $schematext = $jsondataobj->readJsonFromPredefined('openschema');
         $error = "<b>" . wfMessage('jsondata-servervalidationerror') . "</b>: ";
         $error .= wfMessage('jsondata-invalidjson');
     }
     $data = json_decode($json, true);
     if (is_null($data)) {
         $error = "<b>" . wfMessage('jsondata-servervalidationerror') . "</b>: ";
         $error .= wfMessage('jsondata-invalidjson');
         return true;
     }
     $schema = json_decode($schematext, true);
     $rootjson = new JsonTreeRef($data);
     $rootjson->attachSchema($schema);
     try {
         $rootjson->validate();
     } catch (JsonSchemaException $e) {
         $error = "<b>" . wfMessage('jsondata-servervalidationerror') . "</b>: ";
         $error .= htmlspecialchars($e->getMessage());
     }
     return true;
 }
Пример #2
0
 public function getJsonRef()
 {
     if (is_null($this->jsonref)) {
         $json = JsonData::stripOuterTagsFromText($this->getEditorText());
         $schematext = $this->getSchemaText();
         $data = json_decode($json, true);
         $schema = json_decode($schematext, true);
         $this->jsonref = new JsonTreeRef($data);
         $this->jsonref->attachSchema($schema);
     }
     return $this->jsonref;
 }