30fa9623aa933751bfeba6fd7ae05b1540b2cdb8
[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 // Force a real 30x so the real url is always exposed
17 $wgOut->redirect( Http::makeFullURL( $file->getURL() ) );
18 } else {
19 $wgOut->setStatusCode( 404 );
20 $cform = new FilepathForm( $title );
21 $cform->execute();
22 }
23 }
24 }
25
26 class FilepathForm {
27 var $mTitle;
28
29 function FilepathForm( &$title ) {
30 $this->mTitle =& $title;
31 }
32
33 function execute() {
34 global $wgOut, $wgTitle, $wgScript;
35
36 $wgOut->addHTML(
37 Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript, 'id' => 'specialfilepath' ) ) .
38 Xml::openElement( 'fieldset' ) .
39 Xml::element( 'legend', null, wfMsg( 'filepath' ) ) .
40 Xml::hidden( 'title', $wgTitle->getPrefixedText() ) .
41 Xml::inputLabel( wfMsg( 'filepath-page' ), 'file', 'file', 25, is_object( $this->mTitle ) ? $this->mTitle->getText() : '' ) . ' ' .
42 Xml::submitButton( wfMsg( 'filepath-submit' ) ) . "\n" .
43 Xml::closeElement( 'fieldset' ) .
44 Xml::closeElement( 'form' )
45 );
46 }
47 }