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) - `$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) - `$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) - `$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 ## Usage
See: https://community.fandom.com/wiki/Help:Infoboxes See: https://community.fandom.com/wiki/Help:Infoboxes

View file

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

View file

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