Skip to content

Commit

Permalink
Add wgPortableInfoboxUseFileDescriptionPage (#122)
Browse files Browse the repository at this point in the history
Fixes #111

Co-authored-by: BlankEclair <blankeclair@waifu.club>
  • Loading branch information
AverageHelper and BlankEclair committed May 7, 2024
1 parent 2d964bc commit 1c52d83
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
},
"PortableInfoboxResponsiblyOpenCollapsed": {
"value": true
},
"PortableInfoboxUseFileDescriptionPage": {
"value": false
}
},
"MessagesDirs": {
Expand Down
11 changes: 9 additions & 2 deletions includes/services/Parser/Nodes/NodeMedia.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ private function getImageData( $title, $alt, $caption ) {

$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,
Expand Down Expand Up @@ -225,9 +225,16 @@ protected function getImageHelper() {
/**
* 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() : '';
}

Expand Down

0 comments on commit 1c52d83

Please sign in to comment.