简单的 MediaWiki 扩展调试
我正在尝试编写我的第一个 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
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!
将这些添加到
LocalSettings.php
进行调试:您可以使用
wfDebug();
记录调试消息https://www.mediawiki.org/wiki/Manual:Structured_logging/en
Add these to
LocalSettings.php
for debugging:You can log debug messages with
wfDebug();
Learn more at https://www.mediawiki.org/wiki/Manual:Structured_logging/en