Merge "Add GetContentModels hook to allow extensions to enumerate dynamic content...
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Wed, 8 Feb 2017 08:55:57 +0000 (08:55 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Wed, 8 Feb 2017 08:55:58 +0000 (08:55 +0000)
docs/hooks.txt
includes/content/ContentHandler.php
tests/phpunit/includes/content/ContentHandlerTest.php

index 1459b89..846a073 100644 (file)
@@ -1092,6 +1092,8 @@ $title: the Title in question
 'ContentHandlerForModelID': Called when a ContentHandler is requested for
 a given content model name, but no entry for that model exists in
 $wgContentHandlers.
+Note: if your extension implements additional models via this hook, please
+use GetContentModels hook to make them known to core. 
 $modeName: the requested content model name
 &$handler: set this to a ContentHandler object, if desired.
 
@@ -1562,6 +1564,9 @@ notifications.
 &$url: string value as output (out parameter, can modify)
 $query: query options passed to Title::getCanonicalURL()
 
+'GetContentModels': Add content models to the list of available models.
+&$models: array containing current model list, as strings. Extensions should add to this list.
+
 'GetDefaultSortkey': Override the default sortkey for a page.
 $title: Title object that we need to get a sortkey for
 &$sortkey: Sortkey to use.
index 119144a..58665bb 100644 (file)
@@ -361,7 +361,9 @@ abstract class ContentHandler {
        public static function getContentModels() {
                global $wgContentHandlers;
 
-               return array_keys( $wgContentHandlers );
+               $models = array_keys( $wgContentHandlers );
+               Hooks::run( 'GetContentModels', [ &$models ] );
+               return $models;
        }
 
        public static function getAllContentFormats() {
index efd60e5..ae66253 100644 (file)
@@ -461,4 +461,13 @@ class ContentHandlerTest extends MediaWikiTestCase {
                $this->assertContains( 'one who smiths', $out->getRawText() );
        }
 
+       /**
+        * @covers ContentHandler::getContentModels
+        */
+       public function testGetContentModelsHook() {
+               $this->setTemporaryHook( 'GetContentModels', function ( &$models ) {
+                       $models[] = 'Ferrari';
+               } );
+               $this->assertContains( 'Ferrari', ContentHandler::getContentModels() );
+       }
 }