]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blobdiff - includes/specials/SpecialFilepath.php
MediaWiki 1.17.0
[autoinstalls/mediawiki.git] / includes / specials / SpecialFilepath.php
index 4a724b1f35f30740faee59892b9540cac912d1dd..8bb0890c6c777bacef6ebf81d195b293346c6359 100644 (file)
@@ -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() {
-               global $wgOut, $wgTitle, $wgScript;
+       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', $wgTitle->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' )
                );
        }
 }