Content-Length: 27848 | pFad | https://www.mediawiki.org/wiki/Special:Code/MediaWiki/80813

r80813 MediaWiki - Code Review archive

r80813 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r80812‎ | r80813 | r80814 >
Date:13:09, 23 January 2011
Author:krinkle
Status:ok (Comments)
Tags:
Comment:
Bug 26870 - add width/height param to {{filepath:}}
* In addition to r80381
* Expanded comments in SpecialFilePath a little bit
Modified paths:
  • /trunk/phase3/includes/parser/CoreParserFunctions.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialFilepath.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/parser/CoreParserFunctions.php
@@ -615,11 +615,39 @@
616616 '</span>' );
617617 }
618618
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='' ) {
620621 $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' ) {
624652 return array( $url, 'nowiki' => true );
625653 }
626654 return $url;
Index: trunk/phase3/includes/specials/SpecialFilepath.php
@@ -52,12 +52,13 @@
5353 $url = $file->getURL();
5454 $width = $wgRequest->getInt( 'width', -1 );
5555 $height = $wgRequest->getInt( 'height', -1 );
56 -
 56+
 57+ // If a width is requested...
5758 if ( $width != -1 ) {
58 - // If we can, and it's requested,
59 - // change the URL to point to a thumbnail.
6059 $mto = $file->transform( array( 'width' => $width, 'height' => $height ) );
 60+ // ... and we can
6161 if ( $mto && !$mto->isError() ) {
 62+ // ... change the URL to point to a thumbnail.
6263 $url = $mto->getURL();
6364 }
6465 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r80814update RELEASE-NOTES for r80813 and r80381krinkle13:15, 23 January 2011
r80815Follow-up per r80813 CRkrinkle14:34, 23 January 2011
r852561.17wmf1: MFT r80813, r80815, r83798, r84459, r84729, r84820, r84921, r84985,...catrope14:13, 3 April 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r80381Add width parameter to Special:Filepath to allow getting the file path of a t...catrope11:20, 15 January 2011

Comments

#Comment by Reedy (talk | contribs)   13:32, 23 January 2011

Minor comment, when you're doing like intval casts/transformations, and doing them potentially twice on the same variable, it's saner to do it to a temp variable :)

#Comment by Krinkle (talk | contribs)   14:34, 23 January 2011

Thanks, I wasn't sure whether to introduce two additional variables or not, but I performance wise the difference is small although a temp variable does sound faster. Done in r80815.

#Comment by Bawolff (talk | contribs)   23:47, 23 January 2011

Might want to consider supporting Special:Filepath (200 wide 300 high) and Special:Filepath (height of 300), to be consistent with how image links work.

#Comment by Bawolff (talk | contribs)   23:49, 23 January 2011

*Sigh* Lets try that again with nowiki ;)

Might want to consider supporting {{Filepath:foo|200x300}} (200 wide 300 high) and {{Filepath:foo|x300}} (height of 300), to be consistent with how image links work.

#Comment by Krinkle (talk | contribs)   17:04, 28 March 2011

See also r80815. Wikipedia is currently using a funny way with {{#titleparts:}} and {{filepath:}} [1]

We might as well deploy this one ? Tagging 1.17wmf1


Status & tagging log









ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://www.mediawiki.org/wiki/Special:Code/MediaWiki/80813

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy