Merge "Move section ID fallbacks into headers themselves"
[lhc/web/wiklou.git] / includes / specials / SpecialPermanentLink.php
index 17115e8..b1772b7 100644 (file)
  * @ingroup SpecialPage
  */
 class SpecialPermanentLink extends RedirectSpecialPage {
-       function __construct() {
+       public function __construct() {
                parent::__construct( 'PermanentLink' );
-               $this->mAllowedRedirectParams = array();
+               $this->mAllowedRedirectParams = [];
        }
 
-       function getRedirect( $subpage ) {
+       /**
+        * @param string|null $subpage
+        * @return Title|bool
+        */
+       public function getRedirect( $subpage ) {
                $subpage = intval( $subpage );
                if ( $subpage === 0 ) {
-                       # throw an error page when no subpage was given
-                       throw new ErrorPageError( 'nopagetitle', 'nopagetext' );
+                       return false;
                }
                $this->mAddedRedirectParams['oldid'] = $subpage;
 
                return true;
        }
+
+       protected function showNoRedirectPage() {
+               $this->setHeaders();
+               $this->outputHeader();
+               $this->showForm();
+       }
+
+       private function showForm() {
+               $form = HTMLForm::factory( 'ooui', [
+                       'revid' => [
+                               'type' => 'int',
+                               'name' => 'revid',
+                               'label-message' => 'permanentlink-revid',
+                       ],
+               ], $this->getContext(), 'permanentlink' );
+               $form->setSubmitTextMsg( 'permanentlink-submit' );
+               $form->setSubmitCallback( [ $this, 'onFormSubmit' ] );
+               $form->show();
+       }
+
+       public function onFormSubmit( $formData ) {
+               $revid = $formData['revid'];
+               $title = $this->getPageTitle( $revid ?: null );
+               $url = $title->getFullUrlForRedirect();
+               $this->getOutput()->redirect( $url );
+       }
+
+       public function isListed() {
+               return true;
+       }
+
+       protected function getGroupName() {
+               return 'redirects';
+       }
 }