jenkins-bot has submitted this change and it was merged.

Change subject: Explain deleted Revisions
......................................................................


Explain deleted Revisions

The DifferenceEngine in core could do with a huge refactor to
allow better reusability by inheriting classes.

This breaks out a lot of the functions into separate functions
If Max is happy with these changes, I will write a patch trying
to make them part of DifferenceEngine.php itself.

Bug: 62553
Change-Id: I3ecce8b06afe7846ff2c17b83517edce4234a2cd
---
M includes/diff/InlineDifferenceEngine.php
M includes/specials/SpecialMobileDiff.php
2 files changed, 103 insertions(+), 0 deletions(-)

Approvals:
  Kaldari: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/diff/InlineDifferenceEngine.php 
b/includes/diff/InlineDifferenceEngine.php
index f5f4eba..8fcb3a8 100644
--- a/includes/diff/InlineDifferenceEngine.php
+++ b/includes/diff/InlineDifferenceEngine.php
@@ -1,6 +1,96 @@
 <?php
 
 class InlineDifferenceEngine extends DifferenceEngine {
+       /**
+        * Checks whether the given Revision was deleted
+        * FIXME: Upstream to DifferenceEngine - refactor showDiffPage
+        *
+        * @return boolean
+        */
+       public function isDeletedDiff() {
+               return $this->mNewRev && $this->mNewRev->isDeleted( 
Revision::DELETED_TEXT );
+       }
+
+       /**
+        * Checks whether the given Revision was deleted or if it is delete
+        * restricted.
+        * FIXME: Upstream to DifferenceEngine - refactor showDiffPage
+        *
+        * @return boolean
+        */
+       public function isSuppressedDiff() {
+               return $this->isDeletedDiff() &&
+                       $this->mNewRev->isDeleted( Revision::DELETED_RESTRICTED 
);
+       }
+
+       /**
+        * Checks whether the current user has permission to view the old
+        * and current revisions.
+        * FIXME: Upstream to DifferenceEngine - refactor showDiffPage
+        *
+        * @return boolean
+        */
+       public function isUserAllowedToSee() {
+               $user = $this->getUser();
+               $allowed = $this->mNewRev->userCan( Revision::DELETED_TEXT, 
$user );
+               if ( $this->mOldRev &&
+                       !$this->mOldRev->userCan( Revision::DELETED_TEXT, $user 
)
+               ) {
+                       $allowed = false;
+               }
+               return $allowed;
+       }
+
+       /**
+        * Checks whether the diff should be hidden from the current user
+        * This is based on whether the user is allowed to see it and whether
+        * the flag unhide is set to allow viewing deleted revisions.
+        * FIXME: Upstream to DifferenceEngine - refactor showDiffPage
+        *
+        * @return boolean
+        */
+       public function isHiddenFromUser() {
+               if ( $this->isDeletedDiff() && ( !$this->unhide || 
!$this->isUserAllowedToSee() ) ) {
+                       return true;
+               } else {
+                       return false;
+               }
+       }
+
+       /**
+        * Returns warning messages in situations where a revision cannot be 
viewed by a user
+        * explaining to them why.
+        * Returns empty string when the revision can be viewed.
+        *
+        * @return string
+        */
+       public function getWarningMessageText() {
+               $msg = '';
+               if ( $this->isHiddenFromUser() ) {
+                       $allowed = $this->isUserAllowedToSee();
+                       $suppressed = $this->isSuppressedDiff();
+
+                       if ( !$allowed ) {
+                               $msg = $suppressed ? 'rev-suppressed-no-diff' : 
'rev-deleted-no-diff';
+                               $msg = wfMessage( $msg )->parse();
+                       } else {
+                               # Give explanation and add a link to view the 
diff...
+                               $query = $this->getRequest()->appendQueryValue( 
'unhide', '1', true );
+                               $link = $this->getTitle()->getFullURL( $query );
+                               $msg = $suppressed ? 
'rev-suppressed-unhide-diff' : 'rev-deleted-unhide-diff';
+                               $msg = wfMessage( $msg, $link )->parse();
+                       }
+               }
+               return $msg;
+       }
+
+       /**
+        * Creates an inline diff
+        * @param Content $otext Old content
+        * @param Content $ntext New content
+        *
+        * @return string
+        */
        function generateTextDiffBody( $otext, $ntext ) {
                global $wgContLang;
 
@@ -27,6 +117,9 @@
                return $difftext;
        }
 
+       /**
+        * @see DifferenceEngine:getDiffBodyCacheKey
+        */
        protected function getDiffBodyCacheKey() {
                if ( !$this->mOldid || !$this->mNewid ) {
                        throw new MWException( 'mOldid and mNewid must be set 
to get diff cache key.' );
diff --git a/includes/specials/SpecialMobileDiff.php 
b/includes/specials/SpecialMobileDiff.php
index b1f3bd6..5a670d2 100644
--- a/includes/specials/SpecialMobileDiff.php
+++ b/includes/specials/SpecialMobileDiff.php
@@ -164,7 +164,17 @@
                } else {
                        $diff = '<ins>' . htmlspecialchars( 
$this->rev->getText() ) . '</ins>';
                }
+               $warnings = $de->getWarningMessageText();
+               if ( $warnings ) {
+                       $warnings = Html::openElement( 'div',
+                               array(
+                                       'class' => 'warning alert',
+                               ) ) .
+                               $warnings .
+                               Html::closeElement( 'div' );
+               }
                $this->getOutput()->addHtml(
+                       $warnings .
                        '<div id="mw-mf-minidiff">' .
                        $diff .
                        '</div>'

-- 
To view, visit https://gerrit.wikimedia.org/r/118744
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I3ecce8b06afe7846ff2c17b83517edce4234a2cd
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <[email protected]>
Gerrit-Reviewer: Awjrichards <[email protected]>
Gerrit-Reviewer: JGonera <[email protected]>
Gerrit-Reviewer: Jdlrobson <[email protected]>
Gerrit-Reviewer: Kaldari <[email protected]>
Gerrit-Reviewer: MaxSem <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to