Topic on Extension talk:SyntaxHighlight

Setting $wgSyntaxHighlightModels

7
Peculiar Investor (talkcontribs)

On my CentOS Stream release 8 testing environment with PHP 7.4.15 (cli) I made the suggested configuration of $wgSyntaxHighlightModels[CONTENT_MODEL_SCRIBUNTO] = 'lua'; in my LocalSettings.php.

Then I ran php maintenance/update.phpand I get the error message:

PHP Warning:  Use of undefined constant CONTENT_MODEL_SCRIBUNTO - assumed 'CONTENT_MODEL_SCRIBUNTO' (this will throw an Error in a future version of PHP) in /var/www/html/w/LocalSettings.php

My edit to update the article with the address the PHP Warning was reverted, per this revision.

Which is correct, the PHP Warning or the revision?

Tacsipacsi (talkcontribs)

Both. Pppery is right that the solution is not to replace it with a string, but PHP’s also right that you shouldn’t use an undefined constant in the first place. However, PHP’s assumption of what this constant should be is wrong (which is not surprising, since it’s just an assumption)—probably it should be the integer 828. Have you Extension:Scribunto installed at all? Without that, configuring syntax highlight for Scribunto modules makes no sense.

Peculiar Investor (talkcontribs)

@Tacsipacsi @Pppery Yes Extension:Scribunto is installed and working on MediaWiki 1.35.1. I'm trying to get Syntax Highlighting functioning properly. The Installation and Configuration sections, plus the Talk pages give lots of helpful information but there still seems to be some dark arts to getting everything working. It doesn't help when the maintenance/update.php script throws a PHP Warning when following the configuration information for the extension.

Tacsipacsi (talkcontribs)

Then maybe you load things in the wrong order? LocalSettings.php is executed from top to bottom, so Scribunto should have already been loaded at the point you want to use its constant.

This won’t work:

wfLoadExtension( 'SyntaxHighlight_GeSHi' );
$wgSyntaxHighlightModels[CONTENT_MODEL_SCRIBUNTO] = 'lua';

// ...

wfLoadExtension( 'Scribunto' );

But this should:

wfLoadExtension( 'Scribunto' );

// ...

wfLoadExtension( 'SyntaxHighlight_GeSHi' );
$wgSyntaxHighlightModels[CONTENT_MODEL_SCRIBUNTO] = 'lua';
Peculiar Investor (talkcontribs)

@Tacsipacsi Per you suggestion I did change the order in LocalSettings.php. The PHP Warning message still appears however. My LocalSettings.php contains the following snippet:

wfLoadExtension( 'Scribunto' );

$wgScribuntoDefaultEngine = 'luastandalone';
// For a more pleasant user interface, with syntax highlighting and a code editor with autoindent
$wgScribuntoUseGeSHi = true;
$wgScribuntoUseCodeEditor = true;

wfLoadExtension( 'SyntaxHighlight_GeSHi' );
$wgSyntaxHighlightModels[CONTENT_MODEL_SCRIBUNTO] = 'lua';

FWIW Lua modules are working and <syntaxhighlight> tags are also working on the wiki.

Tacsipacsi (talkcontribs)

Have you cleared your browser cache, restarted the web server etc.? You might even try to intentionally cause another warning in LocalSettings.php to make sure it’s not just stuck in the cache. If it isn’t a cache issue, then I have no idea why it doesn’t work. By the way, guessing from the name, $wgScribuntoUseGeSHi should enable syntax highlighting on its own, without the line causing the warning. Doesn’t that work?

Peculiar Investor (talkcontribs)

I can confirm that using $wgScribuntoUseGeSHi = true; does work without also having $wgSyntaxHighlightModels[CONTENT_MODEL_SCRIBUNTO] = 'lua';. Perhaps the configuration section should clarify how the two settings interact or which one to set.

As a testcase I commented out $wgScribuntoUseGeSHi = true; and then added $wgSyntaxHighlightModels[CONTENT_MODEL_SCRIBUNTO] = 'lua'; and I still get the PHP Warning.

I've checked and my extensions are up-to-date 1.35 versions. So the mystery remains as to what's causing the PHP Warning.

Reply to "Setting $wgSyntaxHighlightModels"