Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
MobileFrontendHookHandlers
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
42
0.00% covered (danger)
0.00%
0 / 1
 onSpecialMobileEditWatchlist__images
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
42
1<?php
2
3// phpcs:disable MediaWiki.NamingConventions.LowerCamelFunctionsName.FunctionName
4
5namespace PageImages\Hooks;
6
7use IContextSource;
8use MediaWiki\Title\Title;
9use MobileFrontend\Hooks\SpecialMobileEditWatchlistImagesHook;
10use PageImages\PageImages;
11
12/**
13 * Hooks from MobileFrontend extension,
14 * which is optional to use with this extension.
15 */
16class MobileFrontendHookHandlers implements SpecialMobileEditWatchlistImagesHook {
17
18    /**
19     * SpecialMobileEditWatchlist::images hook handler, adds images to mobile watchlist A-Z view
20     *
21     * @param IContextSource $context Context object. Ignored
22     * @param array[] &$watchlist Array of relevant pages on the watchlist, sorted by namespace
23     * @param array[] &$images Array of images to populate
24     */
25    public function onSpecialMobileEditWatchlist__images(
26        IContextSource $context, array &$watchlist, array &$images
27    ) {
28        $ids = [];
29        foreach ( $watchlist as $ns => $pages ) {
30            foreach ( array_keys( $pages ) as $dbKey ) {
31                $title = Title::makeTitle( $ns, $dbKey );
32                // Getting page ID here is safe because SpecialEditWatchlist::getWatchlistInfo()
33                // uses LinkBatch
34                $id = $title->getArticleID();
35                if ( $id ) {
36                    $ids[$id] = $dbKey;
37                }
38            }
39        }
40
41        $data = PageImages::getImages( array_keys( $ids ) );
42        foreach ( $data as $id => $page ) {
43            if ( isset( $page['pageimage'] ) ) {
44                $images[ $page['ns'] ][ $ids[$id] ] = $page['pageimage'];
45            }
46        }
47    }
48
49}