| 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 |
|
| 11 |
|
| 12 |
|
| 13 |
class OnWikiList implements ContainmentList { |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
protected $title; |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 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 |
|
| 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 |
|
| 54 |
|
| 55 |
public function getCacheKey() { |
| 56 |
if ( !$this->title ) { |
| 57 |
return ''; |
| 58 |
} |
| 59 |
|
| 60 |
return (string)$this->title->getLatestRevID(); |
| 61 |
} |
| 62 |
} |