Page MenuHomePhabricator

Fatal error: Uncaught Error: Undefined constant "APCOND_FR_EDITSUMMARYCOUNT" with PHP >= 8
Closed, DeclinedPublicBUG REPORT

Description

After upgrading MediaWiki to 1.37 and to FlaggedRevs – (4dec80b) 14:21, 10 October 2021, I get the following error on the wiki, making it unusable:

Fatal error: Uncaught Error: Undefined constant "APCOND_FR_EDITSUMMARYCOUNT" in /var/www/vhosts/example.com/httpdocs/extensions/FlaggedRevs/FlaggedRevsSetup.php:55 

Stack trace:
#0 /var/www/vhosts/example.com/httpdocs/extensions/FlaggedRevs/FlaggedRevsSetup.php(31): FlaggedRevsSetup->setAutopromoteConfig() 
#1 /var/www/vhosts/example.com/httpdocs/extensions/FlaggedRevs/backend/FlaggedRevsHooks.php(68): FlaggedRevsSetup->doSetup()
#2 /var/www/vhosts/example.com/httpdocs/includes/HookContainer/HookContainer.php(338): FlaggedRevsHooks::onMediaWikiServices()
#3 /var/www/vhosts/example.com/httpdocs/includes/HookContainer/HookContainer.php(137): MediaWiki\HookContainer\HookContainer->callLegacyHook()
#4 /var/www/vhosts/example.com/httpdocs/includes/HookContainer/HookRunner.php(2517): MediaWiki\HookContainer\HookContainer->run()
#5 /var/www/vhosts/example.com/httpdocs/includes/MediaWikiServices.php(268): MediaWiki\HookContainer\HookRunner->onMediaWikiServices()
#6 /var/www/vhosts/example.com/httpdocs/extensions/BootstrapComponents/src/HookRegistry.php(381): MediaWiki\MediaWikiServices::getInstance()
#7 /var/www/vhosts/example.com/httpdocs/extensions/BootstrapComponents/src/HookRegistry.php(87): BootstrapComponents\HookRegistry->registerMyConfiguration()
#8 /var/www/vhosts/example.com/httpdocs/extensions/BootstrapComponents/src/BootstrapComponents.php(90): BootstrapComponents\HookRegistry->__construct() 
#9 /var/www/vhosts/example.com/httpdocs/includes/registration/ExtensionRegistry.php(546): BootstrapComponents\BootstrapComponents::init() 
#10 /var/www/vhosts/example.com/httpdocs/includes/registration/ExtensionRegistry.php(231): ExtensionRegistry->exportExtractedData() 
#11 /var/www/vhosts/example.com/httpdocs/includes/Setup.php(168): ExtensionRegistry->loadFromQueue() 
#12 /var/www/vhosts/example.com/httpdocs/includes/WebStart.php(90): require_once('...') 
#13 /var/www/vhosts/example.com/httpdocs/index.php(44): require('...') 
#14 {main} thrown in /var/www/vhosts/example.com/httpdocs/extensions/FlaggedRevs/FlaggedRevsSetup.php on line 55

If I comment my current configuration in LocalSettings.php out OR downgrade to FlaggedRevs for 1.36 OR downgrade my PHP to 7.4 the error goes away.

#$wgFlaggedRevsAutoconfirm = [
#    'days' => 15, # days since registration
#    'edits' => 25, # total edit count
#    'spacing' => 3, # spacing of edit intervals
#    'benchmarks'    => 5, # how many edit intervals are needed?
#    'excludeLastDays' => 1, # exclude the last X days of edits from edit counts
#    'totalContentEdits' => 50, # $wgContentNamespaces edits OR...
#    'totalCheckedEdits' => 25, # ...Edits before the stable version of pages
#    'uniqueContentPages' => 5, # $wgContentNamespaces unique pages edited
#    'editComments' => 10, # how many edit comments used?
#    'email' => true, # user must be emailconfirmed?
#    'neverBlocked' => true, # Can users that were blocked be promoted?
#];
#$wgFlaggedRevsAutopromote = [
#    'days' => 30, # days since registration
#    'edits' => 50, # total edit count
#    'excludeLastDays' => 2, # exclude the last X days of edits from below edit counts
#    'benchmarks'     => 10, # number of "spread out" edits
#    'spacing' => 3, # number of days between these edits (the "spread")
#    'totalContentEdits' => 100, # edits to pages in $wgContentNamespaces
#    'totalCheckedEdits' => 50, # edits before the stable version of pages
#    'uniqueContentPages'    => 10, # unique pages in $wgContentNamespaces edited
#    'editComments' => 25, # number of manual edit summaries used
#    'userpageBytes' => 0, # size of userpage (use 0 to not require a userpage)
#    'neverBlocked' => true, # username was never blocked before?
#    'email' => true, # user must be emailconfirmed?
#    'maxRevertedEditRatio'  => 0.03, # max fraction of edits reverted via "rollback"/"undo"
#];

MediaWiki 1.36 worked with this configuration, PHP 8 and the stable FlaggedRev for 1.36 that can currently be downloaded, the same is true for MediaWiki 1.35 and the respective stable FlaggedRevs version with PHP 8.

(I'm aware MediaWiki states it does not support PHP 8 yet, I've just been using it for a long while with no observed issues)

Event Timeline

Aklapper renamed this task from Issue after upgrading MediaWiki to 1.37 and to FlaggedRevs – (4dec80b) 14:21, 10 October 2021 to Fatal error: Uncaught Error: Undefined constant "APCOND_FR_EDITSUMMARYCOUNT".Nov 23 2021, 2:38 PM
Aklapper updated the task description. (Show Details)
Aklapper updated the task description. (Show Details)
D3nnis3n updated the task description. (Show Details)

This is a PHP > 8 issue. It works fine until 7.4.

I was able to get the errors gone by editing FlaggedRevsSetup and put all constants that have more than one underscore in ' ', e.g.

'APCOND_FR_EDITSUMMARYCOUNT'

Again, I have no idea what I'm doing, but everything is working fine and autopromotions have been tested to work based on my criteria with this 'fix'. I didn't have much choice, as PHP < 8 was abandoned by my host.

D3nnis3n renamed this task from Fatal error: Uncaught Error: Undefined constant "APCOND_FR_EDITSUMMARYCOUNT" to Fatal error: Uncaught Error: Undefined constant "APCOND_FR_EDITSUMMARYCOUNT" with PHP >= 8.Jun 27 2022, 9:24 AM
Bawolff subscribed.

Can you confirm if this still happens on 1.38?

Yes, it happens on 1.38.1 without my manual changes. I haven't gotten the time to update to 1.38.2 and FlaggedRevs for that version, though.

tstarling removed projects: TestMe, PHP 8.0 support.
tstarling subscribed.

You can see what the issue is from the backtrace. BootstrapComponents is calling into MediaWikiServices from a registration callback function, which is too early. It causes the FlaggedRevs MediaWikiServices hook to be called before its registration callback function. The bug is present in the current version of BootstrapComponents\HookRegistry. There is the related issue #31 in their bug tracker — fixing that deprecation warning would also fix this error.

In PHP 7.4 an undefined constant is a warning, whereas in PHP 8.0 it is an error, so that is probably the extent of the PHP version dependence.

Closing since this is not the right place to track bugs in BootstrapComponents.

Loading FlaggedRevs before BootstrapComponents may possibly work around the issue.