2020-11-22 20:03:02 +00:00
< ? php
/**
* DynamicPageList3
* DPL List Class
*
* @ license GPL - 2.0 - or - later
* @ package DynamicPageList3
*
2021-02-22 23:48:01 +00:00
*/
2020-11-22 20:03:02 +00:00
namespace DPL\Lister ;
use DPL\Article ;
use DPL\LST ;
use DPL\UpdateArticle ;
2021-05-30 18:33:21 +00:00
use MediaWiki\MediaWikiServices ;
2020-11-22 20:03:02 +00:00
class Lister {
const LIST_DEFINITION = 1 ;
const LIST_GALLERY = 2 ;
const LIST_HEADING = 3 ;
const LIST_INLINE = 4 ;
const LIST_ORDERED = 5 ;
const LIST_UNORDERED = 6 ;
const LIST_CATEGORY = 7 ;
const LIST_USERFORMAT = 8 ;
/**
* Listing style for this class .
*
2021-02-22 23:48:01 +00:00
* @ var constant
2020-11-22 20:03:02 +00:00
*/
public $style = null ;
/**
* Heading List Start
* Use % s for attribute placement . Example : < div % s >
*
2021-02-22 23:48:01 +00:00
* @ var string
2020-11-22 20:03:02 +00:00
*/
public $headListStart = '' ;
/**
* Heading List End
*
2021-02-22 23:48:01 +00:00
* @ var string
2020-11-22 20:03:02 +00:00
*/
public $headListEnd = '' ;
/**
* Heading List Start
* Use % s for attribute placement . Example : < div % s >
*
2021-02-22 23:48:01 +00:00
* @ var string
2020-11-22 20:03:02 +00:00
*/
public $headItemStart = '' ;
/**
* Heading List End
*
2021-02-22 23:48:01 +00:00
* @ var string
2020-11-22 20:03:02 +00:00
*/
public $headItemEnd = '' ;
/**
* List ( Section ) Start
* Use % s for attribute placement . Example : < div % s >
*
2021-02-22 23:48:01 +00:00
* @ var string
2020-11-22 20:03:02 +00:00
*/
public $listStart = '' ;
/**
* List ( Section ) End
*
2021-02-22 23:48:01 +00:00
* @ var string
2020-11-22 20:03:02 +00:00
*/
public $listEnd = '' ;
/**
* Item Start
* Use % s for attribute placement . Example : < div % s >
*
2021-02-22 23:48:01 +00:00
* @ var string
2020-11-22 20:03:02 +00:00
*/
public $itemStart = '' ;
/**
* Item End
*
2021-02-22 23:48:01 +00:00
* @ var string
2020-11-22 20:03:02 +00:00
*/
public $itemEnd = '' ;
/**
* Extra head list HTML attributes .
*
2021-02-22 23:48:01 +00:00
* @ var array
2020-11-22 20:03:02 +00:00
*/
public $headListAttributes = '' ;
/**
* Extra head item HTML attributes .
*
2021-02-22 23:48:01 +00:00
* @ var array
2020-11-22 20:03:02 +00:00
*/
public $headItemAttributes = '' ;
/**
* Extra list HTML attributes .
*
2021-02-22 23:48:01 +00:00
* @ var array
2020-11-22 20:03:02 +00:00
*/
public $listAttributes = '' ;
/**
* Extra item HTML attributes .
*
2021-02-22 23:48:01 +00:00
* @ var array
2020-11-22 20:03:02 +00:00
*/
public $itemAttributes = '' ;
/**
* Count tipping point to mark a section as dominant .
*
2021-02-22 23:48:01 +00:00
* @ var int
2020-11-22 20:03:02 +00:00
*/
protected $dominantSectionCount = - 1 ;
/**
* Template Suffix
*
2021-02-22 23:48:01 +00:00
* @ var string
2020-11-22 20:03:02 +00:00
*/
protected $templateSuffix = '' ;
/**
* Trim included wiki text .
*
2021-02-22 23:48:01 +00:00
* @ var bool
2020-11-22 20:03:02 +00:00
*/
protected $trimIncluded = false ;
/**
* Trim included wiki text .
*
2021-02-22 23:48:01 +00:00
* @ var bool
2020-11-22 20:03:02 +00:00
*/
protected $escapeLinks = true ;
/**
* Index of the table column to sort by .
*
2021-02-22 23:48:01 +00:00
* @ var int
2020-11-22 20:03:02 +00:00
*/
protected $tableSortColumn = null ;
/**
* Maximum title length .
*
2021-02-22 23:48:01 +00:00
* @ var int
2020-11-22 20:03:02 +00:00
*/
protected $titleMaxLength = null ;
/**
* Section separators that separate transcluded pages / sections of wiki text .
*
2021-02-22 23:48:01 +00:00
* @ var array
2020-11-22 20:03:02 +00:00
*/
protected $sectionSeparators = [];
/**
* Section separators that separate transcluded pages / sections that refer to the same chapter or tempalte of wiki text .
*
2021-02-22 23:48:01 +00:00
* @ var array
2020-11-22 20:03:02 +00:00
*/
protected $multiSectionSeparators = [];
/**
* Include page text in output .
*
2021-02-22 23:48:01 +00:00
* @ var bool
2020-11-22 20:03:02 +00:00
*/
protected $includePageText = false ;
/**
* Maximum length before truncated included wiki text .
*
2021-02-22 23:48:01 +00:00
* @ var int
2020-11-22 20:03:02 +00:00
*/
protected $includePageMaxLength = null ;
/**
* Array of plain text matches for page transclusion . ( include )
*
2021-02-22 23:48:01 +00:00
* @ var array
2020-11-22 20:03:02 +00:00
*/
protected $pageTextMatch = null ;
/**
* Array of regex text matches for page transclusion . ( includematch )
*
2021-02-22 23:48:01 +00:00
* @ var array
2020-11-22 20:03:02 +00:00
*/
protected $pageTextMatchRegex = null ;
/**
* Array of not regex text matches for page transclusion . ( includenotmatch )
*
2021-02-22 23:48:01 +00:00
* @ var array
2020-11-22 20:03:02 +00:00
*/
protected $pageTextMatchNotRegex = null ;
/**
* Parsed wiki text into HTML before running include / includematch / includenotmatch .
*
2021-02-22 23:48:01 +00:00
* @ var bool
2020-11-22 20:03:02 +00:00
*/
protected $includePageParsed = false ;
/**
* Total result count after parsing , transcluding , and such .
*
2021-02-22 23:48:01 +00:00
* @ var int
2020-11-22 20:03:02 +00:00
*/
public $rowCount = 0 ;
/**
* \DPL\Parameters
*
2021-02-22 23:48:01 +00:00
* @ var object
2020-11-22 20:03:02 +00:00
*/
protected $parameters = null ;
/**
* Parser
*
2021-02-22 23:48:01 +00:00
* @ var object
2020-11-22 20:03:02 +00:00
*/
protected $parser = null ;
/**
* Main Constructor
*
* @ access public
* @ param object \DPL\Parameters
* @ param object MediaWiki \Parser
* @ return void
*/
2021-02-22 23:48:01 +00:00
public function __construct ( \DPL\Parameters $parameters , \Parser $parser ) {
$this -> setHeadListAttributes ( $parameters -> getParameter ( 'hlistattr' ) );
$this -> setHeadItemAttributes ( $parameters -> getParameter ( 'hitemattr' ) );
$this -> setListAttributes ( $parameters -> getParameter ( 'listattr' ) );
$this -> setItemAttributes ( $parameters -> getParameter ( 'itemattr' ) );
$this -> setDominantSectionCount ( $parameters -> getParameter ( 'dominantsection' ) );
$this -> setTemplateSuffix ( $parameters -> getParameter ( 'defaulttemplatesuffix' ) );
$this -> setTrimIncluded ( $parameters -> getParameter ( 'includetrim' ) );
$this -> setTableSortColumn ( $parameters -> getParameter ( 'tablesortcol' ) );
$this -> setTitleMaxLength ( $parameters -> getParameter ( 'titlemaxlen' ) );
$this -> setEscapeLinks ( $parameters -> getParameter ( 'escapelinks' ) );
$this -> setSectionSeparators ( $parameters -> getParameter ( 'secseparators' ) );
$this -> setMultiSectionSeparators ( $parameters -> getParameter ( 'multisecseparators' ) );
$this -> setIncludePageText ( $parameters -> getParameter ( 'incpage' ) );
$this -> setIncludePageMaxLength ( $parameters -> getParameter ( 'includemaxlen' ) );
$this -> setPageTextMatch ( ( array ) $parameters -> getParameter ( 'seclabels' ) );
$this -> setPageTextMatchRegex ( ( array ) $parameters -> getParameter ( 'seclabelsmatch' ) );
$this -> setPageTextMatchNotRegex ( ( array ) $parameters -> getParameter ( 'seclabelsnotmatch' ) );
$this -> setIncludePageParsed ( $parameters -> getParameter ( 'incparsed' ) );
2020-11-22 20:03:02 +00:00
$this -> parameters = $parameters ;
$this -> parser = clone $parser ;
}
/**
* Get a new List subclass based on user selection .
*
* @ access public
* @ param string List style .
* @ param object \DPL\Parameters
* @ param object MediaWiki \Parser
* @ return object Lister subclass .
*/
2021-02-22 23:48:01 +00:00
public static function newFromStyle ( $style , \DPL\Parameters $parameters , \Parser $parser ) {
$style = strtolower ( $style );
switch ( $style ) {
2020-11-22 20:03:02 +00:00
case 'category' :
$class = 'CategoryList' ;
break ;
case 'definition' :
$class = 'DefinitionList' ;
break ;
case 'gallery' :
$class = 'GalleryList' ;
break ;
case 'inline' :
$class = 'InlineList' ;
break ;
case 'ordered' :
$class = 'OrderedList' ;
break ;
case 'subpage' :
$class = 'SubPageList' ;
break ;
default :
case 'unordered' :
$class = 'UnorderedList' ;
break ;
case 'userformat' :
$class = 'UserFormatList' ;
break ;
}
$class = '\DPL\Lister\\' . $class ;
2021-02-22 23:48:01 +00:00
return new $class ( $parameters , $parser );
2020-11-22 20:03:02 +00:00
}
/**
* Get the \DPL\Parameters object this object was constructed with .
*
* @ access public
* @ return object \DPL\Parameters
*/
public function getParameters () {
return $this -> parameters ;
}
/**
* Set extra list attributes for header wraps .
*
* @ access public
* @ param string Tag soup attributes , example : this = " that " thing = " no "
* @ return void
*/
2021-02-22 23:48:01 +00:00
public function setHeadListAttributes ( $attributes ) {
$this -> headListAttributes = \Sanitizer :: fixTagAttributes ( $attributes , 'ul' );
2020-11-22 20:03:02 +00:00
}
/**
* Set extra item attributes for header items .
*
* @ access public
* @ param string Tag soup attributes , example : this = " that " thing = " no "
* @ return void
*/
2021-02-22 23:48:01 +00:00
public function setHeadItemAttributes ( $attributes ) {
$this -> headItemAttributes = \Sanitizer :: fixTagAttributes ( $attributes , 'li' );
2020-11-22 20:03:02 +00:00
}
/**
* Set extra list attributes .
*
* @ access public
* @ param string Tag soup attributes , example : this = " that " thing = " no "
* @ return void
*/
2021-02-22 23:48:01 +00:00
public function setListAttributes ( $attributes ) {
$this -> listAttributes = \Sanitizer :: fixTagAttributes ( $attributes , 'ul' );
2020-11-22 20:03:02 +00:00
}
/**
* Set extra item attributes .
*
* @ access public
* @ param string Tag soup attributes , example : this = " that " thing = " no "
* @ return void
*/
2021-02-22 23:48:01 +00:00
public function setItemAttributes ( $attributes ) {
$this -> itemAttributes = \Sanitizer :: fixTagAttributes ( $attributes , 'li' );
2020-11-22 20:03:02 +00:00
}
/**
* Set the count of items to trigger a section as dominant .
*
* @ access public
* @ param integer Count
* @ return void
*/
2021-02-22 23:48:01 +00:00
public function setDominantSectionCount ( $count = - 1 ) {
$this -> dominantSectionCount = intval ( $count );
2020-11-22 20:03:02 +00:00
}
/**
* Get the count of items to trigger a section as dominant .
*
* @ access public
* @ return integer Count
*/
public function getDominantSectionCount () {
return $this -> dominantSectionCount ;
}
/**
* Return the list style .
*
* @ access public
* @ return integer List style constant .
*/
public function getStyle () {
return $this -> style ;
}
/**
* Set the template suffix for whatever the hell uses it .
*
* @ access public
* @ param string Template Suffix
* @ return void
*/
2021-02-22 23:48:01 +00:00
public function setTemplateSuffix ( $suffix = '.default' ) {
2020-11-22 20:03:02 +00:00
$this -> templateSuffix = $suffix ;
}
/**
* Get the template suffix for whatever the hell uses it .
*
* @ access public
* @ return string
*/
public function getTemplateSuffix () {
return $this -> templateSuffix ;
}
/**
* Set if included wiki text should be trimmed .
*
* @ access public
* @ param boolean [ Optional ] Trim
* @ return void
*/
2021-02-22 23:48:01 +00:00
public function setTrimIncluded ( $trim = false ) {
$this -> trimIncluded = boolval ( $trim );
2020-11-22 20:03:02 +00:00
}
/**
* Get if included wiki text should be trimmed .
*
* @ access public
* @ return boolean Trim
*/
public function getTrimIncluded () {
return $this -> trimIncluded ;
}
/**
* Set if links should be escaped ?
* @ todo The naming of this parameter is weird and I am not sure what it does .
*
* @ access public
* @ param boolean [ Optional ] Escape
* @ return void
*/
2021-02-22 23:48:01 +00:00
public function setEscapeLinks ( $escape = true ) {
$this -> escapeLinks = boolval ( $escape );
2020-11-22 20:03:02 +00:00
}
/**
* Get if links should be escaped .
*
* @ access public
* @ return boolean Escape
*/
public function getEscapeLinks () {
return $this -> escapeLinks ;
}
/**
* Set the index of the table column to sort by .
*
* @ access public
* @ param mixed [ Optional ] Integer index or null to disable .
* @ return void
*/
2021-02-22 23:48:01 +00:00
public function setTableSortColumn ( $index = null ) {
$this -> tableSortColumn = $index === null ? null : intval ( $index );
2020-11-22 20:03:02 +00:00
}
/**
* Get the index of the table column to sort by .
*
* @ access public
* @ return mixed Integer index or null to disable .
*/
public function getTableSortColumn () {
return $this -> tableSortColumn ;
}
/**
* Set the maximum title length for display .
*
* @ access public
* @ param mixed [ Optional ] Integer length or null to disable .
* @ return void
*/
2021-02-22 23:48:01 +00:00
public function setTitleMaxLength ( $length = null ) {
$this -> titleMaxLength = $length === null ? null : intval ( $length );
2020-11-22 20:03:02 +00:00
}
/**
* Get the maximum title length for display .
*
* @ access public
* @ return mixed Integer length or null to disable .
*/
public function getTitleMaxLength () {
return $this -> titleMaxLength ;
}
/**
* Set the separators that separate sections of matched page text .
*
* @ access public
* @ param array [ Optional ] Array of section separators .
* @ return void
*/
2021-02-22 23:48:01 +00:00
public function setSectionSeparators ( ? array $separators ) {
2021-02-16 15:52:01 +00:00
$this -> sectionSeparators = ( array ) $separators ? ? [];
2020-11-22 20:03:02 +00:00
}
/**
* Set the separators that separate related sections of matched page text .
*
* @ access public
* @ param array [ Optional ] Array of section separators .
* @ return void
*/
2021-02-22 23:48:01 +00:00
public function setMultiSectionSeparators ( ? array $separators ) {
2021-02-16 15:52:01 +00:00
$this -> multiSectionSeparators = ( array ) $separators ? ? [];
2020-11-22 20:03:02 +00:00
}
/**
* Set if wiki text should be included in output .
*
* @ access public
* @ param boolean [ Optional ] Parse
* @ return void
*/
2021-02-22 23:48:01 +00:00
public function setIncludePageText ( $include = false ) {
$this -> includePageText = boolval ( $include );
2020-11-22 20:03:02 +00:00
}
/**
* Set the maximum included page text length before truncating .
*
* @ access public
* @ param mixed [ Optional ] Integer length or null to disable .
* @ return void
*/
2021-02-22 23:48:01 +00:00
public function setIncludePageMaxLength ( $length = null ) {
$this -> includePageMaxLength = $length === null ? null : intval ( $length );
2020-11-22 20:03:02 +00:00
}
/**
* Set the plain string text matching for page transclusion .
*
* @ access public
* @ param array [ Optional ] Array of plain string matches .
* @ return void
*/
2021-02-22 23:48:01 +00:00
public function setPageTextMatch ( array $pageTextMatch = [] ) {
2020-11-22 20:03:02 +00:00
$this -> pageTextMatch = ( array ) $pageTextMatch ;
}
/**
* Set the regex text matching for page transclusion .
*
* @ access public
* @ param array [ Optional ] Array of regexes .
* @ return void
*/
2021-02-22 23:48:01 +00:00
public function setPageTextMatchRegex ( array $pageTextMatchRegex = [] ) {
2020-11-22 20:03:02 +00:00
$this -> pageTextMatchRegex = ( array ) $pageTextMatchRegex ;
}
/**
* Set the not regex text matching for page transclusion .
*
* @ access public
* @ param array [ Optional ] Array of regexes .
* @ return void
*/
2021-02-22 23:48:01 +00:00
public function setPageTextMatchNotRegex ( array $pageTextMatchNotRegex = [] ) {
2020-11-22 20:03:02 +00:00
$this -> pageTextMatchNotRegex = ( array ) $pageTextMatchNotRegex ;
}
/**
* Set if included wiki text should be parsed before being matched against .
*
* @ access public
* @ param boolean [ Optional ] Parse
* @ return void
*/
2021-02-22 23:48:01 +00:00
public function setIncludePageParsed ( $parse = false ) {
$this -> includePageParsed = boolval ( $parse );
2020-11-22 20:03:02 +00:00
}
/**
* Shortcut to format all articles into a single formatted list .
*
* @ access public
* @ param array List of \DPL\Article
* @ return string Formatted list .
*/
2021-02-22 23:48:01 +00:00
public function format ( $articles ) {
return $this -> formatList ( $articles , 0 , count ( $articles ) );
2020-11-22 20:03:02 +00:00
}
/**
* 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 .
*/
2021-02-22 23:48:01 +00:00
public function formatList ( $articles , $start , $count ) {
2020-11-22 20:03:02 +00:00
$filteredCount = 0 ;
$items = [];
2021-02-22 23:48:01 +00:00
for ( $i = $start ; $i < $start + $count ; $i ++ ) {
2020-11-22 20:03:02 +00:00
$article = $articles [ $i ];
2021-02-22 23:48:01 +00:00
if ( empty ( $article ) || empty ( $article -> mTitle ) ) {
2020-11-22 20:03:02 +00:00
continue ;
}
$pageText = null ;
2021-02-22 23:48:01 +00:00
if ( $this -> includePageText ) {
$pageText = $this -> transcludePage ( $article , $filteredCount );
2020-11-22 20:03:02 +00:00
} else {
$filteredCount ++ ;
}
$this -> rowCount = $filteredCount ;
2021-02-22 23:48:01 +00:00
$items [] = $this -> formatItem ( $article , $pageText );
2020-11-22 20:03:02 +00:00
}
$this -> rowCount = $filteredCount ;
2021-02-22 23:48:01 +00:00
return $this -> getListStart () . $this -> implodeItems ( $items ) . $this -> listEnd ;
2020-11-22 20:03:02 +00:00
}
/**
* Format a single item .
*
* @ access public
* @ param object DPL\Article
* @ param string [ Optional ] Page text to include .
* @ return string Item HTML
*/
2021-02-22 23:48:01 +00:00
public function formatItem ( Article $article , $pageText = null ) {
2021-05-30 18:33:21 +00:00
global $wgLang ;
2020-11-22 20:03:02 +00:00
$item = '' ;
2021-05-30 18:33:21 +00:00
// DPL Article, not MediaWiki.
2020-11-22 20:03:02 +00:00
$date = $article -> getDate ();
2021-02-22 23:48:01 +00:00
if ( $date !== null ) {
2020-11-22 20:03:02 +00:00
$item .= $date . ' ' ;
2021-02-22 23:48:01 +00:00
if ( $article -> mRevision !== null ) {
$item .= '[{{fullurl:' . $article -> mTitle . '|oldid=' . $article -> mRevision . '}} ' . htmlspecialchars ( $article -> mTitle ) . ']' ;
2020-11-22 20:03:02 +00:00
} else {
$item .= $article -> mLink ;
}
} else {
// output the link to the article
$item .= $article -> mLink ;
}
2021-02-22 23:48:01 +00:00
if ( $article -> mSize != null ) {
2020-11-22 20:03:02 +00:00
$byte = 'B' ;
2021-02-22 23:48:01 +00:00
$pageLength = $wgLang -> formatNum ( $article -> mSize );
2020-11-22 20:03:02 +00:00
$item .= " [ { $pageLength } { $byte } ] " ;
}
2021-02-22 23:48:01 +00:00
if ( $article -> mCounter !== null ) {
2021-05-30 18:33:21 +00:00
$contLang = MediaWikiServices :: getInstance () -> getContentLanguage ();
$item .= ' ' . $contLang -> getDirMark () . '(' . wfMessage ( 'hitcounters-nviews' , $wgLang -> formatNum ( $article -> mCounter ) ) -> escaped () . ')' ;
2020-11-22 20:03:02 +00:00
}
2021-02-22 23:48:01 +00:00
if ( $article -> mUserLink !== null ) {
2020-11-22 20:03:02 +00:00
$item .= ' . . [[User:' . $article -> mUser . '|' . $article -> mUser . ']]' ;
2021-02-22 23:48:01 +00:00
if ( $article -> mComment != '' ) {
2020-11-22 20:03:02 +00:00
$item .= ' { ' . $article -> mComment . ' }' ;
}
}
2021-02-22 23:48:01 +00:00
if ( $article -> mContributor !== null ) {
2020-11-22 20:03:02 +00:00
$item .= ' . . [[User:' . $article -> mContributor . '|' . $article -> mContributor . " $article->mContrib ]] " ;
}
2021-02-22 23:48:01 +00:00
if ( ! empty ( $article -> mCategoryLinks ) ) {
$item .= ' . . <small>' . wfMessage ( 'categories' ) . ': ' . implode ( ' | ' , $article -> mCategoryLinks ) . '</small>' ;
2020-11-22 20:03:02 +00:00
}
2021-02-22 23:48:01 +00:00
if ( $this -> getParameters () -> getParameter ( 'addexternallink' ) && $article -> mExternalLink !== null ) {
2020-11-22 20:03:02 +00:00
$item .= ' → ' . $article -> mExternalLink ;
}
2021-02-22 23:48:01 +00:00
if ( $pageText !== null ) {
2020-11-22 20:03:02 +00:00
//Include parsed/processed wiki markup content after each item before the closing tag.
$item .= $pageText ;
}
$item = $this -> getItemStart () . $item . $this -> getItemEnd ();
2021-02-22 23:48:01 +00:00
$item = $this -> replaceTagParameters ( $item , $article );
2020-11-22 20:03:02 +00:00
return $item ;
}
/**
* Return $this -> headListStart with attributes replaced .
*
* @ access public
* @ return string Head List Start
*/
public function getHeadListStart () {
2021-02-22 23:48:01 +00:00
return sprintf ( $this -> headListStart , $this -> headListAttributes );
2020-11-22 20:03:02 +00:00
}
/**
* Return $this -> headItemStart with attributes replaced .
*
* @ access public
* @ return string Head Item Start
*/
public function getHeadItemStart () {
2021-02-22 23:48:01 +00:00
return sprintf ( $this -> headItemStart , $this -> headItemAttributes );
2020-11-22 20:03:02 +00:00
}
/**
* Return $this -> headItemStart with attributes replaced .
*
* @ access public
* @ return string Head Item End
*/
public function getHeadItemEnd () {
return $this -> headItemEnd ;
}
/**
* Return $this -> listStart with attributes replaced .
*
* @ access public
* @ return string List Start
*/
public function getListStart () {
2021-02-22 23:48:01 +00:00
return sprintf ( $this -> listStart , $this -> listAttributes );
2020-11-22 20:03:02 +00:00
}
/**
* Return $this -> itemStart with attributes replaced .
*
* @ access public
* @ return string Item Start
*/
public function getItemStart () {
2021-02-22 23:48:01 +00:00
return sprintf ( $this -> itemStart , $this -> itemAttributes );
2020-11-22 20:03:02 +00:00
}
/**
* Return $this -> itemEnd with attributes replaced .
*
* @ access public
* @ return string Item End
*/
public function getItemEnd () {
return $this -> itemEnd ;
}
/**
* Join together items after being processed by formatItem () .
*
2021-02-22 23:48:01 +00:00
* @ protected
2020-11-22 20:03:02 +00:00
* @ param array Items as formatted by formatItem () .
* @ return string Imploded items .
*/
2021-02-22 23:48:01 +00:00
protected function implodeItems ( $items ) {
return implode ( '' , $items );
2020-11-22 20:03:02 +00:00
}
/**
* Replace user tag parameters .
*
2021-02-22 23:48:01 +00:00
* @ protected
2020-11-22 20:03:02 +00:00
* @ param string Text to perform replacements on .
* @ param object \DPL\Article
* @ return string Text with replacements performed .
*/
2021-02-22 23:48:01 +00:00
protected function replaceTagParameters ( $tag , Article $article ) {
2021-05-30 18:33:21 +00:00
$contLang = MediaWikiServices :: getInstance () -> getContentLanguage ();
2020-11-22 20:03:02 +00:00
2021-05-30 18:33:21 +00:00
$namespaces = $contLang -> getNamespaces ();
2020-11-22 20:03:02 +00:00
2021-02-22 23:48:01 +00:00
if ( strpos ( $tag , '%' ) === false ) {
2020-11-22 20:03:02 +00:00
return $tag ;
}
2021-02-22 23:48:01 +00:00
$imageUrl = $this -> parseImageUrlWithPath ( $article );
2020-11-22 20:03:02 +00:00
$pagename = $article -> mTitle -> getPrefixedText ();
2021-02-22 23:48:01 +00:00
if ( $this -> getEscapeLinks () && ( $article -> mNamespace == NS_CATEGORY || $article -> mNamespace == NS_FILE ) ) {
2020-11-22 20:03:02 +00:00
// links to categories or images need an additional ":"
$pagename = ':' . $pagename ;
}
2021-02-22 23:48:01 +00:00
$tag = str_replace ( '%PAGE%' , $pagename , $tag );
$tag = str_replace ( '%PAGEID%' , $article -> mID , $tag );
$tag = str_replace ( '%NAMESPACE%' , $namespaces [ $article -> mNamespace ], $tag );
$tag = str_replace ( '%IMAGE%' , $imageUrl , $tag );
$tag = str_replace ( '%EXTERNALLINK%' , $article -> mExternalLink , $tag );
$tag = str_replace ( '%EDITSUMMARY%' , $article -> mComment , $tag );
2020-11-22 20:03:02 +00:00
$title = $article -> mTitle -> getText ();
2021-02-22 23:48:01 +00:00
$replaceInTitle = $this -> getParameters () -> getParameter ( 'replaceintitle' );
if ( is_array ( $replaceInTitle ) && count ( $replaceInTitle ) === 2 ) {
$title = preg_replace ( $replaceInTitle [ 0 ], $replaceInTitle [ 1 ], $title );
2020-11-22 20:03:02 +00:00
}
$titleMaxLength = $this -> getTitleMaxLength ();
2021-02-22 23:48:01 +00:00
if ( $titleMaxLength !== null && ( strlen ( $title ) > $titleMaxLength ) ) {
$title = substr ( $title , 0 , $titleMaxLength ) . '...' ;
2020-11-22 20:03:02 +00:00
}
2021-02-22 23:48:01 +00:00
$tag = str_replace ( '%TITLE%' , $title , $tag );
$tag = str_replace ( '%COUNT%' , $article -> mCounter , $tag );
$tag = str_replace ( '%COUNTFS%' , floor ( log ( $article -> mCounter ) * 0.7 ), $tag );
$tag = str_replace ( '%COUNTFS2%' , floor ( sqrt ( log ( $article -> mCounter ) ) ), $tag );
$tag = str_replace ( '%SIZE%' , $article -> mSize , $tag );
$tag = str_replace ( '%SIZEFS%' , floor ( sqrt ( log ( $article -> mSize ) ) * 2.5 - 5 ), $tag );
$tag = str_replace ( '%DATE%' , $article -> getDate (), $tag );
$tag = str_replace ( '%REVISION%' , $article -> mRevision , $tag );
$tag = str_replace ( '%CONTRIBUTION%' , $article -> mContribution , $tag );
$tag = str_replace ( '%CONTRIB%' , $article -> mContrib , $tag );
$tag = str_replace ( '%CONTRIBUTOR%' , $article -> mContributor , $tag );
$tag = str_replace ( '%USER%' , $article -> mUser , $tag );
if ( $article -> mSelTitle != null ) {
if ( $article -> mSelNamespace == 0 ) {
$tag = str_replace ( '%PAGESEL%' , str_replace ( '_' , ' ' , $article -> mSelTitle ), $tag );
2020-11-22 20:03:02 +00:00
} else {
2021-02-22 23:48:01 +00:00
$tag = str_replace ( '%PAGESEL%' , $namespaces [ $article -> mSelNamespace ] . ':' . str_replace ( '_' , ' ' , $article -> mSelTitle ), $tag );
2020-11-22 20:03:02 +00:00
}
}
2021-02-22 23:48:01 +00:00
$tag = str_replace ( '%IMAGESEL%' , str_replace ( '_' , ' ' , $article -> mImageSelTitle ), $tag );
2020-11-22 20:03:02 +00:00
2021-02-22 23:48:01 +00:00
$tag = $this -> replaceTagCategory ( $tag , $article );
2020-11-22 20:03:02 +00:00
return $tag ;
}
/**
* Replace user tag parameters for categories .
*
2021-02-22 23:48:01 +00:00
* @ protected
2020-11-22 20:03:02 +00:00
* @ param string Text to perform replacements on .
* @ param object \DPL\Article
* @ return string Text with replacements performed .
*/
2021-02-22 23:48:01 +00:00
protected function replaceTagCategory ( $tag , Article $article ) {
if ( ! empty ( $article -> mCategoryLinks ) ) {
$tag = str_replace ( '%CATLIST%' , implode ( ', ' , $article -> mCategoryLinks ), $tag );
$tag = str_replace ( '%CATBULLETS%' , '* ' . implode ( " \n * " , $article -> mCategoryLinks ), $tag );
$tag = str_replace ( '%CATNAMES%' , implode ( ', ' , $article -> mCategoryTexts ), $tag );
2020-11-22 20:03:02 +00:00
} else {
2021-02-22 23:48:01 +00:00
$tag = str_replace ( '%CATLIST%' , '' , $tag );
$tag = str_replace ( '%CATBULLETS%' , '' , $tag );
$tag = str_replace ( '%CATNAMES%' , '' , $tag );
2020-11-22 20:03:02 +00:00
}
return $tag ;
}
/**
* Replace the % NR % ( current article sequence number ) in text .
*
2021-02-22 23:48:01 +00:00
* @ protected
2020-11-22 20:03:02 +00:00
* @ param string Text to perform replacements on .
* @ param integer The current article sequence number ( starting from 1 ) .
* @ return string Text with replacements performed .
*/
2021-02-22 23:48:01 +00:00
protected function replaceTagCount ( $tag , $nr ) {
return str_replace ( '%NR%' , $nr , $tag );
2020-11-22 20:03:02 +00:00
}
//
2021-02-22 23:48:01 +00:00
2020-11-22 20:03:02 +00:00
/**
* Format one single item of an entry in the output list ( i . e . one occurence of one item from the include parameter ) .
* @ todo I am not exactly sure how this function differs from replaceTagParameters () . It has something to do with table row formatting . -- Alexia
*
2021-02-22 23:48:01 +00:00
* @ private
2020-11-22 20:03:02 +00:00
* @ param array String pieces to perform replacements on .
* @ param mixed Index of the table row position .
* @ param object \DPL\Article
* @ return void
*/
2021-02-22 23:48:01 +00:00
private function replaceTagTableRow ( & $pieces , $s , Article $article ) {
$tableFormat = $this -> getParameters () -> getParameter ( 'tablerow' );
2020-11-22 20:03:02 +00:00
$firstCall = true ;
2021-02-22 23:48:01 +00:00
foreach ( $pieces as $key => $val ) {
if ( isset ( $tableFormat [ $s ] ) ) {
if ( $s == 0 || $firstCall ) {
$pieces [ $key ] = str_replace ( '%%' , $val , $tableFormat [ $s ] );
2020-11-22 20:03:02 +00:00
} else {
2021-02-22 23:48:01 +00:00
$n = strpos ( $tableFormat [ $s ], '|' );
if ( $n === false || ! ( strpos ( substr ( $tableFormat [ $s ], 0 , $n ), '{' ) === false ) || ! ( strpos ( substr ( $tableFormat [ $s ], 0 , $n ), '[' ) === false ) ) {
$pieces [ $key ] = str_replace ( '%%' , $val , $tableFormat [ $s ] );
2020-11-22 20:03:02 +00:00
} else {
2021-02-22 23:48:01 +00:00
$pieces [ $key ] = str_replace ( '%%' , $val , substr ( $tableFormat [ $s ], $n + 1 ) );
2020-11-22 20:03:02 +00:00
}
}
2021-02-22 23:48:01 +00:00
$pieces [ $key ] = str_replace ( '%IMAGE%' , $this -> parseImageUrlWithPath ( $val ), $pieces [ $key ] );
$pieces [ $key ] = str_replace ( '%PAGE%' , $article -> mTitle -> getPrefixedText (), $pieces [ $key ] );
2020-11-22 20:03:02 +00:00
2021-02-22 23:48:01 +00:00
$pieces [ $key ] = $this -> replaceTagCategory ( $pieces [ $key ], $article );
2020-11-22 20:03:02 +00:00
}
$firstCall = false ;
}
}
/**
* Format one single template argument of one occurence of one item from the include parameter . This is called via a backlink from LST :: includeTemplate () .
* @ todo Again , another poorly documented function with vague functionality . -- Alexia
*
* @ access public
* @ param string Argument to parse and replace .
* @ param mixed Index of the table row position .
* @ param mixed Other part of the index of the table row position ?
* @ param boolean Is this the first time this function was called in this context ?
* @ param integer Maximum text length allowed .
* @ param object \DPL\Article
* @ return strig Formatted text .
*/
2021-02-22 23:48:01 +00:00
public function formatTemplateArg ( $arg , $s , $argNr , $firstCall , $maxLength , Article $article ) {
$tableFormat = $this -> getParameters () -> getParameter ( 'tablerow' );
2020-11-22 20:03:02 +00:00
// we could try to format fields differently within the first call of a template
// currently we do not make such a difference
// if the result starts with a '-' we add a leading space; thus we avoid a misinterpretation of |- as
// a start of a new row (wiki table syntax)
2021-02-22 23:48:01 +00:00
if ( array_key_exists ( " $s . $argNr " , $tableFormat ) ) {
2020-11-22 20:03:02 +00:00
$n = - 1 ;
2021-02-22 23:48:01 +00:00
if ( $s >= 1 && $argNr == 0 && ! $firstCall ) {
$n = strpos ( $tableFormat [ " $s . $argNr " ], '|' );
if ( $n === false || ! ( strpos ( substr ( $tableFormat [ " $s . $argNr " ], 0 , $n ), '{' ) === false ) || ! ( strpos ( substr ( $tableFormat [ " $s . $argNr " ], 0 , $n ), '[' ) === false ) ) {
2020-11-22 20:03:02 +00:00
$n = - 1 ;
}
}
2021-02-22 23:48:01 +00:00
$result = str_replace ( '%%' , $arg , substr ( $tableFormat [ " $s . $argNr " ], $n + 1 ) );
$result = str_replace ( '%PAGE%' , $article -> mTitle -> getPrefixedText (), $result );
$result = str_replace ( '%IMAGE%' , $this -> parseImageUrlWithPath ( $arg ), $result ); //@TODO: This just blindly passes the argument through hoping it is an image. --Alexia
$result = $this -> cutAt ( $maxLength , $result );
if ( strlen ( $result ) > 0 && $result [ 0 ] == '-' ) {
2020-11-22 20:03:02 +00:00
return ' ' . $result ;
} else {
return $result ;
}
}
2021-02-22 23:48:01 +00:00
$result = $this -> cutAt ( $maxLength , $arg );
if ( strlen ( $result ) > 0 && $result [ 0 ] == '-' ) {
2020-11-22 20:03:02 +00:00
return ' ' . $result ;
} else {
return $result ;
}
}
/**
* Truncate a portion of wikitext so that ..
* ... it is not larger that $lim characters
* ... it is balanced in terms of braces , brackets and tags
* ... can be used as content of a wikitable field without spoiling the whole surrounding wikitext structure
*
2021-02-22 23:48:01 +00:00
* @ private
2020-11-22 20:03:02 +00:00
* @ param $lim limit of character count for the result
* @ param $text the wikitext to be truncated
* @ return the truncated text ; note that in some cases it may be slightly longer than the given limit
* if the text is alread shorter than the limit or if the limit is negative , the text
* will be returned without any checks for balance of tags
*/
2021-02-22 23:48:01 +00:00
private function cutAt ( $lim , $text ) {
if ( $lim < 0 ) {
2020-11-22 20:03:02 +00:00
return $text ;
}
2021-02-22 23:48:01 +00:00
return LST :: limitTranscludedText ( $text , $lim );
2020-11-22 20:03:02 +00:00
}
/**
* Prepends an image name with its hash path .
*
2021-02-22 23:48:01 +00:00
* @ protected
2020-11-22 20:03:02 +00:00
* @ param mixed \DPL\Article or string image name of the image ( may start with Image : or File : ) .
* @ return string Image URL
*/
2021-02-22 23:48:01 +00:00
protected function parseImageUrlWithPath ( $article ) {
2020-11-22 20:03:02 +00:00
$imageUrl = '' ;
2021-02-22 23:48:01 +00:00
if ( $article instanceof \DPL\Article ) {
if ( $article -> mNamespace == NS_FILE ) {
2020-11-22 20:03:02 +00:00
// calculate URL for existing images
// $img = Image::newFromName($article->mTitle->getText());
2021-02-22 23:48:01 +00:00
$img = wfFindFile ( \Title :: makeTitle ( NS_FILE , $article -> mTitle -> getText () ) );
if ( $img && $img -> exists () ) {
2020-11-22 20:03:02 +00:00
$imageUrl = $img -> getURL ();
} else {
2021-02-22 23:48:01 +00:00
$fileTitle = \Title :: makeTitleSafe ( NS_FILE , $article -> mTitle -> getDBKey () );
$imageUrl = \RepoGroup :: singleton () -> getLocalRepo () -> newFile ( $fileTitle ) -> getPath ();
2020-11-22 20:03:02 +00:00
}
}
} else {
2021-02-22 23:48:01 +00:00
$title = \Title :: newfromText ( 'File:' . $article );
if ( $title !== null ) {
$fileTitle = \Title :: makeTitleSafe ( 6 , $title -> getDBKey () );
$imageUrl = \RepoGroup :: singleton () -> getLocalRepo () -> newFile ( $fileTitle ) -> getPath ();
2020-11-22 20:03:02 +00:00
}
}
//@TODO: Check this preg_replace. Probably only works for stock file repositories. --Alexia
2021-02-22 23:48:01 +00:00
$imageUrl = preg_replace ( '~^.*images/(.*)~' , '\1' , $imageUrl );
2020-11-22 20:03:02 +00:00
return $imageUrl ;
}
/**
* Transclude a page contents .
*
* @ access public
* @ param object \DPL\Article
* @ param integer Filtered Article Count
* @ return string Page Text
*/
2021-02-22 23:48:01 +00:00
public function transcludePage ( Article $article , & $filteredCount ) {
2020-11-22 20:03:02 +00:00
$matchFailed = false ;
2021-02-22 23:48:01 +00:00
if ( empty ( $this -> pageTextMatch ) || $this -> pageTextMatch [ 0 ] == '*' ) { // include whole article
2020-11-22 20:03:02 +00:00
$title = $article -> mTitle -> getPrefixedText ();
2021-02-22 23:48:01 +00:00
if ( $this -> getStyle () == self :: LIST_USERFORMAT ) {
2020-11-22 20:03:02 +00:00
$pageText = '' ;
} else {
$pageText = '<br/>' ;
}
2021-02-22 23:48:01 +00:00
$text = $this -> parser -> fetchTemplate ( \Title :: newFromText ( $title ) );
if ( ( count ( $this -> pageTextMatchRegex ) <= 0 || $this -> pageTextMatchRegex [ 0 ] == '' || ! preg_match ( $this -> pageTextMatchRegex [ 0 ], $text ) == false ) && ( count ( $this -> pageTextMatchNotRegex ) <= 0 || $this -> pageTextMatchNotRegex [ 0 ] == '' || preg_match ( $this -> pageTextMatchNotRegex [ 0 ], $text ) == false ) ) {
if ( $this -> includePageMaxLength > 0 && ( strlen ( $text ) > $this -> includePageMaxLength ) ) {
$text = LST :: limitTranscludedText ( $text , $this -> includePageMaxLength , ' [[' . $title . '|..→]]' );
2020-11-22 20:03:02 +00:00
}
$filteredCount = $filteredCount + 1 ;
// update article if include=* and updaterules are given
2021-02-22 23:48:01 +00:00
$updateRules = $this -> getParameters () -> getParameter ( 'updaterules' );
$deleteRules = $this -> getParameters () -> getParameter ( 'deleterules' );
if ( ! empty ( $updateRules ) ) {
$ruleOutput = UpdateArticle :: updateArticleByRule ( $title , $text , $updateRules );
2020-11-22 20:03:02 +00:00
// append update message to output
$pageText .= $ruleOutput ;
2021-02-22 23:48:01 +00:00
} elseif ( ! empty ( $deleteRules ) ) {
$ruleOutput = UpdateArticle :: deleteArticleByRule ( $title , $text , $deleteRules );
2020-11-22 20:03:02 +00:00
// append delete message to output
$pageText .= $ruleOutput ;
} else {
// append full text to output
2021-02-22 23:48:01 +00:00
if ( is_array ( $this -> sectionSeparators ) && array_key_exists ( '0' , $this -> sectionSeparators ) ) {
$pageText .= $this -> replaceTagCount ( $this -> sectionSeparators [ 0 ], $filteredCount );
2020-11-22 20:03:02 +00:00
$pieces = [
0 => $text
];
2021-02-22 23:48:01 +00:00
$this -> replaceTagTableRow ( $pieces , 0 , $article );
2020-11-22 20:03:02 +00:00
$pageText .= $pieces [ 0 ];
} else {
$pageText .= $text ;
}
}
} else {
return '' ;
}
} else {
// identify section pieces
$secPiece = [];
$dominantPieces = false ;
// ONE section can be marked as "dominant"; if this section contains multiple entries
// we will create a separate output row for each value of the dominant section
// the values of all other columns will be repeated
2021-02-22 23:48:01 +00:00
foreach ( $this -> pageTextMatch as $s => $sSecLabel ) {
$sSecLabel = trim ( $sSecLabel );
if ( $sSecLabel == '' ) {
2020-11-22 20:03:02 +00:00
break ;
}
// if sections are identified by number we have a % at the beginning
2021-02-22 23:48:01 +00:00
if ( $sSecLabel [ 0 ] == '%' ) {
2020-11-22 20:03:02 +00:00
$sSecLabel = '#' . $sSecLabel ;
}
$maxLength = - 1 ;
2021-02-22 23:48:01 +00:00
if ( $sSecLabel == '-' ) {
2020-11-22 20:03:02 +00:00
// '-' is used as a dummy parameter which will produce no output
// if maxlen was 0 we suppress all output; note that for matching we used the full text
$secPieces = [
''
];
2021-02-22 23:48:01 +00:00
$this -> replaceTagTableRow ( $secPieces , $s , $article );
} elseif ( $sSecLabel [ 0 ] != '{' ) {
$limpos = strpos ( $sSecLabel , '[' );
2020-11-22 20:03:02 +00:00
$cutLink = 'default' ;
$skipPattern = [];
2021-02-22 23:48:01 +00:00
if ( $limpos > 0 && $sSecLabel [ strlen ( $sSecLabel ) - 1 ] == ']' ) {
2020-11-22 20:03:02 +00:00
// regular expressions which define a skip pattern may precede the text
2021-02-22 23:48:01 +00:00
$fmtSec = explode ( '~' , substr ( $sSecLabel , $limpos + 1 , strlen ( $sSecLabel ) - $limpos - 2 ) );
$sSecLabel = substr ( $sSecLabel , 0 , $limpos );
$cutInfo = explode ( " " , $fmtSec [ count ( $fmtSec ) - 1 ], 2 );
$maxLength = intval ( $cutInfo [ 0 ] );
if ( array_key_exists ( '1' , $cutInfo ) ) {
2020-11-22 20:03:02 +00:00
$cutLink = $cutInfo [ 1 ];
}
2021-02-22 23:48:01 +00:00
foreach ( $fmtSec as $skipKey => $skipPat ) {
if ( $skipKey == count ( $fmtSec ) - 1 ) {
2020-11-22 20:03:02 +00:00
continue ;
}
$skipPattern [] = $skipPat ;
}
}
2021-02-22 23:48:01 +00:00
if ( $maxLength < 0 ) {
2020-11-22 20:03:02 +00:00
$maxLength = - 1 ; // without valid limit include whole section
}
}
// find out if the user specified an includematch / includenotmatch condition
2021-02-22 23:48:01 +00:00
if ( is_array ( $this -> pageTextMatchRegex ) && count ( $this -> pageTextMatchRegex ) > $s && ! empty ( $this -> pageTextMatchRegex [ $s ] ) ) {
2020-11-22 20:03:02 +00:00
$mustMatch = $this -> pageTextMatchRegex [ $s ];
} else {
$mustMatch = '' ;
}
2021-02-22 23:48:01 +00:00
if ( is_array ( $this -> pageTextMatchNotRegex ) && count ( $this -> pageTextMatchNotRegex ) > $s && ! empty ( $this -> pageTextMatchNotRegex [ $s ] ) ) {
2020-11-22 20:03:02 +00:00
$mustNotMatch = $this -> pageTextMatchNotRegex [ $s ];
} else {
$mustNotMatch = '' ;
}
// if chapters are selected by number, text or regexp we get the heading from LST::includeHeading
$sectionHeading [ 0 ] = '' ;
2021-02-22 23:48:01 +00:00
if ( $sSecLabel == '-' ) {
2020-11-22 20:03:02 +00:00
$secPiece [ $s ] = $secPieces [ 0 ];
2021-02-22 23:48:01 +00:00
} elseif ( $sSecLabel [ 0 ] == '#' || $sSecLabel [ 0 ] == '@' ) {
$sectionHeading [ 0 ] = substr ( $sSecLabel , 1 );
2020-11-22 20:03:02 +00:00
// Uses LST::includeHeading() from LabeledSectionTransclusion extension to include headings from the page
2021-02-22 23:48:01 +00:00
$secPieces = LST :: includeHeading ( $this -> parser , $article -> mTitle -> getPrefixedText (), substr ( $sSecLabel , 1 ), '' , $sectionHeading , false , $maxLength , $cutLink , $this -> getTrimIncluded (), $skipPattern );
if ( $mustMatch != '' || $mustNotMatch != '' ) {
2020-11-22 20:03:02 +00:00
$secPiecesTmp = $secPieces ;
$offset = 0 ;
2021-02-22 23:48:01 +00:00
foreach ( $secPiecesTmp as $nr => $onePiece ) {
if ( ( $mustMatch != '' && preg_match ( $mustMatch , $onePiece ) == false ) || ( $mustNotMatch != '' && preg_match ( $mustNotMatch , $onePiece ) != false ) ) {
array_splice ( $secPieces , $nr - $offset , 1 );
2020-11-22 20:03:02 +00:00
$offset ++ ;
}
}
}
// if maxlen was 0 we suppress all output; note that for matching we used the full text
2021-02-22 23:48:01 +00:00
if ( $maxLength == 0 ) {
2020-11-22 20:03:02 +00:00
$secPieces = [
''
];
}
2021-02-22 23:48:01 +00:00
$this -> replaceTagTableRow ( $secPieces , $s , $article );
if ( ! array_key_exists ( 0 , $secPieces ) ) {
2020-11-22 20:03:02 +00:00
// avoid matching against a non-existing array element
// and skip the article if there was a match condition
2021-02-22 23:48:01 +00:00
if ( $mustMatch != '' || $mustNotMatch != '' ) {
2020-11-22 20:03:02 +00:00
$matchFailed = true ;
}
break ;
}
$secPiece [ $s ] = $secPieces [ 0 ];
2021-02-22 23:48:01 +00:00
for ( $sp = 1 ; $sp < count ( $secPieces ); $sp ++ ) {
if ( isset ( $this -> multiSectionSeparators [ $s ] ) ) {
$secPiece [ $s ] .= str_replace ( '%SECTION%' , $sectionHeading [ $sp ], $this -> replaceTagCount ( $this -> multiSectionSeparators [ $s ], $filteredCount ) );
2020-11-22 20:03:02 +00:00
}
$secPiece [ $s ] .= $secPieces [ $sp ];
}
2021-02-22 23:48:01 +00:00
if ( $this -> getDominantSectionCount () >= 0 && $s == $this -> getDominantSectionCount () && count ( $secPieces ) > 1 ) {
2020-11-22 20:03:02 +00:00
$dominantPieces = $secPieces ;
}
2021-02-22 23:48:01 +00:00
if ( ( $mustMatch != '' || $mustNotMatch != '' ) && count ( $secPieces ) <= 0 ) {
2020-11-22 20:03:02 +00:00
$matchFailed = true ; // NOTHING MATCHED
break ;
}
2021-02-22 23:48:01 +00:00
} elseif ( $sSecLabel [ 0 ] == '{' ) {
2020-11-22 20:03:02 +00:00
// Uses LST::includeTemplate() from LabeledSectionTransclusion extension to include templates from the page
// primary syntax {template}suffix
2021-02-22 23:48:01 +00:00
$template1 = trim ( substr ( $sSecLabel , 1 , strpos ( $sSecLabel , '}' ) - 1 ) );
$template2 = trim ( str_replace ( '}' , '' , substr ( $sSecLabel , 1 ) ) );
2020-11-22 20:03:02 +00:00
// alternate syntax: {template|surrogate}
2021-02-22 23:48:01 +00:00
if ( $template2 == $template1 && strpos ( $template1 , '|' ) > 0 ) {
$template1 = preg_replace ( '/\|.*/' , '' , $template1 );
$template2 = preg_replace ( '/^.+\|/' , '' , $template2 );
2020-11-22 20:03:02 +00:00
}
//Why the hell was defaultTemplateSuffix be passed all over the place for just fucking here? --Alexia
2021-02-22 23:48:01 +00:00
$secPieces = LST :: includeTemplate ( $this -> parser , $this , $s , $article , $template1 , $template2 , $template2 . $this -> getTemplateSuffix (), $mustMatch , $mustNotMatch , $this -> includePageParsed , implode ( ', ' , $article -> mCategoryLinks ) );
$secPiece [ $s ] = implode ( isset ( $this -> multiSectionSeparators [ $s ] ) ? $this -> replaceTagCount ( $this -> multiSectionSeparators [ $s ], $filteredCount ) : '' , $secPieces );
if ( $this -> getDominantSectionCount () >= 0 && $s == $this -> getDominantSectionCount () && count ( $secPieces ) > 1 ) {
2020-11-22 20:03:02 +00:00
$dominantPieces = $secPieces ;
}
2021-02-22 23:48:01 +00:00
if ( ( $mustMatch != '' || $mustNotMatch != '' ) && count ( $secPieces ) <= 1 && $secPieces [ 0 ] == '' ) {
2020-11-22 20:03:02 +00:00
$matchFailed = true ; // NOTHING MATCHED
break ;
}
} else {
// Uses LST::includeSection() from LabeledSectionTransclusion extension to include labeled sections from the page
2021-02-22 23:48:01 +00:00
$secPieces = LST :: includeSection ( $this -> parser , $article -> mTitle -> getPrefixedText (), $sSecLabel , '' , false , $this -> getTrimIncluded (), $skipPattern );
$secPiece [ $s ] = implode ( isset ( $this -> multiSectionSeparators [ $s ] ) ? $this -> replaceTagCount ( $this -> multiSectionSeparators [ $s ], $filteredCount ) : '' , $secPieces );
if ( $this -> getDominantSectionCount () >= 0 && $s == $this -> getDominantSectionCount () && count ( $secPieces ) > 1 ) {
2020-11-22 20:03:02 +00:00
$dominantPieces = $secPieces ;
}
2021-02-22 23:48:01 +00:00
if ( ( $mustMatch != '' && preg_match ( $mustMatch , $secPiece [ $s ] ) == false ) || ( $mustNotMatch != '' && preg_match ( $mustNotMatch , $secPiece [ $s ] ) != false ) ) {
2020-11-22 20:03:02 +00:00
$matchFailed = true ;
break ;
}
}
// separator tags
2021-02-22 23:48:01 +00:00
if ( is_array ( $this -> sectionSeparators ) && count ( $this -> sectionSeparators ) == 1 ) {
2020-11-22 20:03:02 +00:00
// If there is only one separator tag use it always
2021-02-22 23:48:01 +00:00
$septag [ $s * 2 ] = str_replace ( '%SECTION%' , $sectionHeading [ 0 ], $this -> replaceTagCount ( $this -> sectionSeparators [ 0 ], $filteredCount ) );
} elseif ( isset ( $this -> sectionSeparators [ $s * 2 ] ) ) {
$septag [ $s * 2 ] = str_replace ( '%SECTION%' , $sectionHeading [ 0 ], $this -> replaceTagCount ( $this -> sectionSeparators [ $s * 2 ], $filteredCount ) );
2020-11-22 20:03:02 +00:00
} else {
$septag [ $s * 2 ] = '' ;
}
2021-02-22 23:48:01 +00:00
if ( isset ( $this -> sectionSeparators [ $s * 2 + 1 ] ) ) {
$septag [ $s * 2 + 1 ] = str_replace ( '%SECTION%' , $sectionHeading [ 0 ], $this -> replaceTagCount ( $this -> sectionSeparators [ $s * 2 + 1 ], $filteredCount ) );
2020-11-22 20:03:02 +00:00
} else {
$septag [ $s * 2 + 1 ] = '' ;
}
}
// if there was a match condition on included contents which failed we skip the whole page
2021-02-22 23:48:01 +00:00
if ( $matchFailed ) {
2020-11-22 20:03:02 +00:00
return '' ;
}
$filteredCount = $filteredCount + 1 ;
// assemble parts with separators
$pageText = '' ;
2021-02-22 23:48:01 +00:00
if ( $dominantPieces != false ) {
foreach ( $dominantPieces as $dominantPiece ) {
foreach ( $secPiece as $s => $piece ) {
if ( $s == $this -> getDominantSectionCount () ) {
$pageText .= $this -> joinSectionTagPieces ( $dominantPiece , $septag [ $s * 2 ], $septag [ $s * 2 + 1 ] );
2020-11-22 20:03:02 +00:00
} else {
2021-02-22 23:48:01 +00:00
$pageText .= $this -> joinSectionTagPieces ( $piece , $septag [ $s * 2 ], $septag [ $s * 2 + 1 ] );
2020-11-22 20:03:02 +00:00
}
}
}
} else {
2021-02-22 23:48:01 +00:00
foreach ( $secPiece as $s => $piece ) {
$pageText .= $this -> joinSectionTagPieces ( $piece , $septag [ $s * 2 ], $septag [ $s * 2 + 1 ] );
2020-11-22 20:03:02 +00:00
}
}
}
return $pageText ;
}
/**
* Wrap seciton pieces with start and end tags .
*
2021-02-22 23:48:01 +00:00
* @ protected
2020-11-22 20:03:02 +00:00
* @ param string Piece to be wrapped .
* @ param string Text to prepend .
* @ param string Text to append .
* @ return string Wrapped text .
*/
2021-02-22 23:48:01 +00:00
protected function joinSectionTagPieces ( $piece , $start , $end ) {
2020-11-22 20:03:02 +00:00
return $start . $piece . $end ;
}
/**
* Get the count of listed items after formatting , transcluding , and such .
*
* @ access public
* @ return integer Row Count
*/
public function getRowCount () {
return $this -> rowCount ;
}
}