Gergő Tisza has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/405237 )
Change subject: [POC] Disallow <templatestyles> tags in non-template namespaces
......................................................................
[POC] Disallow <templatestyles> tags in non-template namespaces
Bug: T176269
Change-Id: Ic0f68bb13cc962acd8880b6ddb4e5b68b338cec8
---
M TemplateStylesHooks.php
M extension.json
2 files changed, 32 insertions(+), 3 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/TemplateStyles
refs/changes/37/405237/1
diff --git a/TemplateStylesHooks.php b/TemplateStylesHooks.php
index 70eb8c6..28476a0 100644
--- a/TemplateStylesHooks.php
+++ b/TemplateStylesHooks.php
@@ -179,6 +179,31 @@
}
/**
+ * Reject the save if the user included a <templatestyles> tag in an
unsupported namespace.
+ * @param WikiPage $wikiPage
+ * @param User $user
+ * @param Content $content
+ * @param string $summary
+ * @param bool $isMinor
+ * @param null $isWatch
+ * @param null $section
+ * @param int $flags
+ * @param Status $status
+ * @return bool
+ */
+ public static function onPageContentSave(
+ &$wikiPage, &$user, &$content, &$summary, $isMinor, $isWatch,
$section, &$flags, &$status
+ ) {
+ $errorMsg = $content->getParserOutput( $wikiPage->getTitle() )
+ ->getExtensionData( 'TemplateStylesParseError' );
+ if ( $errorMsg ) {
+ $status->fatal( $errorMsg );
+ return false;
+ }
+ return true;
+ }
+
+ /**
* Parser hook for `<templatestyles>`
* @param string $text Contents of the tag (ignored).
* @param array $params Tag attributes
@@ -200,9 +225,10 @@
function ( $ns ) use ( $targetLanguage ) {
return
$targetLanguage->convertNamespace( $ns );
}, $allowedNamespaces ) );
- $error = wfMessage( 'templatestyles-wrong-namespace',
$allowedNamespacesText,
- count( $allowedNamespaces )
)->inContentLanguage()->parse();
- return '<strong class="error">' . $error . '</strong>';
+ $errorMsg = wfMessage(
'templatestyles-wrong-namespace', $allowedNamespacesText,
+ count( $allowedNamespaces )
)->inContentLanguage();
+ $parser->getOutput()->setExtensionData(
'TemplateStylesParseError', $errorMsg );
+ return '<strong class="error">' . $errorMsg->parse() .
'</strong>';
}
if ( !isset( $params['src'] ) || trim( $params['src'] ) === ''
) {
diff --git a/extension.json b/extension.json
index a3bdb0e..727d254 100644
--- a/extension.json
+++ b/extension.json
@@ -38,6 +38,9 @@
"ParserAfterTidy": [
"TemplateStylesHooks::onParserAfterTidy"
],
+ "PageContentSave": [
+ "TemplateStylesHooks::onPageContentSave"
+ ],
"ContentHandlerDefaultModelFor": [
"TemplateStylesHooks::onContentHandlerDefaultModelFor"
],
--
To view, visit https://gerrit.wikimedia.org/r/405237
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic0f68bb13cc962acd8880b6ddb4e5b68b338cec8
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/TemplateStyles
Gerrit-Branch: master
Gerrit-Owner: Gergő Tisza <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits