Cscott has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/61073


Change subject: Reimplement Special:Filepath as a redirect through 
Special:Redirect/File.
......................................................................

Reimplement Special:Filepath as a redirect through Special:Redirect/File.

Reduces code duplication (and some ugly deprecated code patterns in the
Special:Filepath implementation).  In the long term, reduces the need for
one-off redirection pages (Special:PermanentLink, Special:Filepath, etc)
in favor of an extensible system based around Special:Redirect.

Change-Id: I42d5879342bc18412f0383c538e83c68b1c3cc2a
---
M includes/specials/SpecialFilepath.php
M languages/messages/MessagesEn.php
M languages/messages/MessagesQqq.php
M maintenance/language/messages.inc
4 files changed, 5 insertions(+), 87 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/73/61073/1

diff --git a/includes/specials/SpecialFilepath.php 
b/includes/specials/SpecialFilepath.php
index d4b0285..7784c57 100644
--- a/includes/specials/SpecialFilepath.php
+++ b/includes/specials/SpecialFilepath.php
@@ -26,74 +26,14 @@
  *
  * @ingroup SpecialPage
  */
-class SpecialFilepath extends SpecialPage {
+class SpecialFilepath extends RedirectSpecialPage {
        function __construct() {
                parent::__construct( 'Filepath' );
+               $this->mAllowedRedirectParams = array( 'width', 'height' );
        }
-
-       function execute( $par ) {
-               $this->setHeaders();
-               $this->outputHeader();
-
-               $request = $this->getRequest();
-               $file = $par ?: $request->getText( 'file' );
-
-               $title = Title::newFromText( $file, NS_FILE );
-
-               if ( !( $title instanceof Title ) || $title->getNamespace() != 
NS_FILE ) {
-                       $this->showForm( $title );
-               } else {
-                       $file = wfFindFile( $title );
-
-                       if ( $file && $file->exists() ) {
-                               // Default behavior: Use the direct link to the 
file.
-                               $url = $file->getURL();
-                               $width = $request->getInt( 'width', -1 );
-                               $height = $request->getInt( 'height', -1 );
-
-                               // If a width is requested...
-                               if ( $width != -1 ) {
-                                       $mto = $file->transform( array( 'width' 
=> $width, 'height' => $height ) );
-
-                                       // ... and we can
-                                       if ( $mto && !$mto->isError() ) {
-                                               // ... change the URL to point 
to a thumbnail.
-                                               $url = $mto->getURL();
-                                       }
-                               }
-                               $this->getOutput()->redirect( $url );
-                       } else {
-                               $this->getOutput()->setStatusCode( 404 );
-                               $this->showForm( $title );
-                       }
-               }
-       }
-
-       /**
-        * @param Title $title Title requested, or null.
-        */
-       function showForm( $title ) {
-               global $wgScript;
-
-               $this->getOutput()->addHTML(
-                       Html::openElement(
-                               'form',
-                               array( 'method' => 'get', 'action' => 
$wgScript, 'id' => 'specialfilepath' )
-                       ) .
-                               Html::openElement( 'fieldset' ) .
-                               Html::element( 'legend', null, $this->msg( 
'filepath' )->text() ) .
-                               Html::hidden( 'title', 
$this->getTitle()->getPrefixedText() ) .
-                               Xml::inputLabel(
-                                       $this->msg( 'filepath-page' )->text(),
-                                       'file',
-                                       'file',
-                                       25,
-                                       is_object( $title ) ? $title->getText() 
: ''
-                               ) . ' ' .
-                               Xml::submitButton( $this->msg( 
'filepath-submit' )->text() ) . "\n" .
-                               Html::closeElement( 'fieldset' ) .
-                               Html::closeElement( 'form' )
-               );
+       // implement by redirecting through Special:Redirect/file
+       function getRedirect( $par ) {
+               return SpecialPage::getSafeTitleFor( 'Redirect', 'file/' . $par 
);
        }
 
        protected function getGroupName() {
diff --git a/languages/messages/MessagesEn.php 
b/languages/messages/MessagesEn.php
index 96f2fc9..cdfdeab 100644
--- a/languages/messages/MessagesEn.php
+++ b/languages/messages/MessagesEn.php
@@ -4788,13 +4788,6 @@
 'version-entrypoints-api-php'           => 
'[https://www.mediawiki.org/wiki/Manual:api.php api.php]', # do not translate 
or duplicate this message to other languages
 'version-entrypoints-load-php'          => 
'[https://www.mediawiki.org/wiki/Manual:load.php load.php]', # do not translate 
or duplicate this message to other languages
 
-# Special:FilePath
-'filepath'         => 'File path',
-'filepath-page'    => 'File:',
-'filepath-submit'  => 'Go',
-'filepath-summary' => 'This special page returns the complete path for a file.
-Images are shown in full resolution, other file types are started with their 
associated program directly.',
-
 # Special:Redirect
 'redirect'         => 'Redirect by file, user, or revision ID',
 'redirect-legend'  => 'Redirect to a file or page',
diff --git a/languages/messages/MessagesQqq.php 
b/languages/messages/MessagesQqq.php
index b8b6b1e..ffd2585 100644
--- a/languages/messages/MessagesQqq.php
+++ b/languages/messages/MessagesQqq.php
@@ -8505,15 +8505,6 @@
 'version-entrypoints-scriptpath' => '{{Optional}}
 A short description of the script path entry point. Links to the mediawiki.org 
documentation page for $wgScriptPath.',
 
-# Special:FilePath
-'filepath' => 'Legend of fieldset around input box in [[Special:FilePath]].',
-'filepath-page' => 'Shown next to input box in [[Special:FilePath]]
-
-{{Identical|File}}',
-'filepath-submit' => 'Button label in [[Special:FilePath]].
-{{Identical|Go}}',
-'filepath-summary' => 'Shown in [[Special:FilePath]]',
-
 # Special:Redirect
 'redirect'         => 'Main heading of [[Special:Redirect]] page',
 'redirect-legend'  => 'Legend of fieldset around input box in 
[[Special:Redirect]]',
diff --git a/maintenance/language/messages.inc 
b/maintenance/language/messages.inc
index f4f3105..819043c 100644
--- a/maintenance/language/messages.inc
+++ b/maintenance/language/messages.inc
@@ -3637,12 +3637,6 @@
                'version-entrypoints-api-php',
                'version-entrypoints-load-php',
        ),
-       'filepath' => array(
-               'filepath',
-               'filepath-page',
-               'filepath-submit',
-               'filepath-summary',
-       ),
        'redirect' => array(
                'redirect',
                'redirect-legend',

-- 
To view, visit https://gerrit.wikimedia.org/r/61073
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I42d5879342bc18412f0383c538e83c68b1c3cc2a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Cscott <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to