mirror of
https://github.com/Universal-Omega/DynamicPageList3
synced 2024-11-28 01:50:34 +00:00
df4ff9632a
In gallery mode, attempting to automatically detect whether: - PageImages is enabled - If it is, if a non file page has a PageImage If both are true, it should try to use the PageImage for the gallery and the page name for the image caption. Right now, it also makes the page name in the caption a link, and points the image link to the page as well. Could not figure out how to make this behavior optional. Gallery mode for file pages should be untouched. Notes: - This behavior is similar, but not a perfect match to DPL_(Wikimedia)'s PageImages in gallery mode. - Unsure if some of the solutions are the most optimal. The way its detecting if PageImages is enabled is a bit clumsy. Co-authored-by: CosmicAlpha <cosmic.alpha24@gmail.com>
80 lines
1.7 KiB
PHP
80 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Extension\DynamicPageList3\Lister;
|
|
|
|
use ExtensionRegistry;
|
|
use MediaWiki\Extension\DynamicPageList3\Article;
|
|
|
|
class GalleryList extends Lister {
|
|
/**
|
|
* Listing style for this class.
|
|
*
|
|
* @var int
|
|
*/
|
|
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.
|
|
*
|
|
* @param Article $article
|
|
* @param string|null $pageText
|
|
* @return string
|
|
*/
|
|
public function formatItem( Article $article, $pageText = null ) {
|
|
$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;
|
|
|
|
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;
|
|
}
|
|
|
|
$item = $this->getItemStart() . $item . $this->itemEnd;
|
|
}
|
|
|
|
$item = $this->replaceTagParameters( $item, $article );
|
|
|
|
return $item;
|
|
}
|
|
}
|