From: PiRSquared17 Date: Thu, 10 Aug 2017 16:33:30 +0000 (+0200) Subject: Document Special:Diff and Special:PermanentLink X-Git-Tag: 1.31.0-rc.0~2423^2 X-Git-Url: http://git.heureux-cyclage.org/?a=commitdiff_plain;h=3430278e374f8b5baeb4cf7cf802eb19f11b9be8;p=lhc%2Fweb%2Fwiklou.git Document Special:Diff and Special:PermanentLink If no revision is given to Special:Diff or PermaLink show a form (cf. Special:ComparePages) List these on Special:SpecialPages under "redirects". Bug: 45221 Change-Id: I77edd4a1bbd342d4d18c27d5bc10dac76b8ab6c9 --- diff --git a/includes/specialpage/RedirectSpecialPage.php b/includes/specialpage/RedirectSpecialPage.php index 9b5d5f463d..4e5da9701b 100644 --- a/includes/specialpage/RedirectSpecialPage.php +++ b/includes/specialpage/RedirectSpecialPage.php @@ -52,8 +52,7 @@ abstract class RedirectSpecialPage extends UnlistedSpecialPage { return $redirect; } else { - $class = static::class; - throw new MWException( "RedirectSpecialPage $class doesn't redirect!" ); + $this->showNoRedirectPage(); } } @@ -106,6 +105,11 @@ abstract class RedirectSpecialPage extends UnlistedSpecialPage { public function personallyIdentifiableTarget() { return false; } + + protected function showNoRedirectPage() { + $class = static::class; + throw new MWException( "RedirectSpecialPage $class doesn't redirect!" ); + } } /** diff --git a/includes/specials/SpecialDiff.php b/includes/specials/SpecialDiff.php index 9804e777b1..28cd0d195a 100644 --- a/includes/specials/SpecialDiff.php +++ b/includes/specials/SpecialDiff.php @@ -56,11 +56,64 @@ class SpecialDiff extends RedirectSpecialPage { $this->mAddedRedirectParams['oldid'] = $parts[0]; $this->mAddedRedirectParams['diff'] = $parts[1]; } else { - // Wrong number of parameters, bail out - $this->addHelpLink( 'Help:Diff' ); - throw new ErrorPageError( 'nopagetitle', 'nopagetext' ); + return false; } return true; } + + protected function showNoRedirectPage() { + $this->addHelpLink( 'Help:Diff' ); + $this->setHeaders(); + $this->outputHeader(); + $this->showForm(); + } + + private function showForm() { + $form = HTMLForm::factory( 'ooui', [ + 'oldid' => [ + 'name' => 'oldid', + 'type' => 'int', + 'label-message' => 'diff-form-oldid', + ], + 'diff' => [ + 'name' => 'diff', + 'class' => 'HTMLTextField', + 'label-message' => 'diff-form-revid', + ], + ], $this->getContext(), 'diff-form' ); + $form->setSubmitTextMsg( 'diff-form-submit' ); + $form->setSubmitCallback( [ $this, 'onFormSubmit' ] ); + $form->show(); + } + + public function onFormSubmit( $formData ) { + $params = []; + if ( $formData['oldid'] ) { + $params[] = $formData['oldid']; + } + if ( $formData['diff'] ) { + $params[] = $formData['diff']; + } + $title = $this->getPageTitle( $params ? implode( '/', $params ) : null ); + $url = $title->getFullUrlForRedirect(); + $this->getOutput()->redirect( $url ); + } + + public function getDescription() { + // 'diff' message is in lowercase, using own message + return $this->msg( 'diff-form' )->text(); + } + + public function getName() { + return 'diff-form'; + } + + public function isListed() { + return true; + } + + protected function getGroupName() { + return 'redirects'; + } } diff --git a/includes/specials/SpecialPermanentLink.php b/includes/specials/SpecialPermanentLink.php index 2bd3ab7d76..b1772b78e3 100644 --- a/includes/specials/SpecialPermanentLink.php +++ b/includes/specials/SpecialPermanentLink.php @@ -39,11 +39,44 @@ class SpecialPermanentLink extends RedirectSpecialPage { 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'; + } } diff --git a/languages/i18n/en.json b/languages/i18n/en.json index 61a113e894..86ac78ef77 100644 --- a/languages/i18n/en.json +++ b/languages/i18n/en.json @@ -3917,6 +3917,15 @@ "compare-invalid-title": "The title you specified is invalid.", "compare-title-not-exists": "The title you specified does not exist.", "compare-revision-not-exists": "The revision you specified does not exist.", + "diff-form": "Differences", + "diff-form-oldid": "Old revision ID (optional)", + "diff-form-revid": "Revision ID of difference", + "diff-form-submit": "Show differences", + "diff-form-summary": "", + "permanentlink": "Permanent link", + "permanentlink-revid": "Revision ID", + "permanentlink-submit": "Go to revision", + "permanentlink-summary": "", "dberr-problems": "Sorry! This site is experiencing technical difficulties.", "dberr-again": "Try waiting a few minutes and reloading.", "dberr-info": "(Cannot access the database: $1)", diff --git a/languages/i18n/qqq.json b/languages/i18n/qqq.json index 7be71f0037..62b4d669a7 100644 --- a/languages/i18n/qqq.json +++ b/languages/i18n/qqq.json @@ -4107,6 +4107,15 @@ "compare-invalid-title": "Used as error message in [[Special:ComparePages]].", "compare-title-not-exists": "Used as error message in [[Special:ComparePages]].", "compare-revision-not-exists": "Used as error message in [[Special:ComparePages]].", + "permanentlink": "The title of [[Special:PermanentLink]]", + "permanentlink-revid": "Label for the field for the revision ID in [[Special:PermanentLink]]", + "permanentlink-submit": "Submit button on [[Special:PermanentLink]]", + "permanentlink-summary": "{{doc-specialpagesummary|permanentlink}}", + "diff-form": "The title of [[Special:Diff]]", + "diff-form-summary": "{{doc-specialpagesummary|diff}}", + "diff-form-oldid": "Label for the field of the old revision in the comparison for [[Special:Diff]]", + "diff-form-revid": "Label for the field of the new revision in the comparison for [[Special:Diff]]", + "diff-form-submit": "Submit button on [[Special:Diff]]", "dberr-problems": "This message does not allow any wiki nor html markup.", "dberr-again": "This message does not allow any wiki nor html markup.", "dberr-info": "This message does not allow any wiki nor html markup. Parameters:\n* $1 - database server name\nSee also:\n* {{msg-mw|Dberr-info-hidden}} - hides database server name",