364ab032acb4316cb1eecacb1a7d52cbcc92913b
[lhc/web/wiklou.git] / includes / specials / SpecialFilepath.php
1 <?php
2 /**
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 * http://www.gnu.org/copyleft/gpl.html
18 */
19
20 /**
21 * @ingroup SpecialPage
22 */
23 class SpecialFilepath extends SpecialPage {
24
25 function __construct() {
26 parent::__construct( 'Filepath' );
27 }
28
29 function execute( $par ) {
30 global $wgRequest, $wgOut;
31
32 $this->setHeaders();
33 $this->outputHeader();
34
35 $file = !is_null( $par ) ? $par : $wgRequest->getText( 'file' );
36
37 $title = Title::makeTitleSafe( NS_FILE, $file );
38
39 if ( ! $title instanceof Title || $title->getNamespace() != NS_FILE ) {
40 $this->showForm( $title );
41 } else {
42 $file = wfFindFile( $title );
43 if ( $file && $file->exists() ) {
44 $wgOut->redirect( $file->getURL() );
45 } else {
46 $wgOut->setStatusCode( 404 );
47 $this->showForm( $title );
48 }
49 }
50 }
51
52 function showForm( $title ) {
53 global $wgOut, $wgScript;
54
55 $wgOut->addHTML(
56 Html::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript, 'id' => 'specialfilepath' ) ) .
57 Html::openElement( 'fieldset' ) .
58 Html::element( 'legend', null, wfMsg( 'filepath' ) ) .
59 Html::hidden( 'title', $this->getTitle()->getPrefixedText() ) .
60 Xml::inputLabel( wfMsg( 'filepath-page' ), 'file', 'file', 25, is_object( $title ) ? $title->getText() : '' ) . ' ' .
61 Xml::submitButton( wfMsg( 'filepath-submit' ) ) . "\n" .
62 Html::closeElement( 'fieldset' ) .
63 Html::closeElement( 'form' )
64 );
65 }
66 }