Page MenuHomePhabricator

ShortUrl and Semantic Mediawiki conflict
Closed, ResolvedPublic

Description

[[Extension:SemanticMediaWiki]] and [[Extension:SemanticForms]] don't work correctly after installing ShortUrl:

  • page [[Special:Properties]] (SMW) contains “NO_VALID_VALUE” instead of the names of predefined properties;
  • page [[Special:CreateProperty]] (SF) displays a message “This appears to be a cross-site request forgery; canceling save” when you try to save or preview property.

Tested on rel. 1.23.7 and 1.24, clean installation.

I was able to fix it by editing the function setupUrlRouting (ShortUrl.hooks.php): replaced

$router->add( $wgShortUrlTemplate,
              array( 'title' => SpecialPage::getTitleFor( 'ShortUrl', '$1' )->getPrefixedText() )
            );

with

$router->add( $wgShortUrlTemplate,
              array( 'title' => 'Special:ShortUrl/$1' ) 
            );

After that everything is working correctly.

Event Timeline

StasR raised the priority of this task from to Needs Triage.
StasR updated the task description. (Show Details)
StasR changed Security from none to None.
StasR subscribed.

This bug remains in MW1.25.1. Here it affects [[Extension:Admin Links]].

The error remains in MW1.25.3.

Same in 1.27RC0 for Extension:AdminLinks
But without installing ShortUrls

Still present in master, in fact none of the SMW special pages work at all if $wgShortUrlTemplate is set.

The issue is that ShortUrl calls SpecialPageFactory::getPageList before Semantic MediaWiki is set up properly in $wgExtensionFunctions. SpecialPageFactory::getPageList uses a cache so it doesn't help that the special pages are registered later.

Normal request without ShortUrl:
string(171) "MediaWiki->run/MediaWiki->main/MediaWiki->performRequest/Title->isSpecial/SpecialPageFactory::resolveAlias/SpecialPageFactory::getAliasList/SpecialPageFactory::getPageList"

Request with ShortUrl:
string(282) "include/include/WebRequest->interpolateTitle/WebRequest::getPathInfo/Hooks::run/Hooks::callHook/ShortUrlHooks::setupUrlRouting/SpecialPage::getTitleFor/SpecialPage::getTitleValueFor/SpecialPageFactory::getLocalNameFor/SpecialPageFactory::getAliasList/SpecialPageFactory::getPageList

It is unclear whether WebRequestPathInfoRouter hook is called too early, or whether ShortUrl should avoid requesting special page name this early. Latter seems easy to do.

Change 389994 had a related patch set uploaded (by Nikerabbit; owner: Nikerabbit):
[mediawiki/extensions/ShortUrl@master] Make compatible with SemanticMediaWiki

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

This is basically the same problem as T104954: ExtensionRegistry / wgExtensionFunctions not treated as array?, SemanticMediaWiki needs to stop registering its hooks in a $wgExtensionFunctions, which is too late. +cc @mwjames.

It is unclear whether WebRequestPathInfoRouter hook is called too early, or whether ShortUrl should avoid requesting special page name this early. Latter seems easy to do.

The use of the WebRequestPathInfoRouter like this is OK, the problem is on SMW's side. But the workaround is probably acceptable for now :(

Change 389994 merged by jenkins-bot:
[mediawiki/extensions/ShortUrl@master] Make compatible with SemanticMediaWiki

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

Another problem I observed is that mergeMessageFiles.php doesn't pick up the i18n files from SMW (because of late registration?).

T104954: ExtensionRegistry / wgExtensionFunctions not treated as array?, SemanticMediaWiki needs to stop registering its hooks in a $wgExtensionFunctions, which is too late. +cc @mwjames.

In regards to ExtensionRegistry\ extension.json, [0] contains my statement especially on the matter of registration of dynamic namespace IDs.

needs to stop registering its hooks in a $wgExtensionFunctions, which is too late.

To avoid misunderstandings on the part of "... needs to stop registering its hooks ..." note, I added some notes to the topic [1].

[0] https://github.com/SemanticMediaWiki/SemanticMediaWiki/pull/1732#issuecomment-336614098
[1] https://github.com/SemanticMediaWiki/SemanticMediaWiki/issues/2813

I'll follow up on the SMW issue tracker.