Debian Codegraph @

extensions/Echo/includes/OnWikiList.php

raw symbols SCIP
1 <?php
2
3 namespace MediaWiki\Extension\Notifications;
4
5 use MediaWiki\Content\TextContent;
6 use MediaWiki\MediaWikiServices;
7 use MediaWiki\Title\Title;
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 */
13 class 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 }