summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'Echo/includes/EchoOnWikiList.php')
-rw-r--r--Echo/includes/EchoOnWikiList.php54
1 files changed, 54 insertions, 0 deletions
diff --git a/Echo/includes/EchoOnWikiList.php b/Echo/includes/EchoOnWikiList.php
new file mode 100644
index 00000000..5bdc4dd6
--- /dev/null
+++ b/Echo/includes/EchoOnWikiList.php
@@ -0,0 +1,54 @@
+<?php
+
+/**
+ * Implements EchoContainmentList interface for sourcing a list of items from a wiki
+ * page. Uses the pages latest revision ID as cache key.
+ */
+class EchoOnWikiList implements EchoContainmentList {
+ /**
+ * @var Title|null A title object representing the page to source the list from,
+ * or null if the page does not exist.
+ */
+ 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 );
+ if ( $title !== null && $title->getArticleId() ) {
+ $this->title = $title;
+ }
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function getValues() {
+ if ( !$this->title ) {
+ return [];
+ }
+
+ $article = WikiPage::newFromID( $this->title->getArticleId() );
+ if ( $article === null || !$article->exists() ) {
+ return [];
+ }
+ $text = ContentHandler::getContentText( $article->getContent() );
+ if ( $text === null ) {
+ return [];
+ }
+ return array_filter( array_map( 'trim', explode( "\n", $text ) ) );
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function getCacheKey() {
+ if ( !$this->title ) {
+ return '';
+ }
+
+ return $this->title->getLatestRevID();
+ }
+}