mediawiki/parser-hooks 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mediawiki/parser-hooks

Composer 安装命令:

composer require mediawiki/parser-hooks

包简介

OOP and declarative parser hook interface on top of MediaWiki

README 文档

README

GitHub Workflow Status Latest Stable Version Download count

OOP interface for creating MediaWiki parser hooks in a declarative fashion.

This is a PHP library for MediaWiki extensions. It does not in itself add or enhance functionality of your wiki.

Platform compatibility and release status

The PHP and MediaWiki version ranges listed are those in which ParserHooks is known to work. It might also work with more recent versions of PHP and MediaWiki, though this is not guaranteed. Increases of minimum requirements are indicated in bold. For a detailed list of changes, see the release notes.

ParserHooks PHP MediaWiki Release status
3.0.x 8.1 - 8.5 1.43 - 1.45 Stable release
2.0.x 8.1 - 8.4 1.43 - 1.45 Superseded by 3.0
1.6.x 7.2 - 8.3 1.31 - 1.43 Bugfixes only
1.5.x 5.3 - 7.1 1.16 - 1.30 Obsolete release, no support
1.0.x - 1.4.x 5.3 - 5.6 1.16 - 1.23 Obsolete release, no support

Installation

ParserHooks is a PHP library distributed via Composer. Add a dependency on mediawiki/parser-hooks to your project's composer.json:

{
    "require": {
        "mediawiki/parser-hooks": "~3.0"
    }
}

No LocalSettings.php change is required. ParserHooks no longer ships extension.json and is not registered as a MediaWiki extension; the classes are autoloaded by Composer.

Usage

All classes are located in the ParserHooks namespace, which is PSR-4 mapped onto the src/ directory.

General concept

The declarative OOP interface provided by this library allows you to define the signatures of your parser hooks and the handlers for them separately. The library makes use of the parameters specified in this definition to do parameter processing via the ParamProcessor library. This means that the handler you write for your parser function will not need to care about what the name of the parser function is, or how the parameters for it should be processed. It has a "sizes" parameter that takes an array of positive integers? Your handler will always get an actual PHP array of integer without needing to do any parsing, validation, defaulting, etc.

HookDefinition

An instance of the HookDefinition class represents the signature of a parser hook. It defines the name of the parser hook and the parameters (including their types, default values, etc) it accepts. It does not define any behaviour, and is thus purely declarative. Instances of this class are used in handling of actual parser hooks, though can also be used in other contexts. For instance, you can feed these definitions to a tool that generates parser hook documentation based on them.

The parameter definitions are ParamProcessor\ParamDefinition objects. See the ParamProcessor documentation on how to specify these.

HookHandler

The actual behaviour for your parser hook is implemented in an implementation of HookHandler. These implementations have a handle method which gets a Parser and a ParamProcssor\ProcessingResult, which is supposed to return a string.

Knitting it all together

This library also provides two additional classes, FunctionRunner, and HookRegistrant. The former takes care of invoking the ParamProcessor library based on a HookDefinition. The later takes care of registering the parser hooks defined by your HookDefinition objects to a MediaWiki Parser object.

$awesomeHookDefinition = new HookDefinition( 'awesome', [ /* ... */ ] );
$anotherHookDefinition = new HookDefinition( 'another', [ /* ... */ ] );

$awesomeHookHandler = new AwesomeHookHandler( /* ... */ );
$anotherHookHandler = new AnotherHookHandler( /* ... */ );

$hookRegistrant = new HookRegistrant( $mediaWikiParser );

$hookRegistrant->registerFunctionHandler( $awesomeHookDefinition, $awesomeHookHandler );
$hookRegistrant->registerFunctionHandler( $anotherHookDefinition, $anotherHookHandler );

If you want to have the same hook, but with other default behaviour, you can avoid any kind of duplication by doing something as follows on top of the above code:

$hookRegistrant->registerFunctionHandler( $extraAwesomeHookDefinition, $awesomeHookHandler );

Where $extraAwesomeHookDefinition is a variation of $awesomeHookDefinition.

Parser functions and tag hooks

To register a parser function, use HookRegistrant::registerFunctionHandler.

$hookRegistrant->registerFunctionHandler( $awesomeHookDefinition, $awesomeHookHandler );

To register a tag hook, use HookRegistrant::registerHookHandler.

$hookRegistrant->registerHookHandler( $awesomeHookDefinition, $awesomeHookHandler );

Both functions take the exact same arguments, so once you created a HookDefinition and a HookHandler, you can have them registered as both parser function and tag hook with no extra work.

Tests

This library comes with a set of PHPUnit tests that cover all non-trivial code. The tests are run on every push and pull request via GitHub Actions.

The tests can be run from the tests/phpunit directory of your MediaWiki installation with this command:

php tests/phpunit/phpunit.php -c extensions/ParserHooks/

Authors

ParserHooks has been written by Jeroen De Dauw as a hobby project to support the SubPageList MediaWiki extension.

Release notes

3.0.0 (2026-05-10)

  • ParserHooks is now a pure PHP library, distributed via Composer. The MediaWiki extension registration files (extension.json and i18n/) have been removed.
  • Remove wfLoadExtension( 'ParserHooks' ) from LocalSettings.php. ParserHooks classes load automatically when the package is installed via Composer.
  • ParserHooks no longer appears on Special:Version.

2.0.0 (2026-05-10)

  • Increased PHP requirement to PHP 8.1
  • Increased MediaWiki requirement to MediaWiki 1.43
  • Removed the ParserHooks.php entry point. Load the extension via wfLoadExtension( 'ParserHooks' ) instead.
  • Updated translations

1.6.1 (2020-01-14)

  • Updated translations

1.6 (2019-07-14)

  • Added support for PHP 7.2, 7.3 and 7.4
  • Added support for MediaWiki 1.31, 1.32 and 1.33
  • Dropped support for PHP 7.1 and older
  • Dropped support for MediaWiki 1.30 and older
  • Updated translations

1.5 (2016-03-05)

  • Added license now shown on Special:Version
  • Updated translations
  • Made minor style improvements
  • Ensured the extension works with PHP 7 and MediaWiki up to at least 1.27

1.4 (2014-07-05)

  • Changed the PHPUnit bootstrap so that the tests can be run via the MediaWiki test runner
  • Updated the CI configuration to test the code against multiple MediaWiki versions
  • Updated translations

1.3 (2014-06-25)

  • Updated translations
  • Changed class loading to PSR-4
  • Updated the used Validator version to 2.x >= 2.0.4

1.2.1 (2013-11-22)

  • Updated the used Validator version from 1.0 alpha to 1.0.0.1 stable, or later

1.2 (2013-09-30)

  • Fixed parameter handling bug in FunctionRunner
  • Added system test for tag hook handling

1.1 (2013-09-25)

  • Added HookRunner and HookRegistrant::registerHook
  • Added HookRegistrant::registerFunctionHandler and HookRegistrant::registerHookHandler
  • Fixed parameter handling bug in FunctionRunner
  • Improved HookRegistrantTest

You can read the release blog post

1.0.1 (2013-09-22)

  • Improved HookDefinition documentation
  • Added extra type checking in HookDefinition
  • Added extra tests for HookDefinition
  • Added coveralls.io support
  • Added PHPUnit file whitelisting (for more accurate and faster generated coverage reports)

1.0 (2013-07-14)

Links

mediawiki/parser-hooks 适用场景与选型建议

mediawiki/parser-hooks 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 572.83k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2013 年 07 月 07 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「mediawiki」 「parserhooks」 「parser function」 「parser hook」 「tag extension」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 mediawiki/parser-hooks 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 mediawiki/parser-hooks 我们能提供哪些服务?
定制开发 / 二次开发

基于 mediawiki/parser-hooks 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 572.83k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 6
  • 点击次数: 27
  • 依赖项目数: 6
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 6
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0-or-later
  • 更新时间: 2013-07-07