}
/**
- * Returns the localized name for a given content model,
- * or null if no MIME type is known.
+ * Returns the symbolic name for a given content model.
+ *
+ * @param $id int The content model ID, as given by a CONTENT_MODEL_XXX
+ * constant or returned by Revision::getContentModel().
+ *
+ * @return string The content model's symbolic name.
+ * @throws MWException if the model id isn't known.
+ */
+ public static function getContentModelName( $id ) {
+ $handler = self::getForModelID( $id );
+ return $handler->getModelName();
+ }
+
+
+ /**
+ * Returns the localized name for a given content model.
*
* Model names are localized using system messages. Message keys
- * have the form content-model-$id.
+ * have the form content-model-$name, where $name is getContentModelName( $id ).
*
* @static
* @param $id int The content model ID, as given by a CONTENT_MODEL_XXX
* constant or returned by Revision::getContentModel().
+ * @todo also accept a symbolic name instead of a numeric id
*
- * @return string|null The content format's MIME type.
+ * @return string The content format's localized name.
+ * @throws MWException if the model id isn't known.
*/
- public static function getContentModelName( $id ) {
- $key = "content-model-$id";
+ public static function getLocalizedName( $id ) {
+ $name = self::getContentModelName( $id );
+ $key = "content-model-$name";
- if ( wfEmptyMsg( $key ) ) return null;
+ if ( wfEmptyMsg( $key ) ) return $name;
else return wfMsg( $key );
}
// ------------------------------------------------------------------------
protected $mModelID;
+ protected $mModelName;
protected $mSupportedFormats;
/**
public function __construct( $modelId, $formats ) {
$this->mModelID = $modelId;
$this->mSupportedFormats = $formats;
- }
+ $this->mModelName = preg_replace( '/(Content)?Handler$/', '', get_class( $this ) );
+ $this->mModelName = preg_replace( '/[_\\\\]/', '', $this->mModelName );
+ $this->mModelName = strtolower( $this->mModelName );
+ }
/**
* Serializes a Content object of the type supported by this ContentHandler.
return $this->mModelID;
}
+ /**
+ * Returns the content model's symbolic name.
+ *
+ * The symbolic name is is this object's class name in lower case with the trailing "ContentHandler"
+ * and and special characters removed.
+ *
+ * @since WD.1
+ *
+ * @return String The content model's name
+ */
+ public function getModelName() {
+ return $this->mModelName;
+ }
+
/**
* Throws an MWException if $model_id is not the ID of the content model
* supported by this ContentHandler.
'duration-centuries' => '$1 {{PLURAL:$1|century|centuries}}',
'duration-millennia' => '$1 {{PLURAL:$1|millennium|millennia}}',
-# Content model IDs for the ContentHandler facility; used by ContentHander::getContentModel()
-'content-model-1' => 'wikitext',
-'content-model-2' => 'JavaScript',
-'content-model-3' => 'CSS',
-'content-model-4' => 'plain text',
+# Content model IDs for the ContentHandler facility; used by ContentHandler::getContentModel()
+'content-model-wikitext' => 'wikitext',
+'content-model-javascript' => 'JavaScript',
+'content-model-css' => 'CSS',
+'content-model-text' => 'plain text',
);
'api-error-uploaddisabled' => 'API error message that can be used for client side localisation of API errors.',
'api-error-verification-error' => 'The word "extension" refers to the part behind the last dot in a file name, that by convention gives a hint about the kind of data format which a files contents are in.',
-# Content model IDs for the ContentHandler facility; used by ContentHander::getContentModel()
-'content-model-1' => 'Name for the wikitext content model, used when decribing what type of content a page contains.',
-'content-model-2' => 'Name for the JavaScript content model, used when decribing what type of content a page contains.',
-'content-model-3' => 'Name for the CSS content model, used when decribing what type of content a page contains.',
-'content-model-4' => 'Name for the plain text content model, used when decribing what type of content a page contains.',
+# Content model IDs for the ContentHandler facility; used by ContentHandler::getContentModel()
+'content-model-wikitext' => 'Name for the wikitext content model, used when decribing what type of content a page contains.',
+'content-model-javascript' => 'Name for the JavaScript content model, used when decribing what type of content a page contains.',
+'content-model-css' => 'Name for the CSS content model, used when decribing what type of content a page contains.',
+'content-model-text' => 'Name for the plain text content model, used when decribing what type of content a page contains.',
);
$this->assertEquals( $expectedId, $id );
}
- public function dataGetContentModelName() {
+ public function dataGetLocalizedNameName() {
return array(
array( 0, null ),
array( null, null ),
);
}
+ /**
+ * @dataProvider dataGetLocalizedNameName
+ */
+ public function testGetLocalizedName( $id, $expected ) {
+ try{
+ $name = ContentHandler::getLocalizedName( $id );
+
+ if ( !$expected ) $this->fail("should not have a name for content id #$id");
+
+ $this->assertNotNull( $name, "no name found for content model #$id" );
+ $this->assertTrue( preg_match( $expected, $name ) > 0 , "content model name for #$id did not match pattern $expected" );
+ } catch (MWException $e) {
+ if ( $expected ) $this->fail("failed to get name for content id #$id");
+ }
+ }
+
+ public function dataGetContentModelName() {
+ return array(
+ array( 0, null ),
+ array( null, null ),
+ array( 99887766, null ),
+
+ array( CONTENT_MODEL_JAVASCRIPT, 'javascript' ),
+ );
+ }
+
/**
* @dataProvider dataGetContentModelName
*/
public function testGetContentModelName( $id, $expected ) {
- $name = ContentHandler::getContentModelName( $id );
+ try {
+ $name = ContentHandler::getContentModelName( $id );
+
+ if ( !$expected ) $this->fail("should not have a name for content id #$id");
- if ( $expected === null ) {
- $this->assertNull( $name, "content model name for #$id was expected to be null" );
- } else {
$this->assertNotNull( $name, "no name found for content model #$id" );
- $this->assertTrue( preg_match( $expected, $name ) > 0 , "content model name for #$id did not match pattern $expected" );
+ $this->assertEquals( $expected, $name);
+ } catch (MWException $e) {
+ if ( $expected ) $this->fail("failed to get name for content id #$id");
+ }
+ }
+
+ /**
+ * @dataProvider dataGetContentModelName
+ */
+ public function testGetModelName( $id, $expected ) {
+ try {
+ $handler = ContentHandler::getForModelID( $id );
+ $name = $handler->getModelName();
+
+ if ( !$expected ) $this->fail("should not have a name for content id #$id");
+
+ $this->assertNotNull( $name, "no name found for content model #$id" );
+ $this->assertEquals( $expected, $name);
+ } catch (MWException $e) {
+ if ( $expected ) $this->fail("failed to get name for content id #$id");
}
}
}
}
}
+
+ public function testSupportsSections() {
+ $this->markTestIncomplete( "not yet implemented" );
+ }
}
class DummyContentHandlerForTesting extends ContentHandler {
timeoutForSmallTests="2"
timeoutForMediumTests="10"
timeoutForLargeTests="60"
- strict="false"
- verbose="true">
+ strict="false"
+ verbose="false">
<testsuites>
<testsuite name="includes">
<directory>includes</directory>