Index: trunk/extensions/EducationProgram/actions/EPDeleteAction.php |
— | — | @@ -44,16 +44,6 @@ |
45 | 45 | } |
46 | 46 | |
47 | 47 | /** |
48 | | - * Do something exciting on successful processing of the form. This might be to show |
49 | | - * a confirmation message (watch, rollback, etc) or to redirect somewhere else (edit, |
50 | | - * protect, etc). |
51 | | - */ |
52 | | - public function onSuccess() { |
53 | | - $title = SpecialPage::getTitleFor( $this->table->getListPage() ); |
54 | | - $this->getOutput()->getRedirect( $title->getLocalURL( array( 'deleted' => $this->getTitle()->getText() ) ) ); |
55 | | - } |
56 | | - |
57 | | - /** |
58 | 48 | * (non-PHPdoc) |
59 | 49 | * @see FormlessAction::onView() |
60 | 50 | */ |
— | — | @@ -67,12 +57,54 @@ |
68 | 58 | $this->getOutput()->setSubtitle( '' ); |
69 | 59 | } |
70 | 60 | else { |
71 | | - $this->displayForm( $object ); |
| 61 | + $req = $this->getRequest(); |
| 62 | + |
| 63 | + if ( $req->wasPosted() && $this->getUser()->matchEditToken( $req->getText( 'deleteToken' ), $this->getSalt() ) ) { |
| 64 | + $success = $this->doDelete( $object ); |
| 65 | + |
| 66 | + if ( $success ) { |
| 67 | + $title = SpecialPage::getTitleFor( $this->table->getListPage() ); |
| 68 | + $query = array( 'deleted' => $this->getTitle()->getText() ); // TODO: handle |
| 69 | + } |
| 70 | + else { |
| 71 | + $title = $this->getTitle(); |
| 72 | + $query = array( 'delfailed' => '1' ); // TODO: handle |
| 73 | + } |
| 74 | + |
| 75 | + $this->getOutput()->redirect( $title->getLocalURL( $query ) ); |
| 76 | + } |
| 77 | + else { |
| 78 | + $this->displayForm( $object ); |
| 79 | + } |
72 | 80 | } |
73 | 81 | |
74 | 82 | return ''; |
75 | 83 | } |
| 84 | + |
| 85 | + /** |
| 86 | + * Does the actual deletion action. |
| 87 | + * |
| 88 | + * @since 0.1 |
| 89 | + * |
| 90 | + * @return boolean Success indicator |
| 91 | + */ |
| 92 | + protected function doDelete( EPPageObject $object ) { |
| 93 | + $revAction = new EPRevisionAction(); |
| 94 | + |
| 95 | + $revAction->setUser( $this->getUser() ); |
| 96 | + $revAction->setComment( $this->getRequest()->getText( 'summary', '' ) ); |
| 97 | + $revAction->setDelete( true ); |
| 98 | + |
| 99 | + return $object->revisionedRemove( $revAction ); |
| 100 | + } |
76 | 101 | |
| 102 | + /** |
| 103 | + * Display the deletion form for the provided EPPageObject. |
| 104 | + * |
| 105 | + * @since 0.1 |
| 106 | + * |
| 107 | + * @param EPPageObject $object |
| 108 | + */ |
77 | 109 | protected function displayForm( EPPageObject $object ) { |
78 | 110 | $out = $this->getOutput(); |
79 | 111 | |
— | — | @@ -82,7 +114,7 @@ |
83 | 115 | 'form', |
84 | 116 | array( |
85 | 117 | 'method' => 'post', |
86 | | - 'action' => $this->getTitle()->getLocalURL(), |
| 118 | + 'action' => $this->getTitle()->getLocalURL( array( 'action' => 'delete' ) ), |
87 | 119 | ) |
88 | 120 | ) ); |
89 | 121 | |
— | — | @@ -119,11 +151,24 @@ |
120 | 152 | wfMsg( $this->prefixMsg( 'cancel-button' ) ) |
121 | 153 | ); |
122 | 154 | |
123 | | - $out->addHTML( Html::hidden( 'deleteToken', $this->getUser()->getEditToken( 'delete' . $this->getTitle()->getLocalURL() ) ) ); |
| 155 | + $out->addHTML( Html::hidden( 'deleteToken', $this->getUser()->getEditToken( $this->getSalt() ) ) ); |
124 | 156 | |
125 | 157 | $out->addHTML( '</form>' ); |
126 | 158 | } |
| 159 | + |
| 160 | + protected function getSalt() { |
| 161 | + return 'delete' . $this->getTitle()->getLocalURL(); |
| 162 | + } |
127 | 163 | |
| 164 | + /** |
| 165 | + * Returns a prefixed message name. |
| 166 | + * |
| 167 | + * @since 0.1 |
| 168 | + * |
| 169 | + * @param string $name |
| 170 | + * |
| 171 | + * @return string |
| 172 | + */ |
128 | 173 | protected function prefixMsg( $name ) { |
129 | 174 | return strtolower( get_called_class() ) . '-' . $name; |
130 | 175 | } |