Page MenuHomePhabricator

[1.38.0-wmf.7] WikidataPageBanner: Disable mechanism of table of contents is no longer working on preview mode
Open, MediumPublicBUG REPORT

Description

List of steps to reproduce (step by step, including full links if applicable):

  • Pages should not have table of contents in preview mode (just like the view mode as per T295003)

What happens?:
For some reason, the table of contents are coming up on Wikivoyage on preview mode, which is not usually normal. The affected language versions (for example) are: en:voy, fr:voy, ru:voy.
it:voy is not affected, although apparently the template looks equivalent.
Compare the preview mode of the following two pages:

What should have happened instead?:
The table of contents should have been restricted to the pagebanner

Software version (if not a Wikimedia wiki), browser information, screenshots, other information, etc:

QA steps

beta cluster

Visit https://en.wikivoyage.beta.wmflabs.org/wiki/Bannerda?action=edit and click "show preview" button
Expected: The vertical table of contents should not be present in the page. It should be present inside the banner image at the top of the page as a horizontal bar.

WRONGCORRECT
Screen Shot 2021-12-06 at 4.43.21 PM.png (1×2 px, 1 MB)
Screen Shot 2021-12-06 at 4.43.43 PM.png (1×1 px, 1 MB)

Production

Visit https://en.wikivoyage.org/w/index.php?title=Emilia-Romagna&action=edit & press "Show preview" button.
Expected: The vertical table of contents should not be present in the page. It should be present inside the banner image at the top of the page as a horizontal bar.

Event Timeline

@cscott as per @Jdlrobson request, I've added you on this ticket to check the issue during his two weeks absence. Thanks in advance for your support.

ovasileva triaged this task as Medium priority.Tue, Nov 16, 6:02 PM

@cscott we are going to need a new core hook to restore this behaviour:

diff --git a/includes/EditPage.php b/includes/EditPage.php
index 243042cee6..79ac2f81f0 100644
--- a/includes/EditPage.php
+++ b/includes/EditPage.php
@@ -4250,6 +4250,20 @@ class EditPage implements IEditObject {
                $pstContent = $contentTransformer->preSaveTransform( $content, $this->mTitle, $user, $parserOptions );
                $scopedCallback = $parserOptions->setupFakeRevision( $this->mTitle, $pstContent, $user );
                $parserOutput = $contentRenderer->getParserOutput( $pstContent, $this->mTitle, null, $parserOptions );
+               // @todo: Hook needed here to allow WikidataPageBanner to disable table of contents with code below:
+               if ( $parserOutput->getExtensionData( 'wpb-banner-options' ) !== null ) {
+                       $options = $parserOutput->getExtensionData( 'wpb-banner-options' );
+                       $tocInBanner = $options['enable-toc'] ?? false;
+                       if ( $tocInBanner ) {
+                               $parserOutput->setText(
+                                       Parser::replaceTableOfContentsMarker(
+                                               $parserOutput->getRawText(),
+                                               ''
+                                       )
+                               );
+                       }
+               }
+               // @todo: end book.
                ScopedCallback::consume( $scopedCallback );
                return [
                        'parserOutput' => $parserOutput,

While testing this I also note that table of contents shows up in previews of skins that don't want it. I am going to suggest a more generic hook that allows extensions to explicitly disable the table of contents....

Change 743268 had a related patch set uploaded (by Jdlrobson; author: Jdlrobson):

[mediawiki/extensions/WikidataPageBanner@master] Disable main article table of contents in a less hacky way

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

No need for a new hook in the end. This one works great.

Change 743268 merged by jenkins-bot:

[mediawiki/extensions/WikidataPageBanner@master] Disable main article table of contents in a less hacky way

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