4 * A content handler knows how do deal with a specific type of content on a wiki page.
5 * Content is stored in the database in a serialized form (using a serialization format aka mime type)
6 * and is be unserialized into it's native PHP represenation (the content model).
8 * Some content types have a flat model, that is, their native represenation is the
9 * same as their serialized form. Examples would be JavaScript and CSS code. As of now,
10 * this also applies to wikitext (mediawiki's default content type), but wikitext
11 * content may be represented by a DOM or AST structure in the future.
14 abstract class ContentHandler
{
16 public function __construct( $modelName, $formats ) {
17 $this->mModelName
= $modelName;
18 $this->mSupportedFormats
= $formats;
21 public function getModelName() {
22 # for wikitext: wikitext; in the future: wikiast, wikidom?
23 # for wikidata: wikidata
24 return $this->mModelName
;
28 public function getSupportedFormats() {
29 # for wikitext: "text/x-mediawiki-1", "text/x-mediawiki-2", etc
30 # for wikidata: "application/json", "application/x-php", etc
31 return $this->mSupportedFormats
;
34 public function getDefaultFormat() {
35 return $this->mSupportedFormats
[0];
38 public abstract function serialize( $obj, $format = null );
39 # for wikitext, do nothing (in the future: serialise ast/dom)
40 # for wikidata: serialize arrays to json
42 public abstract function unserialize( $blob, $format = null );
43 # for wikitext, do nothing (in the future: parse into ast/dom)
44 # for wikidata: serialize arrays to json
47 public function getSearchText( $obj ) {
48 # for wikitext, return wikitext
49 # for wikidata, return pseudo-wikitext composed of property values (or some such)
50 $text = $this->serialize( $obj );
51 return $text; # return the default serialization.
54 public function getWikitextForTransclusion( $obj ) {
55 # for wikitext, return text
56 # for wikidata, return false, or some generated wikitext
57 $text = $this->serialize( $obj );
58 return '<pre>' . $text . '</pre>'; # return a pre-formatted block containing the default serialization.
61 public abstract function render( $obj, Title
$title, ParserOptions
$options, $revid = null );
62 # returns a ParserOutput instance!
63 # are parser options, generic?!
65 public function doPreSaveTransform( $title, $obj );
67 # TODO: getPreloadText()
71 * Return an Article object suitable for viewing the given object
76 * @todo Article is being refactored into an action class, keep track of that
78 public function createArticle( $title, $obj ) {
79 $article = new Article($title);
84 * Return an EditPage object suitable for editing the given object
88 * @param type $article
91 public function createEditPage( $title, $obj, $article ) {
92 $editPage = new EditPage($article);
97 public function updatePage( $title, $obj ) {
101 public function getDiffEngine( $article ) {
102 $de = new DifferenceEngine( $article->getContext() );
106 public function getIndexUpdateJobs( $title, $parserOutput, $recursive = true ) {
107 # for wikitext, create a LinksUpdate object
108 # for wikidata: serialize arrays to json
109 $update = new LinksUpdate( $title, $parserOutput, $recursive );
113 #XXX: is the native model for wikitext a string or the parser output? parse early or parse late?
116 abstract class WikitextContentHandler
extends ContentHandler
{
119 abstract class JavaScriptContentHandler
extends WikitextHandler
{
122 abstract class CssContentHandler
extends WikitextHandler
{