r112651 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r112650‎ | r112651 | r112652 >
Date:22:51, 28 February 2012
Author:jeroendedauw
Status:deferred
Tags:
Comment:
work on undeletion
Modified paths:
  • /trunk/extensions/EducationProgram/EducationProgram.i18n.php (modified) (history)
  • /trunk/extensions/EducationProgram/EducationProgram.php (modified) (history)
  • /trunk/extensions/EducationProgram/actions/EPDeleteAction.php (modified) (history)
  • /trunk/extensions/EducationProgram/actions/EPEditAction.php (modified) (history)
  • /trunk/extensions/EducationProgram/actions/EPHistoryAction.php (modified) (history)
  • /trunk/extensions/EducationProgram/actions/EPRestoreAction.php (modified) (history)
  • /trunk/extensions/EducationProgram/actions/EPUndeleteAction.php (added) (history)
  • /trunk/extensions/EducationProgram/actions/EPUndoAction.php (modified) (history)
  • /trunk/extensions/EducationProgram/actions/EPViewAction.php (modified) (history)
  • /trunk/extensions/EducationProgram/actions/EditCourseAction.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPRevision.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPRevisionedObject.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPRevisions.php (modified) (history)
  • /trunk/extensions/EducationProgram/maintenance/truncate.sql (added) (history)
  • /trunk/extensions/EducationProgram/pages/EPPage.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/maintenance/truncate.sql
@@ -0,0 +1,9 @@
 2+TRUNCATE TABLE `mw_ep_orgs`;
 3+TRUNCATE TABLE `mw_ep_courses`;
 4+TRUNCATE TABLE `mw_ep_students`;
 5+TRUNCATE TABLE `mw_ep_users_per_course`;
 6+TRUNCATE TABLE `mw_ep_instructors`;
 7+TRUNCATE TABLE `mw_ep_oas`;
 8+TRUNCATE TABLE `mw_ep_cas`;
 9+TRUNCATE TABLE `mw_ep_articles`;
 10+TRUNCATE TABLE `mw_ep_revisions`;
\ No newline at end of file
Property changes on: trunk/extensions/EducationProgram/maintenance/truncate.sql
___________________________________________________________________
Added: svn:eol-style
111 + native
Index: trunk/extensions/EducationProgram/EducationProgram.php
@@ -61,6 +61,7 @@
6262
6363 $wgAutoloadClasses['EditCourseAction'] = dirname( __FILE__ ) . '/actions/EditCourseAction.php';
6464 $wgAutoloadClasses['EditOrgAction'] = dirname( __FILE__ ) . '/actions/EditOrgAction.php';
 65+$wgAutoloadClasses['EPAction'] = dirname( __FILE__ ) . '/actions/EPAction.php';
6566 $wgAutoloadClasses['EPAddArticleAction'] = dirname( __FILE__ ) . '/actions/EPAddArticleAction.php';
6667 $wgAutoloadClasses['EPAddReviewerAction'] = dirname( __FILE__ ) . '/actions/EPAddReviewerAction.php';
6768 $wgAutoloadClasses['EPDeleteAction'] = dirname( __FILE__ ) . '/actions/EPDeleteAction.php';
Index: trunk/extensions/EducationProgram/pages/EPPage.php
@@ -169,39 +169,4 @@
170170 return static::$info['log-type'];
171171 }
172172
173 - // TODO
174 - public static function displayDeletionLog( IContextSource $context, $messageKey ) {
175 - $out = $context->getOutput();
176 -
177 - if ( true ) { // $context->getUser()->isAllowed( '' )
178 - $revisionCount = EPRevisions::singleton()->count( array(
179 - 'object_identifier' => $context->getTitle()->getText()
180 - ) );
181 -
182 - if ( $revisionCount > 0 ) {
183 - $out->addHTML( $context->msg( 'thisisdeleted' )->rawParams(
184 - Linker::linkKnown(
185 - $context->getTitle(),
186 - $context->msg( 'restorelink' )->numParams( $revisionCount )->escaped(),
187 - array(),
188 - array( 'action' => 'epundelete' )
189 - )
190 - )->text() );
191 - }
192 - }
193 -
194 - LogEventsList::showLogExtract(
195 - $out,
196 - array( static::$info['log-type'] ),
197 - $context->getTitle(),
198 - '',
199 - array(
200 - 'lim' => 10,
201 - 'conds' => array( 'log_action' => 'remove' ),
202 - 'showIfEmpty' => false,
203 - 'msgKey' => array( $messageKey )
204 - )
205 - );
206 - }
207 -
208173 }
Index: trunk/extensions/EducationProgram/actions/EPViewAction.php
@@ -12,7 +12,7 @@
1313 * @licence GNU GPL v3+
1414 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1515 */
16 -abstract class EPViewAction extends FormlessAction {
 16+abstract class EPViewAction extends EPAction {
1717
1818 /**
1919 * @since 0.1
@@ -76,10 +76,7 @@
7777 else {
7878 $out->addWikiMsg( strtolower( get_called_class() ) . '-none', $name );
7979
80 - $this->page->displayDeletionLog(
81 - $this->getContext(),
82 - 'ep-' . strtolower( $this->getName() ) . '-deleted'
83 - );
 80+ $this->displayDeletionLog();
8481 }
8582 }
8683 else {
Index: trunk/extensions/EducationProgram/actions/EditCourseAction.php
@@ -58,10 +58,8 @@
5959 $this->getOutput()->addModules( array( 'ep.datepicker', 'ep.combobox' ) );
6060
6161 if ( !$this->isNewPost() && !$this->table->hasIdentifier( $this->getTitle()->getText() ) ) {
62 - $this->page->displayDeletionLog(
63 - $this->getContext(),
64 - 'ep-' . strtolower( $this->getName() ) . '-deleted'
65 - );
 62+ $this->displayUndeletionLink();
 63+ $this->displayDeletionLog();
6664
6765 list( $name, $term ) = $this->titleToNameAndTerm( $this->getTitle()->getText() );
6866
Index: trunk/extensions/EducationProgram/actions/EPRestoreAction.php
@@ -12,7 +12,7 @@
1313 * @licence GNU GPL v3+
1414 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1515 */
16 -class EPRestoreAction extends FormlessAction {
 16+class EPRestoreAction extends EPAction {
1717
1818 /**
1919 * (non-PHPdoc)
@@ -172,30 +172,6 @@
173173 }
174174
175175 /**
176 - * Returns a salt based on the action and the page name.
177 - *
178 - * @since 0.1
179 - *
180 - * @return string
181 - */
182 - protected function getSalt() {
183 - return 'restore' . $this->getTitle()->getLocalURL();
184 - }
185 -
186 - /**
187 - * Returns a prefixed message name.
188 - *
189 - * @since 0.1
190 - *
191 - * @param string $name
192 - *
193 - * @return string
194 - */
195 - protected function prefixMsg( $name ) {
196 - return strtolower( get_class( $this->page ) ) . '-' . $this->getName() . '-' . $name;
197 - }
198 -
199 - /**
200176 * Returns the page title.
201177 *
202178 * @since 0.1
Index: trunk/extensions/EducationProgram/actions/EPEditAction.php
@@ -12,7 +12,7 @@
1313 * @licence GNU GPL v3+
1414 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1515 */
16 -abstract class EPEditAction extends FormlessAction {
 16+abstract class EPEditAction extends EPAction {
1717
1818 /**
1919 * Instance of the object being edited or created.
@@ -100,10 +100,7 @@
101101 }
102102 else {
103103 if ( $object === false ) {
104 - $this->page->displayDeletionLog(
105 - $this->getContext(),
106 - 'ep-' . strtolower( $this->getName() ) . '-deleted'
107 - );
 104+ $this->displayDeletionLog();
108105
109106 $this->isNew = true;
110107 $object = $this->table->newFromArray( $data, true );
Index: trunk/extensions/EducationProgram/actions/EPHistoryAction.php
@@ -12,7 +12,7 @@
1313 * @licence GNU GPL v3+
1414 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1515 */
16 -class EPHistoryAction extends FormlessAction {
 16+class EPHistoryAction extends EPAction {
1717
1818 /**
1919 * (non-PHPdoc)
@@ -44,10 +44,7 @@
4545 protected function displayNoRevisions() {
4646 $this->getOutput()->addWikiMsg( $this->prefixMsg( 'norevs' ) );
4747
48 - $this->page->displayDeletionLog(
49 - $this->getContext(),
50 - $this->prefixMsg( 'deleted' )
51 - );
 48+ $this->displayDeletionLog();
5249 }
5350
5451 /**
@@ -147,17 +144,4 @@
148145 );
149146 }
150147
151 - /**
152 - * Returns a prefixed message name.
153 - *
154 - * @since 0.1
155 - *
156 - * @param string $name
157 - *
158 - * @return string
159 - */
160 - protected function prefixMsg( $name ) {
161 - return strtolower( get_class( $this->page ) ) . '-' . $this->getName() . '-' . $name;
162 - }
163 -
164148 }
Index: trunk/extensions/EducationProgram/actions/EPDeleteAction.php
@@ -12,7 +12,7 @@
1313 * @licence GNU GPL v3+
1414 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1515 */
16 -class EPDeleteAction extends FormlessAction {
 16+class EPDeleteAction extends EPAction {
1717
1818 /**
1919 * (non-PHPdoc)
@@ -156,30 +156,6 @@
157157 }
158158
159159 /**
160 - * Returns a salt based on the action and the page name.
161 - *
162 - * @since 0.1
163 - *
164 - * @return string
165 - */
166 - protected function getSalt() {
167 - return 'delete' . $this->getTitle()->getLocalURL();
168 - }
169 -
170 - /**
171 - * Returns a prefixed message name.
172 - *
173 - * @since 0.1
174 - *
175 - * @param string $name
176 - *
177 - * @return string
178 - */
179 - protected function prefixMsg( $name ) {
180 - return strtolower( get_class( $this->page ) ) . '-' . $this->getName() . '-' . $name;
181 - }
182 -
183 - /**
184160 * Returns the page title.
185161 *
186162 * @since 0.1
Index: trunk/extensions/EducationProgram/actions/EPUndeleteAction.php
@@ -0,0 +1,182 @@
 2+<?php
 3+
 4+/**
 5+ * Action for undoing a change to an EPPageObject.
 6+ *
 7+ * @since 0.1
 8+ *
 9+ * @file EPUndeleteAction.php
 10+ * @ingroup EducationProgram
 11+ * @ingroup Action
 12+ *
 13+ * @licence GNU GPL v3+
 14+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
 15+ */
 16+class EPUndeleteAction extends EPAction {
 17+
 18+ /**
 19+ * (non-PHPdoc)
 20+ * @see Action::getName()
 21+ */
 22+ public function getName() {
 23+ return 'epundelete';
 24+ }
 25+
 26+ /**
 27+ * (non-PHPdoc)
 28+ * @see Action::getRestriction()
 29+ */
 30+ public function getRestriction() {
 31+ return $this->page->getEditRight();
 32+ }
 33+
 34+ /**
 35+ * (non-PHPdoc)
 36+ * @see Action::getDescription()
 37+ */
 38+ protected function getDescription() {
 39+ return '';
 40+ }
 41+
 42+ /**
 43+ * (non-PHPdoc)
 44+ * @see FormlessAction::onView()
 45+ */
 46+ public function onView() {
 47+ $this->getOutput()->setPageTitle( $this->getPageTitle() );
 48+
 49+ $object = $this->page->getTable()->get( $this->getTitle()->getText() );
 50+
 51+ if ( $object === false ) {
 52+ $revision = EPRevisions::singleton()->getLatestRevision( array(
 53+ 'object_identifier' => $this->getTitle()->getText()
 54+ ) );
 55+
 56+ if ( $revision === false ) {
 57+ $query = array( 'undeletefailed' => 'norevs' ); // TODO: handle
 58+ $this->getOutput()->redirect( $this->getTitle()->getLocalURL( $query ) );
 59+ }
 60+ else {
 61+ $req = $this->getRequest();
 62+
 63+ if ( $req->wasPosted() && $this->getUser()->matchEditToken( $req->getText( 'undeleteToken' ), $this->getSalt() ) ) {
 64+ $success = $this->doUndelete( $revision );
 65+
 66+ if ( $success ) {
 67+ $query = array( 'undeleted' => '1' ); // TODO: handle
 68+ }
 69+ else {
 70+ $query = array( 'undeletefailed' => 'fail' ); // TODO: handle
 71+ }
 72+
 73+ $this->getOutput()->redirect( $this->getTitle()->getLocalURL( $query ) );
 74+ }
 75+ else {
 76+ $this->displayForm( $revision );
 77+ }
 78+ }
 79+ }
 80+ else {
 81+ $query = array( 'undeletefailed' => 'exists' ); // TODO: handle
 82+ $this->getOutput()->redirect( $this->getTitle()->getLocalURL( $query ) );
 83+ }
 84+
 85+ return '';
 86+ }
 87+
 88+ /**
 89+ * Does the actual undeletion action.
 90+ *
 91+ * @since 0.1
 92+ *
 93+ * @param EPRevision $revision
 94+ *
 95+ * @return boolean Success indicator
 96+ */
 97+ protected function doUndelete( EPRevision $revision ) {
 98+ $revAction = new EPRevisionAction();
 99+
 100+ $revAction->setUser( $this->getUser() );
 101+ $revAction->setComment( $this->getRequest()->getText( 'summary', '' ) );
 102+
 103+ return $revision->getObject()->undelete( $revAction );
 104+ }
 105+
 106+ /**
 107+ * Display the undeletion form for the provided EPPageObject.
 108+ *
 109+ * @since 0.1
 110+ *
 111+ * @param EPRevision $revision
 112+ */
 113+ protected function displayForm( EPRevision $revision ) {
 114+ $out = $this->getOutput();
 115+
 116+ $out->addModules( 'ep.formpage' );
 117+
 118+ $object = $revision->getObject();
 119+
 120+ $out->addWikiMsg( $this->prefixMsg( 'text' ), $object->getField( 'name' ) );
 121+
 122+ $out->addHTML( Html::openElement(
 123+ 'form',
 124+ array(
 125+ 'method' => 'post',
 126+ 'action' => $this->getTitle()->getLocalURL( array( 'action' => 'epundelete' ) ),
 127+ )
 128+ ) );
 129+
 130+ $out->addHTML( '&#160;' . Xml::inputLabel(
 131+ wfMsg( $this->prefixMsg( 'summary' ) ),
 132+ 'summary',
 133+ 'summary',
 134+ 65,
 135+ false,
 136+ array(
 137+ 'maxlength' => 250,
 138+ 'spellcheck' => true,
 139+ )
 140+ ) );
 141+
 142+ $out->addHTML( '<br />' );
 143+
 144+ $out->addHTML( Html::input(
 145+ 'undelete',
 146+ wfMsg( $this->prefixMsg( 'undelete-button' ) ),
 147+ 'submit',
 148+ array(
 149+ 'class' => 'ep-undelete',
 150+ )
 151+ ) );
 152+
 153+ $out->addElement(
 154+ 'button',
 155+ array(
 156+ 'id' => 'cancelUndeletion',
 157+ 'class' => 'ep-undelete-cancel ep-cancel',
 158+ 'data-target-url' => $this->getTitle()->getLocalURL(),
 159+ ),
 160+ wfMsg( $this->prefixMsg( 'cancel-button' ) )
 161+ );
 162+
 163+ $out->addHTML( Html::hidden( 'undeleteToken', $this->getUser()->getEditToken( $this->getSalt() ) ) );
 164+
 165+ $out->addHTML( '</form>' );
 166+ }
 167+
 168+ /**
 169+ * Returns the page title.
 170+ *
 171+ * @since 0.1
 172+ *
 173+ * @return string
 174+ */
 175+ protected function getPageTitle() {
 176+ return wfMsgExt(
 177+ $this->prefixMsg( 'title' ),
 178+ 'parsemag',
 179+ $this->getTitle()->getText()
 180+ );
 181+ }
 182+
 183+}
\ No newline at end of file
Property changes on: trunk/extensions/EducationProgram/actions/EPUndeleteAction.php
___________________________________________________________________
Added: svn:eol-style
1184 + native
Index: trunk/extensions/EducationProgram/actions/EPUndoAction.php
@@ -12,7 +12,7 @@
1313 * @licence GNU GPL v3+
1414 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1515 */
16 -class EPUndoAction extends FormlessAction {
 16+class EPUndoAction extends EPAction {
1717
1818 /**
1919 * (non-PHPdoc)
@@ -153,32 +153,8 @@
154154
155155 $out->addHTML( '</form>' );
156156 }
157 -
158 - /**
159 - * Returns a salt based on the action and the page name.
160 - *
161 - * @since 0.1
162 - *
163 - * @return string
164 - */
165 - protected function getSalt() {
166 - return 'undo' . $this->getTitle()->getLocalURL();
167 - }
168157
169158 /**
170 - * Returns a prefixed message name.
171 - *
172 - * @since 0.1
173 - *
174 - * @param string $name
175 - *
176 - * @return string
177 - */
178 - protected function prefixMsg( $name ) {
179 - return strtolower( get_class( $this->page ) ) . '-' . $this->getName() . '-' . $name;
180 - }
181 -
182 - /**
183159 * Returns the page title.
184160 *
185161 * @since 0.1
Index: trunk/extensions/EducationProgram/includes/EPRevisions.php
@@ -113,8 +113,7 @@
114114 null,
115115 $conds,
116116 array(
117 - 'SORT BY' => $this->getPrefixedField( 'id' ),
118 - 'ORDER' => 'DESC',
 117+ 'ORDER BY' => $this->getPrefixedField( 'id' ) . ' DESC',
119118 )
120119 );
121120 }
Index: trunk/extensions/EducationProgram/includes/EPRevisionedObject.php
@@ -284,12 +284,22 @@
285285 ), $options );
286286 }
287287
288 - public function undelete() {
 288+ /**
 289+ *
 290+ * Enter description here ...
 291+ */
 292+ public function undelete( EPRevisionAction $revAction ) {
 293+ $this->setRevisionAction( $revAction );
289294
290 - }
291 -
292 - public function revert() {
 295+ $result = parent::insert();
 296+
 297+ if ( $result ) {
 298+ $this->log( 'undelete' );
 299+ }
293300
 301+ $this->setRevisionAction( false );
 302+
 303+ return $result;
294304 }
295305
296306 /**
Index: trunk/extensions/EducationProgram/includes/EPRevision.php
@@ -77,16 +77,5 @@
7878
7979 return $this->user;
8080 }
81 -
82 - public static function getLastRevision( array $conditions ) {
83 - return EPRevision::selectRow(
84 - null,
85 - $conditions,
86 - array(
87 - 'SORT BY' => EPRevision::getPrefixedField( 'time' ),
88 - 'ORDER' => 'DESC',
89 - )
90 - );
91 - }
9281
9382 }
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php
@@ -88,10 +88,12 @@
8989 'logentry-institution-add' => '$1 created institution $3',
9090 'logentry-institution-remove' => '$1 removed institution $3',
9191 'logentry-institution-update' => '$1 updated institution $3',
 92+ 'logentry-institution-undelete' => '$1 undeleted institution $3',
9293
9394 'logentry-course-add' => '$1 created course $3',
9495 'logentry-course-remove' => '$1 removed course $3',
9596 'logentry-course-update' => '$1 updated course $3',
 97+ 'logentry-course-undelete' => '$1 undeleted course $3',
9698
9799 'logentry-instructor-add' => '$1 {{GENDER:$2|added}} {{PLURAL:$4|instructor|instructors}} $5 to course $3',
98100 'logentry-instructor-remove' => '$1 {{GENDER:$2|removed}} {{PLURAL:$4|instructor|instructors}} $5 from course $3',
@@ -363,10 +365,11 @@
364366 'ep-editorg-exists-already' => 'This institution already exists. You are editing it.',
365367 'ep-editorg-edit' => 'Editing institution: $1',
366368 'ep-editorg-add' => 'Adding institution: $1',
367 - 'ep-editorg-deleted' => "'''Warning: You are recreating an institution that was previously deleted.'''
 369+ 'orgpage-editorg-deleted' => "'''Warning: You are recreating an institution that was previously deleted.'''
368370
369371 You should consider whether it is appropriate to continue editing this institution.
370372 The deletion log for this institution is provided below for convenience:",
 373+ 'orgpage-editorg-undelete-link' => 'restore $1 {{PLURAL:$1|revision|revisions}}',
371374
372375 // Course editing
373376 'editcourse-add-legend' => 'Add course',
@@ -392,7 +395,7 @@
393396 'ep-editcourse-exists-already' => 'This course already exists. You are editing it.',
394397 'ep-editcourse-edit' => 'Editing course: $1',
395398 'ep-editcourse-add' => 'Adding course: $1',
396 - 'ep-editcourse-deleted' => "'''Warning: You are recreating a course that was previously deleted.'''
 399+ 'coursepage-editcourse-deleted' => "'''Warning: You are recreating a course that was previously deleted.'''
397400
398401 You should consider whether it is appropriate to continue editing this course.
399402 The deletion log for this course is provided below for convenience:",
@@ -401,6 +404,8 @@
402405 'ep-course-invalid-token' => 'The token needs to be at least contain $1 {{PLURAL:$1|character|characters}}.',
403406 'ep-course-invalid-description' => 'The description needs to be at least contain $1 {{PLURAL:$1|character|characters}}.',
404407 'ep-course-invalid-lang' => 'This language is not valid.',
 408+ 'coursepage-editcourse-undelete-revisions' => 'This page has been deleted. You can $1.',
 409+ 'coursepage-editcourse-undelete-link' => 'restore $1 {{PLURAL:$1|revision|revisions}}',
405410
406411 // ep.pager
407412 'ep-pager-confirm-delete' => 'Are you sure you want to delete this item?',

Status & tagging log