jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/335188 )
Change subject: Add GetContentModels hook to allow extensions to enumerate
dynamic content models.
..
Add GetContentModels hook to allow extensions to enumerate dynamic content
models.
Bug: T155139
Change-Id: Icb41c470dfa4638676eb3ba0e74f437e85acc792
---
M docs/hooks.txt
M includes/content/ContentHandler.php
M tests/phpunit/includes/content/ContentHandlerTest.php
3 files changed, 17 insertions(+), 1 deletion(-)
Approvals:
Daniel Kinzler: Looks good to me, approved
jenkins-bot: Verified
diff --git a/docs/hooks.txt b/docs/hooks.txt
index 1459b89..846a073 100644
--- a/docs/hooks.txt
+++ b/docs/hooks.txt
@@ -1092,6 +1092,8 @@
'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 @@
&$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.
diff --git a/includes/content/ContentHandler.php
b/includes/content/ContentHandler.php
index 119144a..58665bb 100644
--- a/includes/content/ContentHandler.php
+++ b/includes/content/ContentHandler.php
@@ -361,7 +361,9 @@
public static function getContentModels() {
global $wgContentHandlers;
- return array_keys( $wgContentHandlers );
+ $models = array_keys( $wgContentHandlers );
+ Hooks::run( 'GetContentModels', [ &$models ] );
+ return $models;
}
public static function getAllContentFormats() {
diff --git a/tests/phpunit/includes/content/ContentHandlerTest.php
b/tests/phpunit/includes/content/ContentHandlerTest.php
index efd60e5fb..ae662532 100644
--- a/tests/phpunit/includes/content/ContentHandlerTest.php
+++ b/tests/phpunit/includes/content/ContentHandlerTest.php
@@ -461,4 +461,13 @@
$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() );
+ }
}
--
To view, visit https://gerrit.wikimedia.org/r/335188
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Icb41c470dfa4638676eb3ba0e74f437e85acc792
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Smalyshev
Gerrit-Reviewer: Anomie
Gerrit-Reviewer: Daniel Kinzler
Gerrit-Reviewer: Jackmcbarn
Gerrit-Reviewer: Legoktm
Gerrit-Reviewer: Smalyshev
Gerrit-Reviewer: jenkins-bot <>
___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits