前两周同事开始对阿里云服务器上的PHP 5升级为PHP 7,遇到的问题以及解决办法我记录在《PHP5.x升级到PHP7.x后Drupal网站出现的问题》一文中,本周对MediaWiki所在服务器要进行升级,所以先进行了一些测试,把Wiki站文件复制到已经升级为PHP 7.3.5的服务器上,马上看到了一堆报错,逐个去检查、搜索、修改以致全部解决,下面也来进行一些记录。
首先在MediaWiki官方网站上找到MediaWiki各个版本对PHP的要求,我们目前的MediaWiki 1.27支持PHP 5.5.9+, 5.6.x, 7.0.x, 7.1.x,并没有说支持7.2.x或者7.3.x,更多的第三方开发的扩展程序编写时间更老、版本更新不及时,估计对PHP的兼容性也更差,程序总是需要修改的,所以我们干脆就把MediaWiki 1.27直接放在安装好PHP 7.3.5的服务器上。一些错误如下:
1.27核心程序的报错:
- LocalisationCache.php报错:这里找到解决办法,修改mediawiki/core / includes/cache/localisation/LocalisationCache.php文件;
还有很多类似这样的报错:
Warning: Parameter 1 to setupMetaDescriptionTagParserHooks() expected to be a reference, value given in includes/Hooks.php on line 195
Warning: Parameter 1 to SyntaxHighlight_GeSHi::onParserFirstCallInit() expected to be a reference, value given in includes/Hooks.php on line 195
Warning: Parameter 1 to PdfHandler::registerWarningModule() expected to be a reference, value given in includes/Hooks.php on line 195
Warning: Parameter 1 to InputBoxHooks::register() expected to be a reference, value given in includes/Hooks.php on line 195
Warning: Parameter 1 to ImageMap::onParserFirstCallInit() expected to be a reference, value given in includes/Hooks.php on line 195
Warning: Parameter 1 to GoogleRichCards() expected to be a reference, value given in includes/Hooks.php on line 195
Warning: Parameter 1 to GadgetHooks::registerModules() expected to be a reference, value given in includes/Hooks.php on line 195
Warning: Parameter 1 to ExtVariables::onParserClearState() expected to be a reference, value given in includes/Hooks.php on line 195
Warning: Parameter 1 to ExtVariables::onInternalParseBeforeSanitize() expected to be a reference, value given in includes/Hooks.php on line 195
Warning: Parameter 1 to ExtVariables::init() expected to be a reference, value given in includes/Hooks.php on line 195
Warning: Parameter 1 to ExtLoops::onParserClearState() expected to be a reference, value given in includes/Hooks.php on line 195
Warning: Parameter 1 to ExtLoops::init() expected to be a reference, value given in includes/Hooks.php on line 195
查看Hooks.php文件195行也没有什么特别,在Google中搜索“Warning: Parameter 1 to expected to be a reference, value given in Hooks.php on line 195”,都是说需要修改对应的第三方扩展中的public static function函数定义写法,将&$this替换为$this,涉及到下面一些内容:
1.27发行版本带的扩展程序的报错:
- ConfirmEdit/includes/ConfirmEditHooks.php
- Gadgets/GadgetHooks.php
- ImageMap/ImageMap_body.php
- InputBox/InputBox.hooks.php
- ParserFunctions/ParserFunctions.hooks.php
- PdfHandler/PdfHandler_body.php
- SyntaxHighlight_GeSHi/SyntaxHighlight_GeSHi.class.php
我们自行下载安装的扩展程序的报错:
- GoogleRichCards/GoogleRichCards.php
- Loops/Loops.php
- MetaDescriptionTag/MetaDescriptionTag.php
- Variables/Variables.php
- Include/Include.php
- Memcached/Memcached.php (修改办法稍微有点不一样,来源:https://www.mediawiki.org/wiki/Extension_talk:Memcached )
我们自己开发的扩展中的报错:
- ZhConvert/ZhConvert.php
这个过程还在进行中,后面发现新的问题会及时更新本文。
其它的错误:
Deprecated: The each() function is deprecated. This message will be suppressed on further calls in mediawiki_code-1.27.0/includes/MagicWordArray.php on line 197
修改includes/MagicWordArray.php on line 197
//jamesqi 2019-6-19 while (list( $key, $value ) = each( $m ) ) { foreach ( $m as $key => $value ) {
再有这样的报错:
Deprecated: assert(): Calling assert() with a string argument is deprecated in mediawiki_code-1.27.0/includes/parser/Preprocessor_DOM.phpon line 542
修改includes/parser/Preprocessor_DOM.phpon line 542
// A heading must be open, otherwise \n wouldn't have been in the search list //jamesqi 2019-6-19//assert( '$piece->open == "\n"' ); $piece->open == "\n"; $part = $piece->getCurrentPart();
再一个报错:
Warning: session_id(): Cannot change session id when session is active in mediawiki_code-1.27.0/includes/Setup.php on line 773
暂未解决
2019-6-18补充:还可以在程序中添加:error_reporting(E_ALL ^ E_DEPRECATED); 来让这种报错不显示,或者在php.ini里面设置error_reporting = E_ALL &~E_NOTICE &~E_DEPRECATED。
评论4
wiki那边也会遇到报错:PHP Notice: A
wiki那边也会遇到报错:PHP Notice: A non well formed numeric value encountered in /mnt/gb/htdocs/mediawiki_code-1.27.0/vendor/cssjanus/cssjanus/src/CSSJanus.php on line 421PHP 报错 session_id():
登录用户还有这个问题:PHP Warning: session_id(): Cannot change session id when session is active in /mnt/gb/htdocs/mediawiki_code-1.27.0/includes/Setup.php on line 773 网上搜索到的修改办法: https://gerrit.wikimedia.org/r/#/c/mediawiki/core/+/484687/1/includes/Setup.php请问mediawiki添加统计代码应该放在哪个文件里
请问mediawiki添加统计代码应该放在哪个文件里?网页和手机版都想统计的到。你好!我的统计代码是放在LocalSettings
你好!我的统计代码是放在LocalSettings.php里面的,这个里面对电脑版、手机版进行判断,然后用$wgOut->addHeadItem的办法来在网页head部分加入统计代码,$wgOut的用法可以去MediaWiki的官方网站查找或者在Google中搜索。