Page MenuHomePhabricator

PHP Notice: Undefined offset: 1 in LocalisationCache.php on line 579
Closed, ResolvedPublicBUG REPORT

Description

Setup

  • Product Version
  • MediaWiki 1.39.5 (dc07ba7) 13:33, 17 October 2023
  • PHP 7.4.33 (apache2handler)
  • MariaDB 10.5.21-MariaDB-0+deb11u1

Issue
When running maintenance scripts, e.g., "updateSpecialPages.php" I get the following notices:

2023-10-17 15:44:36 myserver 0212020151020-mw_: [e8972b875f071ad74fb7d12d] /   PHP Notice: Undefined offset: 1
#0 /../w/includes/language/LocalisationCache.php(579): MWExceptionHandler::handleError()
#1 /../w/includes/language/LocalisationCache.php(453): LocalisationCache->initLanguage()
#2 /../w/includes/language/LocalisationCache.php(352): LocalisationCache->loadSubitem()
#3 /../w/includes/language/LocalisationCache.php(368): LocalisationCache->getSubitem()
#4 /../w/includes/language/MessageCache.php(1147): LocalisationCache->getSubitemWithSource()
#5 /../w/includes/language/MessageCache.php(1097): MessageCache->getMessageForLang()
#6 /../w/includes/language/MessageCache.php(1039): MessageCache->getMessageFromFallbackChain()
#7 /../w/includes/language/Message.php(1473): MessageCache->get()
#8 /../w/includes/language/Message.php(970): Message->fetchMessage()
#9 /../w/includes/language/Message.php(1053): Message->format()
#10 /../w/includes/title/MalformedTitleException.php(55): Message->text()
#11 /../w/includes/title/MediaWikiTitleCodec.php(92): MalformedTitleException->__construct()
#12 /../w/includes/title/MediaWikiTitleCodec.php(405): MediaWikiTitleCodec::{closure}()
#13 /../w/includes/Title.php(2982): MediaWikiTitleCodec->splitTitleString()
#14 /../w/includes/Title.php(480): Title->secureAndSplit()
#15 /../w/includes/MediaWiki.php(89): Title::newFromURL()
#16 /../w/includes/MediaWiki.php(162): MediaWiki->parseTitle()
#17 /../w/includes/MediaWiki.php(860): MediaWiki->getTitle()
#18 /../w/includes/MediaWiki.php(562): MediaWiki->main()
#19 /../w/index.php(50): MediaWiki->run()
#20 /../w/index.php(46): wfIndexMain()
#21 {main}
2023-10-17 15:44:37 myserver 0212020151020-mw_: [e83e313edf7d24bf1c3a528f] /Widgets_Catalog   PHP Notice: Undefined offset: 1
#0 /../w/includes/language/LocalisationCache.php(579): MWExceptionHandler::handleError()
#1 /../w/includes/language/LocalisationCache.php(410): LocalisationCache->initLanguage()
#2 /../w/includes/language/LocalisationCache.php(330): LocalisationCache->loadItem()
#3 /../w/includes/language/Language.php(626): LocalisationCache->getItem()
#4 /../w/includes/title/MediaWikiTitleCodec.php(119): Language->needsGenderDistinction()
#5 /../w/includes/Title.php(1178): MediaWikiTitleCodec->getNamespaceName()
#6 /../w/includes/page/Article.php(472): Title->getNsText()
#7 /../w/includes/actions/ViewAction.php(78): Article->view()
#8 /../w/includes/MediaWiki.php(542): ViewAction->show()
#9 /../w/includes/MediaWiki.php(322): MediaWiki->performAction()
#10 /../w/includes/MediaWiki.php(904): MediaWiki->performRequest()
#11 /../w/includes/MediaWiki.php(562): MediaWiki->main()
#12 /../w/index.php(50): MediaWiki->run()
#13 /../w/index.php(46): wfIndexMain()
#14 {main}

This started recently and this is not the only wiki with the issue.

Event Timeline

Aklapper added a subscriber: Func.

@Kghbln: Thanks for reporting this. For future reference, please use the bug report form (linked from the top of the task creation page) to create a bug report. Thanks.

That code area was changed a few days ago by rMW06d96fbefc40a5fb8a2efdb0d6af7ea4c1b7bc9d as part of T229992; CC'ing the author

Aklapper changed the subtype of this task from "Task" to "Bug Report".Oct 17 2023, 4:11 PM

Is this issue persistent?
I bumped the cache version in that commit, the old cache should have been replaced before causing any issues.

By the way, the backport of my follow-up change also can not pass some tests on 1.39, so there may be something wrong with parts that I didn't touch.

We may need to revert the backport if the issue persists.

Is this issue persistent?

Yes, it is. I also rebuilt the localization cache with "rebuildLocalisationCache.php" but this did not change the situation either.

Was "rebuildLocalisationCache.php" running for a specific language or all? If only run for one language, all fallback languages for the content language (including en) must be rebuilded as well.

Always do a db-backup before this: In case of using the database for caching it should also work to truncate l10n_cache. When using $wgLocalisationCacheConf['manualRecache'] = true; it could be problematic to get the cache back, so it maybe needs a false after the truncation or the rebuild maintenance script.


The offset 1 is missing after the explode in this code snippet:

571			foreach ( self::$sourcePrefixKeys as $key ) {
572				if ( !isset( $preload[$key] ) ) {
573					continue;
574				}
575				foreach ( $preload[$key] as $subkey => $value ) {
576					[
577						$this->sourceLanguage[$code][$key][$subkey],
578						$preload[$key][$subkey]
579					] = explode( self::SOURCEPREFIX_SEPARATOR, $value, 2 );
580				}
581			}
582

Maybe it is safe to skip the $value without the separator to be sure that offset are set. Or defining a valid fallback

Was "rebuildLocalisationCache.php" running for a specific language or all?

It was done for all languages.

PS Thanks for your additional information.

I suggest to revert the change. This issue is spamming my logs day by day.

I also observe this error on 1.40.1. I’m not completely sure, but it seems to appear when the (default?) skin in not Vector ($wgDefaultSkin = 'chameleon'; in my case), I had these notices for only 3 message keys vector-view-(view|edit|history) whose the value is NULL in the $preload array.

How we ended in this error message?

  1. It can be remarked that these 3 message keys are declared in MessagesEn.php array $preloadedMessages.
  2. In LocalisationCache::buildPreload, the preloadedMessages keys are put in $preload['messages'] if defined, else null is put
  3. In LocalisationCache::initLanguage, it is assumed that $preload['messages'][$subkey] is a string: it is very often one, but there might be null values too

As a side note, in LocalisationCache::loadSubitem, there is a check that the value is not null before explode()-ing it.

I also observe this error on 1.40.1. I’m not completely sure, but it seems to appear when the (default?) skin in not Vector

Interesting observation. In my case, no Vector is involved either. Foreground, Pivot, and Timeless are at play on my end.

Change 973202 had a related patch set uploaded (by Seb35; author: Seb35):

[mediawiki/core@master] LocalisationCache: Fix a rare case in fallback source language

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

Change 973202 merged by jenkins-bot:

[mediawiki/core@master] LocalisationCache: Fix a rare case in fallback source language

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

Change 977160 had a related patch set uploaded (by Func; author: Seb35):

[mediawiki/core@REL1_41] LocalisationCache: Fix a rare case in fallback source language

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

Change 977161 had a related patch set uploaded (by Func; author: Seb35):

[mediawiki/core@REL1_40] LocalisationCache: Fix a rare case in fallback source language

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

Change 977162 had a related patch set uploaded (by Func; author: Seb35):

[mediawiki/core@REL1_39] LocalisationCache: Fix a rare case in fallback source language

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

Change 977160 merged by jenkins-bot:

[mediawiki/core@REL1_41] LocalisationCache: Fix a rare case in fallback source language

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

Change 977162 merged by jenkins-bot:

[mediawiki/core@REL1_39] LocalisationCache: Fix a rare case in fallback source language

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

Change 977161 merged by jenkins-bot:

[mediawiki/core@REL1_40] LocalisationCache: Fix a rare case in fallback source language

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

Thanks a lot for fixing the issue. My wiki logs are silent now.