From 3cc14d4bf85f1c756ed712ca139ce3ab20721f1b Mon Sep 17 00:00:00 2001 From: Krinkle Date: Sun, 23 Jan 2011 13:09:15 +0000 Subject: [PATCH] Bug 26870 - add width/height param to {{filepath:}} * In addition to r80381 * Expanded comments in SpecialFilePath a little bit --- includes/parser/CoreParserFunctions.php | 36 ++++++++++++++++++++++--- includes/specials/SpecialFilepath.php | 7 ++--- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/includes/parser/CoreParserFunctions.php b/includes/parser/CoreParserFunctions.php index a98c5d3e44..b0f2f2586b 100644 --- a/includes/parser/CoreParserFunctions.php +++ b/includes/parser/CoreParserFunctions.php @@ -615,11 +615,39 @@ class CoreParserFunctions { '' ); } - public static function filepath( $parser, $name='', $option='' ) { + // Usage {{filepath|300}}, {{filepath|nowiki}}, {{filepath|nowiki|300}} or {{filepath|300|nowiki}} + public static function filepath( $parser, $name='', $argA='', $argB='' ) { $file = wfFindFile( $name ); - if( $file ) { - $url = $file->getFullUrl(); - if( $option == 'nowiki' ) { + $size = ''; + + if ( intval( $argB ) > 0 ) { + // {{filepath: | option | size }} + $size = intval( $argB ); + $option = $argA; + + } elseif ( intval( $argA ) > 0 ) { + // {{filepath: | size [|option] }} + $size = intval( $argA ); + $option = $argB; + + } else { + // {{filepath: [|option] }} + $option = $argA; + } + + if ( $file ) { + $url = $file->getUrl(); + + // If a size is requested... + if ( is_integer( $size ) ) { + $mto = $file->transform( array( 'width' => $size ) ); + // ... and we can + if ( $mto && !$mto->isError() ) { + // ... change the URL to point to a thumbnail. + $url = wfExpandUrl( $mto->getUrl() ); + } + } + if ( $option == 'nowiki' ) { return array( $url, 'nowiki' => true ); } return $url; diff --git a/includes/specials/SpecialFilepath.php b/includes/specials/SpecialFilepath.php index 46d340aecb..3e27b4353c 100644 --- a/includes/specials/SpecialFilepath.php +++ b/includes/specials/SpecialFilepath.php @@ -52,12 +52,13 @@ class SpecialFilepath extends SpecialPage { $url = $file->getURL(); $width = $wgRequest->getInt( 'width', -1 ); $height = $wgRequest->getInt( 'height', -1 ); - + + // If a width is requested... if ( $width != -1 ) { - // If we can, and it's requested, - // change the URL to point to a thumbnail. $mto = $file->transform( array( 'width' => $width, 'height' => $height ) ); + // ... and we can if ( $mto && !$mto->isError() ) { + // ... change the URL to point to a thumbnail. $url = $mto->getURL(); } } -- 2.20.1