SpecialPermanentLink.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /**
  3. * Redirect from Special:PermanentLink/### to index.php?oldid=###.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program; if not, write to the Free Software Foundation, Inc.,
  17. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. * http://www.gnu.org/copyleft/gpl.html
  19. *
  20. * @file
  21. * @ingroup SpecialPage
  22. */
  23. /**
  24. * Redirect from Special:PermanentLink/### to index.php?oldid=###.
  25. *
  26. * @ingroup SpecialPage
  27. */
  28. class SpecialPermanentLink extends RedirectSpecialPage {
  29. public function __construct() {
  30. parent::__construct( 'PermanentLink' );
  31. $this->mAllowedRedirectParams = [];
  32. }
  33. /**
  34. * @param string|null $subpage
  35. * @return Title|bool
  36. */
  37. public function getRedirect( $subpage ) {
  38. $subpage = intval( $subpage );
  39. if ( $subpage === 0 ) {
  40. return false;
  41. }
  42. $this->mAddedRedirectParams['oldid'] = $subpage;
  43. return true;
  44. }
  45. protected function showNoRedirectPage() {
  46. $this->addHelpLink( 'Help:PermanentLink' );
  47. $this->setHeaders();
  48. $this->outputHeader();
  49. $this->showForm();
  50. }
  51. private function showForm() {
  52. $form = HTMLForm::factory( 'ooui', [
  53. 'revid' => [
  54. 'type' => 'int',
  55. 'name' => 'revid',
  56. 'label-message' => 'permanentlink-revid',
  57. ],
  58. ], $this->getContext(), 'permanentlink' );
  59. $form->setSubmitTextMsg( 'permanentlink-submit' );
  60. $form->setSubmitCallback( [ $this, 'onFormSubmit' ] );
  61. $form->show();
  62. }
  63. public function onFormSubmit( $formData ) {
  64. $revid = $formData['revid'];
  65. $title = $this->getPageTitle( $revid ?: null );
  66. $url = $title->getFullUrlForRedirect();
  67. $this->getOutput()->redirect( $url );
  68. }
  69. public function isListed() {
  70. return true;
  71. }
  72. protected function getGroupName() {
  73. return 'redirects';
  74. }
  75. }