X-Git-Url: https://scripts.mit.edu/gitweb/autoinstallsdev/mediawiki.git/blobdiff_plain/19e297c21b10b1b8a3acad5e73fc71dcb35db44a..6932310fd58ebef145fa01eb76edf7150284d8ea:/includes/specials/SpecialFilepath.php diff --git a/includes/specials/SpecialFilepath.php b/includes/specials/SpecialFilepath.php index 8bb0890c..c18faa12 100644 --- a/includes/specials/SpecialFilepath.php +++ b/includes/specials/SpecialFilepath.php @@ -26,56 +26,30 @@ * * @ingroup SpecialPage */ -class SpecialFilepath extends SpecialPage { - - function __construct() { +class SpecialFilepath extends RedirectSpecialPage { + public function __construct() { parent::__construct( 'Filepath' ); + $this->mAllowedRedirectParams = [ 'width', 'height' ]; } - function execute( $par ) { - global $wgRequest, $wgOut; - - $this->setHeaders(); - $this->outputHeader(); - - $file = !is_null( $par ) ? $par : $wgRequest->getText( 'file' ); - - $title = Title::makeTitleSafe( NS_FILE, $file ); - - if ( ! $title instanceof Title || $title->getNamespace() != NS_FILE ) { - $this->showForm( $title ); + /** + * Implement by redirecting through Special:Redirect/file. + * + * @param string|null $par + * @return Title + */ + public function getRedirect( $par ) { + $file = $par ?: $this->getRequest()->getText( 'file' ); + + if ( $file ) { + $argument = "file/$file"; } 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 ); - } + $argument = 'file'; } + return SpecialPage::getSafeTitleFor( 'Redirect', $argument ); } - function showForm( $title ) { - global $wgOut, $wgScript; - - $wgOut->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" . - Html::closeElement( 'fieldset' ) . - Html::closeElement( 'form' ) - ); + protected function getGroupName() { + return 'media'; } }