Gergő Tisza has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/161471

Change subject: Introduce ContentAlterParserOutput hook
......................................................................

Introduce ContentAlterParserOutput hook

This hook is the counterpart of ContentGetParserOutput: it gives
high-level access to the parsing of a content object (as opposed
to lower-level parser hooks like ParserBefore*/ParserAfter* which
are called for all kinds of non-content input like interface
messages and don't have the necessary context to know what kind of
input is being parsed), but it is called when the parsing has
already finished.

The intention is to provide a convenient location for ParserOutput
modifications which depend on some global property of the parsed
content, but need to happen before LinksUpdate. Currently there are
no hooks between parsing (initiated by WikiPage::doEditUpdates()
calling WikiPage::prepareContentForEdit()) and updating the link
tables (initiated by the same method calling
Content::getSecondaryDataUpdates()), so any hook an extension would
try to use would face one of the following problems:
* the parsing output is not available yet
* LinksUpdate has run already, modifying list properties is unsafe
* there is not enough context to tell what's being parsed

A typical use of this hook would be to add tracking categories when
something is missing from the text (e.g. there are no references).
For the concrete use case, see I43ed79b6a54cd31820ecae8139e29c5880f5dd1b

Alternative approaches that have been suggested and do not require
a new hook but are not robust / do not rely on a clear contract:
* use ParserAfterTidy or a similar hook, assume that the input
  being parsed is the main page content iff limit reporting is
  enabled
* use ParserAfterTidy or a similar hook, assume that the input
  being parsed is the main page content iff
  ParserOptions::getInterfaceMessage() is fale (this would yield
  some false positives, but in those cases adding a tracking
  category would probably have no effect)

Change-Id: I685b285fcc772382993116f7822a832eeecc0681
---
M docs/hooks.txt
M includes/content/TextContent.php
M includes/content/WikitextContent.php
3 files changed, 10 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/71/161471/1

diff --git a/docs/hooks.txt b/docs/hooks.txt
index f4b8ef2..8b18c17 100644
--- a/docs/hooks.txt
+++ b/docs/hooks.txt
@@ -912,6 +912,14 @@
 ParserOutput object.
 &$output: ParserOutput, to manipulate or replace
 
+'ContentAlterParserOutput': Modify parser output for a given content object.
+Called by AbstractContent::getParserOutput after parsing has finished. Can be
+used for changes that depend on the result of the parsing but have to be done 
before
+LinksUpdate is called.
+$content: The Content to render
+$title: Title of the page, as context
+$parserOutput: ParserOutput to manipulate
+
 'ConvertContent': Called by AbstractContent::convert when a conversion to 
another
 content model is requested.
 $content: The Content object to be converted.
diff --git a/includes/content/TextContent.php b/includes/content/TextContent.php
index c479f20..6ed1b8e 100644
--- a/includes/content/TextContent.php
+++ b/includes/content/TextContent.php
@@ -223,6 +223,7 @@
                if ( in_array( $this->getModel(), $wgTextModelsToParse ) ) {
                        // parse just to get links etc into the database, HTML 
is replaced below.
                        $output = $wgParser->parse( $this->getNativeData(), 
$title, $options, true, true, $revId );
+                       wfRunHooks( 'ContentAlterParserOutput', array( $this, 
$title, $wgParser, $output ) );
                }
 
                if ( $generateHtml ) {
diff --git a/includes/content/WikitextContent.php 
b/includes/content/WikitextContent.php
index 9a8ab3a..ca843bf 100644
--- a/includes/content/WikitextContent.php
+++ b/includes/content/WikitextContent.php
@@ -336,6 +336,7 @@
 
                list( $redir, $text ) = $this->getRedirectTargetAndText();
                $output = $wgParser->parse( $text, $title, $options, true, 
true, $revId );
+               wfRunHooks( 'ContentAlterParserOutput', array( $this, $title, 
$wgParser, $output ) );
 
                // Add redirect indicator at the top
                if ( $redir ) {

-- 
To view, visit https://gerrit.wikimedia.org/r/161471
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I685b285fcc772382993116f7822a832eeecc0681
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: GergÅ‘ Tisza <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to