Merge "Standardise preview warning box when using ?action=edit"
[lhc/web/wiklou.git] / includes / specials / SpecialFilepath.php
index 542589f..618fd1d 100644 (file)
 class SpecialFilepath extends RedirectSpecialPage {
        public function __construct() {
                parent::__construct( 'Filepath' );
-               $this->mAllowedRedirectParams = array( 'width', 'height' );
+               $this->mAllowedRedirectParams = [ 'width', 'height' ];
        }
 
        /**
         * Implement by redirecting through Special:Redirect/file.
         *
-        * @param string|null $subpage
+        * @param string|null $par
         * @return Title
         */
        public function getRedirect( $par ) {
                $file = $par ?: $this->getRequest()->getText( 'file' );
 
+               $redirect = null;
                if ( $file ) {
-                       $argument = "file/$file";
-               } else {
-                       $argument = 'file';
+                       $redirect = SpecialPage::getSafeTitleFor( 'Redirect', "file/$file" );
                }
-               return SpecialPage::getSafeTitleFor( 'Redirect', $argument );
+               if ( $redirect === null ) {
+                       // The user input is empty or an invalid title,
+                       // redirect to form of Special:Redirect with the invalid value prefilled
+                       $this->mAddedRedirectParams['wpvalue'] = $file;
+                       $redirect = SpecialPage::getSafeTitleFor( 'Redirect', 'file' );
+               }
+               return $redirect;
        }
 
        protected function getGroupName() {