From 93421f64c54ac186aa0be5b6d44470d5e0b7e48c Mon Sep 17 00:00:00 2001 From: Daniel Kinzler Date: Wed, 1 Feb 2012 22:07:47 +0000 Subject: [PATCH] first brain dump for ContentHandler interface --- includes/ContentHandler.php | 123 ++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 includes/ContentHandler.php diff --git a/includes/ContentHandler.php b/includes/ContentHandler.php new file mode 100644 index 0000000000..7b076de647 --- /dev/null +++ b/includes/ContentHandler.php @@ -0,0 +1,123 @@ +mModelName = $modelName; + $this->mSupportedFormats = $formats; + } + + public function getModelName() { + # for wikitext: wikitext; in the future: wikiast, wikidom? + # for wikidata: wikidata + return $this->mModelName; + } + + + public function getSupportedFormats() { + # for wikitext: "text/x-mediawiki-1", "text/x-mediawiki-2", etc + # for wikidata: "application/json", "application/x-php", etc + return $this->mSupportedFormats; + } + + public function getDefaultFormat() { + return $this->mSupportedFormats[0]; + } + + public abstract function serialize( $obj, $format = null ); + # for wikitext, do nothing (in the future: serialise ast/dom) + # for wikidata: serialize arrays to json + + public abstract function unserialize( $blob, $format = null ); + # for wikitext, do nothing (in the future: parse into ast/dom) + # for wikidata: serialize arrays to json + + + public function getSearchText( $obj ) { + # for wikitext, return wikitext + # for wikidata, return pseudo-wikitext composed of property values (or some such) + $text = $this->serialize( $obj ); + return $text; # return the default serialization. + } + + public function getWikitextForTransclusion( $obj ) { + # for wikitext, return text + # for wikidata, return false, or some generated wikitext + $text = $this->serialize( $obj ); + return '
' . $text . '
'; # return a pre-formatted block containing the default serialization. + } + + public abstract function render( $obj, Title $title, ParserOptions $options, $revid = null ); + # returns a ParserOutput instance! + # are parser options, generic?! + + public function doPreSaveTransform( $title, $obj ); + + # TODO: getPreloadText() + # TODO: preprocess() + + /** + * Return an Article object suitable for viewing the given object + * + * @param type $title + * @param type $obj + * @return \Article + * @todo Article is being refactored into an action class, keep track of that + */ + public function createArticle( $title, $obj ) { + $article = new Article($title); + return $article; + } + + /** + * Return an EditPage object suitable for editing the given object + * + * @param type $title + * @param type $obj + * @param type $article + * @return \EditPage + */ + public function createEditPage( $title, $obj, $article ) { + $editPage = new EditPage($article); + return $editPage; + } + + /** + public function updatePage( $title, $obj ) { + } + **/ + + public function getDiffEngine( $article ) { + $de = new DifferenceEngine( $article->getContext() ); + return $de; + } + + public function getIndexUpdateJobs( $title, $parserOutput, $recursive = true ) { + # for wikitext, create a LinksUpdate object + # for wikidata: serialize arrays to json + $update = new LinksUpdate( $title, $parserOutput, $recursive ); + return $update; + } + + #XXX: is the native model for wikitext a string or the parser output? parse early or parse late? +} + +abstract class WikitextContentHandler extends ContentHandler { +} + +abstract class JavaScriptContentHandler extends WikitextHandler { +} + +abstract class CssContentHandler extends WikitextHandler { +} -- 2.20.1