Page MenuHomePhabricator

Some OAuth special pages are not recognized ('no such special page')
Closed, ResolvedPublic

Description

When I want to use the special pages Special:OAuthConsumerRegistration and Special:OAuthManageConsumers MediaWiki throws a 'no such special page' error.

Special pages that aren't be defined by 'MWOAuthUISetup::conditionalSetup()' (which all other special pages, because they are defined by 'MWOAuthUISetup::unconditionalSetup()').

I managed to get the two affected special pages work by applying this hacky patch:

diff --git a/OAuth.php b/OAuth.php
index 2f5c20a..31e05ca 100644
--- a/OAuth.php
+++ b/OAuth.php
@@ -45,6 +45,7 @@ MWOAuthSetup::defineSourcePaths( $wgAutoloadClasses, $wgExtensionMessagesFiles,
 # Setup steps that does not depend on configuration
 MWOAuthSetup::unconditionalSetup();
 MWOAuthUISetup::unconditionalSetup();
+MWOAuthUISetup::conditionalSetup();
 MWOAuthAPISetup::unconditionalSetup();

 # Actually register special pages and set default $wgMWOAuthCentralWiki
@@ -58,5 +59,6 @@ $wgExtensionFunctions[] = function() {
                // There is actually a central wiki, requiring global user IDs via hook
                $wgMWOAuthSharedUserIDs = true;
        }
+
        \MediaWiki\Extensions\OAuth\MWOAuthUISetup::conditionalSetup();
 };
diff --git a/frontend/MWOAuthUI.setup.php b/frontend/MWOAuthUI.setup.php
index d3aa768..c6ccd10 100644
--- a/frontend/MWOAuthUI.setup.php
+++ b/frontend/MWOAuthUI.setup.php
@@ -49,7 +49,7 @@ class MWOAuthUISetup {
                global $wgSpecialPages;
                global $wgLogTypes, $wgLogNames, $wgLogHeaders, $wgLogActionsHandlers;

-               if ( MWOAuthUtils::isCentralWiki() ) {
+               // if ( MWOAuthUtils::isCentralWiki() ) {
                        $wgSpecialPages['OAuthConsumerRegistration'] = 'MediaWiki\Extensions\OAuth\SpecialMWOAuthConsumerRegistration';
                        $wgSpecialPages['OAuthManageConsumers'] = 'MediaWiki\Extensions\OAuth\SpecialMWOAuthManageConsumers';

@@ -57,6 +57,6 @@ class MWOAuthUISetup {
                        $wgLogNames['mwoauthconsumer'] = 'mwoauthconsumer-consumer-logpage';
                        $wgLogHeaders['mwoauthconsumer'] = 'mwoauthconsumer-consumer-logpagetext';
                        $wgLogActionsHandlers['mwoauthconsumer/*'] = 'LogFormatter';
-               }
+               // }
        }
 }

I wonder why MWOAuthUISetup::conditionalSetup() needs to be wrapped into a wgExtensionFunctions thing?

Help is welcome! If you need more information please do not hesitate to ask.

OAuth version: 6d6bf97364cb31c7b48d90d3eee42dec582721a3 (REL1_26)
MediaWiki version: 1.26.2
PHP version: 5.6.17-0+deb8u1

MediaWiki Configuration: https://github.com/miraheze/mw-config/blob/master/LocalSettings.php#L1146

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald TranscriptApr 12 2016, 3:03 PM
Tgr added a subscriber: Tgr.Apr 12 2016, 3:26 PM

Those pages only exist on $wgMWOAuthCentralWiki. You can either not set that (in which case they will exist on each wiki but the wikis won't really be aware of each other and you will have to register and authorize OAuth consumers on each wiki separately) or set it to a central wiki which will be the one where registration and management of consumers must happen.

Does that solve your issue or did you intend it as a feature request to make management pages available from any wiki?

revi added a comment.Apr 12 2016, 3:54 PM

$wgMWOAuthCentralWiki is already defined (see the link in the description.), but it doesn't solve anything.

Tgr added a comment.Apr 12 2016, 3:56 PM

So Special:OAuthConsumerRegistration etc. does not exist on metawiki?

revi added a comment.Apr 12 2016, 3:59 PM

So Special:OAuthConsumerRegistration etc. does not exist on metawiki?

You have requested an invalid special page.

And just to be sure it's installed, Version has OAuth (version above).

Tgr added a comment.EditedApr 13 2016, 7:47 AM

There might be some problem with your wiki configuration then. MWOAuthUtils::isCentralWiki() simply checks wfWikiId() === $wgMWOAuthCentralWiki so you should debug those.

@Tgr: I applied this patch:

diff --git a/frontend/MWOAuthUI.setup.php b/frontend/MWOAuthUI.setup.php
index d3aa768..6abe29e 100644
--- a/frontend/MWOAuthUI.setup.php
+++ b/frontend/MWOAuthUI.setup.php
@@ -49,7 +49,10 @@ class MWOAuthUISetup {
                global $wgSpecialPages;
                global $wgLogTypes, $wgLogNames, $wgLogHeaders, $wgLogActionsHandlers;

+               if ( $_SERVER['REMOTE_ADDR'] == '::ffff:[REDACTED]' ) { var_dump( MWOAuthUtils::isCentralWiki() ); }
+
                if ( MWOAuthUtils::isCentralWiki() ) {
+                       if ( $_SERVER['REMOTE_ADDR'] == '::ffff:[REDACTED]' ) { echo 'This is a central wiki'; }
                        $wgSpecialPages['OAuthConsumerRegistration'] = 'MediaWiki\Extensions\OAuth\SpecialMWOAuthConsumerRegistration';
                        $wgSpecialPages['OAuthManageConsumers'] = 'MediaWiki\Extensions\OAuth\SpecialMWOAuthManageConsumers';

I get this in my browser: bool(true) This is a central wiki

When I apply this patch to the literal end of LocalSettings.php:

--- a/LocalSettings.php
+++ b/LocalSettings.php
@@ -2210,3 +2210,5 @@ if ( $wgDBname == 'metawiki' ) {
 if ( $wgDBname == 'extloadwiki' ) {
        require_once( "$IP/extensions/OpenGraphMeta/OpenGraphMeta.php" );
 }
+
+if ( $_SERVER['REMOTE_ADDR'] == '::ffff:[REDACTED]' ) { var_dump( $wgSpecialPages['OAuthConsumerRegistration'] ); }

I get this: <b>Notice</b>: Undefined index: OAuthConsumerRegistration in <b>/srv/mediawiki/config/LocalSettings.php</b> on line <b>2214</b><br>
NULL

Something is just going horribly wrong when adding the special page to the wgSpecialPages array. It should have nothing to do with isCentralWiki() I guess? I experience this same issue with the Translate extension.

Tgr added a comment.Apr 13 2016, 9:08 PM

Maybe something is overwriting $wgSpecialPages instead of adding to it. Pepper LocalSetting with var_dumps and find the place where the contents disappear I guess?

array(23) {
  ["OAuth"]=>
  string(41) "MediaWiki\Extensions\OAuth\SpecialMWOAuth"
  ["OAuthManageMyGrants"]=>
  string(55) "MediaWiki\Extensions\OAuth\SpecialMWOAuthManageMyGrants"
  ["OAuthListConsumers"]=>
  string(54) "MediaWiki\Extensions\OAuth\SpecialMWOAuthListConsumers"
}

I added this var_dump after the require of OAuth, so it is not like any of my extensions should be messing with the array..

Southparkfan renamed this task from Some OAuth special pages are not recognized ('no such special page' to Some OAuth special pages are not recognized ('no such special page').Apr 16 2016, 1:22 PM
Reception123 added a comment.EditedApr 16 2016, 3:30 PM

https://meta.miraheze.org/wiki/Special:OAuthConsumerRegistration works for me now.
EDIT: Seems that Southparkfan patched MW1, so that's why it works now (it doesn't work fully) as on some refreshes it still gives errors

Reception123 added a comment.EditedApr 17 2016, 4:33 PM

It no longer works at all. (back to No such special page)

What other extensions do you have installed?

Anyways, it's an OAuth bug, registering special pages inside a $wgExtensionFunctions is too late. The SpecialPage_initList hook should be used instead.

It would be cool if this bug could be fixed (whatever the solution is).

However, I was surprised when I tried this extension on another MediaWiki 1.26 installation (which has a lot less extensions): it just worked without any patch! After some debugging I found the culprit: the onWebRequestPathInfoRouter hook in the UrlShortener extension: https://github.com/wikimedia/mediawiki-extensions-UrlShortener/blob/master/UrlShortener.hooks.php#L22-L24

I do not know anything about PathRouter, but it somehow seems to cause issues. Could it be a wrong REQUEST_URI parameter set by nginx? Or a bug in PathRouter?

I am not sure if @Legoktm is still right about '$wgExtensionFunctions being too late', it could be a bug in my nginx config, PathRouter or something else.

I do not know anything about PathRouter, but it somehow seems to cause issues. Could it be a wrong REQUEST_URI parameter set by nginx? Or a bug in PathRouter?

No, it's none of those.

I am not sure if @Legoktm is still right about '$wgExtensionFunctions being too late', it could be a bug in my nginx config, PathRouter or something else.

I'm fairly sure he is.

I'm sure Legoktm is right :-)! But I failed to make it work, so someone else should take it over honestly...

Aklapper triaged this task as Low priority.Aug 1 2016, 9:04 AM
jayvdb added a subscriber: jayvdb.Nov 2 2016, 11:07 AM
Tgr closed this task as Invalid.Mar 7 2017, 3:52 AM

Closing - almost certainly a configuration problem and no activity for over 6 months.

Legoktm reopened this task as Open.Mar 7 2017, 3:53 AM

Anyways, it's an OAuth bug, registering special pages inside a $wgExtensionFunctions is too late. The SpecialPage_initList hook should be used instead.

As far as I know, this is still accurate.

And it's not necessarily a configuration issue. If an extension like UrlShortner is installed which initializes the SpecialPage list before extension functions are run, it's too late to register more special pages, which is why you need to use the hook.

Tgr raised the priority of this task from Low to Medium.Mar 7 2017, 3:59 AM

Ah, sorry, was reading too fast.

Restricted Application added a subscriber: TerraCodes. · View Herald TranscriptMar 7 2017, 4:00 AM
Legoktm claimed this task.Mar 7 2017, 7:01 AM

Change 341493 had a related patch set uploaded (by legoktm):
[mediawiki/extensions/OAuth] Move conditional special page registration to a hook

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

Change 341493 merged by jenkins-bot:
[mediawiki/extensions/OAuth] Move conditional special page registration to a hook

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

Legoktm closed this task as Resolved.Mar 10 2017, 2:58 AM