r112375 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r112374‎ | r112375 | r112376 >
Date:23:45, 24 February 2012
Author:jeroendedauw
Status:deferred
Tags:
Comment:
work on deletion page
Modified paths:
  • /trunk/extensions/EducationProgram/actions/EPDeleteAction.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/actions/EPDeleteAction.php
@@ -44,16 +44,6 @@
4545 }
4646
4747 /**
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 - /**
5848 * (non-PHPdoc)
5949 * @see FormlessAction::onView()
6050 */
@@ -67,12 +57,54 @@
6858 $this->getOutput()->setSubtitle( '' );
6959 }
7060 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+ }
7280 }
7381
7482 return '';
7583 }
 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+ }
76101
 102+ /**
 103+ * Display the deletion form for the provided EPPageObject.
 104+ *
 105+ * @since 0.1
 106+ *
 107+ * @param EPPageObject $object
 108+ */
77109 protected function displayForm( EPPageObject $object ) {
78110 $out = $this->getOutput();
79111
@@ -82,7 +114,7 @@
83115 'form',
84116 array(
85117 'method' => 'post',
86 - 'action' => $this->getTitle()->getLocalURL(),
 118+ 'action' => $this->getTitle()->getLocalURL( array( 'action' => 'delete' ) ),
87119 )
88120 ) );
89121
@@ -119,11 +151,24 @@
120152 wfMsg( $this->prefixMsg( 'cancel-button' ) )
121153 );
122154
123 - $out->addHTML( Html::hidden( 'deleteToken', $this->getUser()->getEditToken( 'delete' . $this->getTitle()->getLocalURL() ) ) );
 155+ $out->addHTML( Html::hidden( 'deleteToken', $this->getUser()->getEditToken( $this->getSalt() ) ) );
124156
125157 $out->addHTML( '</form>' );
126158 }
 159+
 160+ protected function getSalt() {
 161+ return 'delete' . $this->getTitle()->getLocalURL();
 162+ }
127163
 164+ /**
 165+ * Returns a prefixed message name.
 166+ *
 167+ * @since 0.1
 168+ *
 169+ * @param string $name
 170+ *
 171+ * @return string
 172+ */
128173 protected function prefixMsg( $name ) {
129174 return strtolower( get_called_class() ) . '-' . $name;
130175 }

Status & tagging log