X-Git-Url: https://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2Fspecials%2FSpecialFilepath.php;h=101a33f4d1ebcf25b7bcd8c44769f48cd6d433dd;hb=e220d83381808ec98b4f32b85dc546904602799d;hp=af80e2f6f2bd3c189cc7e41c678f4845f1d8d82f;hpb=19f1fa7576a7f33de0845e4f00ed9a13f73b8476;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/specials/SpecialFilepath.php b/includes/specials/SpecialFilepath.php index af80e2f6f2..101a33f4d1 100644 --- a/includes/specials/SpecialFilepath.php +++ b/includes/specials/SpecialFilepath.php @@ -1,53 +1,89 @@ getText( 'file' ); + function __construct() { + parent::__construct( 'Filepath' ); + } - $title = Title::makeTitleSafe( NS_IMAGE, $file ); + function execute( $par ) { + $this->setHeaders(); + $this->outputHeader(); - if ( ! $title instanceof Title || $title->getNamespace() != NS_IMAGE ) { - $cform = new FilepathForm( $title ); - $cform->execute(); - } else { - $file = wfFindFile( $title ); - if ( $file && $file->exists() ) { - $wgOut->redirect( $file->getURL() ); + $request = $this->getRequest(); + $file = !is_null( $par ) ? $par : $request->getText( 'file' ); + + $title = Title::newFromText( $file, NS_FILE ); + + if ( ! $title instanceof Title || $title->getNamespace() != NS_FILE ) { + $this->showForm( $title ); } else { - $wgOut->setStatusCode( 404 ); - $cform = new FilepathForm( $title ); - $cform->execute(); - } - } -} + $file = wfFindFile( $title ); -/** - * @ingroup SpecialPage - */ -class FilepathForm { - var $mTitle; + if ( $file && $file->exists() ) { + // Default behaviour: Use the direct link to the file. + $url = $file->getURL(); + $width = $request->getInt( 'width', -1 ); + $height = $request->getInt( 'height', -1 ); - function FilepathForm( &$title ) { - $this->mTitle =& $title; + // If a width is requested... + if ( $width != -1 ) { + $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(); + } + } + $this->getOutput()->redirect( $url ); + } else { + $this->getOutput()->setStatusCode( 404 ); + $this->showForm( $title ); + } + } } - function execute() { - global $wgOut, $wgTitle, $wgScript; + /** + * @param $title Title + */ + function showForm( $title ) { + global $wgScript; - $wgOut->addHTML( - Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript, 'id' => 'specialfilepath' ) ) . - Xml::openElement( 'fieldset' ) . - Xml::element( 'legend', null, wfMsg( 'filepath' ) ) . - Xml::hidden( 'title', $wgTitle->getPrefixedText() ) . - Xml::inputLabel( wfMsg( 'filepath-page' ), 'file', 'file', 25, is_object( $this->mTitle ) ? $this->mTitle->getText() : '' ) . ' ' . + $this->getOutput()->addHTML( + Html::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript, 'id' => 'specialfilepath' ) ) . + Html::openElement( 'fieldset' ) . + Html::element( 'legend', null, wfMsg( 'filepath' ) ) . + Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) . + Xml::inputLabel( wfMsg( 'filepath-page' ), 'file', 'file', 25, is_object( $title ) ? $title->getText() : '' ) . ' ' . Xml::submitButton( wfMsg( 'filepath-submit' ) ) . "\n" . - Xml::closeElement( 'fieldset' ) . - Xml::closeElement( 'form' ) + Html::closeElement( 'fieldset' ) . + Html::closeElement( 'form' ) ); } }