简单的 MediaWiki 扩展调试

发布于 2025-01-07 13:44:36 字数 865 浏览 2 评论 0原文

我正在尝试编写我的第一个 MediaWiki 扩展,并且需要某种方法来调试它。最简单的方法是什么?显示消息、登录文件等就可以了。我只是想慢慢地浏览代码,看看它在哪里中断以及变量的内容是什么。

我已经尝试过(来自 http://www.mediawiki.org/wiki/Manual:How_to_debug #Useful_debugging_functions)

// ...somewhere in your code
if ( true ) {
    wfDebugLog( 'myext', 'Something is not right: ' . print_r( 'asdf', true ) );
}

在 extensions/myext/myext.php 中并添加到 LocalSettings.php

require_once( 'extensions/myext/myext.php' );
# debugging on
$wgDebugLogGroups = array(
     'myext'     => 'extensions/myext/myextension.log'
);

但随后我的 Wiki 根本无法工作(错误500)。从 myext.php 中删除上述代码后,一切都很好(在 myext.php 中使用 $wgExtensionCredits,我可以在 Special:Version 中看到 myext)。

这是正确的做法(那么错误是什么)还是有更好/更简单的方法来开始?

I am trying to write my very first MediaWiki extension and need some way to debug it. What is the simplest way to do it? Showing a message, logging into a file etc. would be fine. I just want to slowly progress over the code and see where it breaks and what the content of a variable is.

I've tried (from http://www.mediawiki.org/wiki/Manual:How_to_debug#Useful_debugging_functions)

// ...somewhere in your code
if ( true ) {
    wfDebugLog( 'myext', 'Something is not right: ' . print_r( 'asdf', true ) );
}

in extensions/myext/myext.php and added to LocalSettings.php

require_once( 'extensions/myext/myext.php' );
# debugging on
$wgDebugLogGroups = array(
     'myext'     => 'extensions/myext/myextension.log'
);

but then my Wiki doesn't work at all (error 500). With the above code removed from myext.php everything's fine (with $wgExtensionCredits in myext.php, I can see myext in the Special:Version).

Is it the right thing to do (then what is the mistake) or is there a better/simpler way to start with?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

初见终念 2025-01-14 13:44:36

500 表示您在某处有语法错误或配置错误。您是否按照手册:如何调试中的说明操作并打开了 PHP 日志记录,以便您至少可以看到是什么导致了错误?或者,查看您的 Apache 服务器日志。

另外,您需要在加载自己的扩展之前打开调试!

500 means you have a syntax error or wrong configuration somewhere. Have you followed the instructions at Manual:How to debug and turned on PHP logging, so you can at least see what is causing the error? Alternatively, take a look at your Apache server log.

Also, you'll want to turn on debugging before you load your own extension!

电影里的梦 2025-01-14 13:44:36

将这些添加到 LocalSettings.php 进行调试:

error_reporting( -1 );
ini_set( 'display_startup_errors', 1 );
ini_set( 'display_errors', 1 );

$wgShowExceptionDetails=true;
$wgDebugToolbar=true;
$wgShowDebug=true;
$wgDevelopmentWarnings=true;
$wgDebugDumpSql = true;
$wgDebugLogFile = '/tmp/debug.log';
$wgDebugComments = true;
$wgEnableParserCache = false;
$wgCachePages = false;

您可以使用 wfDebug(); 记录调试消息

https://www.mediawiki.org/wiki/Manual:Structured_logging/en

Add these to LocalSettings.php for debugging:

error_reporting( -1 );
ini_set( 'display_startup_errors', 1 );
ini_set( 'display_errors', 1 );

$wgShowExceptionDetails=true;
$wgDebugToolbar=true;
$wgShowDebug=true;
$wgDevelopmentWarnings=true;
$wgDebugDumpSql = true;
$wgDebugLogFile = '/tmp/debug.log';
$wgDebugComments = true;
$wgEnableParserCache = false;
$wgCachePages = false;

You can log debug messages with wfDebug();

Learn more at https://www.mediawiki.org/wiki/Manual:Structured_logging/en

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文