Bug 26870 - add width/height param to {{filepath:}}
authorKrinkle <krinkle@users.mediawiki.org>
Sun, 23 Jan 2011 13:09:15 +0000 (13:09 +0000)
committerKrinkle <krinkle@users.mediawiki.org>
Sun, 23 Jan 2011 13:09:15 +0000 (13:09 +0000)
* In addition to r80381
* Expanded comments in SpecialFilePath a little bit

includes/parser/CoreParserFunctions.php
includes/specials/SpecialFilepath.php

index a98c5d3..b0f2f25 100644 (file)
@@ -615,11 +615,39 @@ class CoreParserFunctions {
                                '</span>' );
        }
 
-       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;
index 46d340a..3e27b43 100644 (file)
@@ -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();
                                        }
                                }