DPL3 with 1.35 support

This commit is contained in:
Universal Omega 2020-11-22 13:03:02 -07:00 committed by GitHub
parent 55a7e03de1
commit 4c17ac0ea0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 2020 additions and 0 deletions

View file

@ -0,0 +1,63 @@
<?php
/**
* DynamicPageList3
* DPL CategoryList Class
*
* @license GPL-2.0-or-later
* @package DynamicPageList3
*
**/
namespace DPL\Lister;
use DPL\Article;
use DPL\Config;
class CategoryList extends Lister {
/**
* Listing style for this class.
*
* @var constant
*/
public $style = parent::LIST_CATEGORY;
/**
* Format the list of articles.
*
* @access public
* @param array List of \DPL\Article
* @param integer Start position of the array to process.
* @param integer Total objects from the array to process.
* @return string Formatted list.
*/
public function formatList($articles, $start, $count) {
$filteredCount = 0;
for ($i = $start; $i < $start + $count; $i++) {
$articleLinks[] = $articles[$i]->mLink;
$articleStartChars[] = $articles[$i]->mStartChar;
$filteredCount = $filteredCount + 1;
}
$this->rowCount = $filteredCount;
if (count($articleLinks) > Config::getSetting('categoryStyleListCutoff')) {
return "__NOTOC____NOEDITSECTION__" . \CategoryViewer::columnList($articleLinks, $articleStartChars);
} elseif (count($articleLinks) > 0) {
// for short lists of articles in categories.
return "__NOTOC____NOEDITSECTION__" . \CategoryViewer::shortList($articleLinks, $articleStartChars);
}
return '';
}
/**
* Format a single item.
*
* @access public
* @param object DPL\Article
* @param string [Optional] Page text to include.
* @return string Item HTML
*/
public function formatItem(Article $article, $pageText = null) {
return '';
}
}

View file

@ -0,0 +1,78 @@
<?php
/**
* DynamicPageList3
* DPL DefinitionList Class
*
* @license GPL-2.0-or-later
* @package DynamicPageList3
*
**/
namespace DPL\Lister;
class DefinitionList extends Lister {
/**
* Listing style for this class.
*
* @var constant
*/
public $style = parent::LIST_DEFINITION;
/**
* Heading List Start
* Use %s for attribute placement. Example: <div%s>
*
* @var string
*/
public $headListStart = '<dt%s>';
/**
* Heading List End
*
* @var string
*/
public $headListEnd = '</dt>';
/**
* Heading List Start
* Use %s for attribute placement. Example: <div%s>
*
* @var string
*/
public $headItemStart = '';
/**
* Heading List End
*
* @var string
*/
public $headItemEnd = '';
/**
* List(Section) Start
*
* @var string
*/
public $listStart = '<dl%s>';
/**
* List(Section) End
*
* @var string
*/
public $listEnd = '</dl>';
/**
* Item Start
*
* @var string
*/
public $itemStart = '<dd%s>';
/**
* Item End
*
* @var string
*/
public $itemEnd = '</dd>';
}

View file

@ -0,0 +1,73 @@
<?php
/**
* DynamicPageList3
* DPL GalleryList Class
*
* @license GPL-2.0-or-later
* @package DynamicPageList3
*
**/
namespace DPL\Lister;
use DPL\Article;
class GalleryList extends Lister {
/**
* Listing style for this class.
*
* @var constant
*/
public $style = parent::LIST_GALLERY;
/**
* List(Section) Start
*
* @var string
*/
public $listStart = '<gallery%s>';
/**
* List(Section) End
*
* @var string
*/
public $listEnd = '</gallery>';
/**
* Item Start
*
* @var string
*/
public $itemStart = "\n";
/**
* Item End
*
* @var string
*/
public $itemEnd = "|";
/**
* Format an item.
*
* @access public
* @param object DPL\Article
* @param string [Optional] Page text to include.include.
* @return string Item HTML
*/
public function formatItem(Article $article, $pageText = null) {
$item = $article->mTitle;
if ($pageText !== null) {
//Include parsed/processed wiki markup content after each item before the closing tag.
$item .= $pageText;
}
$item = $this->getItemStart() . $item . $this->itemEnd;
$item = $this->replaceTagParameters($item, $article);
return $item;
}
}

View file

@ -0,0 +1,93 @@
<?php
/**
* DynamicPageList3
* DPL InlineList Class
*
* @license GPL-2.0-or-later
* @package DynamicPageList3
*
**/
namespace DPL\Lister;
class InlineList extends Lister {
/**
* Listing style for this class.
*
* @var constant
*/
public $style = parent::LIST_INLINE;
/**
* Heading Start
*
* @var string
*/
public $headingStart = '';
/**
* Heading End
*
* @var string
*/
public $headingEnd = '';
/**
* List(Section) Start
*
* @var string
*/
public $listStart = '<div%s>';
/**
* List(Section) End
*
* @var string
*/
public $listEnd = '</div>';
/**
* Item Start
*
* @var string
*/
public $itemStart = '<span%s>';
/**
* Item End
*
* @var string
*/
public $itemEnd = '</span>';
/**
* Inline item text separator.
*
* @var string
*/
protected $textSeparator = '';
/**
* Main Constructor
*
* @access public
* @param object \DPL\Parameters
* @param object MediaWiki \Parser
* @return void
*/
public function __construct(\DPL\Parameters $parameters, \Parser $parser) {
parent::__construct($parameters, $parser);
$this->textSeparator = $parameters->getParameter('inlinetext');
}
/**
* Join together items after being processed by formatItem().
*
* @access public
* @param array Items as formatted by formatItem().
* @return string Imploded items.
*/
protected function implodeItems($items) {
return implode($this->textSeparator, $items);
}
}

1278
classes/lister/Lister.php Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,74 @@
<?php
/**
* DynamicPageList3
* DPL OrderedList Class
*
* @license GPL-2.0-or-later
* @package DynamicPageList3
*
**/
namespace DPL\Lister;
class OrderedList extends UnorderedList {
/**
* Listing style for this class.
*
* @var constant
*/
public $style = parent::LIST_ORDERED;
/**
* List(Section) Start
*
* @var string
*/
public $listStart = '<ol%s>';
/**
* List(Section) End
*
* @var string
*/
public $listEnd = '</ol>';
/**
* Offset Count
*
* @var integer
*/
private $offsetCount = 0;
/**
* Format the list of articles.
*
* @access public
* @param array List of \DPL\Article
* @param integer Start position of the array to process.
* @param integer Total objects from the array to process.
* @return string Formatted list.
*/
public function formatList($articles, $start, $count) {
$this->offsetCount = $count;
return parent::formatList($articles, $start, $count);
}
/**
* Return $this->listStart with attributes replaced.
*
* @access public
* @return string List Start
*/
public function getListStart() {
// increase start value of ordered lists at multi-column output
//The offset that comes from the URL parameter is zero based, but has to be +1'ed for display.
$offset = $this->getParameters()->getParameter('offset') + 1;
if ($offset != 0) {
//@TODO: So this adds the total count of articles to the offset. I have not found a case where this does not mess up the displayed count. I am commenting this out for now.
//$offset += $this->offsetCount;
}
return sprintf($this->listStart, $this->listAttributes . ' start="' . $offset . '"');
}
}

View file

@ -0,0 +1,128 @@
<?php
/**
* DynamicPageList3
* DPL SubPageList Class
*
* @license GPL-2.0-or-later
* @package DynamicPageList3
*
**/
namespace DPL\Lister;
class SubPageList extends UnorderedList {
/**
* Listing style for this class.
*
* @var constant
*/
public $style = parent::LIST_UNORDERED;
/**
* List(Section) Start
*
* @var string
*/
public $listStart = '<ul%s>';
/**
* List(Section) End
*
* @var string
*/
public $listEnd = '</ul>';
/**
* Item Start
*
* @var string
*/
public $itemStart = '<li%s>';
/**
* Item End
*
* @var string
*/
public $itemEnd = '</li>';
/**
* Format a list of articles into a singular list.
*
* @access public
* @param array List of \DPL\Article
* @param integer Start position of the array to process.
* @param integer Total objects from the array to process.
* @return string Formatted list.
*/
public function formatList($articles, $start, $count) {
$filteredCount = 0;
$items = [];
for ($i = $start; $i < $start + $count; $i++) {
$article = $articles[$i];
if (empty($article) || empty($article->mTitle)) {
continue;
}
$pageText = null;
if ($this->includePageText) {
$pageText = $this->transcludePage($article, $filteredCount);
} else {
$filteredCount++;
}
$this->rowCount = $filteredCount++;
$parts = explode('/', $article->mTitle);
$item = $this->formatItem($article, $pageText);
$items = $this->nestItem($parts, $items, $item);
}
return $this->getListStart() . $this->implodeItems($items) . $this->listEnd;
}
/**
* Nest items down to the proper level.
*
* @access private
* @param array Part levels to nest down to.
* @param array Items holder to nest the item into.
* @param string Formatted Item
* @return array Nest Items
*/
private function nestItem(&$parts, $items, $item) {
$firstPart = reset($parts);
if (count($parts) > 1) {
array_shift($parts);
if (!isset($items[$firstPart])) {
$items[$firstPart] = [];
}
$items[$firstPart] = $this->nestItem($parts, $items[$firstPart], $item);
return $items;
}
$items[$firstPart][] = $item;
return $items;
}
/**
* Join together items after being processed by formatItem().
*
* @access protected
* @param array Items as formatted by formatItem().
* @return string Imploded items.
*/
protected function implodeItems($items) {
$list = '';
foreach ($items as $key => $item) {
if (is_string($item)) {
$list .= $item;
continue;
}
if (is_array($item)) {
$list .= $this->getItemStart() . $key . $this->getListStart() . $this->implodeItems($item) . $this->listEnd . $this->getItemEnd();
}
}
return $list;
}
}

View file

@ -0,0 +1,48 @@
<?php
/**
* DynamicPageList3
* DPL UnorderedList Class
*
* @license GPL-2.0-or-later
* @package DynamicPageList3
*
**/
namespace DPL\Lister;
class UnorderedList extends Lister {
/**
* Listing style for this class.
*
* @var constant
*/
public $style = parent::LIST_UNORDERED;
/**
* List(Section) Start
*
* @var string
*/
public $listStart = '<ul%s>';
/**
* List(Section) End
*
* @var string
*/
public $listEnd = '</ul>';
/**
* Item Start
*
* @var string
*/
public $itemStart = '<li%s>';
/**
* Item End
*
* @var string
*/
public $itemEnd = '</li>';
}

View file

@ -0,0 +1,185 @@
<?php
/**
* DynamicPageList3
* DPL UserFormatList Class
*
* @license GPL-2.0-or-later
* @package DynamicPageList3
*
**/
namespace DPL\Lister;
use DPL\Article;
class UserFormatList extends Lister {
/**
* Listing style for this class.
*
* @var constant
*/
public $style = parent::LIST_USERFORMAT;
/**
* Inline item text separator.
*
* @var string
*/
protected $textSeparator = '';
/**
* Main Constructor
*
* @access public
* @param object \DPL\Parameters
* @param object MediaWiki \Parser
* @return void
*/
public function __construct(\DPL\Parameters $parameters, \Parser $parser) {
parent::__construct($parameters, $parser);
$this->textSeparator = $parameters->getParameter('inlinetext');
$listSeparators = $parameters->getParameter('listseparators');
if (isset($listSeparators[0])) {
$this->listStart = $listSeparators[0];
}
if (isset($listSeparators[1])) {
$this->itemStart = $listSeparators[1];
}
if (isset($listSeparators[2])) {
$this->itemEnd = $listSeparators[2];
}
if (isset($listSeparators[3])) {
$this->listEnd = $listSeparators[3];
}
}
/**
* Format the list of articles.
*
* @access public
* @param array List of \DPL\Article
* @param integer Start position of the array to process.
* @param integer Total objects from the array to process.
* @return string Formatted list.
*/
public function formatList($articles, $start, $count) {
$filteredCount = 0;
$items = [];
for ($i = $start; $i < $start + $count; $i++) {
$article = $articles[$i];
if (empty($article) || empty($article->mTitle)) {
continue;
}
$pageText = null;
if ($this->includePageText) {
$pageText = $this->transcludePage($article, $filteredCount);
} else {
$filteredCount++;
}
$this->rowCount = $filteredCount;
$items[] = $this->formatItem($article, $pageText);
}
$this->rowCount = $filteredCount;
// if requested we sort the table by the contents of a given column
$sortColumn = $this->getTableSortColumn();
if ($sortColumn != 0) {
$rowsKey = [];
foreach ($items as $index => $item) {
$item = trim($item);
if (strpos($item, '|-') === 0) {
$item = explode('|-', $item, 2);
if (count($item) == 2) {
$item = $item[1];
} else {
$rowsKey[$index] = $item;
continue;
}
}
if (strlen($item) > 0) {
$word = explode("\n|", $item);
if (isset($word[0]) && empty($word[0])) {
array_shift($word);
}
if (isset($word[abs($sortColumn) - 1])) {
$test = trim($word[abs($sortColumn) - 1]);
if (strpos($test, '|') > 0) {
$test = trim(explode('|', $test)[1]);
}
$rowsKey[$index] = $test;
}
}
}
if ($sortColumn < 0) {
arsort($rowsKey);
} else {
asort($rowsKey);
}
$newItems = [];
foreach ($rowsKey as $index => $val) {
$newItems[] = $items[$index];
}
$items = $newItems;
}
return $this->listStart . $this->implodeItems($items) . $this->listEnd;
}
/**
* Format a single item.
*
* @access public
* @param object DPL\Article
* @param string [Optional] Page text to include.
* @return string Item HTML
*/
public function formatItem(Article $article, $pageText = null) {
$item = '';
if ($pageText !== null) {
//Include parsed/processed wiki markup content after each item before the closing tag.
$item .= $pageText;
}
$item = $this->getItemStart() . $item . $this->getItemEnd();
$item = $this->replaceTagParameters($item, $article);
return $item;
}
/**
* Return $this->itemStart with attributes replaced.
*
* @access public
* @return string Item Start
*/
public function getItemStart() {
return $this->replaceTagCount($this->itemStart, $this->getRowCount());
}
/**
* Return $this->itemEnd with attributes replaced.
*
* @access public
* @return string Item End
*/
public function getItemEnd() {
return $this->replaceTagCount($this->itemEnd, $this->getRowCount());
}
/**
* Join together items after being processed by formatItem().
*
* @access public
* @param array Items as formatted by formatItem().
* @return string Imploded items.
*/
protected function implodeItems($items) {
return implode($this->textSeparator, $items);
}
}