mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Gadgets
synced 2024-11-28 01:00:02 +00:00
Update hooks to use PageSaveComplete
hook in MW 1.35+
Bug: T250566 Change-Id: Ieccc1cae8c4b53a582391066a1a6336eae6c9277
This commit is contained in:
parent
314bf0933f
commit
f5ecc23c17
|
@ -83,18 +83,17 @@
|
||||||
"GadgetDefinitionDeletionUpdate": "includes/content/GadgetDefinitionDeletionUpdate.php"
|
"GadgetDefinitionDeletionUpdate": "includes/content/GadgetDefinitionDeletionUpdate.php"
|
||||||
},
|
},
|
||||||
"Hooks": {
|
"Hooks": {
|
||||||
"PageContentSaveComplete": "GadgetHooks::onPageContentSaveComplete",
|
|
||||||
"BeforePageDisplay": "GadgetHooks::beforePageDisplay",
|
"BeforePageDisplay": "GadgetHooks::beforePageDisplay",
|
||||||
"CodeEditorGetPageLanguage": "GadgetHooks::onCodeEditorGetPageLanguage",
|
"CodeEditorGetPageLanguage": "GadgetHooks::onCodeEditorGetPageLanguage",
|
||||||
"ContentHandlerDefaultModelFor": "GadgetHooks::onContentHandlerDefaultModelFor",
|
"ContentHandlerDefaultModelFor": "GadgetHooks::onContentHandlerDefaultModelFor",
|
||||||
"EditFilterMergedContent": "GadgetHooks::onEditFilterMergedContent",
|
"EditFilterMergedContent": "GadgetHooks::onEditFilterMergedContent",
|
||||||
"PageContentInsertComplete": "GadgetHooks::onPageContentInsertComplete",
|
|
||||||
"UserGetDefaultOptions": "GadgetHooks::userGetDefaultOptions",
|
"UserGetDefaultOptions": "GadgetHooks::userGetDefaultOptions",
|
||||||
"GetPreferences": "GadgetHooks::getPreferences",
|
"GetPreferences": "GadgetHooks::getPreferences",
|
||||||
"ResourceLoaderRegisterModules": "GadgetHooks::registerModules",
|
"ResourceLoaderRegisterModules": "GadgetHooks::registerModules",
|
||||||
"wgQueryPages": "GadgetHooks::onwgQueryPages",
|
"wgQueryPages": "GadgetHooks::onwgQueryPages",
|
||||||
"DeleteUnknownPreferences": "GadgetHooks::onDeleteUnknownPreferences"
|
"DeleteUnknownPreferences": "GadgetHooks::onDeleteUnknownPreferences"
|
||||||
},
|
},
|
||||||
|
"callback": "GadgetHooks::onRegistration",
|
||||||
"config": {
|
"config": {
|
||||||
"GadgetsRepoClass": {
|
"GadgetsRepoClass": {
|
||||||
"value": "MediaWikiGadgetsDefinitionRepo"
|
"value": "MediaWikiGadgetsDefinitionRepo"
|
||||||
|
|
|
@ -24,18 +24,88 @@ use Wikimedia\Rdbms\IDatabase;
|
||||||
use Wikimedia\WrappedString;
|
use Wikimedia\WrappedString;
|
||||||
|
|
||||||
class GadgetHooks {
|
class GadgetHooks {
|
||||||
|
/**
|
||||||
|
* Callback on extension registration
|
||||||
|
*
|
||||||
|
* Register hooks based on version to keep support for mediawiki versions before 1.35
|
||||||
|
*/
|
||||||
|
public static function onRegistration() {
|
||||||
|
global $wgHooks;
|
||||||
|
|
||||||
|
if ( version_compare( MW_VERSION, '1.35', '>=' ) ) {
|
||||||
|
// Use PageSaveComplete
|
||||||
|
$wgHooks['PageSaveComplete'][] = 'GadgetHooks::onPageSaveComplete';
|
||||||
|
} else {
|
||||||
|
// Use both PageContentInsertComplete and PageContentSaveComplete
|
||||||
|
$wgHooks['PageContentSaveComplete'][] = 'GadgetHooks::onPageContentSaveComplete';
|
||||||
|
$wgHooks['PageContentInsertComplete'][] = 'GadgetHooks::onPageContentInsertComplete';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PageContentSaveComplete hook handler.
|
* PageContentSaveComplete hook handler.
|
||||||
*
|
*
|
||||||
|
* Only run in versions of mediawiki before 1.35; in 1.35+, ::onPageSaveComplete is used
|
||||||
|
*
|
||||||
|
* @note Hook provides other parameters, but only the wikipage is needed
|
||||||
* @param WikiPage $wikiPage
|
* @param WikiPage $wikiPage
|
||||||
* @param User $user
|
|
||||||
* @param Content $content New page content
|
|
||||||
*/
|
*/
|
||||||
public static function onPageContentSaveComplete( WikiPage $wikiPage, $user, $content ) {
|
public static function onPageContentSaveComplete( WikiPage $wikiPage ) {
|
||||||
// update cache if MediaWiki:Gadgets-definition was edited
|
// update cache if MediaWiki:Gadgets-definition was edited
|
||||||
GadgetRepo::singleton()->handlePageUpdate( $wikiPage->getTitle() );
|
GadgetRepo::singleton()->handlePageUpdate( $wikiPage->getTitle() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* After a new page is created in the Gadget definition namespace,
|
||||||
|
* invalidate the list of gadget ids
|
||||||
|
*
|
||||||
|
* Only run in versions of mediawiki before 1.35; in 1.35+, ::onPageSaveComplete is used
|
||||||
|
*
|
||||||
|
* @note Hook provides other parameters, but only the wikipage is needed
|
||||||
|
* @param WikiPage $page
|
||||||
|
*/
|
||||||
|
public static function onPageContentInsertComplete( WikiPage $page ) {
|
||||||
|
if ( $page->getTitle()->inNamespace( NS_GADGET_DEFINITION ) ) {
|
||||||
|
GadgetRepo::singleton()->handlePageCreation( $page->getTitle() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PageSaveComplete hook handler
|
||||||
|
*
|
||||||
|
* Only run in versions of mediawiki begining 1.35; before 1.35, ::onPageContentSaveComplete
|
||||||
|
* and ::onPageContentInsertComplete are used
|
||||||
|
*
|
||||||
|
* @note paramaters include classes not available before 1.35, so for those typehints
|
||||||
|
* are not used. The variable name reflects the class
|
||||||
|
*
|
||||||
|
* @param WikiPage $wikiPage
|
||||||
|
* @param mixed $userIdentity unused
|
||||||
|
* @param string $summary
|
||||||
|
* @param int $flags
|
||||||
|
* @param mixed $revisionRecord unused
|
||||||
|
* @param mixed $editResult unused
|
||||||
|
*/
|
||||||
|
public static function onPageSaveComplete(
|
||||||
|
WikiPage $wikiPage,
|
||||||
|
$userIdentity,
|
||||||
|
string $summary,
|
||||||
|
int $flags,
|
||||||
|
$revisionRecord,
|
||||||
|
$editResult
|
||||||
|
) {
|
||||||
|
$title = $wikiPage->getTitle();
|
||||||
|
$repo = GadgetRepo::singleton();
|
||||||
|
|
||||||
|
if ( $flags & EDIT_NEW ) {
|
||||||
|
if ( $title->inNamespace( NS_GADGET_DEFINITION ) ) {
|
||||||
|
$repo->handlePageCreation( $title );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$repo->handlePageUpdate( $title );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* UserGetDefaultOptions hook handler
|
* UserGetDefaultOptions hook handler
|
||||||
* @param array &$defaultOptions Array of default preference keys and values
|
* @param array &$defaultOptions Array of default preference keys and values
|
||||||
|
@ -258,18 +328,6 @@ class GadgetHooks {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* After a new page is created in the Gadget definition namespace,
|
|
||||||
* invalidate the list of gadget ids
|
|
||||||
*
|
|
||||||
* @param WikiPage $page
|
|
||||||
*/
|
|
||||||
public static function onPageContentInsertComplete( WikiPage $page ) {
|
|
||||||
if ( $page->getTitle()->inNamespace( NS_GADGET_DEFINITION ) ) {
|
|
||||||
GadgetRepo::singleton()->handlePageCreation( $page->getTitle() );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mark the Title as having a content model of javascript or css for pages
|
* Mark the Title as having a content model of javascript or css for pages
|
||||||
* in the Gadget namespace based on their file extension
|
* in the Gadget namespace based on their file extension
|
||||||
|
|
Loading…
Reference in a new issue