'ZhClient' => 'includes/ZhClient.php',
'ZipDirectoryReader' => 'includes/ZipDirectoryReader.php',
+ # content handler
+ 'Content' => 'includes/Content.php',
+ 'ContentHandler' => 'includes/ContentHandler.php',
+ 'CssContent' => 'includes/Content.php',
+ 'CssContentHandler' => 'includes/ContentHandler.php',
+ 'JavaScriptContent' => 'includes/Content.php',
+ 'JavaScriptContentHandler' => 'includes/ContentHandler.php',
+ 'MessageContent' => 'includes/Content.php',
+ 'TextContent' => 'includes/Content.php',
+ 'WikitextContent' => 'includes/Content.php',
+ 'WikitextContentHandler' => 'includes/ContentHandler.php',
+
# includes/actions
'CreditsAction' => 'includes/actions/CreditsAction.php',
'DeleteAction' => 'includes/actions/DeleteAction.php',
return $wgContentHandlers[$modelName];
}
-
+ # ----------------------------------------------------------------------------------------------------------
public function __construct( $modelName, $formats ) {
$this->mModelName = $modelName;
$this->mSupportedFormats = $formats;
return $this->mSupportedFormats[0];
}
- public abstract function serialize( $obj, Title $title, $format = null );
- # for wikitext, do nothing (in the future: serialise ast/dom)
- # for wikidata: serialize arrays to json
+ public abstract function serialize( Content $content, Title $title, $format = null );
public abstract function unserialize( $blob, Title $title, $format = null ); #FIXME: ...and revId?
- # for wikitext, do nothing (in the future: parse into ast/dom)
- # for wikidata: serialize arrays to json
-
- public abstract function doPreSaveTransform( $title, $obj );
+ # public abstract function doPreSaveTransform( $title, $obj ); #TODO...
- # TODO: getPreloadText()
- # TODO: preprocess()
-
- /**
+ /**
* Return an Article object suitable for viewing the given object
*
* @param type $title
* @return \Article
* @todo Article is being refactored into an action class, keep track of that
*/
- public function createArticle( $title, $obj ) {
+ public function createArticle( Title $title, $obj ) { #TODO: use this!
$article = new Article($title);
return $article;
}
* @param type $article
* @return \EditPage
*/
- public function createEditPage( $title, $obj, $article ) {
+ public function createEditPage( Title $title, $obj, Article $article ) { #TODO: use this!
$editPage = new EditPage($article);
return $editPage;
}
}
**/
- public function getDiffEngine( $article ) {
+ public function getDiffEngine( Article $article ) {
$de = new DifferenceEngine( $article->getContext() );
return $de;
}
- public function getIndexUpdateJobs( $title, $parserOutput, $recursive = true ) {
+ public function getIndexUpdateJobs( Title $title, ParserOutput $parserOutput, $recursive = true ) {
# for wikitext, create a LinksUpdate object
# for wikidata: serialize arrays to json
$update = new LinksUpdate( $title, $parserOutput, $recursive );
#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 TextContentHandler extends ContentHandler {
+
+ public function __construct( $modelName, $formats ) {
+ super::__construct( $modelName, $formats );
+ }
+
+ public function serialize( Content $content, Title $title, $format = null ) {
+ return $content->getRawData();
+ }
+
}
+class WikitextContentHandler extends TextContentHandler {
+
+ public function __construct( $modelName = CONTENT_MODEL_WIKITEXT ) {
+ super::__construct( $modelName, array( 'application/x-wikitext' ) ); #FIXME: mime
+ }
+
+ public function unserialize( $text, Title $title, $format = null ) {
+ return new WikitextContent($text, $title);
+ }
+
+}
+
+class JavaScriptContentHandler extends TextContentHandler {
+
+ public function __construct( $modelName = CONTENT_MODEL_WIKITEXT ) {
+ super::__construct( $modelName, array( 'text/javascript' ) );
+ }
+
+ public function unserialize( $text, Title $title, $format = null ) {
+ return new JavaScriptContent($text, $title);
+ }
-abstract class JavaScriptContentHandler extends WikitextHandler {
}
-abstract class CssContentHandler extends WikitextHandler {
+class CssContentHandler extends TextContentHandler {
+
+ public function __construct( $modelName = CONTENT_MODEL_WIKITEXT ) {
+ super::__construct( $modelName, array( 'text/css' ) );
+ }
+
+ public function unserialize( $text, Title $title, $format = null ) {
+ return new CssContent($text, $title);
+ }
+
}