Download the PHP package mediawiki/parser-hooks without Composer

On this page you can find all versions of the php package mediawiki/parser-hooks. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package parser-hooks

ParserHooks

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.

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:

Where $extraAwesomeHookDefinition is a variation of $awesomeHookDefinition.

Parser functions and tag hooks

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

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

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)

2.0.0 (2026-05-10)

1.6.1 (2020-01-14)

1.6 (2019-07-14)

1.5 (2016-03-05)

1.4 (2014-07-05)

1.3 (2014-06-25)

1.2.1 (2013-11-22)

1.2 (2013-09-30)

1.1 (2013-09-25)

You can read the release blog post

1.0.1 (2013-09-22)

1.0 (2013-07-14)

Links


All versions of parser-hooks with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
param-processor/param-processor Version ^1.12
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package mediawiki/parser-hooks contains the following files

Loading the files please wait ...