mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/PageImages
synced 2024-12-18 02:51:04 +00:00
Use HookHandlers for MobileFrontend hook
Bug: T271021 Change-Id: I9293e1fee102b9a4274ef460b9c7556e0c7c6f6a
This commit is contained in:
parent
d96e200072
commit
7f3a11f327
|
@ -2,4 +2,18 @@
|
||||||
|
|
||||||
$cfg = require __DIR__ . '/../vendor/mediawiki/mediawiki-phan-config/src/config.php';
|
$cfg = require __DIR__ . '/../vendor/mediawiki/mediawiki-phan-config/src/config.php';
|
||||||
|
|
||||||
|
$cfg['directory_list'] = array_merge(
|
||||||
|
$cfg['directory_list'],
|
||||||
|
[
|
||||||
|
'../../extensions/MobileFrontend',
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
$cfg['exclude_analysis_directory_list'] = array_merge(
|
||||||
|
$cfg['exclude_analysis_directory_list'],
|
||||||
|
[
|
||||||
|
'../../extensions/MobileFrontend',
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
return $cfg;
|
return $cfg;
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
"ParserModifyImageHTML": "parser",
|
"ParserModifyImageHTML": "parser",
|
||||||
"ParserTestGlobals": "parser",
|
"ParserTestGlobals": "parser",
|
||||||
"SearchResultProvideThumbnail": "search",
|
"SearchResultProvideThumbnail": "search",
|
||||||
"SpecialMobileEditWatchlist::images": "PageImages\\PageImages::onSpecialMobileEditWatchlistImages"
|
"SpecialMobileEditWatchlist::images": "mobile"
|
||||||
},
|
},
|
||||||
"HookHandlers": {
|
"HookHandlers": {
|
||||||
"main": {
|
"main": {
|
||||||
|
@ -45,6 +45,9 @@
|
||||||
"search": {
|
"search": {
|
||||||
"class": "PageImages\\Hooks\\SearchResultProvideThumbnailHookHandler",
|
"class": "PageImages\\Hooks\\SearchResultProvideThumbnailHookHandler",
|
||||||
"services": [ "SearchResultThumbnailProvider", "PageProps", "RepoGroup" ]
|
"services": [ "SearchResultThumbnailProvider", "PageProps", "RepoGroup" ]
|
||||||
|
},
|
||||||
|
"mobile": {
|
||||||
|
"class": "PageImages\\Hooks\\MobileFrontendHookHandlers"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"JobClasses": {
|
"JobClasses": {
|
||||||
|
|
49
includes/Hooks/MobileFrontendHookHandlers.php
Normal file
49
includes/Hooks/MobileFrontendHookHandlers.php
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
// phpcs:disable MediaWiki.NamingConventions.LowerCamelFunctionsName.FunctionName
|
||||||
|
|
||||||
|
namespace PageImages\Hooks;
|
||||||
|
|
||||||
|
use IContextSource;
|
||||||
|
use MediaWiki\Title\Title;
|
||||||
|
use MobileFrontend\Hooks\SpecialMobileEditWatchlistImagesHook;
|
||||||
|
use PageImages\PageImages;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hooks from MobileFrontend extension,
|
||||||
|
* which is optional to use with this extension.
|
||||||
|
*/
|
||||||
|
class MobileFrontendHookHandlers implements SpecialMobileEditWatchlistImagesHook {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SpecialMobileEditWatchlist::images hook handler, adds images to mobile watchlist A-Z view
|
||||||
|
*
|
||||||
|
* @param IContextSource $context Context object. Ignored
|
||||||
|
* @param array[] &$watchlist Array of relevant pages on the watchlist, sorted by namespace
|
||||||
|
* @param array[] &$images Array of images to populate
|
||||||
|
*/
|
||||||
|
public function onSpecialMobileEditWatchlist__images(
|
||||||
|
IContextSource $context, array &$watchlist, array &$images
|
||||||
|
) {
|
||||||
|
$ids = [];
|
||||||
|
foreach ( $watchlist as $ns => $pages ) {
|
||||||
|
foreach ( array_keys( $pages ) as $dbKey ) {
|
||||||
|
$title = Title::makeTitle( $ns, $dbKey );
|
||||||
|
// Getting page ID here is safe because SpecialEditWatchlist::getWatchlistInfo()
|
||||||
|
// uses LinkBatch
|
||||||
|
$id = $title->getArticleID();
|
||||||
|
if ( $id ) {
|
||||||
|
$ids[$id] = $dbKey;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = PageImages::getImages( array_keys( $ids ) );
|
||||||
|
foreach ( $data as $id => $page ) {
|
||||||
|
if ( isset( $page['pageimage'] ) ) {
|
||||||
|
$images[ $page['ns'] ][ $ids[$id] ] = $page['pageimage'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -218,37 +218,6 @@ class PageImages implements
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* SpecialMobileEditWatchlist::images hook handler, adds images to mobile watchlist A-Z view
|
|
||||||
*
|
|
||||||
* @param IContextSource $context Context object. Ignored
|
|
||||||
* @param array[] $watchlist Array of relevant pages on the watchlist, sorted by namespace
|
|
||||||
* @param array[] &$images Array of images to populate
|
|
||||||
*/
|
|
||||||
public static function onSpecialMobileEditWatchlistImages(
|
|
||||||
IContextSource $context, array $watchlist, array &$images
|
|
||||||
) {
|
|
||||||
$ids = [];
|
|
||||||
foreach ( $watchlist as $ns => $pages ) {
|
|
||||||
foreach ( array_keys( $pages ) as $dbKey ) {
|
|
||||||
$title = Title::makeTitle( $ns, $dbKey );
|
|
||||||
// Getting page ID here is safe because SpecialEditWatchlist::getWatchlistInfo()
|
|
||||||
// uses LinkBatch
|
|
||||||
$id = $title->getArticleID();
|
|
||||||
if ( $id ) {
|
|
||||||
$ids[$id] = $dbKey;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$data = self::getImages( array_keys( $ids ) );
|
|
||||||
foreach ( $data as $id => $page ) {
|
|
||||||
if ( isset( $page['pageimage'] ) ) {
|
|
||||||
$images[ $page['ns'] ][ $ids[$id] ] = $page['pageimage'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns image information for pages with given ids
|
* Returns image information for pages with given ids
|
||||||
*
|
*
|
||||||
|
@ -257,7 +226,7 @@ class PageImages implements
|
||||||
*
|
*
|
||||||
* @return array[]
|
* @return array[]
|
||||||
*/
|
*/
|
||||||
private static function getImages( array $pageIds, $size = 0 ) {
|
public static function getImages( array $pageIds, $size = 0 ) {
|
||||||
$ret = [];
|
$ret = [];
|
||||||
foreach ( array_chunk( $pageIds, ApiBase::LIMIT_SML1 ) as $chunk ) {
|
foreach ( array_chunk( $pageIds, ApiBase::LIMIT_SML1 ) as $chunk ) {
|
||||||
$request = [
|
$request = [
|
||||||
|
|
Loading…
Reference in a new issue