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 all 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
25 changes: 20 additions & 5 deletions includes/Lister/GalleryList.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace MediaWiki\Extension\DynamicPageList3\Lister;

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

class GalleryList extends Lister {
Expand Down Expand Up @@ -50,12 +51,26 @@
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 {

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.
// Failed to get a page image
$item = $this->getItemStart() . $item . $this->itemEnd . '[[' . $item . ']]';
}
} else {

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.
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 );

Expand Down
32 changes: 32 additions & 0 deletions includes/Lister/Lister.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -970,6 +971,7 @@
*/
protected function parseImageUrlWithPath( $article ) {
$repoGroup = MediaWikiServices::getInstance()->getRepoGroup();
$pageImagesEnabled = ExtensionRegistry::getInstance()->isLoaded( 'PageImages' );

$imageUrl = '';
if ( $article instanceof Article ) {
Expand All @@ -984,6 +986,17 @@
$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 ) );
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 = '';
}
}
} else {
$title = Title::newfromText( 'File:' . $article );
Expand Down Expand Up @@ -1301,4 +1314,23 @@
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