aboutsummaryrefslogtreecommitdiffstats
path: root/includes/editpage/EditPage.php
diff options
context:
space:
mode:
authorNovem Linguae <novemlinguae@gmail.com>2024-07-05 20:42:23 -0700
committerNovem Linguae <novemlinguae@gmail.com>2024-07-17 00:35:01 -0700
commit5d8e5376440f86be3f52945779a18e073fa9f26d (patch)
tree27e95e4e25b40aac247828a1de86c7318135bad7 /includes/editpage/EditPage.php
parent2a763ca81d124e60ebb958214eb4c5c828d6545e (diff)
downloadmediawikicore-5d8e5376440f86be3f52945779a18e073fa9f26d.tar.gz
mediawikicore-5d8e5376440f86be3f52945779a18e073fa9f26d.zip
EditPage: refactor to create generateUndoEditSummary()
This code was in a big method and had a single responsibility so was a good candidate for extracting into its own private method - Cut and paste a big block of code - Move `$disableAnonTalk = $services->getMainConfig()->get( MainConfigNames::DisableAnonTalk );` into the new method - Add docblock - Change #comment to //comment in the new method, for consistency within the new method - No-op Change-Id: I379bfa67a4518ca46da482578271471fa43ea4e2
Diffstat (limited to 'includes/editpage/EditPage.php')
-rw-r--r--includes/editpage/EditPage.php117
1 files changed, 66 insertions, 51 deletions
diff --git a/includes/editpage/EditPage.php b/includes/editpage/EditPage.php
index 4a80983dbbfb..9d786e4ae0ea 100644
--- a/includes/editpage/EditPage.php
+++ b/includes/editpage/EditPage.php
@@ -1424,7 +1424,6 @@ class EditPage implements IEditObject {
*/
protected function getContentObject( $defaultContent = null ) {
$services = MediaWikiServices::getInstance();
- $disableAnonTalk = $services->getMainConfig()->get( MainConfigNames::DisableAnonTalk );
$request = $this->context->getRequest();
$content = false;
@@ -1518,56 +1517,7 @@ class EditPage implements IEditObject {
} else {
# Inform the user of our success and set an automatic edit summary
$undoMsg = 'success';
-
- # If we just undid one rev, use an autosummary
- $firstrev = $this->revisionStore->getNextRevision( $oldrev );
- if ( $firstrev && $firstrev->getId() == $undo ) {
- $userText = $undorev->getUser() ?
- $undorev->getUser()->getName() :
- '';
- if ( $userText === '' ) {
- $undoSummary = $this->context->msg(
- 'undo-summary-username-hidden',
- $undo
- )->inContentLanguage()->text();
- // Handle external users (imported revisions)
- } elseif ( ExternalUserNames::isExternal( $userText ) ) {
- $userLinkTitle = ExternalUserNames::getUserLinkTitle( $userText );
- if ( $userLinkTitle ) {
- $userLink = $userLinkTitle->getPrefixedText();
- $undoSummary = $this->context->msg(
- 'undo-summary-import',
- $undo,
- $userLink,
- $userText
- )->inContentLanguage()->text();
- } else {
- $undoSummary = $this->context->msg(
- 'undo-summary-import2',
- $undo,
- $userText
- )->inContentLanguage()->text();
- }
- } else {
- $undoIsAnon =
- !$undorev->getUser() ||
- !$undorev->getUser()->isRegistered();
- $undoMessage = ( $undoIsAnon && $disableAnonTalk ) ?
- 'undo-summary-anon' :
- 'undo-summary';
- $undoSummary = $this->context->msg(
- $undoMessage,
- $undo,
- $userText
- )->inContentLanguage()->text();
- }
- if ( $this->summary === '' ) {
- $this->summary = $undoSummary;
- } else {
- $this->summary = $undoSummary . $this->context->msg( 'colon-separator' )
- ->inContentLanguage()->text() . $this->summary;
- }
- }
+ $this->generateUndoEditSummary( $oldrev, $undo, $undorev, $services );
$this->undidRev = $undo;
$this->undoAfter = $undoafter;
$this->formtype = 'diff';
@@ -1602,6 +1552,71 @@ class EditPage implements IEditObject {
}
/**
+ * When using the "undo" action, generate a default edit summary and save it
+ * to $this->summary
+ *
+ * @param RevisionRecord|null $oldrev The revision in the URI "undoafter" field
+ * @param int $undo The integer in the URI "undo" field
+ * @param RevisionRecord|null $undorev The revision in the URI "undo" field
+ * @param MediaWikiServices $services Service container
+ * @return void
+ */
+ private function generateUndoEditSummary( ?RevisionRecord $oldrev, int $undo,
+ ?RevisionRecord $undorev, MediaWikiServices $services
+ ) {
+ // If we just undid one rev, use an autosummary
+ $firstrev = $this->revisionStore->getNextRevision( $oldrev );
+ if ( $firstrev && $firstrev->getId() == $undo ) {
+ $userText = $undorev->getUser() ?
+ $undorev->getUser()->getName() :
+ '';
+ if ( $userText === '' ) {
+ $undoSummary = $this->context->msg(
+ 'undo-summary-username-hidden',
+ $undo
+ )->inContentLanguage()->text();
+ // Handle external users (imported revisions)
+ } elseif ( ExternalUserNames::isExternal( $userText ) ) {
+ $userLinkTitle = ExternalUserNames::getUserLinkTitle( $userText );
+ if ( $userLinkTitle ) {
+ $userLink = $userLinkTitle->getPrefixedText();
+ $undoSummary = $this->context->msg(
+ 'undo-summary-import',
+ $undo,
+ $userLink,
+ $userText
+ )->inContentLanguage()->text();
+ } else {
+ $undoSummary = $this->context->msg(
+ 'undo-summary-import2',
+ $undo,
+ $userText
+ )->inContentLanguage()->text();
+ }
+ } else {
+ $undoIsAnon =
+ !$undorev->getUser() ||
+ !$undorev->getUser()->isRegistered();
+ $disableAnonTalk = $services->getMainConfig()->get( MainConfigNames::DisableAnonTalk );
+ $undoMessage = ( $undoIsAnon && $disableAnonTalk ) ?
+ 'undo-summary-anon' :
+ 'undo-summary';
+ $undoSummary = $this->context->msg(
+ $undoMessage,
+ $undo,
+ $userText
+ )->inContentLanguage()->text();
+ }
+ if ( $this->summary === '' ) {
+ $this->summary = $undoSummary;
+ } else {
+ $this->summary = $undoSummary . $this->context->msg( 'colon-separator' )
+ ->inContentLanguage()->text() . $this->summary;
+ }
+ }
+ }
+
+ /**
* Returns the result of a three-way merge when undoing changes.
*
* @param RevisionRecord $undoRev Newest revision being undone. Corresponds to `undo`