mirror of
https://github.com/Universal-Omega/DynamicPageList3
synced 2024-11-30 19:04:32 +00:00
PageImages support for mode=gallery on non file pages (#275)
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>
This commit is contained in:
parent
b58a5cb981
commit
df4ff9632a
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace MediaWiki\Extension\DynamicPageList3\Lister;
|
||||
|
||||
use ExtensionRegistry;
|
||||
use MediaWiki\Extension\DynamicPageList3\Article;
|
||||
|
||||
class GalleryList extends Lister {
|
||||
|
@ -50,12 +51,26 @@ class GalleryList extends Lister {
|
|||
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;
|
||||
}
|
||||
// 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->getItemStart() . $item . $this->itemEnd;
|
||||
}
|
||||
|
||||
$item = $this->replaceTagParameters( $item, $article );
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace MediaWiki\Extension\DynamicPageList3\Lister;
|
||||
|
||||
use ExtensionRegistry;
|
||||
use MediaWiki\Extension\DynamicPageList3\Article;
|
||||
use MediaWiki\Extension\DynamicPageList3\LST;
|
||||
use MediaWiki\Extension\DynamicPageList3\Parameters;
|
||||
|
@ -970,6 +971,7 @@ class Lister {
|
|||
*/
|
||||
protected function parseImageUrlWithPath( $article ) {
|
||||
$repoGroup = MediaWikiServices::getInstance()->getRepoGroup();
|
||||
$pageImagesEnabled = ExtensionRegistry::getInstance()->isLoaded( 'PageImages' );
|
||||
|
||||
$imageUrl = '';
|
||||
if ( $article instanceof Article ) {
|
||||
|
@ -984,6 +986,17 @@ class Lister {
|
|||
$fileTitle = Title::makeTitleSafe( NS_FILE, $article->mTitle->getDBKey() );
|
||||
$imageUrl = $repoGroup->getLocalRepo()->newFile( $fileTitle )->getPath();
|
||||
}
|
||||
} elseif ( $pageImagesEnabled ) {
|
||||
$pageImage = self::getPageImage( $article->mID ) ?: false;
|
||||
if ( !$pageImage ) {
|
||||
return '';
|
||||
}
|
||||
$img = $repoGroup->findFile( Title::makeTitle( NS_FILE, $pageImage ) );
|
||||
if ( $img && $img->exists() ) {
|
||||
$imageUrl = $img->getURL();
|
||||
} else {
|
||||
$imageUrl = '';
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$title = Title::newfromText( 'File:' . $article );
|
||||
|
@ -1301,4 +1314,23 @@ class Lister {
|
|||
public function getRowCount() {
|
||||
return $this->rowCount;
|
||||
}
|
||||
|
||||
public function getPageImage( int $pageID ) {
|
||||
$dbr = MediaWikiServices::getInstance()->getDBLoadBalancer()->getConnection( DB_REPLICA );
|
||||
// In the future, a check could be made for page_image too, but page_image_free is the default, should do for now
|
||||
$propValue = $dbr->selectField(
|
||||
// Table to use
|
||||
'page_props',
|
||||
// Field to select
|
||||
'pp_value',
|
||||
// Where conditions
|
||||
[
|
||||
'pp_page' => $pageID,
|
||||
'pp_propname' => 'page_image_free',
|
||||
],
|
||||
__METHOD__
|
||||
);
|
||||
|
||||
return $propValue;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue