Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PageImages support for mode=gallery on non file pages #275

Merged
merged 34 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
5b9d46b
PageImages support
domino-1 Dec 31, 2022
d5823f9
Added Ext:PageImages support + comments
domino-1 Dec 31, 2022
6c14400
inheritance
domino-1 Dec 31, 2022
78879e7
Merge branch 'Universal-Omega:master' into update
domino-1 May 23, 2024
5cee7de
Merge pull request #1 from DogcraftNet/update
domino-1 May 23, 2024
ad49c6b
Code cleanup and 1.40 compatibility
domino-1 May 23, 2024
77abf5a
Update includes/Lister/GalleryList.php
domino-1 May 23, 2024
ddebdfc
Update includes/Lister/GalleryList.php
domino-1 May 23, 2024
261f874
Update includes/Lister/GalleryList.php
domino-1 May 23, 2024
502240f
Update includes/Lister/GalleryList.php
domino-1 May 23, 2024
c33d2c5
Update includes/Lister/Lister.php
domino-1 May 23, 2024
299a13a
Update includes/Lister/Lister.php
domino-1 May 23, 2024
19fa71d
Update includes/Lister/Lister.php
domino-1 May 23, 2024
e82df99
Update includes/Lister/Lister.php
domino-1 May 23, 2024
c1032aa
Update includes/Lister/Lister.php
domino-1 May 23, 2024
d25e905
Update includes/Lister/Lister.php
domino-1 May 23, 2024
2613619
Update includes/Lister/Lister.php
domino-1 May 23, 2024
081c652
Update includes/Lister/Lister.php
domino-1 May 23, 2024
d4b15e0
Update includes/Lister/Lister.php
domino-1 May 23, 2024
d0ec423
Update includes/Lister/Lister.php
domino-1 May 23, 2024
0ef4efc
did suggested change by Universal-Omega
domino-1 May 23, 2024
2c12508
Update includes/Lister/Lister.php
domino-1 May 23, 2024
90af623
Update includes/Lister/Lister.php
domino-1 May 23, 2024
b25f157
deleted redundant comments
domino-1 May 23, 2024
1fb6ee3
Merge branch 'master' of https://github.com/domino-1/DynamicPageList3
domino-1 May 23, 2024
59bc79b
Update includes/Lister/GalleryList.php
domino-1 May 23, 2024
911a84a
formatting else block
domino-1 May 23, 2024
99728bf
Update includes/Lister/GalleryList.php
domino-1 May 23, 2024
c61dec1
Update includes/Lister/GalleryList.php
domino-1 May 23, 2024
5d14c52
Update includes/Lister/GalleryList.php
domino-1 May 23, 2024
d2860be
Update includes/Lister/Lister.php
domino-1 May 23, 2024
5cd4748
Update includes/Lister/Lister.php
domino-1 May 23, 2024
98087be
Merge branch 'master' of https://github.com/domino-1/DynamicPageList3
domino-1 May 23, 2024
86a6f37
removed unused PageImages\PageImages imports and moved ExtensionRegis…
domino-1 May 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions includes/Lister/GalleryList.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace MediaWiki\Extension\DynamicPageList3\Lister;

use MediaWiki\Extension\DynamicPageList3\Article;
use PageImages\PageImages;
use ExtensionRegistry;
domino-1 marked this conversation as resolved.
Show resolved Hide resolved

class GalleryList extends Lister {
/**
Expand Down Expand Up @@ -50,12 +52,31 @@
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' ) ) {
domino-1 marked this conversation as resolved.
Show resolved Hide resolved

$pageImage = $this->getPageImage( $article->mID ) ?: false;

if ( $pageImage ) {
// Successfully got a pageimage, wrapping it
domino-1 marked this conversation as resolved.
Show resolved Hide resolved
$item = $this->getItemStart() . $pageImage . "| [[" . $item . "]]" . $this->itemEnd . "link=" . $item . "";
domino-1 marked this conversation as resolved.
Show resolved Hide resolved
}
else {
Fixed Show fixed Hide fixed
domino-1 marked this conversation as resolved.
Show resolved Hide resolved
// Failed to get a pageimage
domino-1 marked this conversation as resolved.
Show resolved Hide resolved
$item = $this->getItemStart() . $item . $this->itemEnd . "[[" . $item . "]]";
domino-1 marked this conversation as resolved.
Show resolved Hide resolved
}

domino-1 marked this conversation as resolved.
Show resolved Hide resolved
}
else {
Fixed Show fixed Hide fixed
domino-1 marked this conversation as resolved.
Show resolved Hide resolved

domino-1 marked this conversation as resolved.
Show resolved Hide resolved
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;

domino-1 marked this conversation as resolved.
Show resolved Hide resolved
}

$item = $this->replaceTagParameters( $item, $article );

Expand Down
37 changes: 37 additions & 0 deletions includes/Lister/Lister.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use MediaWiki\Extension\DynamicPageList3\Parameters;
use MediaWiki\Extension\DynamicPageList3\UpdateArticle;
use MediaWiki\MediaWikiServices;
use PageImages\PageImages;
use ExtensionRegistry;
domino-1 marked this conversation as resolved.
Show resolved Hide resolved
use Parser;
use RequestContext;
use Sanitizer;
Expand Down Expand Up @@ -970,6 +972,7 @@
*/
protected function parseImageUrlWithPath( $article ) {
$repoGroup = MediaWikiServices::getInstance()->getRepoGroup();
$pageImagesEnabled = ExtensionRegistry::getInstance()->isLoaded( 'PageImages' );

$imageUrl = '';
if ( $article instanceof Article ) {
Expand All @@ -984,6 +987,20 @@
$fileTitle = Title::makeTitleSafe( NS_FILE, $article->mTitle->getDBKey() );
$imageUrl = $repoGroup->getLocalRepo()->newFile( $fileTitle )->getPath();
}
} else if ( $pageImagesEnabled ) {
domino-1 marked this conversation as resolved.
Show resolved Hide resolved

domino-1 marked this conversation as resolved.
Show resolved Hide resolved
$pageImage = self::getPageImage( $article->mID ) ?: false;
if ( !$pageImage ) {
return "";
domino-1 marked this conversation as resolved.
Show resolved Hide resolved
}
$img = $repoGroup->findFile( Title::makeTitle( NS_FILE, $pageImage ) );
Dismissed Show dismissed Hide dismissed
if ( $img && $img->exists() ) {
$imageUrl = $img->getURL();
} else {

Check warning

Code scanning / Phpmd (reported by Codacy)

Use return statements instead of else expression Warning

The method parseImageUrlWithPath uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.

Check warning

Code scanning / Phpmd (reported by Codacy)

Use return statements instead of else expression Warning

The method formatItem uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
$imageUrl = "";
domino-1 marked this conversation as resolved.
Show resolved Hide resolved
//$fileTitle = Title::makeTitleSafe( NS_FILE, $article->mTitle->getDBKey() );
domino-1 marked this conversation as resolved.
Show resolved Hide resolved
//$imageUrl = $repoGroup->getLocalRepo()->newFile( $fileTitle )->getPath();
}
}
} else {
$title = Title::newfromText( 'File:' . $article );
Expand Down Expand Up @@ -1301,4 +1318,24 @@
public function getRowCount() {
return $this->rowCount;
}

domino-1 marked this conversation as resolved.
Show resolved Hide resolved

public function getPageImage( int $pageID ) {

domino-1 marked this conversation as resolved.
Show resolved Hide resolved
$dbl = MediaWikiServices::getInstance()->getDBLoadBalancer();
domino-1 marked this conversation as resolved.
Show resolved Hide resolved
$dbr = $dbl->getConnection( DB_REPLICA );
domino-1 marked this conversation as resolved.
Show resolved Hide resolved
//in the future, a check could be made for page_image too, but page_image_free is the default, should do for now
domino-1 marked this conversation as resolved.
Show resolved Hide resolved
$propValue = $dbr->selectField( 'page_props', // table to use
domino-1 marked this conversation as resolved.
Show resolved Hide resolved
'pp_value', // Field to select
domino-1 marked this conversation as resolved.
Show resolved Hide resolved
[ 'pp_page' => $pageID, 'pp_propname' => "page_image_free" ], // where conditions
domino-1 marked this conversation as resolved.
Show resolved Hide resolved
__METHOD__
domino-1 marked this conversation as resolved.
Show resolved Hide resolved
);
if ( $propValue === false ) {
domino-1 marked this conversation as resolved.
Show resolved Hide resolved
// No prop stored for this page
return false;
}

return $propValue;
}

domino-1 marked this conversation as resolved.
Show resolved Hide resolved
}
Loading