前兩周同事開始對阿裡雲服務器上的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中搜索。