Index: trunk/phase3/includes/parser/CoreParserFunctions.php |
— | — | @@ -615,11 +615,39 @@ |
616 | 616 | '</span>' ); |
617 | 617 | } |
618 | 618 | |
619 | | - public static function filepath( $parser, $name='', $option='' ) { |
| 619 | + // Usage {{filepath|300}}, {{filepath|nowiki}}, {{filepath|nowiki|300}} or {{filepath|300|nowiki}} |
| 620 | + public static function filepath( $parser, $name='', $argA='', $argB='' ) { |
620 | 621 | $file = wfFindFile( $name ); |
621 | | - if( $file ) { |
622 | | - $url = $file->getFullUrl(); |
623 | | - if( $option == 'nowiki' ) { |
| 622 | + $size = ''; |
| 623 | + |
| 624 | + if ( intval( $argB ) > 0 ) { |
| 625 | + // {{filepath: | option | size }} |
| 626 | + $size = intval( $argB ); |
| 627 | + $option = $argA; |
| 628 | + |
| 629 | + } elseif ( intval( $argA ) > 0 ) { |
| 630 | + // {{filepath: | size [|option] }} |
| 631 | + $size = intval( $argA ); |
| 632 | + $option = $argB; |
| 633 | + |
| 634 | + } else { |
| 635 | + // {{filepath: [|option] }} |
| 636 | + $option = $argA; |
| 637 | + } |
| 638 | + |
| 639 | + if ( $file ) { |
| 640 | + $url = $file->getUrl(); |
| 641 | + |
| 642 | + // If a size is requested... |
| 643 | + if ( is_integer( $size ) ) { |
| 644 | + $mto = $file->transform( array( 'width' => $size ) ); |
| 645 | + // ... and we can |
| 646 | + if ( $mto && !$mto->isError() ) { |
| 647 | + // ... change the URL to point to a thumbnail. |
| 648 | + $url = wfExpandUrl( $mto->getUrl() ); |
| 649 | + } |
| 650 | + } |
| 651 | + if ( $option == 'nowiki' ) { |
624 | 652 | return array( $url, 'nowiki' => true ); |
625 | 653 | } |
626 | 654 | return $url; |
Index: trunk/phase3/includes/specials/SpecialFilepath.php |
— | — | @@ -52,12 +52,13 @@ |
53 | 53 | $url = $file->getURL(); |
54 | 54 | $width = $wgRequest->getInt( 'width', -1 ); |
55 | 55 | $height = $wgRequest->getInt( 'height', -1 ); |
56 | | - |
| 56 | + |
| 57 | + // If a width is requested... |
57 | 58 | if ( $width != -1 ) { |
58 | | - // If we can, and it's requested, |
59 | | - // change the URL to point to a thumbnail. |
60 | 59 | $mto = $file->transform( array( 'width' => $width, 'height' => $height ) ); |
| 60 | + // ... and we can |
61 | 61 | if ( $mto && !$mto->isError() ) { |
| 62 | + // ... change the URL to point to a thumbnail. |
62 | 63 | $url = $mto->getURL(); |
63 | 64 | } |
64 | 65 | } |