From 1ade5c518b3e89ca83cbd7650ca01621938f9681 Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Sat, 3 Jul 2010 18:39:20 +0000 Subject: [PATCH] Modified Special:Filepath to subclass SpecialPage; also changed some calls from Xml:: to Html:: --- includes/AutoLoader.php | 1 + includes/SpecialPage.php | 2 +- includes/specials/SpecialFilepath.php | 63 ++++++++++++--------------- 3 files changed, 31 insertions(+), 35 deletions(-) diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index b4ae511b80..edb3b9728f 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -582,6 +582,7 @@ $wgAutoloadLocalClasses = array( 'SpecialBookSources' => 'includes/specials/SpecialBooksources.php', 'SpecialComparePages' => 'includes/specials/SpecialComparePages.php', 'SpecialExport' => 'includes/specials/SpecialExport.php', + 'SpecialFilepath' => 'includes/specials/SpecialFilepath.php', 'SpecialImport' => 'includes/specials/SpecialImport.php', 'SpecialListGroupRights' => 'includes/specials/SpecialListgrouprights.php', 'SpecialLockdb' => 'includes/specials/SpecialLockdb.php', diff --git a/includes/SpecialPage.php b/includes/SpecialPage.php index f76966a449..182c1497ec 100644 --- a/includes/SpecialPage.php +++ b/includes/SpecialPage.php @@ -143,7 +143,7 @@ class SpecialPage { # Media reports and uploads 'Listfiles' => array( 'SpecialPage', 'Listfiles' ), - 'Filepath' => array( 'SpecialPage', 'Filepath' ), + 'Filepath' => 'SpecialFilepath', 'MIMEsearch' => array( 'SpecialPage', 'MIMEsearch' ), 'FileDuplicateSearch' => array( 'SpecialPage', 'FileDuplicateSearch' ), 'Upload' => 'SpecialUpload', diff --git a/includes/specials/SpecialFilepath.php b/includes/specials/SpecialFilepath.php index d9a4c67be9..364ab032ac 100644 --- a/includes/specials/SpecialFilepath.php +++ b/includes/specials/SpecialFilepath.php @@ -18,54 +18,49 @@ */ /** - * @file * @ingroup SpecialPage */ +class SpecialFilepath extends SpecialPage { -function wfSpecialFilepath( $par ) { - global $wgRequest, $wgOut; + function __construct() { + parent::__construct( 'Filepath' ); + } - $file = isset( $par ) ? $par : $wgRequest->getText( 'file' ); + function execute( $par ) { + global $wgRequest, $wgOut; - $title = Title::makeTitleSafe( NS_FILE, $file ); + $this->setHeaders(); + $this->outputHeader(); - 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(); - } - } -} + $file = !is_null( $par ) ? $par : $wgRequest->getText( 'file' ); -/** - * @ingroup SpecialPage - */ -class FilepathForm { - var $mTitle; + $title = Title::makeTitleSafe( NS_FILE, $file ); - function FilepathForm( &$title ) { - $this->mTitle =& $title; + if ( ! $title instanceof Title || $title->getNamespace() != NS_FILE ) { + $this->showForm( $title ); + } else { + $file = wfFindFile( $title ); + if ( $file && $file->exists() ) { + $wgOut->redirect( $file->getURL() ); + } 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' ) ); } } -- 2.20.1