MediaWiki
REL1_19
|
00001 <?php 00029 class SpecialFilepath extends SpecialPage { 00030 00031 function __construct() { 00032 parent::__construct( 'Filepath' ); 00033 } 00034 00035 function execute( $par ) { 00036 $this->setHeaders(); 00037 $this->outputHeader(); 00038 00039 $request = $this->getRequest(); 00040 $file = !is_null( $par ) ? $par : $request->getText( 'file' ); 00041 00042 $title = Title::newFromText( $file, NS_FILE ); 00043 00044 if ( ! $title instanceof Title || $title->getNamespace() != NS_FILE ) { 00045 $this->showForm( $title ); 00046 } else { 00047 $file = wfFindFile( $title ); 00048 00049 if ( $file && $file->exists() ) { 00050 // Default behaviour: Use the direct link to the file. 00051 $url = $file->getURL(); 00052 $width = $request->getInt( 'width', -1 ); 00053 $height = $request->getInt( 'height', -1 ); 00054 00055 // If a width is requested... 00056 if ( $width != -1 ) { 00057 $mto = $file->transform( array( 'width' => $width, 'height' => $height ) ); 00058 // ... and we can 00059 if ( $mto && !$mto->isError() ) { 00060 // ... change the URL to point to a thumbnail. 00061 $url = $mto->getURL(); 00062 } 00063 } 00064 $this->getOutput()->redirect( $url ); 00065 } else { 00066 $this->getOutput()->setStatusCode( 404 ); 00067 $this->showForm( $title ); 00068 } 00069 } 00070 } 00071 00075 function showForm( $title ) { 00076 global $wgScript; 00077 00078 $this->getOutput()->addHTML( 00079 Html::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript, 'id' => 'specialfilepath' ) ) . 00080 Html::openElement( 'fieldset' ) . 00081 Html::element( 'legend', null, wfMsg( 'filepath' ) ) . 00082 Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) . 00083 Xml::inputLabel( wfMsg( 'filepath-page' ), 'file', 'file', 25, is_object( $title ) ? $title->getText() : '' ) . ' ' . 00084 Xml::submitButton( wfMsg( 'filepath-submit' ) ) . "\n" . 00085 Html::closeElement( 'fieldset' ) . 00086 Html::closeElement( 'form' ) 00087 ); 00088 } 00089 }