/**
* Conveniance function for creating a Content object from a given textual representation.
*
- * $text will be deserialized into a Content object of the model specified by $modelName (or,
- * if that is not given, $title->getContentModelName()) using the given format.
+ * $text will be deserialized into a Content object of the model specified by $modelId (or,
+ * if that is not given, $title->getContentModel()) using the given format.
*
+ * @since WD.1
+ *
* @static
* @param string $text the textual represenation, will be unserialized to create the Content object
* @param Title $title the title of the page this text belongs to, required as a context for deserialization
*
* If none of the above applies, the wikitext model is used.
*
- * Note: this is used by, and may thus not use, Title::getContentModelName()
+ * Note: this is used by, and may thus not use, Title::getContentModel()
*
+ * @since WD.1
+ *
* @static
* @param Title $title
* @return null|string default model name for the page given by $title
* If a class name in encountered when looking up the singleton for a given model name, the class is
* instantiated and the class name is replaced by te resulting singleton in $wgContentHandlers.
*
- * If no ContentHandler is defined for the desired $modelName, the ContentHandler may be provided by the
- * a ContentHandlerForModelName hook. if no Contenthandler can be determined, an MWException is raised.
+ * If no ContentHandler is defined for the desired $modelId, the ContentHandler may be provided by the
+ * a ContentHandlerForModelID hook. if no Contenthandler can be determined, an MWException is raised.
*
+ * @since WD.1
+ *
* @static
- * @param $modelName String the name of the content model for which to get a handler. Use CONTENT_MODEL_XXX constants.
- * @return ContentHandler the ContentHandler singleton for handling the model given by $modelName
- * @throws MWException if no handler is known for $modelName.
+ * @param $modelId int the id of the content model for which to get a handler. Use CONTENT_MODEL_XXX constants.
+ * @return ContentHandler the ContentHandler singleton for handling the model given by $modelId
+ * @throws MWException if no handler is known for $modelId.
*/
- public static function getForModelName( $modelName ) {
+ public static function getForModelID( $modelId ) {
global $wgContentHandlers;
- if ( empty( $wgContentHandlers[$modelName] ) ) {
+ if ( empty( $wgContentHandlers[$modelId] ) ) {
$handler = null;
- wfRunHooks( 'ContentHandlerForModelName', array( $modelName, &$handler ) );
+ wfRunHooks( 'ContentHandlerForModelID', array( $modelId, &$handler ) );
if ( $handler ) { // NOTE: may be a string or an object, either is fine!
- $wgContentHandlers[$modelName] = $handler;
+ $wgContentHandlers[$modelId] = $handler;
} else {
- throw new MWException( "No handler for model $modelName registered in \$wgContentHandlers" );
+ throw new MWException( "No handler for model #$modelId registered in \$wgContentHandlers" );
}
}
public abstract function makeEmptyContent();
/**
- * Returns the model name that identifies the content model this ContentHandler can handle.
+ * Returns the model id that identifies the content model this ContentHandler can handle.
* Use with the CONTENT_MODEL_XXX constants.
*
- * @return String the model name
+ * @since WD.1
+ *
+ * @return int the model id
*/
- public function getModelName() {
- return $this->mModelName;
+ public function getModelID() {
+ return $this->mModelID;
}
/**
- * Throws an MWException if $modelName is not the content model handeled by this ContentHandler.
+ * Throws an MWException if $model_id is not the id of the content model
+ * supported by this ContentHandler.
*
- * @param String $modelName the model name to check
+ * @since WD.1
+ *
+ * @param int $model_id the model to check
*/
- protected function checkModelName( $modelName ) {
- if ( $modelName !== $this->mModelName ) {
- throw new MWException( "Bad content model: expected " . $this->mModelName . " but got found " . $modelName );
+ protected function checkModelID( $model_id ) {
+ if ( $model_id !== $this->mModelID ) {
+ $model_name = ContentHandler::getContentModelName( $model_id );
+ $own_model_name = ContentHandler::getContentModelName( $this->mModelID );
+
+ throw new MWException( "Bad content model: expected {$this->mModelID} ($own_model_name) but got found $model_id ($model_name)." );
}
}
}
}
-
+ /**
+ * @since WD.1
+ */
abstract class TextContentHandler extends ContentHandler {
- public function __construct( $modelName, $formats ) {
- parent::__construct( $modelName, $formats );
+ public function __construct( $modelId, $formats ) {
+ parent::__construct( $modelId, $formats );
}
public function serializeContent( Content $content, $format = null ) {
}
+
+ /**
+ * @since WD.1
+ */
class WikitextContentHandler extends TextContentHandler {
- public function __construct( $modelName = CONTENT_MODEL_WIKITEXT ) {
- parent::__construct( $modelName, array( 'text/x-wiki' ) );
+ public function __construct( $modelId = CONTENT_MODEL_WIKITEXT ) {
+ parent::__construct( $modelId, array( CONTENT_FORMAT_WIKITEXT ) );
}
public function unserializeContent( $text, $format = null ) {
#XXX: make ScriptContentHandler base class with plugin interface for syntax highlighting?
+ /**
+ * @since WD.1
+ */
class JavaScriptContentHandler extends TextContentHandler {
- public function __construct( $modelName = CONTENT_MODEL_WIKITEXT ) {
- parent::__construct( $modelName, array( 'text/javascript' ) ); #XXX: or use $wgJsMimeType? this is for internal storage, not HTTP...
+ public function __construct( $modelId = CONTENT_MODEL_JAVASCRIPT ) {
+ parent::__construct( $modelId, array( CONTENT_FORMAT_JAVASCRIPT ) );
}
public function unserializeContent( $text, $format = null ) {
}
}
+ /**
+ * @since WD.1
+ */
class CssContentHandler extends TextContentHandler {
- public function __construct( $modelName = CONTENT_MODEL_WIKITEXT ) {
- parent::__construct( $modelName, array( 'text/css' ) );
+ public function __construct( $modelId = CONTENT_MODEL_CSS ) {
+ parent::__construct( $modelId, array( CONTENT_FORMAT_CSS ) );
}
public function unserializeContent( $text, $format = null ) {