SpecialFilepath.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /**
  3. * @file
  4. * @ingroup SpecialPage
  5. */
  6. function wfSpecialFilepath( $par ) {
  7. global $wgRequest, $wgOut;
  8. $file = isset( $par ) ? $par : $wgRequest->getText( 'file' );
  9. $title = Title::makeTitleSafe( NS_FILE, $file );
  10. if ( ! $title instanceof Title || $title->getNamespace() != NS_FILE ) {
  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. * @ingroup SpecialPage
  26. */
  27. class FilepathForm {
  28. var $mTitle;
  29. function FilepathForm( &$title ) {
  30. $this->mTitle =& $title;
  31. }
  32. function execute() {
  33. global $wgOut, $wgTitle, $wgScript;
  34. $wgOut->addHTML(
  35. Xml::openElement( 'form', array( 'method' => 'get', 'action' => $wgScript, 'id' => 'specialfilepath' ) ) .
  36. Xml::openElement( 'fieldset' ) .
  37. Xml::element( 'legend', null, wfMsg( 'filepath' ) ) .
  38. Xml::hidden( 'title', $wgTitle->getPrefixedText() ) .
  39. Xml::inputLabel( wfMsg( 'filepath-page' ), 'file', 'file', 25, is_object( $this->mTitle ) ? $this->mTitle->getText() : '' ) . ' ' .
  40. Xml::submitButton( wfMsg( 'filepath-submit' ) ) . "\n" .
  41. Xml::closeElement( 'fieldset' ) .
  42. Xml::closeElement( 'form' )
  43. );
  44. }
  45. }