Mailing List Archive

help mediawiki extension
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
Re: help mediawiki extension [ In reply to ]
$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 <tim@timmoody.com> 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 -- wikitech-l@lists.wikimedia.org
> To unsubscribe send an email to wikitech-l-leave@lists.wikimedia.org
> https://lists.wikimedia.org/postorius/lists/wikitech-l.lists.wikimedia.org/
Re: help mediawiki extension [ In reply to ]
I'm still a brick shy of a load:

in extension.json I have

"HookHandlers": {
"main": {
"class": "MediaWiki\\Extension\\OurWorldInData\\Hooks",
"services": [
"MainConfig",
"UrlUtils"
]
}
},

in Hooks.php I have

use Config;
use Html;
use UrlUtils;
use MediaWiki\Hook\ParserFirstCallInitHook;
use MWException;
use Parser;
use PPFrame;

class Hooks implements ParserFirstCallInitHook {
/** @var Config Main config */
private Config $config;
private UrlUtils $urlUtils;

/**
* @param Config $config Main config
*/
public function __construct( Config $config, UrlUtils $urlUtils ) {
$this->config = $config;
$this->urlUtils = $urlUtils;
}


I get

TypeError: MediaWiki\Extension\OurWorldInData\Hooks::__construct():
Argument #2 ($urlUtils) must be of type UrlUtils, MediaWiki\Utils\UrlUtils
given


On Wed, Jan 11, 2023 at 10:14 PM D <dylssswp@gmail.com> wrote:

> $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 <tim@timmoody.com> 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 -- wikitech-l@lists.wikimedia.org
>> To unsubscribe send an email to wikitech-l-leave@lists.wikimedia.org
>>
>> https://lists.wikimedia.org/postorius/lists/wikitech-l.lists.wikimedia.org/
>
> _______________________________________________
> Wikitech-l mailing list -- wikitech-l@lists.wikimedia.org
> To unsubscribe send an email to wikitech-l-leave@lists.wikimedia.org
> https://lists.wikimedia.org/postorius/lists/wikitech-l.lists.wikimedia.org/
Re: help mediawiki extension [ In reply to ]
Hi!

Change

use UrlUtils;

to

use MediaWiki\Utils\UrlUtils;

-
Robert
________________________________
Von: Tim Moody <tim@timmoody.com>
Gesendet: Donnerstag, 12. Januar 2023 16:27
An: Wikitech-l <wikitech-l@lists.wikimedia.org>
Betreff: [Wikitech-l] Re: help mediawiki extension

I'm still a brick shy of a load:

in extension.json I have

"HookHandlers": {
"main": {
"class": "MediaWiki\\Extension\\OurWorldInData\\Hooks",
"services": [
"MainConfig",
"UrlUtils"
]
}
},

in Hooks.php I have

use Config;
use Html;
use UrlUtils;
use MediaWiki\Hook\ParserFirstCallInitHook;
use MWException;
use Parser;
use PPFrame;

class Hooks implements ParserFirstCallInitHook {
/** @var Config Main config */
private Config $config;
private UrlUtils $urlUtils;

/**
* @param Config $config Main config
*/
public function __construct( Config $config, UrlUtils $urlUtils ) {
$this->config = $config;
$this->urlUtils = $urlUtils;
}


I get

TypeError: MediaWiki\Extension\OurWorldInData\Hooks::__construct(): Argument #2 ($urlUtils) must be of type UrlUtils, MediaWiki\Utils\UrlUtils given


On Wed, Jan 11, 2023 at 10:14 PM D <dylssswp@gmail.com<mailto:dylssswp@gmail.com>> wrote:
$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 <tim@timmoody.com<mailto:tim@timmoody.com>> 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 -- wikitech-l@lists.wikimedia.org<mailto:wikitech-l@lists.wikimedia.org>
To unsubscribe send an email to wikitech-l-leave@lists.wikimedia.org<mailto:wikitech-l-leave@lists.wikimedia.org>
https://lists.wikimedia.org/postorius/lists/wikitech-l.lists.wikimedia.org/
_______________________________________________
Wikitech-l mailing list -- wikitech-l@lists.wikimedia.org<mailto:wikitech-l@lists.wikimedia.org>
To unsubscribe send an email to wikitech-l-leave@lists.wikimedia.org<mailto:wikitech-l-leave@lists.wikimedia.org>
https://lists.wikimedia.org/postorius/lists/wikitech-l.lists.wikimedia.org/
Re: help mediawiki extension [ In reply to ]
thanks. that got me going again.

On Thu, Jan 12, 2023 at 10:34 AM Robert Vogel via Wikitech-l <
wikitech-l@lists.wikimedia.org> wrote:

> Hi!
>
> Change
>
> use UrlUtils;
>
> to
>
> use MediaWiki\Utils\UrlUtils;
>
> -
> Robert
> ------------------------------
> *Von:* Tim Moody <tim@timmoody.com>
> *Gesendet:* Donnerstag, 12. Januar 2023 16:27
> *An:* Wikitech-l <wikitech-l@lists.wikimedia.org>
> *Betreff:* [Wikitech-l] Re: help mediawiki extension
>
> I'm still a brick shy of a load:
>
> in extension.json I have
>
> "HookHandlers": {
> "main": {
> "class": "MediaWiki\\Extension\\OurWorldInData\\Hooks",
> "services": [
> "MainConfig",
> "UrlUtils"
> ]
> }
> },
>
> in Hooks.php I have
>
> use Config;
> use Html;
> use UrlUtils;
> use MediaWiki\Hook\ParserFirstCallInitHook;
> use MWException;
> use Parser;
> use PPFrame;
>
> class Hooks implements ParserFirstCallInitHook {
> /** @var Config Main config */
> private Config $config;
> private UrlUtils $urlUtils;
>
> /**
> * @param Config $config Main config
> */
> public function __construct( Config $config, UrlUtils $urlUtils ) {
> $this->config = $config;
> $this->urlUtils = $urlUtils;
> }
>
>
> I get
>
> TypeError: MediaWiki\Extension\OurWorldInData\Hooks::__construct():
> Argument #2 ($urlUtils) must be of type UrlUtils, MediaWiki\Utils\UrlUtils
> given
>
>
> On Wed, Jan 11, 2023 at 10:14 PM D <dylssswp@gmail.com> wrote:
>
> $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 <tim@timmoody.com> 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 -- wikitech-l@lists.wikimedia.org
> To unsubscribe send an email to wikitech-l-leave@lists.wikimedia.org
> https://lists.wikimedia.org/postorius/lists/wikitech-l.lists.wikimedia.org/
>
> _______________________________________________
> Wikitech-l mailing list -- wikitech-l@lists.wikimedia.org
> To unsubscribe send an email to wikitech-l-leave@lists.wikimedia.org
> https://lists.wikimedia.org/postorius/lists/wikitech-l.lists.wikimedia.org/
>
> _______________________________________________
> Wikitech-l mailing list -- wikitech-l@lists.wikimedia.org
> To unsubscribe send an email to wikitech-l-leave@lists.wikimedia.org
> https://lists.wikimedia.org/postorius/lists/wikitech-l.lists.wikimedia.org/
>