PageRenderTime 44ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/includes/actions/RollbackAction.php

https://github.com/daevid/MWFork
PHP | 122 lines | 73 code | 19 blank | 30 comment | 19 complexity | 85a77be0f2ad46067f015a73f11ad1e9 MD5 | raw file
  1. <?php
  2. /**
  3. * Edit rollback user interface
  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
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  18. *
  19. * @file
  20. * @ingroup Action
  21. */
  22. /**
  23. * User interface for the rollback action
  24. *
  25. * @ingroup Action
  26. */
  27. class RollbackAction extends FormlessAction {
  28. public function getName() {
  29. return 'rollback';
  30. }
  31. public function getRestriction() {
  32. return 'rollback';
  33. }
  34. public function onView() {
  35. $details = null;
  36. $request = $this->getRequest();
  37. $result = $this->page->doRollback(
  38. $request->getVal( 'from' ),
  39. $request->getText( 'summary' ),
  40. $request->getVal( 'token' ),
  41. $request->getBool( 'bot' ),
  42. $details,
  43. $this->getUser()
  44. );
  45. if ( in_array( array( 'actionthrottledtext' ), $result ) ) {
  46. throw new ThrottledError;
  47. }
  48. if ( isset( $result[0][0] ) && ( $result[0][0] == 'alreadyrolled' || $result[0][0] == 'cantrollback' ) ) {
  49. $this->getOutput()->setPageTitle( wfMsg( 'rollbackfailed' ) );
  50. $errArray = $result[0];
  51. $errMsg = array_shift( $errArray );
  52. $this->getOutput()->addWikiMsgArray( $errMsg, $errArray );
  53. if ( isset( $details['current'] ) ) {
  54. $current = $details['current'];
  55. if ( $current->getComment() != '' ) {
  56. $this->getOutput()->addHTML( wfMessage( 'editcomment' )->rawParams(
  57. Linker::formatComment( $current->getComment() ) )->parse() );
  58. }
  59. }
  60. return;
  61. }
  62. # Display permissions errors before read-only message -- there's no
  63. # point in misleading the user into thinking the inability to rollback
  64. # is only temporary.
  65. if ( !empty( $result ) && $result !== array( array( 'readonlytext' ) ) ) {
  66. # array_diff is completely broken for arrays of arrays, sigh.
  67. # Remove any 'readonlytext' error manually.
  68. $out = array();
  69. foreach ( $result as $error ) {
  70. if ( $error != array( 'readonlytext' ) ) {
  71. $out [] = $error;
  72. }
  73. }
  74. $this->getOutput()->showPermissionsErrorPage( $out );
  75. return;
  76. }
  77. if ( $result == array( array( 'readonlytext' ) ) ) {
  78. throw new ReadOnlyError;
  79. }
  80. $current = $details['current'];
  81. $target = $details['target'];
  82. $newId = $details['newid'];
  83. $this->getOutput()->setPageTitle( wfMsg( 'actioncomplete' ) );
  84. $this->getOutput()->setRobotPolicy( 'noindex,nofollow' );
  85. if ( $current->getUserText() === '' ) {
  86. $old = wfMsg( 'rev-deleted-user' );
  87. } else {
  88. $old = Linker::userLink( $current->getUser(), $current->getUserText() )
  89. . Linker::userToolLinks( $current->getUser(), $current->getUserText() );
  90. }
  91. $new = Linker::userLink( $target->getUser(), $target->getUserText() )
  92. . Linker::userToolLinks( $target->getUser(), $target->getUserText() );
  93. $this->getOutput()->addHTML( wfMsgExt( 'rollback-success', array( 'parse', 'replaceafter' ), $old, $new ) );
  94. $this->getOutput()->returnToMain( false, $this->getTitle() );
  95. if ( !$request->getBool( 'hidediff', false ) && !$this->getUser()->getBoolOption( 'norollbackdiff', false ) ) {
  96. $de = new DifferenceEngine( $this->getTitle(), $current->getId(), $newId, false, true );
  97. $de->showDiff( '', '' );
  98. }
  99. }
  100. protected function getDescription() {
  101. return '';
  102. }
  103. }