$urlUtils->parse() is not a static method.

Non-dependency injection way:

use MediaWiki\MediaWikiServices;

$urlUtils = MediaWikiServices::getInstance()->getUrlUtils()

$urlUtils->parse()

Otherwise inject the UrlUtils service. For example, if using
HookHandlers[1], add the service to your extension registration
extension.json:
{
    "HookHandlers": {
        "main": {
            "class": "MediaWiki\\Extension\\Example\\Hooks",
            "services": [ "UrlUtils" ]
        }
    },
    "Hooks": {
        "ParserFirstCallInit": "main"
    }
}

Then the service will be injected into your __construct(UrlUtils $urlUtils)
method as an argument.

[1]
https://www.mediawiki.org/wiki/Manual:Hooks#Handling_hooks_in_MediaWiki_1.35_and_later

On Wed, Jan 11, 2023 at 6:36 PM Tim Moody <[email protected]> wrote:

> On MW 1.39.0 and .1 and PHP 8.1.2-1ubuntu2.9,
>
> I am trying to revise a parserhook extension to mediawiki that uses
> wfParseUrl().
> https://doc.wikimedia.org/mediawiki-core/master/php/GlobalFunctions_8php.html#a178b2b51ef87926e5daa08f66fbae9b0
> says that is deprecated and I should use UrlUtils::parse().
>
> The former looks like a function and the latter looks like a class,
> perhaps a subclass of Utils. My first question is what if any use statement
> do I need. The extension already has use Html, but use UrlUtils gives an
> error because it can't be found.
>
> Do I need to instantiate Utils or UrlUtils and invoke the urlparser as
> $urlUtils -> parse()? When I invoke UrlUtils::parse I get a complaint about
> calling a non-static method statically.
>
> The old code was
> $url_parts = wfParseUrl( $graph_url );
> and the new
> $url_parts = UrlUtils::parse( $graph_url );
>
> Any help would be appreciated.
>
> Tim
> _______________________________________________
> Wikitech-l mailing list -- [email protected]
> To unsubscribe send an email to [email protected]
> https://lists.wikimedia.org/postorius/lists/wikitech-l.lists.wikimedia.org/
_______________________________________________
Wikitech-l mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://lists.wikimedia.org/postorius/lists/wikitech-l.lists.wikimedia.org/

Reply via email to