Nighttime commit when I'm tired and want to get this thing checked in and go to bed...
[lhc/web/wiklou.git] / includes / SpecialFilepath.php
1 <?php
2
3 function wfSpecialFilepath( $par ) {
4 global $wgRequest, $wgOut;
5
6 $file = isset( $par ) ? $par : $wgRequest->getText( 'file' );
7
8 $title = Title::newFromText( $file, NS_IMAGE );
9
10 if ( ! $title instanceof Title || $title->getNamespace() != NS_IMAGE ) {
11 $cform = new FilepathForm( $title );
12 $cform->execute();
13 } else {
14 $file = wfFindFile( $title );
15 if ( $file && $file->exists() ) {
16 $wgOut->redirect( $file->getURL() );
17 } else {
18 $wgOut->setStatusCode( 404 );
19 $cform = new FilepathForm( $title );
20 $cform->execute();
21 }
22 }
23 }
24
25 class FilepathForm {
26 var $mTitle;
27
28 function FilepathForm( &$title ) {
29 $this->mTitle =& $title;
30 }
31
32 function execute() {
33 global $wgOut, $wgTitle, $wgScript;
34
35 $wgOut->addHTML(
36 Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript, 'id' => 'specialfilepath' ) ) .
37 Xml::openElement( 'fieldset' ) .
38 Xml::element( 'legend', null, wfMsg( 'filepath' ) ) .
39 Xml::hidden( 'title', $wgTitle->getPrefixedText() ) .
40 Xml::inputLabel( wfMsg( 'filepath-page' ), 'file', 'file', 25, is_object( $this->mTitle ) ? $this->mTitle->getText() : '' ) . ' ' .
41 Xml::submitButton( wfMsg( 'filepath-submit' ) ) . "\n" .
42 Xml::closeElement( 'fieldset' ) .
43 Xml::closeElement( 'form' )
44 );
45 }
46 }