User:Florianschmidtwelzow/MobileFrontend/Hooks

From mediawiki.org

The MobileFrontend Extension introduces some new hooks, but they are all undocumented. This page tries to document these hooks. Please notice: It's possible, that the Hooks will be replaced or removed in a newer version of MobileFrontend.

MobileFrontendBeforeDOM[edit]

MobileFrontendBeforeDOM
Available from version master
Use page content before it is formatted by MobileFrontend.
Define function:
public static function onMobileFrontendBeforeDOM( MobileContext $context, MobileFormatter $formatter ) { ... }
Attach hook: In extension.json:
{
	"Hooks": {
		"MobileFrontendBeforeDOM": "MediaWiki\\Extension\\MyExtension\\Hooks::onMobileFrontendBeforeDOM"
	}
}
Called from: File(s): MobileFrontend extension/MobileFrontend.body.php
Interface: MobileFrontendBeforeDOMHook.php

For more information about attaching hooks, see Manual:Hooks .
For examples of extensions using this hook, see Category:MobileFrontendBeforeDOM extensions.


Details[edit]

This hook os called before the content parsed by MobileFormatter.

Usage[edit]

Example usage in ZeroBanner[1][2]

SkinMinervaDefaultModules[edit]

SkinMinervaDefaultModules
Available from version master
Add or remove modules loaded by Minerva skin.
Define function:
public static function onSkinMinervaDefaultModules( SkinMinerva $skin, array &$modules ) { ... }
Attach hook: In extension.json:
{
	"Hooks": {
		"SkinMinervaDefaultModules": "MediaWiki\\Extension\\MyExtension\\Hooks::onSkinMinervaDefaultModules"
	}
}
Called from: File(s): MobileFrontend extension/SkinMinerva.php, MobileFrontend extension/SkinMinervaBeta.php
Interface: SkinMinervaDefaultModulesHook.php

For more information about attaching hooks, see Manual:Hooks .
For examples of extensions using this hook, see Category:SkinMinervaDefaultModules extensions.


Details[edit]

The array $modules, submitted with this hook, contains a bunch of JavaScript modules which will be loaded. You can change, remove or add modules with this hook.

Usage[edit]

To add the module test23 to MobileFrontend, you can use the following code:

// Define the module to load and add a dependency to mobile.stable
$wgResourceModules = array_merge( $wgResourceModules, array(
	'mobile.test23' => $wgMFMobileResourceBoilerplate + array(
		'dependencies' => array(
			'mobile.stable',
		),
		'scripts' => array(
			'javascripts/test23.js',
		),
		'targets' => array( 'mobile' ),
	)
) );

// Hook definition
$wgHooks['SkinMinervaDefaultModules'][] = 'onSkinMinervaDefaultModules';

// add the module to MobileFrontend
function onSkinMinervaDefaultModules( $skin, &$modules ) {
	$modules['test23'] = array( 'mobile.test23' );
}

EnableMobileModules (deprecated)[edit]

EnableMobileModules
Available from version 3b5e3c07f39ef070389a00597b996912f47cad7b
(deprecated) Allow other extensions to add modules depending on the MobileFrontend mode.
Define function:
public static function onEnableMobileModules( OutputPage $out, string $mode ) { ... }
Attach hook: In extension.json:
{
	"Hooks": {
		"EnableMobileModules": "MediaWiki\\Extension\\MyExtension\\Hooks::onEnableMobileModules"
	}
}
Called from: File(s): MobileFrontend extension/SkinMinerva.php
Interface: EnableMobileModulesHook.php

For more information about attaching hooks, see Manual:Hooks .
For examples of extensions using this hook, see Category:EnableMobileModules extensions.


Details[edit]

Notice: This Hook is depreacted and will be removed in a later version of MobileFrontend. Please use RessourceLoader to load your Module for mobile deveices.

  • $out: OutputPage
  • $mode: String, such as 'alpha', 'beta', 'stable'

BeforePageDisplayMobile[edit]

BeforePageDisplayMobile
Available from version master
Allow other extensions to use OutputPage before outputPage generates script and style tags.
Define function:
public static function onBeforePageDisplayMobile( OutputPage $out ) { ... }
Attach hook: In extension.json:
{
	"Hooks": {
		"BeforePageDisplayMobile": "MediaWiki\\Extension\\MyExtension\\Hooks::onBeforePageDisplayMobile"
	}
}
Called from: File(s): MobileFrontend extension/SkinMinerva.php
Interface: BeforePageDisplayMobileHook.php

For more information about attaching hooks, see Manual:Hooks .
For examples of extensions using this hook, see Category:BeforePageDisplayMobile extensions.


Details[edit]

  • $out: OutputPage

MinervaPreRender[edit]

MinervaPreRender
Available from version master
Called before the entire page is rendered to change the content or something else.
Define function:
public static function onMinervaPreRender( MinervaTemplate $template ) { ... }
Attach hook: In extension.json:
{
	"Hooks": {
		"MinervaPreRender": "MediaWiki\\Extension\\MyExtension\\Hooks::onMinervaPreRender"
	}
}
Called from: File(s): MobileFrontend extension/MinervaTemplate.php
Interface: MinervaPreRenderHook.php

For more information about attaching hooks, see Manual:Hooks .
For examples of extensions using this hook, see Category:MinervaPreRender extensions.


Details[edit]

  • $template: MinervaTemplate

BeforeSpecialMobileDiffDisplay[edit]

BeforeSpecialMobileDiffDisplay
Available from version master
Last chance to change content of Difference page before output
Define function:
public static function onBeforeSpecialMobileDiffDisplay( OutputPage &$output, MobileContext $ctx, array $revisions ) { ... }
Attach hook: In extension.json:
{
	"Hooks": {
		"BeforeSpecialMobileDiffDisplay": "MediaWiki\\Extension\\MyExtension\\Hooks::onBeforeSpecialMobileDiffDisplay"
	}
}
Called from: File(s): MobileFrontend extension/MinervaTemplate.php
Interface: BeforeSpecialMobileDiffDisplayHook.php

For more information about attaching hooks, see Manual:Hooks .
For examples of extensions using this hook, see Category:BeforeSpecialMobileDiffDisplay extensions.


Details[edit]

  • &$output: OutputPage
  • $ctx: MobileContext
  • $revisions: array of revisions to compare ($revisions[1] -> Revision; $revisions[0] -> previous Revision)

EnterMobileMode[edit]

follows

GetMobileUrl[edit]

follows

SpecialWatchlistQuery[edit]

follows

References[edit]