mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/MultimediaViewer
synced 2024-11-24 00:03:56 +00:00
Use HookHandlers for core hooks
The use of "HookHandlers" attribute in extension.json makes it possible to inject services into hook handler classes in a future patch. Bug: T271019 Change-Id: I57dac8d590b5afa7524000d93c8477a10148c052
This commit is contained in:
parent
5ed21318bc
commit
ad1f6a6ee0
|
@ -417,13 +417,13 @@
|
|||
]
|
||||
},
|
||||
"Hooks": {
|
||||
"UserGetDefaultOptions": "MediaWiki\\Extension\\MultimediaViewer\\Hooks::onUserGetDefaultOptions",
|
||||
"GetPreferences": "MediaWiki\\Extension\\MultimediaViewer\\Hooks::onGetPreferences",
|
||||
"BeforePageDisplay": "MediaWiki\\Extension\\MultimediaViewer\\Hooks::onBeforePageDisplay",
|
||||
"CategoryPageView": "MediaWiki\\Extension\\MultimediaViewer\\Hooks::onCategoryPageView",
|
||||
"ResourceLoaderGetConfigVars": "MediaWiki\\Extension\\MultimediaViewer\\Hooks::onResourceLoaderGetConfigVars",
|
||||
"UserGetDefaultOptions": "main",
|
||||
"GetPreferences": "main",
|
||||
"BeforePageDisplay": "main",
|
||||
"CategoryPageView": "main",
|
||||
"ResourceLoaderGetConfigVars": "main",
|
||||
"MakeGlobalVariablesScript": "main",
|
||||
"ThumbnailBeforeProduceHTML": "MediaWiki\\Extension\\MultimediaViewer\\Hooks::onThumbnailBeforeProduceHTML"
|
||||
"ThumbnailBeforeProduceHTML": "main"
|
||||
},
|
||||
"HookHandlers": {
|
||||
"main": {
|
||||
|
|
|
@ -24,17 +24,32 @@
|
|||
namespace MediaWiki\Extension\MultimediaViewer;
|
||||
|
||||
use CategoryPage;
|
||||
use Config;
|
||||
use ExtensionRegistry;
|
||||
use MediaWiki\Category\Category;
|
||||
use MediaWiki\Hook\BeforePageDisplayHook;
|
||||
use MediaWiki\Hook\MakeGlobalVariablesScriptHook;
|
||||
use MediaWiki\Hook\ThumbnailBeforeProduceHTMLHook;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\Page\Hook\CategoryPageViewHook;
|
||||
use MediaWiki\Preferences\Hook\GetPreferencesHook;
|
||||
use MediaWiki\ResourceLoader\Hook\ResourceLoaderGetConfigVarsHook;
|
||||
use MediaWiki\User\Hook\UserGetDefaultOptionsHook;
|
||||
use MediaWiki\User\UserOptionsLookup;
|
||||
use OutputPage;
|
||||
use Skin;
|
||||
use ThumbnailImage;
|
||||
use User;
|
||||
|
||||
class Hooks implements MakeGlobalVariablesScriptHook {
|
||||
class Hooks implements
|
||||
MakeGlobalVariablesScriptHook,
|
||||
UserGetDefaultOptionsHook,
|
||||
GetPreferencesHook,
|
||||
BeforePageDisplayHook,
|
||||
CategoryPageViewHook,
|
||||
ResourceLoaderGetConfigVarsHook,
|
||||
ThumbnailBeforeProduceHTMLHook
|
||||
{
|
||||
/** Link to more information about this module */
|
||||
protected static $infoLink =
|
||||
'https://mediawiki.org/wiki/Special:MyLanguage/Extension:Media_Viewer/About';
|
||||
|
@ -63,7 +78,7 @@ class Hooks implements MakeGlobalVariablesScriptHook {
|
|||
* @see https://www.mediawiki.org/wiki/Manual:Hooks/UserGetDefaultOptions
|
||||
* @param array &$defaultOptions
|
||||
*/
|
||||
public static function onUserGetDefaultOptions( array &$defaultOptions ) {
|
||||
public function onUserGetDefaultOptions( &$defaultOptions ) {
|
||||
global $wgMediaViewerEnableByDefault;
|
||||
|
||||
if ( $wgMediaViewerEnableByDefault ) {
|
||||
|
@ -111,7 +126,7 @@ class Hooks implements MakeGlobalVariablesScriptHook {
|
|||
* @param OutputPage $out
|
||||
* @param Skin $skin
|
||||
*/
|
||||
public static function onBeforePageDisplay( OutputPage $out, $skin ) {
|
||||
public function onBeforePageDisplay( $out, $skin ): void {
|
||||
$pageHasThumbnails = count( $out->getFileSearchOptions() ) > 0;
|
||||
$pageIsFilePage = $out->getTitle()->inNamespace( NS_FILE );
|
||||
// TODO: Have Flow work out if there are any images on the page
|
||||
|
@ -139,7 +154,7 @@ class Hooks implements MakeGlobalVariablesScriptHook {
|
|||
* Add JavaScript to the page if there are images in the category
|
||||
* @param CategoryPage $catPage
|
||||
*/
|
||||
public static function onCategoryPageView( CategoryPage $catPage ) {
|
||||
public function onCategoryPageView( $catPage ) {
|
||||
$title = $catPage->getTitle();
|
||||
$cat = Category::newFromTitle( $title );
|
||||
if ( $cat->getFileCount() > 0 ) {
|
||||
|
@ -154,7 +169,7 @@ class Hooks implements MakeGlobalVariablesScriptHook {
|
|||
* @param User $user
|
||||
* @param array &$prefs
|
||||
*/
|
||||
public static function onGetPreferences( $user, &$prefs ) {
|
||||
public function onGetPreferences( $user, &$prefs ) {
|
||||
$prefs['multimediaviewer-enable'] = [
|
||||
'type' => 'toggle',
|
||||
'label-message' => 'multimediaviewer-optin-pref',
|
||||
|
@ -166,8 +181,10 @@ class Hooks implements MakeGlobalVariablesScriptHook {
|
|||
* @see https://www.mediawiki.org/wiki/Manual:Hooks/ResourceLoaderGetConfigVars
|
||||
* Export variables used in both PHP and JS to keep DRY
|
||||
* @param array &$vars
|
||||
* @param string $skin
|
||||
* @param Config $config
|
||||
*/
|
||||
public static function onResourceLoaderGetConfigVars( array &$vars ) {
|
||||
public function onResourceLoaderGetConfigVars( array &$vars, $skin, Config $config ): void {
|
||||
global $wgMediaViewerUseThumbnailGuessing, $wgMediaViewerExtensions,
|
||||
$wgMediaViewerImageQueryParameter, $wgMediaViewerRecordVirtualViewBeaconURI;
|
||||
|
||||
|
@ -206,9 +223,9 @@ class Hooks implements MakeGlobalVariablesScriptHook {
|
|||
* @param array &$attribs Attributes of the <img> element
|
||||
* @param array|bool &$linkAttribs Attributes of the wrapping <a> element
|
||||
*/
|
||||
public static function onThumbnailBeforeProduceHTML(
|
||||
ThumbnailImage $thumbnail,
|
||||
array &$attribs,
|
||||
public function onThumbnailBeforeProduceHTML(
|
||||
$thumbnail,
|
||||
&$attribs,
|
||||
&$linkAttribs
|
||||
) {
|
||||
$file = $thumbnail->getFile();
|
||||
|
|
Loading…
Reference in a new issue