jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/354641 )

Change subject: Refactor Special:MobileDiff
......................................................................


Refactor Special:MobileDiff

This makes the code a bit more readable, and reduces the size of
functions by extracting the code to their own functions. Also,
the difference engine is created earlier and is therefore be
available to most of the code.

This change also sets the relevant title of the skin to the title
of the revisions, which are viewed. This way, other extensions now,
that the special page shows content of a (probably) content page,
instead of a real special page.

Bug: T165835
Change-Id: I68cf50f5dd339f34802d70df1f32d2c3390944a3
---
M includes/specials/SpecialMobileDiff.php
1 file changed, 39 insertions(+), 21 deletions(-)

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



diff --git a/includes/specials/SpecialMobileDiff.php 
b/includes/specials/SpecialMobileDiff.php
index 0752828..dfefbf9 100644
--- a/includes/specials/SpecialMobileDiff.php
+++ b/includes/specials/SpecialMobileDiff.php
@@ -113,6 +113,7 @@
                $this->rev = $rev;
                $this->prevRev = $prev;
                $this->targetTitle = $this->rev->getTitle();
+               $this->getSkin()->setRelevantTitle( $this->targetTitle );
 
                $output->setPageTitle( $this->msg(
                        'mobile-frontend-diffview-title',
@@ -132,6 +133,7 @@
 
                $output->addHtml( '<div id="mw-mf-diffview" 
class="content-unstyled"><div id="mw-mf-diffarea">' );
 
+               $this->setupDifferenceEngine();
                $this->showHeader();
                $this->showDiff();
                $output->addHtml( '</div>' );
@@ -141,6 +143,39 @@
                $output->addHtml( '</div>' );
 
                return true;
+       }
+
+       /**
+        * Returns the ID of the previous Revision, if it is set, otherwise 0.
+        *
+        * @return int|null
+        */
+       protected function getPrevId() {
+               return $this->prevRev ? $this->prevRev->getId() : 0;
+       }
+
+       /**
+        * Setups the DifferenceEngine.
+        */
+       protected function setupDifferenceEngine() {
+               $contentHandler = $this->rev->getContentHandler();
+               $de = $contentHandler->createDifferenceEngine( 
$this->getContext(), $this->getPrevId(),
+                       $this->revId );
+               // HACK:
+               if ( get_class( $de ) == 'DifferenceEngine' ) {
+                       $de = new $this->diffClass(
+                               $this->getContext(),
+                               $this->getPrevId(),
+                               $this->revId,
+                               0,
+                               false,
+                               (bool)$this->getRequest()->getVal( 'unhide' )
+                       );
+               } else {
+                       $de->showDiffPage();
+                       return;
+               }
+               $this->mDiffEngine = $de;
        }
 
        /**
@@ -220,25 +255,9 @@
        function showDiff() {
                $output = $this->getOutput();
 
-               $prevId = $this->prevRev ? $this->prevRev->getId() : 0;
+               $prevId = $this->getPrevId();
                $unhide = (bool)$this->getRequest()->getVal( 'unhide' );
-               $contentHandler = $this->rev->getContentHandler();
-               $de = $contentHandler->createDifferenceEngine( 
$this->getContext(), $prevId, $this->revId );
-               // HACK:
-               if ( get_class( $de ) == 'DifferenceEngine' ) {
-                       $de = new $this->diffClass(
-                               $this->getContext(),
-                               $prevId,
-                               $this->revId,
-                               0,
-                               false,
-                               $unhide
-                       );
-               } else {
-                       $de->showDiffPage();
-                       return;
-               }
-               $this->mDiffEngine = $de;
+               $de = $this->mDiffEngine;
                $diff = $de->getDiffBody();
                if ( !$prevId ) {
                        $audience = $unhide ? Revision::FOR_THIS_USER : 
Revision::FOR_PUBLIC;
@@ -281,14 +300,13 @@
                        $output->addHtml( $history );
                }
 
-               $diffEngine = $this->mDiffEngine;
-               if ( $diffEngine instanceof InlineDifferenceEngine ) {
+               if ( $de instanceof InlineDifferenceEngine ) {
                        $output->addHtml( Html::rawElement(
                                'div',
                                [
                                        'class' => 'patrollink'
                                ],
-                               $diffEngine->getPatrolledLink()
+                               $de->getPatrolledLink()
                        ) );
                }
        }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I68cf50f5dd339f34802d70df1f32d2c3390944a3
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Florianschmidtwelzow <florian.schmidt.stargatewis...@gmail.com>
Gerrit-Reviewer: Florianschmidtwelzow <florian.schmidt.stargatewis...@gmail.com>
Gerrit-Reviewer: Jdlrobson <jrob...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to