https://www.mediawiki.org/wiki/Special:Code/MediaWiki/112651
Revision: 112651
Author: jeroendedauw
Date: 2012-02-28 22:51:01 +0000 (Tue, 28 Feb 2012)
Log Message:
-----------
work on undeletion
Modified Paths:
--------------
trunk/extensions/EducationProgram/EducationProgram.i18n.php
trunk/extensions/EducationProgram/EducationProgram.php
trunk/extensions/EducationProgram/actions/EPDeleteAction.php
trunk/extensions/EducationProgram/actions/EPEditAction.php
trunk/extensions/EducationProgram/actions/EPHistoryAction.php
trunk/extensions/EducationProgram/actions/EPRestoreAction.php
trunk/extensions/EducationProgram/actions/EPUndoAction.php
trunk/extensions/EducationProgram/actions/EPViewAction.php
trunk/extensions/EducationProgram/actions/EditCourseAction.php
trunk/extensions/EducationProgram/includes/EPRevision.php
trunk/extensions/EducationProgram/includes/EPRevisionedObject.php
trunk/extensions/EducationProgram/includes/EPRevisions.php
trunk/extensions/EducationProgram/pages/EPPage.php
Added Paths:
-----------
trunk/extensions/EducationProgram/actions/EPUndeleteAction.php
trunk/extensions/EducationProgram/maintenance/truncate.sql
Modified: trunk/extensions/EducationProgram/EducationProgram.i18n.php
===================================================================
--- trunk/extensions/EducationProgram/EducationProgram.i18n.php 2012-02-28
22:50:13 UTC (rev 112650)
+++ trunk/extensions/EducationProgram/EducationProgram.i18n.php 2012-02-28
22:51:01 UTC (rev 112651)
@@ -88,10 +88,12 @@
'logentry-institution-add' => '$1 created institution $3',
'logentry-institution-remove' => '$1 removed institution $3',
'logentry-institution-update' => '$1 updated institution $3',
+ 'logentry-institution-undelete' => '$1 undeleted institution $3',
'logentry-course-add' => '$1 created course $3',
'logentry-course-remove' => '$1 removed course $3',
'logentry-course-update' => '$1 updated course $3',
+ 'logentry-course-undelete' => '$1 undeleted course $3',
'logentry-instructor-add' => '$1 {{GENDER:$2|added}}
{{PLURAL:$4|instructor|instructors}} $5 to course $3',
'logentry-instructor-remove' => '$1 {{GENDER:$2|removed}}
{{PLURAL:$4|instructor|instructors}} $5 from course $3',
@@ -363,10 +365,11 @@
'ep-editorg-exists-already' => 'This institution already exists. You
are editing it.',
'ep-editorg-edit' => 'Editing institution: $1',
'ep-editorg-add' => 'Adding institution: $1',
- 'ep-editorg-deleted' => "'''Warning: You are recreating an institution
that was previously deleted.'''
+ 'orgpage-editorg-deleted' => "'''Warning: You are recreating an
institution that was previously deleted.'''
You should consider whether it is appropriate to continue editing this
institution.
The deletion log for this institution is provided below for convenience:",
+ 'orgpage-editorg-undelete-link' => 'restore $1
{{PLURAL:$1|revision|revisions}}',
// Course editing
'editcourse-add-legend' => 'Add course',
@@ -392,7 +395,7 @@
'ep-editcourse-exists-already' => 'This course already exists. You are
editing it.',
'ep-editcourse-edit' => 'Editing course: $1',
'ep-editcourse-add' => 'Adding course: $1',
- 'ep-editcourse-deleted' => "'''Warning: You are recreating a course
that was previously deleted.'''
+ 'coursepage-editcourse-deleted' => "'''Warning: You are recreating a
course that was previously deleted.'''
You should consider whether it is appropriate to continue editing this course.
The deletion log for this course is provided below for convenience:",
@@ -401,6 +404,8 @@
'ep-course-invalid-token' => 'The token needs to be at least contain $1
{{PLURAL:$1|character|characters}}.',
'ep-course-invalid-description' => 'The description needs to be at
least contain $1 {{PLURAL:$1|character|characters}}.',
'ep-course-invalid-lang' => 'This language is not valid.',
+ 'coursepage-editcourse-undelete-revisions' => 'This page has been
deleted. You can $1.',
+ 'coursepage-editcourse-undelete-link' => 'restore $1
{{PLURAL:$1|revision|revisions}}',
// ep.pager
'ep-pager-confirm-delete' => 'Are you sure you want to delete this
item?',
Modified: trunk/extensions/EducationProgram/EducationProgram.php
===================================================================
--- trunk/extensions/EducationProgram/EducationProgram.php 2012-02-28
22:50:13 UTC (rev 112650)
+++ trunk/extensions/EducationProgram/EducationProgram.php 2012-02-28
22:51:01 UTC (rev 112651)
@@ -61,6 +61,7 @@
$wgAutoloadClasses['EditCourseAction'] =
dirname( __FILE__ ) . '/actions/EditCourseAction.php';
$wgAutoloadClasses['EditOrgAction'] = dirname(
__FILE__ ) . '/actions/EditOrgAction.php';
+$wgAutoloadClasses['EPAction']
= dirname( __FILE__ ) . '/actions/EPAction.php';
$wgAutoloadClasses['EPAddArticleAction'] = dirname(
__FILE__ ) . '/actions/EPAddArticleAction.php';
$wgAutoloadClasses['EPAddReviewerAction'] = dirname(
__FILE__ ) . '/actions/EPAddReviewerAction.php';
$wgAutoloadClasses['EPDeleteAction'] = dirname(
__FILE__ ) . '/actions/EPDeleteAction.php';
Modified: trunk/extensions/EducationProgram/actions/EPDeleteAction.php
===================================================================
--- trunk/extensions/EducationProgram/actions/EPDeleteAction.php
2012-02-28 22:50:13 UTC (rev 112650)
+++ trunk/extensions/EducationProgram/actions/EPDeleteAction.php
2012-02-28 22:51:01 UTC (rev 112651)
@@ -12,7 +12,7 @@
* @licence GNU GPL v3+
* @author Jeroen De Dauw < [email protected] >
*/
-class EPDeleteAction extends FormlessAction {
+class EPDeleteAction extends EPAction {
/**
* (non-PHPdoc)
@@ -156,30 +156,6 @@
}
/**
- * Returns a salt based on the action and the page name.
- *
- * @since 0.1
- *
- * @return string
- */
- protected function getSalt() {
- return 'delete' . $this->getTitle()->getLocalURL();
- }
-
- /**
- * Returns a prefixed message name.
- *
- * @since 0.1
- *
- * @param string $name
- *
- * @return string
- */
- protected function prefixMsg( $name ) {
- return strtolower( get_class( $this->page ) ) . '-' .
$this->getName() . '-' . $name;
- }
-
- /**
* Returns the page title.
*
* @since 0.1
Modified: trunk/extensions/EducationProgram/actions/EPEditAction.php
===================================================================
--- trunk/extensions/EducationProgram/actions/EPEditAction.php 2012-02-28
22:50:13 UTC (rev 112650)
+++ trunk/extensions/EducationProgram/actions/EPEditAction.php 2012-02-28
22:51:01 UTC (rev 112651)
@@ -12,7 +12,7 @@
* @licence GNU GPL v3+
* @author Jeroen De Dauw < [email protected] >
*/
-abstract class EPEditAction extends FormlessAction {
+abstract class EPEditAction extends EPAction {
/**
* Instance of the object being edited or created.
@@ -100,10 +100,7 @@
}
else {
if ( $object === false ) {
- $this->page->displayDeletionLog(
- $this->getContext(),
- 'ep-' . strtolower( $this->getName() )
. '-deleted'
- );
+ $this->displayDeletionLog();
$this->isNew = true;
$object = $this->table->newFromArray( $data,
true );
Modified: trunk/extensions/EducationProgram/actions/EPHistoryAction.php
===================================================================
--- trunk/extensions/EducationProgram/actions/EPHistoryAction.php
2012-02-28 22:50:13 UTC (rev 112650)
+++ trunk/extensions/EducationProgram/actions/EPHistoryAction.php
2012-02-28 22:51:01 UTC (rev 112651)
@@ -12,7 +12,7 @@
* @licence GNU GPL v3+
* @author Jeroen De Dauw < [email protected] >
*/
-class EPHistoryAction extends FormlessAction {
+class EPHistoryAction extends EPAction {
/**
* (non-PHPdoc)
@@ -44,10 +44,7 @@
protected function displayNoRevisions() {
$this->getOutput()->addWikiMsg( $this->prefixMsg( 'norevs' ) );
- $this->page->displayDeletionLog(
- $this->getContext(),
- $this->prefixMsg( 'deleted' )
- );
+ $this->displayDeletionLog();
}
/**
@@ -147,17 +144,4 @@
);
}
- /**
- * Returns a prefixed message name.
- *
- * @since 0.1
- *
- * @param string $name
- *
- * @return string
- */
- protected function prefixMsg( $name ) {
- return strtolower( get_class( $this->page ) ) . '-' .
$this->getName() . '-' . $name;
- }
-
}
Modified: trunk/extensions/EducationProgram/actions/EPRestoreAction.php
===================================================================
--- trunk/extensions/EducationProgram/actions/EPRestoreAction.php
2012-02-28 22:50:13 UTC (rev 112650)
+++ trunk/extensions/EducationProgram/actions/EPRestoreAction.php
2012-02-28 22:51:01 UTC (rev 112651)
@@ -12,7 +12,7 @@
* @licence GNU GPL v3+
* @author Jeroen De Dauw < [email protected] >
*/
-class EPRestoreAction extends FormlessAction {
+class EPRestoreAction extends EPAction {
/**
* (non-PHPdoc)
@@ -172,30 +172,6 @@
}
/**
- * Returns a salt based on the action and the page name.
- *
- * @since 0.1
- *
- * @return string
- */
- protected function getSalt() {
- return 'restore' . $this->getTitle()->getLocalURL();
- }
-
- /**
- * Returns a prefixed message name.
- *
- * @since 0.1
- *
- * @param string $name
- *
- * @return string
- */
- protected function prefixMsg( $name ) {
- return strtolower( get_class( $this->page ) ) . '-' .
$this->getName() . '-' . $name;
- }
-
- /**
* Returns the page title.
*
* @since 0.1
Added: trunk/extensions/EducationProgram/actions/EPUndeleteAction.php
===================================================================
--- trunk/extensions/EducationProgram/actions/EPUndeleteAction.php
(rev 0)
+++ trunk/extensions/EducationProgram/actions/EPUndeleteAction.php
2012-02-28 22:51:01 UTC (rev 112651)
@@ -0,0 +1,182 @@
+<?php
+
+/**
+ * Action for undoing a change to an EPPageObject.
+ *
+ * @since 0.1
+ *
+ * @file EPUndeleteAction.php
+ * @ingroup EducationProgram
+ * @ingroup Action
+ *
+ * @licence GNU GPL v3+
+ * @author Jeroen De Dauw < [email protected] >
+ */
+class EPUndeleteAction extends EPAction {
+
+ /**
+ * (non-PHPdoc)
+ * @see Action::getName()
+ */
+ public function getName() {
+ return 'epundelete';
+ }
+
+ /**
+ * (non-PHPdoc)
+ * @see Action::getRestriction()
+ */
+ public function getRestriction() {
+ return $this->page->getEditRight();
+ }
+
+ /**
+ * (non-PHPdoc)
+ * @see Action::getDescription()
+ */
+ protected function getDescription() {
+ return '';
+ }
+
+ /**
+ * (non-PHPdoc)
+ * @see FormlessAction::onView()
+ */
+ public function onView() {
+ $this->getOutput()->setPageTitle( $this->getPageTitle() );
+
+ $object = $this->page->getTable()->get(
$this->getTitle()->getText() );
+
+ if ( $object === false ) {
+ $revision =
EPRevisions::singleton()->getLatestRevision( array(
+ 'object_identifier' =>
$this->getTitle()->getText()
+ ) );
+
+ if ( $revision === false ) {
+ $query = array( 'undeletefailed' => 'norevs' );
// TODO: handle
+ $this->getOutput()->redirect(
$this->getTitle()->getLocalURL( $query ) );
+ }
+ else {
+ $req = $this->getRequest();
+
+ if ( $req->wasPosted() &&
$this->getUser()->matchEditToken( $req->getText( 'undeleteToken' ),
$this->getSalt() ) ) {
+ $success = $this->doUndelete( $revision
);
+
+ if ( $success ) {
+ $query = array( 'undeleted' =>
'1' ); // TODO: handle
+ }
+ else {
+ $query = array(
'undeletefailed' => 'fail' ); // TODO: handle
+ }
+
+ $this->getOutput()->redirect(
$this->getTitle()->getLocalURL( $query ) );
+ }
+ else {
+ $this->displayForm( $revision );
+ }
+ }
+ }
+ else {
+ $query = array( 'undeletefailed' => 'exists' ); //
TODO: handle
+ $this->getOutput()->redirect(
$this->getTitle()->getLocalURL( $query ) );
+ }
+
+ return '';
+ }
+
+ /**
+ * Does the actual undeletion action.
+ *
+ * @since 0.1
+ *
+ * @param EPRevision $revision
+ *
+ * @return boolean Success indicator
+ */
+ protected function doUndelete( EPRevision $revision ) {
+ $revAction = new EPRevisionAction();
+
+ $revAction->setUser( $this->getUser() );
+ $revAction->setComment( $this->getRequest()->getText(
'summary', '' ) );
+
+ return $revision->getObject()->undelete( $revAction );
+ }
+
+ /**
+ * Display the undeletion form for the provided EPPageObject.
+ *
+ * @since 0.1
+ *
+ * @param EPRevision $revision
+ */
+ protected function displayForm( EPRevision $revision ) {
+ $out = $this->getOutput();
+
+ $out->addModules( 'ep.formpage' );
+
+ $object = $revision->getObject();
+
+ $out->addWikiMsg( $this->prefixMsg( 'text' ),
$object->getField( 'name' ) );
+
+ $out->addHTML( Html::openElement(
+ 'form',
+ array(
+ 'method' => 'post',
+ 'action' => $this->getTitle()->getLocalURL(
array( 'action' => 'epundelete' ) ),
+ )
+ ) );
+
+ $out->addHTML( ' ' . Xml::inputLabel(
+ wfMsg( $this->prefixMsg( 'summary' ) ),
+ 'summary',
+ 'summary',
+ 65,
+ false,
+ array(
+ 'maxlength' => 250,
+ 'spellcheck' => true,
+ )
+ ) );
+
+ $out->addHTML( '<br />' );
+
+ $out->addHTML( Html::input(
+ 'undelete',
+ wfMsg( $this->prefixMsg( 'undelete-button' ) ),
+ 'submit',
+ array(
+ 'class' => 'ep-undelete',
+ )
+ ) );
+
+ $out->addElement(
+ 'button',
+ array(
+ 'id' => 'cancelUndeletion',
+ 'class' => 'ep-undelete-cancel ep-cancel',
+ 'data-target-url' =>
$this->getTitle()->getLocalURL(),
+ ),
+ wfMsg( $this->prefixMsg( 'cancel-button' ) )
+ );
+
+ $out->addHTML( Html::hidden( 'undeleteToken',
$this->getUser()->getEditToken( $this->getSalt() ) ) );
+
+ $out->addHTML( '</form>' );
+ }
+
+ /**
+ * Returns the page title.
+ *
+ * @since 0.1
+ *
+ * @return string
+ */
+ protected function getPageTitle() {
+ return wfMsgExt(
+ $this->prefixMsg( 'title' ),
+ 'parsemag',
+ $this->getTitle()->getText()
+ );
+ }
+
+}
\ No newline at end of file
Property changes on:
trunk/extensions/EducationProgram/actions/EPUndeleteAction.php
___________________________________________________________________
Added: svn:eol-style
+ native
Modified: trunk/extensions/EducationProgram/actions/EPUndoAction.php
===================================================================
--- trunk/extensions/EducationProgram/actions/EPUndoAction.php 2012-02-28
22:50:13 UTC (rev 112650)
+++ trunk/extensions/EducationProgram/actions/EPUndoAction.php 2012-02-28
22:51:01 UTC (rev 112651)
@@ -12,7 +12,7 @@
* @licence GNU GPL v3+
* @author Jeroen De Dauw < [email protected] >
*/
-class EPUndoAction extends FormlessAction {
+class EPUndoAction extends EPAction {
/**
* (non-PHPdoc)
@@ -153,32 +153,8 @@
$out->addHTML( '</form>' );
}
-
- /**
- * Returns a salt based on the action and the page name.
- *
- * @since 0.1
- *
- * @return string
- */
- protected function getSalt() {
- return 'undo' . $this->getTitle()->getLocalURL();
- }
/**
- * Returns a prefixed message name.
- *
- * @since 0.1
- *
- * @param string $name
- *
- * @return string
- */
- protected function prefixMsg( $name ) {
- return strtolower( get_class( $this->page ) ) . '-' .
$this->getName() . '-' . $name;
- }
-
- /**
* Returns the page title.
*
* @since 0.1
Modified: trunk/extensions/EducationProgram/actions/EPViewAction.php
===================================================================
--- trunk/extensions/EducationProgram/actions/EPViewAction.php 2012-02-28
22:50:13 UTC (rev 112650)
+++ trunk/extensions/EducationProgram/actions/EPViewAction.php 2012-02-28
22:51:01 UTC (rev 112651)
@@ -12,7 +12,7 @@
* @licence GNU GPL v3+
* @author Jeroen De Dauw < [email protected] >
*/
-abstract class EPViewAction extends FormlessAction {
+abstract class EPViewAction extends EPAction {
/**
* @since 0.1
@@ -76,10 +76,7 @@
else {
$out->addWikiMsg( strtolower(
get_called_class() ) . '-none', $name );
- $this->page->displayDeletionLog(
- $this->getContext(),
- 'ep-' . strtolower( $this->getName() )
. '-deleted'
- );
+ $this->displayDeletionLog();
}
}
else {
Modified: trunk/extensions/EducationProgram/actions/EditCourseAction.php
===================================================================
--- trunk/extensions/EducationProgram/actions/EditCourseAction.php
2012-02-28 22:50:13 UTC (rev 112650)
+++ trunk/extensions/EducationProgram/actions/EditCourseAction.php
2012-02-28 22:51:01 UTC (rev 112651)
@@ -58,10 +58,8 @@
$this->getOutput()->addModules( array( 'ep.datepicker',
'ep.combobox' ) );
if ( !$this->isNewPost() && !$this->table->hasIdentifier(
$this->getTitle()->getText() ) ) {
- $this->page->displayDeletionLog(
- $this->getContext(),
- 'ep-' . strtolower( $this->getName() ) .
'-deleted'
- );
+ $this->displayUndeletionLink();
+ $this->displayDeletionLog();
list( $name, $term ) = $this->titleToNameAndTerm(
$this->getTitle()->getText() );
Modified: trunk/extensions/EducationProgram/includes/EPRevision.php
===================================================================
--- trunk/extensions/EducationProgram/includes/EPRevision.php 2012-02-28
22:50:13 UTC (rev 112650)
+++ trunk/extensions/EducationProgram/includes/EPRevision.php 2012-02-28
22:51:01 UTC (rev 112651)
@@ -77,16 +77,5 @@
return $this->user;
}
-
- public static function getLastRevision( array $conditions ) {
- return EPRevision::selectRow(
- null,
- $conditions,
- array(
- 'SORT BY' => EPRevision::getPrefixedField(
'time' ),
- 'ORDER' => 'DESC',
- )
- );
- }
}
Modified: trunk/extensions/EducationProgram/includes/EPRevisionedObject.php
===================================================================
--- trunk/extensions/EducationProgram/includes/EPRevisionedObject.php
2012-02-28 22:50:13 UTC (rev 112650)
+++ trunk/extensions/EducationProgram/includes/EPRevisionedObject.php
2012-02-28 22:51:01 UTC (rev 112651)
@@ -284,12 +284,22 @@
), $options );
}
- public function undelete() {
+ /**
+ *
+ * Enter description here ...
+ */
+ public function undelete( EPRevisionAction $revAction ) {
+ $this->setRevisionAction( $revAction );
- }
-
- public function revert() {
+ $result = parent::insert();
+
+ if ( $result ) {
+ $this->log( 'undelete' );
+ }
+ $this->setRevisionAction( false );
+
+ return $result;
}
/**
Modified: trunk/extensions/EducationProgram/includes/EPRevisions.php
===================================================================
--- trunk/extensions/EducationProgram/includes/EPRevisions.php 2012-02-28
22:50:13 UTC (rev 112650)
+++ trunk/extensions/EducationProgram/includes/EPRevisions.php 2012-02-28
22:51:01 UTC (rev 112651)
@@ -113,8 +113,7 @@
null,
$conds,
array(
- 'SORT BY' => $this->getPrefixedField( 'id' ),
- 'ORDER' => 'DESC',
+ 'ORDER BY' => $this->getPrefixedField( 'id' ) .
' DESC',
)
);
}
Added: trunk/extensions/EducationProgram/maintenance/truncate.sql
===================================================================
--- trunk/extensions/EducationProgram/maintenance/truncate.sql
(rev 0)
+++ trunk/extensions/EducationProgram/maintenance/truncate.sql 2012-02-28
22:51:01 UTC (rev 112651)
@@ -0,0 +1,9 @@
+TRUNCATE TABLE `mw_ep_orgs`;
+TRUNCATE TABLE `mw_ep_courses`;
+TRUNCATE TABLE `mw_ep_students`;
+TRUNCATE TABLE `mw_ep_users_per_course`;
+TRUNCATE TABLE `mw_ep_instructors`;
+TRUNCATE TABLE `mw_ep_oas`;
+TRUNCATE TABLE `mw_ep_cas`;
+TRUNCATE TABLE `mw_ep_articles`;
+TRUNCATE TABLE `mw_ep_revisions`;
\ No newline at end of file
Property changes on: trunk/extensions/EducationProgram/maintenance/truncate.sql
___________________________________________________________________
Added: svn:eol-style
+ native
Modified: trunk/extensions/EducationProgram/pages/EPPage.php
===================================================================
--- trunk/extensions/EducationProgram/pages/EPPage.php 2012-02-28 22:50:13 UTC
(rev 112650)
+++ trunk/extensions/EducationProgram/pages/EPPage.php 2012-02-28 22:51:01 UTC
(rev 112651)
@@ -169,39 +169,4 @@
return static::$info['log-type'];
}
- // TODO
- public static function displayDeletionLog( IContextSource $context,
$messageKey ) {
- $out = $context->getOutput();
-
- if ( true ) { // $context->getUser()->isAllowed( '' )
- $revisionCount = EPRevisions::singleton()->count( array(
- 'object_identifier' =>
$context->getTitle()->getText()
- ) );
-
- if ( $revisionCount > 0 ) {
- $out->addHTML( $context->msg( 'thisisdeleted'
)->rawParams(
- Linker::linkKnown(
- $context->getTitle(),
- $context->msg( 'restorelink'
)->numParams( $revisionCount )->escaped(),
- array(),
- array( 'action' => 'epundelete'
)
- )
- )->text() );
- }
- }
-
- LogEventsList::showLogExtract(
- $out,
- array( static::$info['log-type'] ),
- $context->getTitle(),
- '',
- array(
- 'lim' => 10,
- 'conds' => array( 'log_action' => 'remove' ),
- 'showIfEmpty' => false,
- 'msgKey' => array( $messageKey )
- )
- );
- }
-
}
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs