Mailing List Archive

array syntax
Hello,

I have some array declarations in my LocalSettings.php from many years ago
that I am worried may not be compatible with PHP 8+. When I try to run
/maintenance/update.php in PHP 8.1 I get errors. It runs fine in PHP 7.4.3,
fortunately. However, is it okay to set arrays like this in PHP 8+?:

$wgSitemapNamespaces = array( 0, 100, 102 );

Thank you :)

Roger
teflpedia.com <- MediaWiki 1.39.1 recently upgraded

-----example from my LocalSettings.php-----

# Site Map see https://www.mediawiki.org/wiki/Manual:$wgSitemapNamespaces
#$wgSitemapNamespaces = array( 0, 2, 4, 12 ); # example, to site map
Main-0, User-2, Project-4, Help-12 namespace
$wgSitemapNamespaces = array( 0, 100, 102 ); # let's site map ONLY Main,
Essay, Lesson namespace

## Extra namespaces
$wgExtraNamespaces[100] = "Lesson";
$wgExtraNamespaces[101] = "Lesson_talk";
$wgExtraNamespaces[102] = "Essay";
$wgExtraNamespaces[103] = "Essay_talk";
$wgExtraNamespaces[104] = "Debate";
$wgExtraNamespaces[105] = "Debate_talk";

## Enable subpages in all namespaces
$wgNamespacesWithSubpages = array_fill(0, 200, true);
$wgNamespacesWithSubpages[NS_MAIN] = false; # per Duncan request Jan 11,
2022


## Set default searching. Roger 2012.11.03, updated array syntax 2023.02.13
$wgNamespacesToBeSearchedDefault = [.
NS_MAIN => true,
NS_TALK => false,
NS_USER => false,
NS_USER_TALK => false,
NS_PROJECT => false,
NS_PROJECT_TALK => false,
NS_IMAGE => false,
NS_IMAGE_TALK => false,
NS_MEDIAWIKI => false,
NS_MEDIAWIKI_TALK => false,
NS_TEMPLATE => false,
NS_TEMPLATE_TALK => false,
NS_HELP => false,
NS_HELP_TALK => false,
NS_CATEGORY => false,
NS_CATEGORY_TALK => false,
100 => true,
101 => false
];

-------/example--------
Re: array syntax [ In reply to ]
Hi Roger, that's still the syntax. What are the errors you're getting?

On Tue, Feb 14, 2023 at 12:15 AM <rogerchrisman@gmail.com> wrote:

> Hello,
>
> I have some array declarations in my LocalSettings.php from many years ago
> that I am worried may not be compatible with PHP 8+. When I try to run
> /maintenance/update.php in PHP 8.1 I get errors. It runs fine in PHP 7.4.3,
> fortunately. However, is it okay to set arrays like this in PHP 8+?:
>
> $wgSitemapNamespaces = array( 0, 100, 102 );
>
> Thank you :)
>
> Roger
> teflpedia.com <- MediaWiki 1.39.1 recently upgraded
>
> -----example from my LocalSettings.php-----
>
> # Site Map see https://www.mediawiki.org/wiki/Manual:$wgSitemapNamespaces
> #$wgSitemapNamespaces = array( 0, 2, 4, 12 ); # example, to site map
> Main-0, User-2, Project-4, Help-12 namespace
> $wgSitemapNamespaces = array( 0, 100, 102 ); # let's site map ONLY Main,
> Essay, Lesson namespace
>
> ## Extra namespaces
> $wgExtraNamespaces[100] = "Lesson";
> $wgExtraNamespaces[101] = "Lesson_talk";
> $wgExtraNamespaces[102] = "Essay";
> $wgExtraNamespaces[103] = "Essay_talk";
> $wgExtraNamespaces[104] = "Debate";
> $wgExtraNamespaces[105] = "Debate_talk";
>
> ## Enable subpages in all namespaces
> $wgNamespacesWithSubpages = array_fill(0, 200, true);
> $wgNamespacesWithSubpages[NS_MAIN] = false; # per Duncan request Jan 11,
> 2022
>
>
> ## Set default searching. Roger 2012.11.03, updated array syntax 2023.02.13
> $wgNamespacesToBeSearchedDefault = [.
> NS_MAIN => true,
> NS_TALK => false,
> NS_USER => false,
> NS_USER_TALK => false,
> NS_PROJECT => false,
> NS_PROJECT_TALK => false,
> NS_IMAGE => false,
> NS_IMAGE_TALK => false,
> NS_MEDIAWIKI => false,
> NS_MEDIAWIKI_TALK => false,
> NS_TEMPLATE => false,
> NS_TEMPLATE_TALK => false,
> NS_HELP => false,
> NS_HELP_TALK => false,
> NS_CATEGORY => false,
> NS_CATEGORY_TALK => false,
> 100 => true,
> 101 => false
> ];
>
> -------/example--------
>
> _______________________________________________
> MediaWiki-l mailing list -- mediawiki-l@lists.wikimedia.org
> To unsubscribe send an email to mediawiki-l-leave@lists.wikimedia.org
>
> https://lists.wikimedia.org/postorius/lists/mediawiki-l.lists.wikimedia.org/
Re: array syntax [ In reply to ]
Yes its fine to use long array syntax.

Are the error messages suggesting that the syntax is wrong?

--
Brian

On Monday, February 13, 2023, <rogerchrisman@gmail.com> wrote:

> Hello,
>
> I have some array declarations in my LocalSettings.php from many years ago
> that I am worried may not be compatible with PHP 8+. When I try to run
> /maintenance/update.php in PHP 8.1 I get errors. It runs fine in PHP 7.4.3,
> fortunately. However, is it okay to set arrays like this in PHP 8+?:
>
> $wgSitemapNamespaces = array( 0, 100, 102 );
>
> Thank you :)
>
> Roger
> teflpedia.com <- MediaWiki 1.39.1 recently upgraded
>
> -----example from my LocalSettings.php-----
>
> # Site Map see https://www.mediawiki.org/wiki/Manual:$wgSitemapNamespaces
> #$wgSitemapNamespaces = array( 0, 2, 4, 12 ); # example, to site map
> Main-0, User-2, Project-4, Help-12 namespace
> $wgSitemapNamespaces = array( 0, 100, 102 ); # let's site map ONLY Main,
> Essay, Lesson namespace
>
> ## Extra namespaces
> $wgExtraNamespaces[100] = "Lesson";
> $wgExtraNamespaces[101] = "Lesson_talk";
> $wgExtraNamespaces[102] = "Essay";
> $wgExtraNamespaces[103] = "Essay_talk";
> $wgExtraNamespaces[104] = "Debate";
> $wgExtraNamespaces[105] = "Debate_talk";
>
> ## Enable subpages in all namespaces
> $wgNamespacesWithSubpages = array_fill(0, 200, true);
> $wgNamespacesWithSubpages[NS_MAIN] = false; # per Duncan request Jan 11,
> 2022
>
>
> ## Set default searching. Roger 2012.11.03, updated array syntax 2023.02.13
> $wgNamespacesToBeSearchedDefault = [.
> NS_MAIN => true,
> NS_TALK => false,
> NS_USER => false,
> NS_USER_TALK => false,
> NS_PROJECT => false,
> NS_PROJECT_TALK => false,
> NS_IMAGE => false,
> NS_IMAGE_TALK => false,
> NS_MEDIAWIKI => false,
> NS_MEDIAWIKI_TALK => false,
> NS_TEMPLATE => false,
> NS_TEMPLATE_TALK => false,
> NS_HELP => false,
> NS_HELP_TALK => false,
> NS_CATEGORY => false,
> NS_CATEGORY_TALK => false,
> 100 => true,
> 101 => false
> ];
>
> -------/example--------
>
>
Re: array syntax [ In reply to ]
Thank you for your replies! It does me tons of good to have your help. So,
no worries about my array syntax. That is a relief. I don't know computer
programming. I'm one of the simple minded people. So I upgrade the wiki
only on LTR dates. Thank you for your help!

I get this error when I run the update.php, in either PHP 8.0 or PHP 8.1:

bilbo@cpanel84:~/www/teflpedia/maintenance$ php update.php
Fatal error: Uncaught Error: Undefined constant "NS_IMAGE" in
/home/bilbo/public_html/teflpedia/LocalSettings.php:309
Stack trace:
#0 /home/bilbo/public_html/teflpedia/includes/Setup.php(218): require_once()
#1 /home/bilbo/public_html/teflpedia/maintenance/doMaintenance.php(83):
require_once('/home/bilbo/pub...')
#2 /home/bilbo/public_html/teflpedia/maintenance/update.php(312):
require_once('/home/bilbo/pub...')
#3 {main}
thrown in /home/bilbo/public_html/teflpedia/LocalSettings.php on line 309
bilbo@cpanel84:~/www/teflpedia/maintenance$

The update.php runs without errors, thankfully, in PHP 7.4.3. Why is that?

I recently upgraded this wiki from MediaWiki 1.35.1 to MediaWiki 1.39.1.
The wiki is over a decade old and uses short URLs which I prefer. I will
run it in PHP 7.4.3 for now, right?

Is there anything I should do?

Roger
Teflpedia.com








On Mon, Feb 13, 2023 at 10:15 PM Brian Wolff <bawolff@gmail.com> wrote:

> Yes its fine to use long array syntax.
>
> Are the error messages suggesting that the syntax is wrong?
>
> --
> Brian
>
> On Monday, February 13, 2023, <rogerchrisman@gmail.com> wrote:
>
>> Hello,
>>
>> I have some array declarations in my LocalSettings.php from many years
>> ago that I am worried may not be compatible with PHP 8+. When I try to run
>> /maintenance/update.php in PHP 8.1 I get errors. It runs fine in PHP 7.4.3,
>> fortunately. However, is it okay to set arrays like this in PHP 8+?:
>>
>> $wgSitemapNamespaces = array( 0, 100, 102 );
>>
>> Thank you :)
>>
>> Roger
>> teflpedia.com <- MediaWiki 1.39.1 recently upgraded
>>
>> -----example from my LocalSettings.php-----
>>
>> # Site Map see https://www.mediawiki.org/wiki/Manual:$wgSitemapNamespaces
>> #$wgSitemapNamespaces = array( 0, 2, 4, 12 ); # example, to site map
>> Main-0, User-2, Project-4, Help-12 namespace
>> $wgSitemapNamespaces = array( 0, 100, 102 ); # let's site map ONLY Main,
>> Essay, Lesson namespace
>>
>> ## Extra namespaces
>> $wgExtraNamespaces[100] = "Lesson";
>> $wgExtraNamespaces[101] = "Lesson_talk";
>> $wgExtraNamespaces[102] = "Essay";
>> $wgExtraNamespaces[103] = "Essay_talk";
>> $wgExtraNamespaces[104] = "Debate";
>> $wgExtraNamespaces[105] = "Debate_talk";
>>
>> ## Enable subpages in all namespaces
>> $wgNamespacesWithSubpages = array_fill(0, 200, true);
>> $wgNamespacesWithSubpages[NS_MAIN] = false; # per Duncan request Jan 11,
>> 2022
>>
>>
>> ## Set default searching. Roger 2012.11.03, updated array syntax
>> 2023.02.13
>> $wgNamespacesToBeSearchedDefault = [.
>> NS_MAIN => true,
>> NS_TALK => false,
>> NS_USER => false,
>> NS_USER_TALK => false,
>> NS_PROJECT => false,
>> NS_PROJECT_TALK => false,
>> NS_IMAGE => false,
>> NS_IMAGE_TALK => false,
>> NS_MEDIAWIKI => false,
>> NS_MEDIAWIKI_TALK => false,
>> NS_TEMPLATE => false,
>> NS_TEMPLATE_TALK => false,
>> NS_HELP => false,
>> NS_HELP_TALK => false,
>> NS_CATEGORY => false,
>> NS_CATEGORY_TALK => false,
>> 100 => true,
>> 101 => false
>> ];
>>
>> -------/example--------
>>
>> _______________________________________________
> MediaWiki-l mailing list -- mediawiki-l@lists.wikimedia.org
> To unsubscribe send an email to mediawiki-l-leave@lists.wikimedia.org
>
> https://lists.wikimedia.org/postorius/lists/mediawiki-l.lists.wikimedia.org/
Re: array syntax [ In reply to ]
The "NS_IMAGE" constant, which you use in your LocalSettings.php, has
been replaced by "NS_FILE" and removed in MediaWiki 1.34 (a while ago).
It looks like PHP 7.4 was just ignoring it (and presumably some of the
configuration you intended for the Image/File namespace was not applying
correctly), but PHP 8 treats it as an error.

The solution is to just replace all occurrences of NS_IMAGE with NS_FILE
(and NS_IMAGE_TALK with NS_FILE_TALK).

(Congrats on running MediaWiki for long enough that your configuration
still used NS_IMAGE ;) )

--
Bartosz Dziewo?ski
_______________________________________________
MediaWiki-l mailing list -- mediawiki-l@lists.wikimedia.org
To unsubscribe send an email to mediawiki-l-leave@lists.wikimedia.org
https://lists.wikimedia.org/postorius/lists/mediawiki-l.lists.wikimedia.org/
Re: array syntax [ In reply to ]
On Tue, Feb 14, 2023 at 1:57 PM Bartosz Dziewo?ski <matma.rex@gmail.com> wrote:
>
> The "NS_IMAGE" constant, which you use in your LocalSettings.php, has
> been replaced by "NS_FILE" and removed in MediaWiki 1.34 (a while ago).
> It looks like PHP 7.4 was just ignoring it (and presumably some of the
> configuration you intended for the Image/File namespace was not applying
> correctly), but PHP 8 treats it as an error.
>
> The solution is to just replace all occurrences of NS_IMAGE with NS_FILE
> (and NS_IMAGE_TALK with NS_FILE_TALK).
>
> (Congrats on running MediaWiki for long enough that your configuration
> still used NS_IMAGE ;) )

This is a recurring problem with LocalSettings.php. The devs keep
changing stuff and breaking things. I can't count how many times we've
had to fix unexpected breaks. (Our wiki and LocalSettings.php dates
back to 2005).

Welcome to the world of software development by web developers. Things
are only expected to last 6 months. It's worse than an automobile in
the salt belt.

Jeff
_______________________________________________
MediaWiki-l mailing list -- mediawiki-l@lists.wikimedia.org
To unsubscribe send an email to mediawiki-l-leave@lists.wikimedia.org
https://lists.wikimedia.org/postorius/lists/mediawiki-l.lists.wikimedia.org/
Re: array syntax [ In reply to ]
Hi Jeffrey,

"NS_FILE" was introduced to replace "NS_IMAGE" in MediaWiki 1.14, which
was released in 2009, fourteen years ago.

--
Bartosz Dziewo?ski
_______________________________________________
MediaWiki-l mailing list -- mediawiki-l@lists.wikimedia.org
To unsubscribe send an email to mediawiki-l-leave@lists.wikimedia.org
https://lists.wikimedia.org/postorius/lists/mediawiki-l.lists.wikimedia.org/
Re: array syntax [ In reply to ]
On Tue, Feb 14, 2023 at 3:30 PM Bartosz Dziewo?ski <matma.rex@gmail.com> wrote:
>
> "NS_FILE" was introduced to replace "NS_IMAGE" in MediaWiki 1.14, which
> was released in 2009, fourteen years ago.

And in 14 years, Mediawiki has never warned users about it.

The first time we learn about these things in practice is when
something breaks. Usually after an upgrade.

The devs really need to supply a linter that we can run on
LocalSettings.php so we can discover the problems earlier than "it
broke after an upgrade." And hopefully the linter will suggest the
next step, like renaming NS_IMAGE to NS_FILE.

Jeff
_______________________________________________
MediaWiki-l mailing list -- mediawiki-l@lists.wikimedia.org
To unsubscribe send an email to mediawiki-l-leave@lists.wikimedia.org
https://lists.wikimedia.org/postorius/lists/mediawiki-l.lists.wikimedia.org/
Re: array syntax [ In reply to ]
That actually wouldn’t be a bad idea to create some kind of app on the
wmflabs that parses/updates LocalSettings.php configs and outputs the
modern standards.

On Tue, Feb 14, 2023 at 5:36 PM Jeffrey Walton <noloader@gmail.com> wrote:

> On Tue, Feb 14, 2023 at 3:30 PM Bartosz Dziewo?ski <matma.rex@gmail.com>
> wrote:
> >
> > "NS_FILE" was introduced to replace "NS_IMAGE" in MediaWiki 1.14, which
> > was released in 2009, fourteen years ago.
>
> And in 14 years, Mediawiki has never warned users about it.
>
> The first time we learn about these things in practice is when
> something breaks. Usually after an upgrade.
>
> The devs really need to supply a linter that we can run on
> LocalSettings.php so we can discover the problems earlier than "it
> broke after an upgrade." And hopefully the linter will suggest the
> next step, like renaming NS_IMAGE to NS_FILE.
>
> Jeff
> _______________________________________________
> MediaWiki-l mailing list -- mediawiki-l@lists.wikimedia.org
> To unsubscribe send an email to mediawiki-l-leave@lists.wikimedia.org
>
> https://lists.wikimedia.org/postorius/lists/mediawiki-l.lists.wikimedia.org/
Re: array syntax [ In reply to ]
> The solution is to just replace all occurrences of NS_IMAGE with NS_FILE
> (and NS_IMAGE_TALK with NS_FILE_TALK).

That fixed it! Thank you! /maintenance/update.php now runs in PHP 8.1
without error. Very glad to have this fixed. Thank you!

> (Congrats on running MediaWiki for long enough that your configuration
> still used NS_IMAGE ;) )

Very kind of you to say that. Thank you!

Roger
Teflpedia.com MW1.39.1

On Tue, Feb 14, 2023 at 2:36 PM Jeffrey Walton <noloader@gmail.com> wrote:

> On Tue, Feb 14, 2023 at 3:30 PM Bartosz Dziewo?ski <matma.rex@gmail.com>
> wrote:
> >
> > "NS_FILE" was introduced to replace "NS_IMAGE" in MediaWiki 1.14, which
> > was released in 2009, fourteen years ago.
>
> And in 14 years, Mediawiki has never warned users about it.
>
> The first time we learn about these things in practice is when
> something breaks. Usually after an upgrade.
>
> The devs really need to supply a linter that we can run on
> LocalSettings.php so we can discover the problems earlier than "it
> broke after an upgrade." And hopefully the linter will suggest the
> next step, like renaming NS_IMAGE to NS_FILE.
>
> Jeff
> _______________________________________________
> MediaWiki-l mailing list -- mediawiki-l@lists.wikimedia.org
> To unsubscribe send an email to mediawiki-l-leave@lists.wikimedia.org
>
> https://lists.wikimedia.org/postorius/lists/mediawiki-l.lists.wikimedia.org/
Re: array syntax [ In reply to ]
There actually sort of is work on that, however the current version
wouldn't detect constants.

--
Brian

On Tuesday, February 14, 2023, Jeffrey Walton <noloader@gmail.com> wrote:

> On Tue, Feb 14, 2023 at 3:30 PM Bartosz Dziewo?ski <matma.rex@gmail.com>
> wrote:
> >
> > "NS_FILE" was introduced to replace "NS_IMAGE" in MediaWiki 1.14, which
> > was released in 2009, fourteen years ago.
>
> And in 14 years, Mediawiki has never warned users about it.
>
> The first time we learn about these things in practice is when
> something breaks. Usually after an upgrade.
>
> The devs really need to supply a linter that we can run on
> LocalSettings.php so we can discover the problems earlier than "it
> broke after an upgrade." And hopefully the linter will suggest the
> next step, like renaming NS_IMAGE to NS_FILE.
>
> Jeff
> _______________________________________________
> MediaWiki-l mailing list -- mediawiki-l@lists.wikimedia.org
> To unsubscribe send an email to mediawiki-l-leave@lists.wikimedia.org
> https://lists.wikimedia.org/postorius/lists/mediawiki-l.
> lists.wikimedia.org/