MediaWiki  master
Hooks Class Reference

Hooks class. More...

Static Public Member Functions

static clear ( $name)
 Clears hooks registered via Hooks::register(). More...
 
static getHandlers ( $name)
 Returns an array of all the event functions attached to a hook This combines functions registered via Hooks::register and with $wgHooks. More...
 
static isRegistered ( $name)
 Returns true if a hook has a function registered to it. More...
 
static register ( $name, $callback)
 Attach an event handler to a given hook in both legacy and non-legacy hook systems. More...
 
static run ( $event, array $args=[], $deprecatedVersion=null)
 Call hook functions defined in Hooks::register and $wgHooks. More...
 
static runner ()
 Get a HookRunner instance for calling hooks using the new interfaces. More...
 
static runWithoutAbort ( $event, array $args=[], $deprecatedVersion=null)
 Call hook functions defined in Hooks::register and $wgHooks. More...
 

Detailed Description

Hooks class.

Legacy wrapper for HookContainer Please use HookContainer instead.

Since
1.18

Definition at line 38 of file Hooks.php.

Member Function Documentation

◆ clear()

static Hooks::clear (   $name)
static

Clears hooks registered via Hooks::register().

Does not touch $wgHooks. This is intended for use while testing and will fail if MW_PHPUNIT_TEST is not defined.

Parameters
string$nameThe name of the hook to clear.
Since
1.21
Deprecated:
since 1.35. Instead of using Hooks::register() and Hooks::clear(), use HookContainer::scopedRegister() instead to register a temporary hook
Exceptions
MWExceptionIf not in testing mode.

Definition at line 70 of file Hooks.php.

References wfDeprecated().

◆ getHandlers()

static Hooks::getHandlers (   $name)
static

Returns an array of all the event functions attached to a hook This combines functions registered via Hooks::register and with $wgHooks.

Since
1.18
Deprecated:
since 1.35
Parameters
string$nameName of the hook
Returns
array

Definition at line 102 of file Hooks.php.

◆ isRegistered()

static Hooks::isRegistered (   $name)
static

Returns true if a hook has a function registered to it.

The function may have been registered either via Hooks::register or in $wgHooks.

Since
1.18
Deprecated:
since 1.35. use HookContainer::isRegistered() instead
Parameters
string$nameName of hook
Returns
bool True if the hook has a function registered to it

Definition at line 88 of file Hooks.php.

Referenced by ApiQueryBase\select(), and Parser\statelessFetchTemplate().

◆ register()

static Hooks::register (   $name,
  $callback 
)
static

Attach an event handler to a given hook in both legacy and non-legacy hook systems.

Parameters
string$nameName of hook
callable$callbackCallback function to attach
Deprecated:
since 1.35. use HookContainer::register() instead
Since
1.18

Definition at line 48 of file Hooks.php.

References wfDeprecatedMsg().

Referenced by BenchmarkParse\execute().

◆ run()

static Hooks::run (   $event,
array  $args = [],
  $deprecatedVersion = null 
)
static

Call hook functions defined in Hooks::register and $wgHooks.

For the given hook event, fetch the array of hook events and process them. Determine the proper callback for each hook and then call the actual hook using the appropriate arguments. Finally, process the return value and return/throw accordingly.

For hook event that are not abortable through a handler's return value, use runWithoutAbort() instead.

Parameters
string$eventEvent name
array$argsArray of parameters passed to hook functions
string | null$deprecatedVersion[optional] Mark hook as deprecated with version number
Returns
bool True if no handler aborted the hook
Exceptions
Exception
Since
1.22 A hook function is not required to return a value for processing to continue. Not returning a value (or explicitly returning null) is equivalent to returning true.
Deprecated:
since 1.35 Use HookContainer::run() instead

Definition at line 134 of file Hooks.php.

References $args.

Referenced by BenchmarkHooks\execute().

◆ runner()

static Hooks::runner ( )
static

Get a HookRunner instance for calling hooks using the new interfaces.

Classes using dependency injection should instead receive a HookContainer and construct a private HookRunner from it.

Classes without dependency injection may alternatively use ProtectedHookAccessorTrait, a trait which provides getHookRunner() as a protected method.

Since
1.35
Returns
HookRunner

Definition at line 172 of file Hooks.php.

Referenced by WikiImporter\__construct(), LogEventsList\__construct(), EmailNotification\actuallyNotifyOnPageChange(), ExternalUserNames\applyPrefix(), ChangeTags\canAddTagsAccompanyingChange(), ChangeTags\canCreateTag(), ChangeTags\canDeleteTag(), EmailNotification\canSendUserTalkEmail(), AbstractContent\convert(), UploadBase\createFromRequest(), ChangeTags\deleteTagEverywhere(), MediaWiki\Block\DatabaseBlock\doAutoblock(), FileDeleteForm\doDelete(), RecentChange\doMarkPatrolled(), TransformationalImageHandler\doTransform(), WatchAction\doUnwatch(), WatchAction\doWatch(), Title\exists(), Collation\factory(), Linker\formatAutocomments(), LegacyLogFormatter\getActionLinks(), Title\getCanonicalURL(), Title\getCategorySortkey(), EditPage\getCopyrightWarning(), Revision\MainSlotRoleHandler\getDefaultModel(), ParserOptions\getDefaults(), Title\getEditNotices(), EditPage\getEditToolbar(), SpecialVersion\getExtensionTypes(), Title\getFullURL(), SpecialUpload\getInitialPageText(), Title\getInternalURL(), WebRequest\getIP(), RequestContext\getLanguage(), IRCColourfulRCFeedFormatter\getLine(), Title\getLocalURL(), SpecialLog\getLogTypesOnUser(), MediaHandler\getMetadataVersion(), SpecialVersion\getMWVersionLinked(), QueryPage\getPages(), AbstractContent\getParserOutput(), WebRequest\getPathInfo(), SpecialEmailUser\getPermissionsError(), UserPasswordPolicy\getPoliciesForUser(), LanguageConverter\getPreferredVariant(), EditPage\getPreviewLimitReport(), MWTimestamp\getRelativeTimestamp(), Title\getRestrictionTypes(), AbstractContent\getSecondaryDataUpdates(), RequestContext\getSkin(), SpecialVersion\getSoftwareInformation(), ParserOutput\getText(), LoginHelper\getValidErrorMessages(), GitInfo\getViewers(), initFromTitle(), UploadFromUrl\isAllowedUrl(), Title\isAlwaysKnown(), TransformationalImageHandler\isImageAreaOkForThumbnaling(), Title\isMovable(), ProxyLookup\isTrustedProxy(), DatabaseUpdater\loadExtensionSchemaUpdates(), ImageGalleryBase\loadModes(), MWExceptionHandler\logError(), MWExceptionHandler\logException(), BotPassword\loginHook(), Linker\makeExternalImage(), Linker\makeExternalLink(), Linker\makeImageLink(), Linker\makeMediaLinkFile(), MediaWiki\Shell\Shell\makeScriptCommand(), Linker\makeSelfLinkObj(), ChangesList\newFromContext(), UserArray\newFromResult(), TitleArray\newFromResult(), Article\newFromTitle(), ParserOptions\optionsHash(), SearchEngine\parseNamespacePrefixes(), ManualLogEntry\publish(), RecentChangesUpdateJob\purgeExpiredRows(), WikitextContent\replaceSection(), RecentChange\save(), PrefixSearch\searchBackend(), UserMailer\send(), UserMailer\sendInternal(), WebResponse\setCookie(), LogEventsList\showLogExtract(), Parser\statelessFetchTemplate(), SpecialEmailUser\submit(), TraditionalImageGallery\toHTML(), ThumbnailImage\toHtml(), ChangeTags\updateTags(), HTMLFileCache\useFileCache(), Linker\userToolLinks(), Sanitizer\validateEmail(), wfApiMain(), wfCanIPUseHTTPS(), wfImageAuthMain(), wfOpenSearchDescMain(), and wfShellWikiCmd().

◆ runWithoutAbort()

static Hooks::runWithoutAbort (   $event,
array  $args = [],
  $deprecatedVersion = null 
)
static

Call hook functions defined in Hooks::register and $wgHooks.

Parameters
string$eventEvent name
array$argsArray of parameters passed to hook functions
string | null$deprecatedVersion[optional] Mark hook as deprecated with version number
Returns
bool Always true
Exceptions
UnexpectedValueExceptioncallback returns an invalid value
Since
1.30
Deprecated:
since 1.35 Use HookContainer::run() with 'abortable' option instead

Definition at line 151 of file Hooks.php.

References $args.


The documentation for this class was generated from the following file: