/**
* Implements Special:Filepath
*
+ * @section LICENSE
* 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
*
* @ingroup SpecialPage
*/
-class SpecialFilepath extends SpecialPage {
+class SpecialFilepath extends RedirectSpecialPage {
function __construct() {
parent::__construct( 'Filepath' );
+ $this->mAllowedRedirectParams = array( 'width', 'height' );
}
- function execute( $par ) {
- $this->setHeaders();
- $this->outputHeader();
-
- $request = $this->getRequest();
- $file = $par ?: $request->getText( 'file' );
-
- $title = Title::newFromText( $file, NS_FILE );
-
- if ( !( $title instanceof Title ) || $title->getNamespace() != NS_FILE ) {
- $this->showForm( $title );
- } else {
- $file = wfFindFile( $title );
-
- if ( $file && $file->exists() ) {
- // Default behavior: Use the direct link to the file.
- $url = $file->getURL();
- $width = $request->getInt( 'width', -1 );
- $height = $request->getInt( 'height', -1 );
-
- // 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 );
- }
- }
- }
-
- /**
- * @param Title $title Title requested, or null.
- */
- function showForm( $title ) {
- global $wgScript;
-
- $this->getOutput()->addHTML(
- Html::openElement(
- 'form',
- array( 'method' => 'get', 'action' => $wgScript, 'id' => 'specialfilepath' )
- ) .
- Html::openElement( 'fieldset' ) .
- Html::element( 'legend', null, $this->msg( 'filepath' )->text() ) .
- Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) .
- Xml::inputLabel(
- $this->msg( 'filepath-page' )->text(),
- 'file',
- 'file',
- 25,
- is_object( $title ) ? $title->getText() : ''
- ) . ' ' .
- Xml::submitButton( $this->msg( 'filepath-submit' )->text() ) . "\n" .
- Html::closeElement( 'fieldset' ) .
- Html::closeElement( 'form' )
- );
+ // implement by redirecting through Special:Redirect/file
+ function getRedirect( $par ) {
+ return SpecialPage::getSafeTitleFor( 'Redirect', 'file/' . $par );
}
protected function getGroupName() {
'version-entrypoints-api-php' => '[https://www.mediawiki.org/wiki/Manual:api.php api.php]', # do not translate or duplicate this message to other languages
'version-entrypoints-load-php' => '[https://www.mediawiki.org/wiki/Manual:load.php load.php]', # do not translate or duplicate this message to other languages
-# Special:FilePath
-'filepath' => 'File path',
-'filepath-page' => 'File:',
-'filepath-submit' => 'Go',
-'filepath-summary' => 'This special page returns the complete path for a file.
-Images are shown in full resolution, other file types are started with their associated program directly.',
-
# Special:Redirect
'redirect' => 'Redirect by file, user, or revision ID',
'redirect-legend' => 'Redirect to a file or page',