r111199 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111198‎ | r111199 | r111200 >
Date:20:52, 10 February 2012
Author:aaron
Status:resolved (Comments)
Tags:
Comment:
* Removed thumb.php comment about ProofreadPage, page numbers are more general.
* Added ExtractThumbParameters hook handlers for ogg and tiff handler extensions.
Modified paths:
  • /trunk/extensions/OggHandler/OggHandler.php (modified) (history)
  • /trunk/extensions/OggHandler/OggHandler_body.php (modified) (history)
  • /trunk/extensions/PagedTiffHandler/PagedTiffHandler.php (modified) (history)
  • /trunk/extensions/PagedTiffHandler/PagedTiffHandler_body.php (modified) (history)
  • /trunk/phase3/thumb.php (modified) (history)

Diff [purge]

Index: trunk/phase3/thumb.php
@@ -271,7 +271,6 @@
272272 }
273273
274274 // Check if the parameters can be extracted from the thumbnail name...
275 - // @TODO: remove 'page' stuff and make ProofreadPage handle it via hook.
276275 if ( preg_match( '!^(page(\d*)-)*(\d*)px-[^/]*$!', $thumbname, $matches ) ) {
277276 list( /* all */, $pagefull, $pagenum, $size ) = $matches;
278277 $params['width'] = $size;
Index: trunk/extensions/OggHandler/OggHandler.php
@@ -30,6 +30,8 @@
3131 $wgExtensionMessagesFiles['OggHandlerMagic'] = "$oggDir/OggHandler.i18n.magic.php";
3232 $wgParserOutputHooks['OggHandler'] = array( 'OggHandler', 'outputHook' );
3333
 34+$wgHooks['ExtractThumbParameters'][] = 'OggHandler::onExtractThumbParameters';
 35+
3436 $wgExtensionCredits['media'][] = array(
3537 'path' => __FILE__,
3638 'name' => 'OggHandler',
Index: trunk/extensions/OggHandler/OggHandler_body.php
@@ -510,6 +510,28 @@
511511 $instance->setHeaders( $outputPage );
512512 }
513513 }
 514+
 515+ /**
 516+ * Handler for the ExtractThumbParameters hook
 517+ *
 518+ * @param $thumbname string URL-decoded basename of URI
 519+ * @param &$params Array Currently parsed thumbnail params
 520+ */
 521+ public static function onExtractThumbParameters( $thumbname, array &$params ) {
 522+ if ( !preg_match( '/\.(?:ogg|ogv|oga)$/i', $params['f'] ) ) {
 523+ return true; // not an ogg file
 524+ }
 525+ // Check if the parameters can be extracted from the thumbnail name...
 526+ if ( preg_match( '!^(mid|seek=[0-9.]+)-[^/]*$!', $thumbname, $m ) ) {
 527+ list( /* all */, $timeFull ) = $m;
 528+ if ( $timeFull != 'mid' ) {
 529+ list( $seek, $thumbtime ) = explode( '=', $timeFull, 2 );
 530+ $params['thumbtime'] = $thumbtime;
 531+ }
 532+ return false; // valid thumbnail URL
 533+ }
 534+ return true; // pass through to next handler
 535+ }
514536 }
515537
516538 class OggTransformOutput extends MediaTransformOutput {
Index: trunk/extensions/PagedTiffHandler/PagedTiffHandler_body.php
@@ -697,4 +697,25 @@
698698 $data = $this->getMetaArray( $image );
699699 return PagedTiffImage::getPageSize( $data, $page );
700700 }
 701+
 702+ /**
 703+ * Handler for the ExtractThumbParameters hook
 704+ *
 705+ * @param $thumbname string URL-decoded basename of URI
 706+ * @param &$params Array Currently parsed thumbnail params
 707+ */
 708+ public static function onExtractThumbParameters( $thumbname, array &$params ) {
 709+ if ( !preg_match( '/\.(?:tiff|tif)$/i', $params['f'] ) ) {
 710+ return true; // not an tiff file
 711+ }
 712+ // Check if the parameters can be extracted from the thumbnail name...
 713+ if ( preg_match( '!^(lossy|lossless)-page(\d+)-(\d+)px-[^/]*$!', $thumbname, $m ) ) {
 714+ list( /* all */, $lossy, $pagenum, $size ) = $matches;
 715+ $params['lossy'] = $lossy;
 716+ $params['width'] = $size;
 717+ $params['page'] = $pagenum;
 718+ return false; // valid thumbnail URL
 719+ }
 720+ return true; // pass through to next handler
 721+ }
701722 }
Index: trunk/extensions/PagedTiffHandler/PagedTiffHandler.php
@@ -130,3 +130,5 @@
131131 //$wgHooks['PagedTiffHandlerRenderCommand'][] = 'PagedTiffHandler::renderCommand';
132132 //$wgHooks['PagedTiffHandlerTiffData'][] = 'PagedTiffImage::tiffData';
133133 //$wgHooks['PagedTiffHandlerExifData'][] = 'PagedTiffImage::exifData';
 134+
 135+$wgHooks['ExtractThumbParameters'][] = 'PagedTiffHandler::onExtractThumbParameters';

Follow-up revisions

RevisionCommit summaryAuthorDate
r111384Followup r111199...reedy16:22, 13 February 2012
r111385MFT r111199reedy16:28, 13 February 2012

Comments

#Comment by Aaron Schulz (talk | contribs)   20:56, 10 February 2012

Also, see /tools/upload-scripts/thumb-handler.php.

Status & tagging log