Page MenuHomePhabricator

Displaytitle onSelfLinkBegin is broken when linking from other context than webrequest.
Closed, ResolvedPublic

Description

I9fc7640ecbc61cb82265899a9fd8ff8e51e09908 and its cherry picks introduces a change in how onSelfLinkBegin hook makes links.

Previous code:

 public function onSelfLinkBegin( $nt, &$html, &$trail, &$prefix, &$ret ) {
        // Do not use DisplayTitle if current page is defined in $wgDisplayTitleExcludes
         $request = $this->config->get( 'Request' );
         $title = $request->getVal( 'title' );
        if ( in_array( $title, $GLOBALS['wgDisplayTitleExcludes'] ) ) {
                return;
        }

        self::handleLink( $nt, $html, false );
}

New code:

public function onSelfLinkBegin( $nt, &$html, &$trail, &$prefix, &$ret ) {
        $request = $this->config->get( 'Request' );
        $title = $request->getVal( 'title' );
       $this->displayTitleService->handleLink( $title, $nt, $html, false );
}

Notable difference:
If title is not given (Because e.g. you are parsing several pages as part of a script or something) it might be that $config->get('Request')->getVal('title) is null, which will error out in the new code with "TypeError: null given should be string".

I suggest we do one of the following:

  1. Get title from target. It is a self-link after all
  2. put ?string inside handleLink

Our problem occurred when using PageSync extension for syncing several pages, which will be parsed during save without $config->get('Request')->getVal('title'); being set.

Event Timeline

Change 941517 had a related patch set uploaded (by Cicalese; author: Cicalese):

[mediawiki/extensions/DisplayTitle@master] Fix title handling in hooks

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

Thank you for catching this. The patch should address this issue.

Change 941517 merged by jenkins-bot:

[mediawiki/extensions/DisplayTitle@master] Fix title handling in hooks

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

Change 941987 had a related patch set uploaded (by Cicalese; author: Cicalese):

[mediawiki/extensions/DisplayTitle@REL1_39] Fix title handling in hooks

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

Change 941988 had a related patch set uploaded (by Cicalese; author: Cicalese):

[mediawiki/extensions/DisplayTitle@REL1_40] Fix title handling in hooks

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

Change 941987 merged by jenkins-bot:

[mediawiki/extensions/DisplayTitle@REL1_39] Fix title handling in hooks

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

Change 941988 merged by jenkins-bot:

[mediawiki/extensions/DisplayTitle@REL1_40] Fix title handling in hooks

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

cicalese claimed this task.
cicalese moved this task from Backlog to Closed on the MediaWiki-extensions-DisplayTitle board.