2020-11-22 20:02:14 +00:00
|
|
|
<?php
|
|
|
|
|
2022-03-13 19:57:34 +00:00
|
|
|
namespace MediaWiki\Extension\DynamicPageList3\Heading;
|
2020-11-22 20:02:14 +00:00
|
|
|
|
2022-03-13 19:57:34 +00:00
|
|
|
use MediaWiki\Extension\DynamicPageList3\Lister\Lister;
|
|
|
|
use MediaWiki\Extension\DynamicPageList3\Parameters;
|
2020-11-22 20:02:14 +00:00
|
|
|
|
|
|
|
class TieredHeading extends Heading {
|
|
|
|
/**
|
|
|
|
* List(Section) Start
|
|
|
|
*
|
2021-02-22 23:48:01 +00:00
|
|
|
* @var string
|
2020-11-22 20:02:14 +00:00
|
|
|
*/
|
|
|
|
public $listStart = '<div%s>';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* List(Section) End
|
|
|
|
*
|
2021-02-22 23:48:01 +00:00
|
|
|
* @var string
|
2020-11-22 20:02:14 +00:00
|
|
|
*/
|
|
|
|
public $listEnd = '</div>';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Item Start
|
|
|
|
*
|
2021-02-22 23:48:01 +00:00
|
|
|
* @var string
|
2020-11-22 20:02:14 +00:00
|
|
|
*/
|
|
|
|
public $itemStart = '<h%2$s%1$s>';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Item End
|
|
|
|
*
|
2021-02-22 23:48:01 +00:00
|
|
|
* @var string
|
2020-11-22 20:02:14 +00:00
|
|
|
*/
|
|
|
|
public $itemEnd = '</h%2$s>';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tier Level
|
|
|
|
*
|
2021-02-22 23:48:01 +00:00
|
|
|
* @var string
|
2020-11-22 20:02:14 +00:00
|
|
|
*/
|
|
|
|
private $tierLevel = 'eader';
|
|
|
|
|
|
|
|
/**
|
2021-10-01 22:52:30 +00:00
|
|
|
* @param Parameters $parameters
|
2020-11-22 20:02:14 +00:00
|
|
|
*/
|
2021-02-22 23:48:01 +00:00
|
|
|
public function __construct( Parameters $parameters ) {
|
|
|
|
parent::__construct( $parameters );
|
2021-10-01 22:52:30 +00:00
|
|
|
|
2021-02-22 23:48:01 +00:00
|
|
|
$this->tierLevel = substr( $parameters->getParameter( 'headingmode' ), 1 );
|
2020-11-22 20:02:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Format a heading group.
|
|
|
|
*
|
2021-10-01 22:52:30 +00:00
|
|
|
* @param int $headingStart
|
|
|
|
* @param int $headingCount
|
|
|
|
* @param string $headingLink
|
|
|
|
* @param array $articles
|
|
|
|
* @param Lister $lister
|
|
|
|
* @return string
|
2020-11-22 20:02:14 +00:00
|
|
|
*/
|
2021-02-22 23:48:01 +00:00
|
|
|
public function formatItem( $headingStart, $headingCount, $headingLink, $articles, Lister $lister ) {
|
2020-11-22 20:02:14 +00:00
|
|
|
$item = '';
|
|
|
|
|
|
|
|
$item .= $this->getItemStart() . $headingLink;
|
2021-10-01 22:52:30 +00:00
|
|
|
|
2021-02-22 23:48:01 +00:00
|
|
|
if ( $this->showHeadingCount ) {
|
|
|
|
$item .= $this->articleCountMessage( $headingCount );
|
2020-11-22 20:02:14 +00:00
|
|
|
}
|
2021-10-01 22:52:30 +00:00
|
|
|
|
2020-11-22 20:02:14 +00:00
|
|
|
$item .= $this->getItemEnd();
|
2021-02-22 23:48:01 +00:00
|
|
|
$item .= $lister->formatList( $articles, $headingStart, $headingCount );
|
2020-11-22 20:02:14 +00:00
|
|
|
|
|
|
|
return $item;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return $this->listStart with attributes replaced.
|
|
|
|
*
|
2021-10-01 22:52:30 +00:00
|
|
|
* @return string
|
2020-11-22 20:02:14 +00:00
|
|
|
*/
|
|
|
|
public function getListStart() {
|
2021-02-22 23:48:01 +00:00
|
|
|
return sprintf( $this->listStart, $this->listAttributes );
|
2020-11-22 20:02:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return $this->itemStart with attributes replaced.
|
|
|
|
*
|
2021-10-01 22:52:30 +00:00
|
|
|
* @return string
|
2020-11-22 20:02:14 +00:00
|
|
|
*/
|
|
|
|
public function getItemStart() {
|
2021-02-22 23:48:01 +00:00
|
|
|
return sprintf( $this->itemStart, $this->itemAttributes, $this->tierLevel );
|
2020-11-22 20:02:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return $this->itemEnd with attributes replaced.
|
|
|
|
*
|
2021-10-01 22:52:30 +00:00
|
|
|
* @return string
|
2020-11-22 20:02:14 +00:00
|
|
|
*/
|
|
|
|
public function getItemEnd() {
|
2021-02-22 23:48:01 +00:00
|
|
|
return sprintf( $this->itemEnd, $this->itemAttributes, $this->tierLevel );
|
2020-11-22 20:02:14 +00:00
|
|
|
}
|
|
|
|
}
|