aria-describedby, aria-flowto, aria-label, aria-labelledby, aria-owns.
* Removed "presentation" restriction on the HTML role attribute in wikitext.
All values are now allowed for the role attribute.
+* $wgContentHandlers now also supports callbacks to create an instance of the
+ appropriate ContentHandler subclass.
=== External library changes in 1.27 ===
There are some new globals that can be used to control the behavior of the ContentHandler facility:
-* $wgContentHandlers associates content model IDs with the names of the appropriate ContentHandler subclasses.
+* $wgContentHandlers associates content model IDs with the names of the appropriate ContentHandler subclasses
+ or callbacks that create an instance of the appropriate ContentHandler subclass.
* $wgNamespaceContentModels maps namespace IDs to a content model that should be the default for that namespace.
/**
* Plugins for page content model handling.
- * Each entry in the array maps a model id to a class name.
+ * Each entry in the array maps a model id to a class name or callback
+ * that creates an instance of the appropriate ContentHandler subclass.
*
* @since 1.21
*/
throw new MWException( "ContentHandlerForModelID must supply a ContentHandler instance" );
}
} else {
- $class = $wgContentHandlers[$modelId];
- $handler = new $class( $modelId );
+ $classOrCallback = $wgContentHandlers[$modelId];
+
+ if ( is_callable( $classOrCallback ) ) {
+ $handler = call_user_func( $classOrCallback, $modelId );
+ } else {
+ $handler = new $classOrCallback( $modelId );
+ }
if ( !( $handler instanceof ContentHandler ) ) {
- throw new MWException( "$class from \$wgContentHandlers is not " .
+ throw new MWException( "$classOrCallback from \$wgContentHandlers is not " .
"compatible with ContentHandler" );
}
}
CONTENT_MODEL_CSS => 'CssContentHandler',
CONTENT_MODEL_TEXT => 'TextContentHandler',
'testing' => 'DummyContentHandlerForTesting',
+ 'testing-callbacks' => function( $modelId ) {
+ return new DummyContentHandlerForTesting( $modelId );
+ }
),
) );
return true;
}
+
+ public function provideGetModelForID() {
+ return array(
+ array( CONTENT_MODEL_WIKITEXT, 'WikitextContentHandler' ),
+ array( CONTENT_MODEL_JAVASCRIPT, 'JavaScriptContentHandler' ),
+ array( CONTENT_MODEL_JSON, 'JsonContentHandler' ),
+ array( CONTENT_MODEL_CSS, 'CssContentHandler' ),
+ array( CONTENT_MODEL_TEXT, 'TextContentHandler' ),
+ array( 'testing', 'DummyContentHandlerForTesting' ),
+ array( 'testing-callbacks', 'DummyContentHandlerForTesting' ),
+ );
+ }
+
+ /**
+ * @dataProvider provideGetModelForID
+ */
+ public function testGetModelForID( $modelId, $handlerClass ) {
+ $handler = ContentHandler::getForModelID( $modelId );
+
+ $this->assertInstanceOf( $handlerClass, $handler );
+ }
+
}