PHP Notice: Use of undefined constant CT_MODE_PAGES - assumed 'CT_MODE_PAGES' since MW 1.28+
Open, Needs TriagePublic

Description

Under MW 1.27 and earlier, the extension works like a charm, when upgrading to MW 1.28:

MediaWiki1.28.0
PHP7.0.13 (apache2handler)
MariaDB10.1.19-MariaDB
ICU58.1
  • Special:Category tree: interface changed and there is a message at the bottom 'Category ⧼rootcategory⧽ not found'. It was not there in 1.27
  • there was message PHP Notice: Use of undefined constant CT_MODE_PAGES - assumed 'CT_MODE_PAGES' already during running of update it script. It refers to the definition $wgCategoryTreeMaxDepth = array(CT_MODE_PAGES => 3); in LocalSettings.php. as advised in mw:Extension:CategoryTree#Configuration. It was not there in 1.27.
  • Downgrade to the version of extension generated for 1.27:
  • Special:Category tree: Interface is to previous version.
    • Category field is prefilled with ⧼rootcategory⧽, it was not there before.
  • <categorytree mode=pages depth=3>Contents</categorytree> works fine under 1.27, under 1.28 it does not show the pages.

Event Timeline

Ciencia_Al_Poder subscribed.

Constants are defined in CategoryTree.php, but they aren't available in LocalSettings.php, even using them after wfLoadExtension( 'CategoryTree' );

This looks like a limitation in extension registration system. Or at least I wasn't able to find how to do this in the schema documentation (thus adding MediaWiki-Configuration project)

In ExtensionRegistry.php I see there's this code:

		foreach ( $info['defines'] as $name => $val ) {
			define( $name, $val );
		}

Maybe defining them in extension.json inside a "defines" section may work, but it's undocumented at best

It looks like they're not going to support constants at all, and this configuration should be changed to use string keys like $wgCategoryTreeMaxDepth = [ 'pages' => 2, 'all' => 2, 'categories' => 3 ];

freephile renamed this task from PHP Notice: Use of undefined constant CT_MODE_PAGES - assumed 'CT_MODE_PAGES' under MW 1.28 to PHP Notice: Use of undefined constant CT_MODE_PAGES - assumed 'CT_MODE_PAGES' since MW 1.28+.Dec 27 2018, 7:49 PM

@freephile: Which most recent version did you test, as you edited the summary to state that it's 1.28+?

I've observed this in 1.28 (I think 1.29) 1.30 1.31.

In ExtensionRegistry.php I see there's this code:

		foreach ( $info['defines'] as $name => $val ) {
			define( $name, $val );
		}

Maybe defining them in extension.json inside a "defines" section may work, but it's undocumented at best

I tried this approach in 1.31 and it didn't appear to change the result (still getting warnings). I believe somebody else said that it's because the code is evaluated too late to be available in LocalSettings.php

It looks like they're not going to support constants at all, and this configuration should be changed to use string keys like $wgCategoryTreeMaxDepth = [ 'pages' => 2, 'all' => 2, 'categories' => 3 ];

This is sort of correct. The documentation of the extension desperately needs updating to reflect this. The new values can be seen in https://gerrit.wikimedia.org/r/#/c/mediawiki/extensions/CategoryTree/+/268624/

$wgCategoryTreeMaxDepth = [ 10 => 2, 20 => 2, 0 => 3 ];

There is also discussion how these probably should be changed to strings instead of vague numbers: https://gerrit.wikimedia.org/r/#/c/mediawiki/extensions/CategoryTree/+/293318/

Was part of T87888: Convert CategoryTree to use extension registration

Change #1319143 had a related patch set uploaded (by TheDJ; author: TheDJ):

[mediawiki/extensions/CategoryTree@master] Log deprecation warnings for numeric CategoryTree constant values

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

Change #293318 merged by jenkins-bot:

[mediawiki/extensions/CategoryTree@master] Use strings for constants values

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

Documentation needs updating
Config of wmf needs updating,
Deprecation warning patch can then be merged.

Change #1319945 had a related patch set uploaded (by TheDJ; author: TheDJ):

[operations/mediawiki-config@master] wgCategoryTreeCategoryPageMode: use the new values

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