return $this->mModelName;
}
+ protected function checkModelName( $modelName ) {
+ if ( $modelName !== $this->mModelName ) {
+ throw new MWException( "Bad content model: expected " . $this->mModelName . " but got found " . $modelName );
+ }
+ }
+
public function getContentHandler() {
return ContentHandler::getForContent( $this );
}
+ public function getDefaultFormat() {
+ return $this->getContentHandler()->getDefaultFormat();
+ }
+
+ public function getSupportedFormats() {
+ return $this->getContentHandler()->getSupportedFormats();
+ }
+
+ public function isSupportedFormat( $format ) {
+ if ( !$format ) return true; # this means "use the default"
+
+ return $this->getContentHandler()->isSupportedFormat( $format );
+ }
+
+ protected function checkFormat( $format ) {
+ if ( !$this->isSupportedFormat( $format ) ) {
+ throw new MWException( "Format $format is not supported for content model " . $this->getModelName() );
+ }
+ }
+
public function serialize( $format = null ) {
return $this->getContentHandler()->serialize( $this, $format );
}
global $wgContentHandlers;
if ( empty( $wgContentHandlers[$modelName] ) ) {
- #FIXME: hook here!
- throw new MWException( "No handler for model $modelName registered in \$wgContentHandlers" );
+ $handler = null;
+ wfRunHooks( "ContentHandlerForModelName", array( $modelName, &$handler ) ); #FIXME: document new hook
+
+ if ( $handler ) { # NOTE: may be a string or an object, either is fine!
+ $wgContentHandlers[$modelName] = $handler;
+ } else {
+ throw new MWException( "No handler for model $modelName registered in \$wgContentHandlers" );
+ }
}
if ( is_string( $wgContentHandlers[$modelName] ) ) {
return $this->mModelName;
}
+ protected function checkModelName( $modelName ) {
+ if ( $modelName !== $this->mModelName ) {
+ throw new MWException( "Bad content model: expected " . $this->mModelName . " but got found " . $modelName );
+ }
+ }
public function getSupportedFormats() {
# for wikitext: "text/x-mediawiki-1", "text/x-mediawiki-2", etc
return $this->mSupportedFormats[0];
}
+ public function isSupportedFormat( $format ) {
+ if ( !$format ) return true; # this means "use the default"
+
+ return in_array( $format, $this->mSupportedFormats );
+ }
+
+ protected function checkFormat( $format ) {
+ if ( !$this->isSupportedFormat( $format ) ) {
+ throw new MWException( "Format $format is not supported for content model " . $this->getModelName() );
+ }
+ }
+
/**
* @abstract
* @param Content $content
* @todo Article is being refactored into an action class, keep track of that
*/
public function createArticle( Title $title ) {
- #XXX: assert that $title->getContentModelName() == $this->getModelname()?
+ $this->checkModelName( $title->getContentModelName() );
+
$article = new Article($title);
return $article;
}
* @return \EditPage
*/
public function createEditPage( Article $article ) {
- #XXX: assert that $article->getContentObject()->getModelName() == $this->getModelname()?
+ $this->checkModelName( $article->getContentObject()->getModelName() );
+
$editPage = new EditPage( $article );
return $editPage;
}
* @return \ExternalEdit
*/
public function createExternalEdit( IContextSource $context ) {
- #XXX: assert that $article->getContentObject()->getModelName() == $this->getModelname()?
+ $this->checkModelName( $context->getTitle()->getModelName() );
+
$externalEdit = new ExternalEdit( $context );
return $externalEdit;
}
public function getDifferenceEngine( IContextSource $context, $old = 0, $new = 0, $rcid = 0, #FIMXE: use everywhere!
$refreshCache = false, $unhide = false ) {
+ $this->checkModelName( $context->getTitle()->getModelName() );
+
$de = new DifferenceEngine( $context, $old, $new, $rcid, $refreshCache, $unhide );
return $de;
#TODO: Article::showCssOrJsPage ---> specialized classes!
#XXX: ImagePage and CategoryPage... wrappers that use ContentHandler? or ContentHandler creates wrappers?
+
+ #TODO: hook into dump generation to serialize and record model and format!
+ #TODO: cover action=raw
+ #TODO: make sure we cover lucene search / wikisearch.
+ #TODO: nice&sane integration of GeSHi syntax highlighting
+ # [11:59] <vvv> Hooks are ugly; make CodeHighlighter interface and a config to set the class which handles syntax highlighting
+ # [12:00] <vvv> And default it to a DummyHighlighter
+ #TODO: make sure we cover the external editor interface (does anyone actually use that?!)
}
}
public function serialize( Content $content, $format = null ) {
- #FIXME: assert format
+ $this->checkFormat( $format );
return $content->getNativeData();
}
* @return Content|Bool
*/
public function merge3( Content $oldContent, Content $myContent, Content $yourContent ) {
+ $this->checkModelName( $oldContent->getModelName() );
+ #TODO: check that all Content objects have the same content model! #XXX: what to do if they don't?
+
$format = $this->getDefaultFormat();
$old = $this->serialize( $oldContent, $format );
}
public function unserialize( $text, $format = null ) {
- #FIXME: assert format
- return new WikitextContent($text);
+ $this->checkFormat( $format );
+
+ return new WikitextContent( $text );
}
public function emptyContent() {
- return new WikitextContent("");
+ return new WikitextContent( "" );
}
}
+#TODO: make ScriptContentHandler base class with plugin interface for syntax highlighting!
+
class JavaScriptContentHandler extends TextContentHandler {
public function __construct( $modelName = CONTENT_MODEL_WIKITEXT ) {
}
public function unserialize( $text, $format = null ) {
- return new JavaScriptContent($text);
+ return new JavaScriptContent( $text );
}
public function emptyContent() {
- return new JavaScriptContent("");
+ return new JavaScriptContent( "" );
}
}
}
public function unserialize( $text, $format = null ) {
- return new CssContent($text);
+ return new CssContent( $text );
}
public function emptyContent() {
- return new CssContent("");
+ return new CssContent( "" );
}
}