Daniel Kinzler has uploaded a new change for review.

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

Change subject: Improve detection of non-content parser runs.
......................................................................

Improve detection of non-content parser runs.

On ParserAfterParse, we pull in sitelinks from the repo and inject
them into the ParserOutputObject. We should only do this when parsing
actual page content. Detecting when this is the case is not trivial
from inside the ParserAfterParse handler function.

In the past, we used $parser->getInterfaceMessage() === false. But that
would pass for any parse that does not use the user interface message.
A number of interface components or actions don't, for instance, the edit
toolbar on the edit page.

This change fixes that by now checking $parser->getRevisionId() !== null;
The revision ID is set whenever actual page content is parsed, and only
then, apparently. Which is exactly what we want.

Note that this means that we no longer inject sitelinks during edit
previews.

Change-Id: I30d12214b04626a903e125d1434b3d37303205a7
---
M client/includes/Hooks/ParserAfterParseHookHandler.php
1 file changed, 10 insertions(+), 16 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/85/210085/1

diff --git a/client/includes/Hooks/ParserAfterParseHookHandler.php 
b/client/includes/Hooks/ParserAfterParseHookHandler.php
index f192897..72269b9 100644
--- a/client/includes/Hooks/ParserAfterParseHookHandler.php
+++ b/client/includes/Hooks/ParserAfterParseHookHandler.php
@@ -72,17 +72,20 @@
         * @return bool
         */
        public static function onParserAfterParse( Parser &$parser = null, 
&$text = null, StripState $stripState = null ) {
-               // this hook tries to access repo SiteLinkTable
-               // it interferes with any test that parses something, like a 
page or a message
-               if ( $parser === null || defined( 'MW_PHPUNIT_TEST' ) ) {
+               if ( $parser === null ) {
                        return true;
                }
 
-               // Only run this once, for the article content and not 
interface stuff
+               // This hook tries to access repo SiteLinkTable
+               // it interferes with any test that parses something, like a 
page or a message.
+               if ( defined( 'MW_PHPUNIT_TEST' ) ) {
+                       return true;
+               }
 
-               // This check needs to be here as this method is being invoked 
a lot,
-               // thus calling self::newFromGlobalState would be quite heavy
-               if ( $parser->getOptions()->getInterfaceMessage() ) {
+               // We only care about existing page content being rendered to 
HTML, not interface
+               // messages or dynamic text or template4 expansion via the API.
+               // CAVEAT: This means we also bail out on edit previews.
+               if ( $parser->getRevisionId() === null || $parser->OutputType() 
!== Parser::OT_HTML ) {
                        return true;
                }
 
@@ -119,15 +122,6 @@
         */
        public function doParserAfterParse( Parser &$parser ) {
                $title = $parser->getTitle();
-
-               // Doing this only makes sense when actually creating html for 
page views, not when
-               // for example substing a template.
-               // Please note: While all cases where this matches don't need 
to go through this many
-               // that don't match (have OT_HTML) still actually wouldn't need 
to go through this...
-               // for example message parses, but we don't have a good way to 
identify those.
-               if ( $parser->OutputType() !== Parser::OT_HTML ) {
-                       return true;
-               }
 
                if ( !$this->namespaceChecker->isWikibaseEnabled( 
$title->getNamespace() ) ) {
                        // shorten out

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I30d12214b04626a903e125d1434b3d37303205a7
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler <[email protected]>

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

Reply via email to