Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
OnWikiList
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 3
110
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
12
 getValues
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
30
 getCacheKey
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3namespace MediaWiki\Extension\Notifications;
4
5use MediaWiki\MediaWikiServices;
6use MediaWiki\Title\Title;
7use TextContent;
8
9/**
10 * Implements ContainmentList interface for sourcing a list of items from a wiki
11 * page. Uses the page's latest revision ID as cache key.
12 */
13class OnWikiList implements ContainmentList {
14    /**
15     * @var Title|null A title object representing the page to source the list from,
16     *  or null if the page does not exist.
17     */
18    protected $title;
19
20    /**
21     * @param int $titleNs An NS_* constant representing the mediawiki namespace of the page
22     * @param string $titleString String portion of the wiki page title
23     */
24    public function __construct( $titleNs, $titleString ) {
25        $title = Title::newFromText( $titleString, $titleNs );
26        if ( $title !== null && $title->getArticleID() ) {
27            $this->title = $title;
28        }
29    }
30
31    /**
32     * @inheritDoc
33     */
34    public function getValues() {
35        if ( !$this->title ) {
36            return [];
37        }
38
39        $article = MediaWikiServices::getInstance()->getWikiPageFactory()->newFromTitle( $this->title );
40        if ( !$article->exists() ) {
41            return [];
42        }
43
44        $content = $article->getContent();
45        $text = ( $content instanceof TextContent ) ? $content->getText() : null;
46        if ( $text === null ) {
47            return [];
48        }
49        return array_filter( array_map( 'trim', explode( "\n", $text ) ) );
50    }
51
52    /**
53     * @inheritDoc
54     */
55    public function getCacheKey() {
56        if ( !$this->title ) {
57            return '';
58        }
59
60        return (string)$this->title->getLatestRevID();
61    }
62}