2015-04-27 14:05:31 +00:00
|
|
|
<?php
|
2015-05-06 12:49:15 +00:00
|
|
|
|
2019-12-18 18:00:05 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2021-09-14 21:26:23 +00:00
|
|
|
use MediaWiki\Revision\RenderedRevision;
|
2019-12-18 18:00:05 +00:00
|
|
|
|
2015-04-27 14:05:31 +00:00
|
|
|
class PortableInfoboxHooks {
|
2015-06-19 12:16:07 +00:00
|
|
|
|
2018-08-18 16:12:16 +00:00
|
|
|
public static function onWgQueryPages( array &$queryPages = [] ) {
|
2021-09-12 21:07:34 +00:00
|
|
|
$queryPages[] = [ 'AllInfoboxesQueryPage', 'AllInfoboxes' ];
|
2015-08-20 13:14:23 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2018-08-15 15:10:55 +00:00
|
|
|
|
2018-10-02 07:41:19 +00:00
|
|
|
public static function onBeforeParserrenderImageGallery(
|
|
|
|
Parser &$parser, ImageGalleryBase &$gallery
|
|
|
|
) {
|
2018-08-18 16:12:16 +00:00
|
|
|
PortableInfobox\Helpers\PortableInfoboxDataBag::getInstance()->setGallery(
|
2021-09-12 21:07:34 +00:00
|
|
|
// @phan-suppress-next-line PhanDeprecatedProperty
|
2018-10-02 07:41:19 +00:00
|
|
|
Parser::MARKER_PREFIX . '-gallery-' . sprintf( '%08X', $parser->mMarkerIndex - 1 ) .
|
|
|
|
Parser::MARKER_SUFFIX,
|
2018-08-18 16:12:16 +00:00
|
|
|
$gallery
|
|
|
|
);
|
2018-08-07 14:02:51 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2015-09-08 17:42:49 +00:00
|
|
|
|
2015-09-22 15:48:38 +00:00
|
|
|
public static function onAllInfoboxesQueryRecached() {
|
2019-12-18 18:00:05 +00:00
|
|
|
$cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
|
2021-09-12 21:07:34 +00:00
|
|
|
$cache->delete( $cache->makeKey( ApiQueryAllInfoboxes::MCACHE_KEY ) );
|
2015-09-22 15:48:38 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Purge memcache before edit
|
|
|
|
*
|
2021-09-14 21:26:23 +00:00
|
|
|
* @param RenderedRevision $renderedRevision
|
2015-09-22 15:48:38 +00:00
|
|
|
*/
|
2021-09-14 21:26:23 +00:00
|
|
|
public static function onMultiContentSave( RenderedRevision $renderedRevision ) {
|
|
|
|
$articleID = $renderedRevision->getRevision()->getPageId();
|
|
|
|
$title = Title::newFromId( $articleID );
|
2018-10-19 18:06:16 +00:00
|
|
|
|
2021-09-14 21:26:23 +00:00
|
|
|
if ( $title ) {
|
|
|
|
$dataService = PortableInfoboxDataService::newFromTitle( $title );
|
|
|
|
$dataService->delete();
|
2015-09-22 15:48:38 +00:00
|
|
|
|
2021-09-14 21:26:23 +00:00
|
|
|
if ( $title->inNamespace( NS_TEMPLATE ) ) {
|
|
|
|
$dataService->reparseArticle();
|
|
|
|
}
|
|
|
|
}
|
2015-09-22 15:48:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-09-25 14:53:39 +00:00
|
|
|
* Purge memcache, this will not rebuild infobox data
|
2015-09-22 15:48:38 +00:00
|
|
|
*
|
2021-09-12 21:07:34 +00:00
|
|
|
* @param Page $article
|
2015-09-22 15:48:38 +00:00
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
2017-08-07 19:26:54 +00:00
|
|
|
public static function onArticlePurge( Page $article ) {
|
2015-09-22 15:48:38 +00:00
|
|
|
PortableInfoboxDataService::newFromTitle( $article->getTitle() )->purge();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2018-09-01 13:36:05 +00:00
|
|
|
|
|
|
|
public static function onResourceLoaderRegisterModules( ResourceLoader &$resourceLoader ) {
|
|
|
|
global $wgResourceModules;
|
|
|
|
|
2018-10-02 07:41:19 +00:00
|
|
|
if ( isset( $wgResourceModules['ext.templateDataGenerator.data'] ) ) {
|
2018-09-01 13:36:05 +00:00
|
|
|
$wgResourceModules['ext.templateDataGenerator.data']['scripts'][] =
|
|
|
|
'../PortableInfobox/resources/PortableInfoboxParams.js';
|
|
|
|
|
|
|
|
$resourceLoader->register(
|
|
|
|
'ext.templateDataGenerator.data',
|
|
|
|
$wgResourceModules['ext.templateDataGenerator.data']
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2015-04-27 14:05:31 +00:00
|
|
|
}
|