00001 <?php 00007 function wfSpecialFilepath( $par ) { 00008 global $wgRequest, $wgOut; 00009 00010 $file = isset( $par ) ? $par : $wgRequest->getText( 'file' ); 00011 00012 $title = Title::makeTitleSafe( NS_FILE, $file ); 00013 00014 if ( ! $title instanceof Title || $title->getNamespace() != NS_FILE ) { 00015 $cform = new FilepathForm( $title ); 00016 $cform->execute(); 00017 } else { 00018 $file = wfFindFile( $title ); 00019 if ( $file && $file->exists() ) { 00020 $wgOut->redirect( $file->getURL() ); 00021 } else { 00022 $wgOut->setStatusCode( 404 ); 00023 $cform = new FilepathForm( $title ); 00024 $cform->execute(); 00025 } 00026 } 00027 } 00028 00032 class FilepathForm { 00033 var $mTitle; 00034 00035 function FilepathForm( &$title ) { 00036 $this->mTitle =& $title; 00037 } 00038 00039 function execute() { 00040 global $wgOut, $wgTitle, $wgScript; 00041 00042 $wgOut->addHTML( 00043 Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript, 'id' => 'specialfilepath' ) ) . 00044 Xml::openElement( 'fieldset' ) . 00045 Xml::element( 'legend', null, wfMsg( 'filepath' ) ) . 00046 Xml::hidden( 'title', $wgTitle->getPrefixedText() ) . 00047 Xml::inputLabel( wfMsg( 'filepath-page' ), 'file', 'file', 25, is_object( $this->mTitle ) ? $this->mTitle->getText() : '' ) . ' ' . 00048 Xml::submitButton( wfMsg( 'filepath-submit' ) ) . "\n" . 00049 Xml::closeElement( 'fieldset' ) . 00050 Xml::closeElement( 'form' ) 00051 ); 00052 } 00053 }