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

PLATFORM-4908 Add ParserAllowExternalImage hook into mediawiki upstream repository #22

Open
wants to merge 2 commits into
base: REL1_33_6-FANDOM
Choose a base branch
from
Open
Changes from all commits
Commits
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
17 changes: 6 additions & 11 deletions includes/parser/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ class Parser {
# RegExp to make image URLs (embeds IPv6 part of EXT_LINK_ADDR)
// phpcs:ignore Generic.Files.LineLength
const EXT_IMAGE_REGEX = '/^(http:\/\/|https:\/\/)((?:\\[(?i:[0-9a-f:.]+)\\])?[^][<>"\\x00-\\x20\\x7F\p{Zs}\x{FFFD}]+)
\\/([A-Za-z0-9_.,~%\\-+&;#*?!=()@\\x80-\\xFF]+)\\.((?i)gif|png|jpg|jpeg)$/Sxu';
\\/((([A-Za-z0-9_.,~%\\-+&;#*?!=()@\\x80-\\xFF]+)\\.((?i)gif|png|jpg|jpeg|webp|ico|svg))|
([0-9a-fA-F]{8}\\-[0-9a-fA-F]{4}\\-[0-9a-fA-F]{4}\\-[0-9a-fA-F]{4}\\-[0-9a-fA-F]{12})(\\/|\\?|$))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think they will agree to add this line to upstream (allow to hotlink static assets like https://static.fandom-dev.pl/13baa06b-d6eb-48fb-a75a-25afa0d37929/thumbnail/width/348/height/348 )

((?:\[(?i:[0-9a-f:.]+)\])?[^][<>"\x00-\x20\x7F\p{Zs}\x{FFFD}]+)?$/Sxu';

# Regular expression for a non-newline space
const SPACE_NOT_NL = '(?:\t|&nbsp;|&\#0*160;|&\#[Xx]0*[Aa]0;|\p{Zs})';
Expand Down Expand Up @@ -2129,24 +2131,17 @@ private function maybeMakeExternalImage( $url ) {
$imagematch = false;
}

// Fandom change - start (@author ttomalak)
// allow fandom image links PLATFORM-4871
$allowed = Hooks::isRegistered( 'ParserAllowExternalImage' )
&& Hooks::run( 'ParserAllowExternalImage', [ $url ] );

if ( $this->mOptions->getAllowExternalImages()
|| $allowed
|| ( $imagesexception && $imagematch )
|| ( $imagesexception && $imagematch )
) {
if ( preg_match( self::EXT_IMAGE_REGEX, $url ) || $allowed ) {
if ( preg_match( self::EXT_IMAGE_REGEX, $url ) ) {
# Image found
$text = Linker::makeExternalImage( $url );
}
}
if ( !$text && $this->mOptions->getEnableImageWhitelist()
&& ( preg_match( self::EXT_IMAGE_REGEX, $url ) || $allowed )
&& preg_match( self::EXT_IMAGE_REGEX, $url )
) {
// Fandom change - end
$whitelist = explode(
"\n",
wfMessage( 'external_image_whitelist' )->inContentLanguage()->text()
Expand Down