Add wgPortableInfoboxUseFileDescriptionPage (#122)

Fixes #111

Co-authored-by: BlankEclair <blankeclair@waifu.club>
This commit is contained in:
MJ 2024-05-07 11:26:46 -06:00 committed by GitHub
parent 2d964bca4f
commit 1c52d83867
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 13 additions and 2 deletions

View file

@ -21,6 +21,7 @@ You can use several variables to modify extension's behaviour:
- `$wgPortableInfoboxUseHeadings` (bool) - use heading tags for infobox titles and group headers, it may cause incompatibilities with other extensions. (default: true)
- `$wgPortableInfoboxUseTidy` (bool) - use [RemexHtml](https://www.mediawiki.org/wiki/RemexHtml) for validating HTML in infoboxes (default: true)
- `$wgPortableInfoboxResponsiblyOpenCollapsed` (bool) - open collapsed groups when the screen is narrow. (default: true)
- `$wgPortableInfoboxUseFileDescriptionPage` (bool) - control whether or not embedded images in the infobox will link to their file description page instead of directly to the file. (default: false)
## Usage
See: https://community.fandom.com/wiki/Help:Infoboxes

View file

@ -34,6 +34,9 @@
},
"PortableInfoboxResponsiblyOpenCollapsed": {
"value": true
},
"PortableInfoboxUseFileDescriptionPage": {
"value": false
}
},
"MessagesDirs": {

View file

@ -152,7 +152,7 @@ class NodeMedia extends Node {
$mediatype = $fileObj->getMediaType();
$image = [
'url' => $this->resolveImageUrl( $fileObj ),
'url' => $this->resolveImageUrl( $fileObj, $titleObj ),
'name' => $titleObj ? $titleObj->getText() : '',
'alt' => $alt ?? ( $titleObj ? $titleObj->getText() : null ),
'caption' => $caption ?: null,
@ -225,9 +225,16 @@ class NodeMedia extends Node {
/**
* Returns image url for given image title
* @param File|null $file
* @param Title|null $title
* @return string url or '' if image doesn't exist
*/
public function resolveImageUrl( $file ) {
public function resolveImageUrl( $file, $title ) {
global $wgPortableInfoboxUseFileDescriptionPage;
if ( $wgPortableInfoboxUseFileDescriptionPage && $title ) {
return $title->getLocalURL();
}
return $file ? $file->getUrl() : '';
}