diff options
Diffstat (limited to 'includes/specials/SpecialFilepath.php')
-rw-r--r-- | includes/specials/SpecialFilepath.php | 94 |
1 files changed, 61 insertions, 33 deletions
diff --git a/includes/specials/SpecialFilepath.php b/includes/specials/SpecialFilepath.php index 8bc1c68b..8bb0890c 100644 --- a/includes/specials/SpecialFilepath.php +++ b/includes/specials/SpecialFilepath.php @@ -1,53 +1,81 @@ <?php /** + * Implements Special:Filepath + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/gpl.html + * * @file * @ingroup SpecialPage */ -function wfSpecialFilepath( $par ) { - global $wgRequest, $wgOut; +/** + * A special page that redirects to the URL of a given file + * + * @ingroup SpecialPage + */ +class SpecialFilepath extends SpecialPage { - $file = isset( $par ) ? $par : $wgRequest->getText( 'file' ); + function __construct() { + parent::__construct( 'Filepath' ); + } - $title = Title::makeTitleSafe( NS_FILE, $file ); + function execute( $par ) { + global $wgRequest, $wgOut; - if ( ! $title instanceof Title || $title->getNamespace() != NS_FILE ) { - $cform = new FilepathForm( $title ); - $cform->execute(); - } else { - $file = wfFindFile( $title ); - if ( $file && $file->exists() ) { - $wgOut->redirect( $file->getURL() ); - } else { - $wgOut->setStatusCode( 404 ); - $cform = new FilepathForm( $title ); - $cform->execute(); - } - } -} + $this->setHeaders(); + $this->outputHeader(); -/** - * @ingroup SpecialPage - */ -class FilepathForm { - var $mTitle; + $file = !is_null( $par ) ? $par : $wgRequest->getText( 'file' ); - function FilepathForm( &$title ) { - $this->mTitle =& $title; + $title = Title::makeTitleSafe( NS_FILE, $file ); + + if ( ! $title instanceof Title || $title->getNamespace() != NS_FILE ) { + $this->showForm( $title ); + } else { + $file = wfFindFile( $title ); + if ( $file && $file->exists() ) { + $url = $file->getURL(); + $width = $wgRequest->getInt( 'width', -1 ); + $height = $wgRequest->getInt( 'height', -1 ); + if ( $width != -1 ) { + $mto = $file->transform( array( 'width' => $width, 'height' => $height ) ); + if ( $mto && !$mto->isError() ) { + $url = $mto->getURL(); + } + } + $wgOut->redirect( $url ); + } else { + $wgOut->setStatusCode( 404 ); + $this->showForm( $title ); + } + } } - function execute() { + function showForm( $title ) { global $wgOut, $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', SpecialPage::getTitleFor( 'Filepath' )->getPrefixedText() ) . - Xml::inputLabel( wfMsg( 'filepath-page' ), 'file', 'file', 25, is_object( $this->mTitle ) ? $this->mTitle->getText() : '' ) . ' ' . + 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' ) ); } } |