Florianschmidtwelzow has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/354641 )

Change subject: Run DiffViewHeader in mobile mode, too
......................................................................

Run DiffViewHeader in mobile mode, too

This change makes it possible for extension to add things to the diff
header in mobile using the (mediawiki core) hook DiffViewHeader, which
is called before the header is generated.

This also ensures, that the relevant title for Special:MobileDiff is
the Title object of the page, where the diff is created from. This is
especially useful for JavaScript code, which needs to now the Title for
which a page is generated.

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


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend 
refs/changes/41/354641/1

diff --git a/includes/specials/SpecialMobileDiff.php 
b/includes/specials/SpecialMobileDiff.php
index 0752828..6221587 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;
        }
 
        /**
@@ -183,6 +218,11 @@
                        $comment = $this->msg( 
'mobile-frontend-changeslist-nocomment' )->escaped();
                }
 
+               if ( $this->mDiffEngine instanceof InlineDifferenceEngine ) {
+                       // TODO: The hook gets originally called in the 
DifferenceEngine::showDiffPage() method
+                       Hooks::run( 'DiffViewHeader', [ $this->mDiffEngine, 
$this->prevRev, $this->rev ] );
+               }
+
                $ts = new MWTimestamp( $this->rev->getTimestamp() );
                $this->getOutput()->addHtml(
                        Html::openElement( 'div', [ 'id' => 'mw-mf-diff-info', 
'class' => 'page-summary' ] )
@@ -220,25 +260,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 +305,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: newchange
Gerrit-Change-Id: I68cf50f5dd339f34802d70df1f32d2c3390944a3
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Florianschmidtwelzow <florian.schmidt.stargatewis...@gmail.com>

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

Reply via email to