2018-01-21 20:52:43 +00:00
|
|
|
<?php
|
|
|
|
|
2022-11-13 06:43:40 +00:00
|
|
|
namespace MediaWiki\Extension\Notifications;
|
|
|
|
|
2022-06-03 21:00:26 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2023-08-19 04:14:59 +00:00
|
|
|
use MediaWiki\Title\Title;
|
2022-11-13 06:43:40 +00:00
|
|
|
use TextContent;
|
2022-06-03 21:00:26 +00:00
|
|
|
|
2018-01-21 20:52:43 +00:00
|
|
|
/**
|
2022-11-13 06:43:40 +00:00
|
|
|
* Implements ContainmentList interface for sourcing a list of items from a wiki
|
|
|
|
* page. Uses the page's latest revision ID as cache key.
|
2018-01-21 20:52:43 +00:00
|
|
|
*/
|
2022-11-13 06:43:40 +00:00
|
|
|
class OnWikiList implements ContainmentList {
|
2018-01-21 20:52:43 +00:00
|
|
|
/**
|
|
|
|
* @var Title|null A title object representing the page to source the list from,
|
2022-11-13 06:43:40 +00:00
|
|
|
* or null if the page does not exist.
|
2018-01-21 20:52:43 +00:00
|
|
|
*/
|
|
|
|
protected $title;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param int $titleNs An NS_* constant representing the mediawiki namespace of the page
|
|
|
|
* @param string $titleString String portion of the wiki page title
|
|
|
|
*/
|
|
|
|
public function __construct( $titleNs, $titleString ) {
|
|
|
|
$title = Title::newFromText( $titleString, $titleNs );
|
2019-03-01 22:34:38 +00:00
|
|
|
if ( $title !== null && $title->getArticleID() ) {
|
2018-01-21 20:52:43 +00:00
|
|
|
$this->title = $title;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public function getValues() {
|
|
|
|
if ( !$this->title ) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
2022-06-03 21:00:26 +00:00
|
|
|
$article = MediaWikiServices::getInstance()->getWikiPageFactory()->newFromTitle( $this->title );
|
|
|
|
if ( !$article->exists() ) {
|
2018-01-21 20:52:43 +00:00
|
|
|
return [];
|
|
|
|
}
|
2021-05-17 21:44:00 +00:00
|
|
|
|
|
|
|
$content = $article->getContent();
|
|
|
|
$text = ( $content instanceof TextContent ) ? $content->getText() : null;
|
2018-01-21 20:52:43 +00:00
|
|
|
if ( $text === null ) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
return array_filter( array_map( 'trim', explode( "\n", $text ) ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public function getCacheKey() {
|
|
|
|
if ( !$this->title ) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2019-12-21 05:45:14 +00:00
|
|
|
return (string)$this->title->getLatestRevID();
|
2018-01-21 20:52:43 +00:00
|
|
|
}
|
|
|
|
}
|