DynamicPageList3/includes/Lister/GalleryList.php

79 lines
1.7 KiB
PHP
Raw Normal View History

2020-11-22 20:03:02 +00:00
<?php
namespace MediaWiki\Extension\DynamicPageList3\Lister;
2020-11-22 20:03:02 +00:00
use ExtensionRegistry;
use MediaWiki\Extension\DynamicPageList3\Article;
2020-11-22 20:03:02 +00:00
class GalleryList extends Lister {
/**
* Listing style for this class.
*
2021-10-01 22:52:30 +00:00
* @var int
2020-11-22 20:03:02 +00:00
*/
public $style = parent::LIST_GALLERY;
/**
* List(Section) Start
*
2021-02-22 23:48:01 +00:00
* @var string
2020-11-22 20:03:02 +00:00
*/
public $listStart = '<gallery%s>';
/**
* List(Section) End
*
2021-02-22 23:48:01 +00:00
* @var string
2020-11-22 20:03:02 +00:00
*/
public $listEnd = '</gallery>';
/**
* Item Start
*
2021-02-22 23:48:01 +00:00
* @var string
2020-11-22 20:03:02 +00:00
*/
public $itemStart = "\n";
/**
* Item End
*
2021-02-22 23:48:01 +00:00
* @var string
2020-11-22 20:03:02 +00:00
*/
2021-10-01 22:52:30 +00:00
public $itemEnd = '|';
2020-11-22 20:03:02 +00:00
/**
* Format an item.
*
2021-10-01 22:52:30 +00:00
* @param Article $article
* @param string|null $pageText
* @return string
2020-11-22 20:03:02 +00:00
*/
2021-02-22 23:48:01 +00:00
public function formatItem( Article $article, $pageText = null ) {
2020-11-22 20:03:02 +00:00
$item = $article->mTitle;
// If PageImages is loaded and we are not in the file namespace, attempt to assemble a gallery of PageImages
if ( $article->mNamespace !== NS_FILE && ExtensionRegistry::getInstance()->isLoaded( 'PageImages' ) ) {
$pageImage = $this->getPageImage( $article->mID ) ?: false;
2024-05-24 16:12:46 +00:00
if ( $pageImage ) {
// Successfully got a page image, wrapping it
$item = $this->getItemStart() . $pageImage . '| [[' . $item . ']]' . $this->itemEnd . 'link=' . $item;
} else {
// Failed to get a page image
$item = $this->getItemStart() . $item . $this->itemEnd . '[[' . $item . ']]';
}
} else {
if ( $pageText !== null ) {
// Include parsed/processed wiki markup content after each item before the closing tag.
$item .= $pageText;
}
2020-11-22 20:03:02 +00:00
$item = $this->getItemStart() . $item . $this->itemEnd;
}
2020-11-22 20:03:02 +00:00
2021-02-22 23:48:01 +00:00
$item = $this->replaceTagParameters( $item, $article );
2020-11-22 20:03:02 +00:00
return $item;
}
}