Jeroen De Dauw has submitted this change and it was merged.
Change subject: Clean Up includes/actions code and classes
......................................................................
Clean Up includes/actions code and classes
Splits classes into individual files
Clean up comments
Change-Id: Ie5c3942f70019b6556df19cba1e2a4bf37698531
---
M repo/Wikibase.classes.php
M repo/includes/actions/EditEntityAction.php
M repo/includes/actions/EditItemAction.php
M repo/includes/actions/EditPropertyAction.php
M repo/includes/actions/HistoryEntityAction.php
M repo/includes/actions/HistoryItemAction.php
M repo/includes/actions/HistoryPropertyAction.php
A repo/includes/actions/SubmitEntityAction.php
A repo/includes/actions/SubmitItemAction.php
A repo/includes/actions/SubmitPropertyAction.php
M repo/includes/actions/ViewEntityAction.php
M repo/includes/actions/ViewItemAction.php
M repo/includes/actions/ViewPropertyAction.php
13 files changed, 185 insertions(+), 220 deletions(-)
Approvals:
Jeroen De Dauw: Looks good to me, approved
jenkins-bot: Verified
diff --git a/repo/Wikibase.classes.php b/repo/Wikibase.classes.php
index cfc9325..8a98f01 100644
--- a/repo/Wikibase.classes.php
+++ b/repo/Wikibase.classes.php
@@ -75,9 +75,9 @@
'Wikibase\ViewEntityAction' =>
'includes/actions/ViewEntityAction.php',
'Wikibase\ViewItemAction' =>
'includes/actions/ViewItemAction.php',
'Wikibase\ViewPropertyAction' =>
'includes/actions/ViewPropertyAction.php',
- 'Wikibase\SubmitEntityAction' =>
'includes/actions/EditEntityAction.php',
- 'Wikibase\SubmitItemAction' =>
'includes/actions/EditItemAction.php',
- 'Wikibase\SubmitPropertyAction' =>
'includes/actions/EditPropertyAction.php',
+ 'Wikibase\SubmitEntityAction' =>
'includes/actions/SubmitEntityAction.php',
+ 'Wikibase\SubmitItemAction' =>
'includes/actions/SubmitItemAction.php',
+ 'Wikibase\SubmitPropertyAction' =>
'includes/actions/SubmitPropertyAction.php',
// includes/api
'Wikibase\Api\ApiWikibase' => 'includes/api/ApiWikibase.php',
diff --git a/repo/includes/actions/EditEntityAction.php
b/repo/includes/actions/EditEntityAction.php
index 03112a5..d6fa713 100644
--- a/repo/includes/actions/EditEntityAction.php
+++ b/repo/includes/actions/EditEntityAction.php
@@ -16,22 +16,15 @@
use Wikibase\Repo\WikibaseRepo;
/**
- * @file
- * @ingroup WikibaseRepo
- * @ingroup Action
- *
- * @licence GNU GPL v2+
- * @author Jeroen De Dauw < [email protected] >
- * @author Jens Ohlig
- * @author Daniel Kinzler
- */
-
-/**
* Handles the edit action for Wikibase entities.
* This shows the forms for the undo and restore operations if requested.
* Otherwise it will just show the normal entity view.
*
* @since 0.1
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < [email protected] >
+ * @author Jens Ohlig
+ * @author Daniel Kinzler
*/
abstract class EditEntityAction extends ViewEntityAction {
@@ -562,138 +555,5 @@
$this->getOutput()->addHTML( Html::closeElement( 'form' ) );
$this->getOutput()->addHTML( Html::closeElement( 'div' ) );
}
-}
-
-/**
- * Handles the submit action for Wikibase entities.
- * This performs the undo and restore operations when requested.
- * Otherwise it will just show the normal entity view.
- *
- * @since 0.1
- */
-class SubmitEntityAction extends EditEntityAction {
-
- public function getName() {
- return 'submit';
- }
-
- /**
- * Show the entity using parent::show(), unless an undo operation is
requested.
- * In that case $this->undo(); is called to perform the action after a
permission check.
- */
- public function show() {
- $req = $this->getRequest();
-
- if ( $req->getCheck('undo') || $req->getCheck('undoafter') ||
$req->getCheck('restore') ) {
- if ( $this->showPermissionError( "read" ) ||
$this->showPermissionError( "edit" ) ) {
- return;
- }
-
- $this->undo();
- return;
- }
-
- parent::show();
- }
-
- /**
- * Perform the undo operation specified by the web request.
- */
- public function undo() {
- $req = $this->getRequest();
-
- if ( !$req->wasPosted() || !$req->getCheck('wpSave') ) {
- $args = array( 'action' => "edit" );
-
- if ( $req->getCheck( 'undo' ) ) {
- $args['undo'] = $req->getInt( 'undo' );
- }
-
- if ( $req->getCheck( 'undoafter' ) ) {
- $args['undoafter'] = $req->getInt( 'undoafter'
);
- }
-
- if ( $req->getCheck( 'restore' ) ) {
- $args['restore'] = $req->getInt( 'restore' );
- }
-
- $undoUrl = $this->getTitle()->getLocalURL( $args );
- $this->getOutput()->redirect( $undoUrl );
- return;
- }
-
- $revisions = $this->loadRevisions();
- if ( !$revisions->isOK() ) {
- $this->showStatusErrorsPage(
'wikibase-undo-revision-error', $revisions );
- return;
- }
-
- /**
- * @var \Revision $olderRevision
- * @var \Revision $newerRevision
- * @var \Revision $latestRevision
- */
- list( $olderRevision, $newerRevision, $latestRevision ) =
$revisions->getValue();
-
- /**
- * @var EntityContent $latestContent
- * @var EntityContent $olderContent
- * @var EntityContent $newerContent
- */
- $olderContent = $olderRevision->getContent();
- $newerContent = $newerRevision->getContent();
- $latestContent = $latestRevision->getContent();
-
- $diff = $newerContent->getEntity()->getDiff(
$olderContent->getEntity() );
- $edit = false;
- $token = $this->getRequest()->getText( 'wpEditToken' );
-
- if ( $newerRevision->getId() == $latestRevision->getId() ) { //
restore
- $summary = $req->getText( 'wpSummary' );
-
- if ( $summary === '' ) {
- $summary = $this->makeRestoreSummary(
$olderRevision, $newerRevision, $latestRevision );
- }
-
- if ( $diff->isEmpty() ) {
- $status = Status::newGood();
- $status->warning( 'wikibase-empty-undo' );
- } else {
- // make the old content the new content.
- // NOTE: conflict detection is not needed for a
plain restore, it's not based on anything.
- $edit = new EditEntity( $olderContent,
$this->getUser(), false, $this->getContext() );
- $status = $edit->attemptSave( $summary, 0,
$token );
- }
- } else { // undo
- $entity = $latestContent->getEntity()->copy();
- $latestContent->getEntity()->patch( $diff );;
-
- if ( $latestContent->getEntity()->getDiff( $entity
)->isEmpty() ) {
- $status = Status::newGood();
- $status->warning( 'wikibase-empty-undo' );
- } else {
- $summary = $req->getText( 'wpSummary' );
-
- if ( $summary === '' ) {
- $summary = $this->makeUndoSummary(
$olderRevision, $newerRevision, $latestRevision );
- }
-
- //NOTE: use latest revision as base revision -
we are saving patched content
- // based on the latest revision.
- $edit = new EditEntity( $latestContent,
$this->getUser(), $latestRevision->getId(), $this->getContext() );
- $status = $edit->attemptSave( $summary, 0,
$token );
- }
- }
-
- if ( $status->isOK() ) {
- $this->getOutput()->redirect(
$this->getTitle()->getFullUrl() );
- } else {
- $edit->showErrorPage();
- }
- }
-
- public function execute() {
- throw new \MWException( "not applicable" );
- }
-}
+}
\ No newline at end of file
diff --git a/repo/includes/actions/EditItemAction.php
b/repo/includes/actions/EditItemAction.php
index 8f47ea7..791b42c 100644
--- a/repo/includes/actions/EditItemAction.php
+++ b/repo/includes/actions/EditItemAction.php
@@ -3,33 +3,13 @@
namespace Wikibase;
/**
- * @file
- * @ingroup WikibaseRepo
- * @ingroup Action
+ * Handles the edit action for Wikibase items.
*
+ * @since 0.1
* @licence GNU GPL v2+
* @author Jeroen De Dauw < [email protected] >
* @author Daniel Kinzler
*/
-
-/**
- * Handles the edit action for Wikibase items.
- *
- * @since 0.1
- */
class EditItemAction extends EditEntityAction {
-
-
-
-}
-
-/**
- * Handles the submit action for Wikibase items.
- *
- * @since 0.1
- */
-class SubmitItemAction extends SubmitEntityAction {
-
-
}
diff --git a/repo/includes/actions/EditPropertyAction.php
b/repo/includes/actions/EditPropertyAction.php
index 275e627..85f3192 100644
--- a/repo/includes/actions/EditPropertyAction.php
+++ b/repo/includes/actions/EditPropertyAction.php
@@ -3,32 +3,14 @@
namespace Wikibase;
/**
- * @file
- * @ingroup WikibaseRepo
- * @ingroup Action
+ * Handles the edit action for Wikibase properties.
*
+ * @since 0.1
* @licence GNU GPL v2+
* @author Jeroen De Dauw < [email protected] >
* @author Daniel Kinzler
*/
-
-/**
- * Handles the edit action for Wikibase properties.
- *
- * @since 0.1
- */
class EditPropertyAction extends EditEntityAction {
-
-
}
-/**
- * Handles the submit action for Wikibase properties.
- *
- * @since 0.1
- */
-class SubmitPropertyAction extends SubmitEntityAction {
-
-
-}
diff --git a/repo/includes/actions/HistoryEntityAction.php
b/repo/includes/actions/HistoryEntityAction.php
index 395e470..4193053 100644
--- a/repo/includes/actions/HistoryEntityAction.php
+++ b/repo/includes/actions/HistoryEntityAction.php
@@ -8,10 +8,6 @@
*
* @since 0.3
*
- * @file
- * @ingroup WikibaseRepo
- * @ingroup Action
- *
* @licence GNU GPL v2+
* @author John Erling Blad < [email protected] >
*/
diff --git a/repo/includes/actions/HistoryItemAction.php
b/repo/includes/actions/HistoryItemAction.php
index 425e0c2..de87836 100644
--- a/repo/includes/actions/HistoryItemAction.php
+++ b/repo/includes/actions/HistoryItemAction.php
@@ -7,15 +7,9 @@
*
* @since 0.1
*
- * @file
- * @ingroup WikibaseRepo
- * @ingroup Action
- *
* @licence GNU GPL v2+
* @author John Erling Blad < [email protected] >
*/
class HistoryItemAction extends HistoryEntityAction {
-
-
}
\ No newline at end of file
diff --git a/repo/includes/actions/HistoryPropertyAction.php
b/repo/includes/actions/HistoryPropertyAction.php
index ee62164..b8d78c5 100644
--- a/repo/includes/actions/HistoryPropertyAction.php
+++ b/repo/includes/actions/HistoryPropertyAction.php
@@ -7,15 +7,9 @@
*
* @since 0.1
*
- * @file
- * @ingroup WikibaseRepo
- * @ingroup Action
- *
* @licence GNU GPL v2+
* @author John Erling Blad < [email protected] >
*/
class HistoryPropertyAction extends HistoryEntityAction {
-
-
}
\ No newline at end of file
diff --git a/repo/includes/actions/SubmitEntityAction.php
b/repo/includes/actions/SubmitEntityAction.php
new file mode 100644
index 0000000..f8d2d45
--- /dev/null
+++ b/repo/includes/actions/SubmitEntityAction.php
@@ -0,0 +1,142 @@
+<?php
+
+namespace Wikibase;
+
+use Status;
+
+/**
+ * Handles the submit action for Wikibase entities.
+ * This performs the undo and restore operations when requested.
+ * Otherwise it will just show the normal entity view.
+ *
+ * @since 0.1
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < [email protected] >
+ * @author Jens Ohlig
+ * @author Daniel Kinzler
+ */
+class SubmitEntityAction extends EditEntityAction {
+
+ public function getName() {
+ return 'submit';
+ }
+
+ /**
+ * Show the entity using parent::show(), unless an undo operation is
requested.
+ * In that case $this->undo(); is called to perform the action after a
permission check.
+ */
+ public function show() {
+ $req = $this->getRequest();
+
+ if ( $req->getCheck('undo') || $req->getCheck('undoafter') ||
$req->getCheck('restore') ) {
+ if ( $this->showPermissionError( "read" ) ||
$this->showPermissionError( "edit" ) ) {
+ return;
+ }
+
+ $this->undo();
+ return;
+ }
+
+ parent::show();
+ }
+
+ /**
+ * Perform the undo operation specified by the web request.
+ */
+ public function undo() {
+ $req = $this->getRequest();
+
+ if ( !$req->wasPosted() || !$req->getCheck('wpSave') ) {
+ $args = array( 'action' => "edit" );
+
+ if ( $req->getCheck( 'undo' ) ) {
+ $args['undo'] = $req->getInt( 'undo' );
+ }
+
+ if ( $req->getCheck( 'undoafter' ) ) {
+ $args['undoafter'] = $req->getInt( 'undoafter'
);
+ }
+
+ if ( $req->getCheck( 'restore' ) ) {
+ $args['restore'] = $req->getInt( 'restore' );
+ }
+
+ $undoUrl = $this->getTitle()->getLocalURL( $args );
+ $this->getOutput()->redirect( $undoUrl );
+ return;
+ }
+
+ $revisions = $this->loadRevisions();
+ if ( !$revisions->isOK() ) {
+ $this->showStatusErrorsPage(
'wikibase-undo-revision-error', $revisions );
+ return;
+ }
+
+ /**
+ * @var \Revision $olderRevision
+ * @var \Revision $newerRevision
+ * @var \Revision $latestRevision
+ */
+ list( $olderRevision, $newerRevision, $latestRevision ) =
$revisions->getValue();
+
+ /**
+ * @var EntityContent $latestContent
+ * @var EntityContent $olderContent
+ * @var EntityContent $newerContent
+ */
+ $olderContent = $olderRevision->getContent();
+ $newerContent = $newerRevision->getContent();
+ $latestContent = $latestRevision->getContent();
+
+ $diff = $newerContent->getEntity()->getDiff(
$olderContent->getEntity() );
+ $edit = false;
+ $token = $this->getRequest()->getText( 'wpEditToken' );
+
+ if ( $newerRevision->getId() == $latestRevision->getId() ) { //
restore
+ $summary = $req->getText( 'wpSummary' );
+
+ if ( $summary === '' ) {
+ $summary = $this->makeRestoreSummary(
$olderRevision, $newerRevision, $latestRevision );
+ }
+
+ if ( $diff->isEmpty() ) {
+ $status = Status::newGood();
+ $status->warning( 'wikibase-empty-undo' );
+ } else {
+ // make the old content the new content.
+ // NOTE: conflict detection is not needed for a
plain restore, it's not based on anything.
+ $edit = new EditEntity( $olderContent,
$this->getUser(), false, $this->getContext() );
+ $status = $edit->attemptSave( $summary, 0,
$token );
+ }
+ } else { // undo
+ $entity = $latestContent->getEntity()->copy();
+ $latestContent->getEntity()->patch( $diff );;
+
+ if ( $latestContent->getEntity()->getDiff( $entity
)->isEmpty() ) {
+ $status = Status::newGood();
+ $status->warning( 'wikibase-empty-undo' );
+ } else {
+ $summary = $req->getText( 'wpSummary' );
+
+ if ( $summary === '' ) {
+ $summary = $this->makeUndoSummary(
$olderRevision, $newerRevision, $latestRevision );
+ }
+
+ //NOTE: use latest revision as base revision -
we are saving patched content
+ // based on the latest revision.
+ $edit = new EditEntity( $latestContent,
$this->getUser(), $latestRevision->getId(), $this->getContext() );
+ $status = $edit->attemptSave( $summary, 0,
$token );
+ }
+ }
+
+ if ( $status->isOK() ) {
+ $this->getOutput()->redirect(
$this->getTitle()->getFullUrl() );
+ } else {
+ $edit->showErrorPage();
+ }
+ }
+
+ public function execute() {
+ throw new \MWException( "not applicable" );
+ }
+}
\ No newline at end of file
diff --git a/repo/includes/actions/SubmitItemAction.php
b/repo/includes/actions/SubmitItemAction.php
new file mode 100644
index 0000000..7394b47
--- /dev/null
+++ b/repo/includes/actions/SubmitItemAction.php
@@ -0,0 +1,15 @@
+<?php
+
+namespace Wikibase;
+
+/**
+ * Handles the submit action for Wikibase items.
+ *
+ * @since 0.1
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < [email protected] >
+ * @author Daniel Kinzler
+ */
+class SubmitItemAction extends SubmitEntityAction {
+
+}
\ No newline at end of file
diff --git a/repo/includes/actions/SubmitPropertyAction.php
b/repo/includes/actions/SubmitPropertyAction.php
new file mode 100644
index 0000000..a43aef2
--- /dev/null
+++ b/repo/includes/actions/SubmitPropertyAction.php
@@ -0,0 +1,16 @@
+<?php
+
+namespace Wikibase;
+
+/**
+ * Handles the submit action for Wikibase properties.
+ *
+ * @since 0.1
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < [email protected] >
+ * @author Daniel Kinzler
+ */
+class SubmitPropertyAction extends SubmitEntityAction {
+
+
+}
\ No newline at end of file
diff --git a/repo/includes/actions/ViewEntityAction.php
b/repo/includes/actions/ViewEntityAction.php
index 372081b..1ed98d1 100644
--- a/repo/includes/actions/ViewEntityAction.php
+++ b/repo/includes/actions/ViewEntityAction.php
@@ -9,10 +9,6 @@
*
* @since 0.1
*
- * @file
- * @ingroup WikibaseRepo
- * @ingroup Action
- *
* @licence GNU GPL v2+
* @author Jeroen De Dauw < [email protected] >
* @author Daniel Kinzler < [email protected] >
diff --git a/repo/includes/actions/ViewItemAction.php
b/repo/includes/actions/ViewItemAction.php
index ae75172..4348bfa 100644
--- a/repo/includes/actions/ViewItemAction.php
+++ b/repo/includes/actions/ViewItemAction.php
@@ -7,10 +7,6 @@
*
* @since 0.1
*
- * @file
- * @ingroup WikibaseRepo
- * @ingroup Action
- *
* @licence GNU GPL v2+
* @author Jeroen De Dauw < [email protected] >
* @author Daniel Kinzler < [email protected] >
diff --git a/repo/includes/actions/ViewPropertyAction.php
b/repo/includes/actions/ViewPropertyAction.php
index e9c35e2..55a7371 100644
--- a/repo/includes/actions/ViewPropertyAction.php
+++ b/repo/includes/actions/ViewPropertyAction.php
@@ -7,15 +7,9 @@
*
* @since 0.1
*
- * @file
- * @ingroup WikibaseRepo
- * @ingroup Action
- *
* @licence GNU GPL v2+
* @author Jeroen De Dauw < [email protected] >
*/
class ViewPropertyAction extends ViewEntityAction {
-
-
}
\ No newline at end of file
--
To view, visit https://gerrit.wikimedia.org/r/87580
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ie5c3942f70019b6556df19cba1e2a4bf37698531
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Addshore <[email protected]>
Gerrit-Reviewer: Aude <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Jeroen De Dauw <[email protected]>
Gerrit-Reviewer: Tobias Gritschacher <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits