jenkins-bot has submitted this change and it was merged.
Change subject: Redirect to mobile diff page
......................................................................
Redirect to mobile diff page
If mobile view is activated (mobile device or link) and only a
one-version diff-view, redirect to Special:MobileDiff.
Bug: 61489
Change-Id: Ice81bc32479a3313baf2b09b6a53fbfb34a338ba
---
M MobileFrontend.php
M includes/MobileFrontend.hooks.php
2 files changed, 40 insertions(+), 0 deletions(-)
Approvals:
MaxSem: Looks good to me, approved
jenkins-bot: Verified
diff --git a/MobileFrontend.php b/MobileFrontend.php
index d105d89..3f87b09 100644
--- a/MobileFrontend.php
+++ b/MobileFrontend.php
@@ -112,6 +112,7 @@
$wgHooks['SkinTemplateOutputPageBeforeExec'][] =
'MobileFrontendHooks::onSkinTemplateOutputPageBeforeExec';
$wgHooks['BeforePageRedirect'][] = 'MobileFrontendHooks::onBeforePageRedirect';
+$wgHooks['DiffViewHeader'][] = 'MobileFrontendHooks::onDiffViewHeader';
$wgHooks['ResourceLoaderTestModules'][] =
'MobileFrontendHooks::onResourceLoaderTestModules';
$wgHooks['GetCacheVaryCookies'][] =
'MobileFrontendHooks::onGetCacheVaryCookies';
$wgHooks['ResourceLoaderGetConfigVars'][] =
'MobileFrontendHooks::onResourceLoaderGetConfigVars';
diff --git a/includes/MobileFrontend.hooks.php
b/includes/MobileFrontend.hooks.php
index 8a638a2..ad179c3 100644
--- a/includes/MobileFrontend.hooks.php
+++ b/includes/MobileFrontend.hooks.php
@@ -180,6 +180,45 @@
}
/**
+ * DiffViewHeader hook handler
+ * @see https://www.mediawiki.org/wiki/Manual:Hooks/DiffViewHeader
+ *
+ * Redirect Diff page to mobile version if appropriate
+ *
+ * @param DifferenceEngine $diff DifferenceEngine object that's calling
+ * @param Revision $oldRev Revision object of the "old" revision (may
be null/invalid)
+ * @param Revision $newRev Revision object of the "new" revision
+ * @return bool
+ */
+ public static function onDiffViewHeader( $diff, $oldRev, $newRev ) {
+ $context = MobileContext::singleton();
+
+ // Only do redirects to MobileDiff if user is in mobile view
+ if ( $context->shouldDisplayMobileView() ) {
+ $output = $context->getOutput();
+ $newRevId = $newRev->getId();
+
+ // The MobileDiff page currently only supports showing
a single revision, so
+ // only redirect to MobileDiff if we are sure this
isn't a multi-revision diff.
+ if ( $oldRev ) {
+ // Get the revision immediately before the new
revision
+ $prevRev = $newRev->getPrevious();
+ if ( $prevRev ) {
+ $prevRevId = $prevRev->getId();
+ $oldRevId = $oldRev->getId();
+ if ( $prevRevId === $oldRevId ) {
+ $output->redirect(
SpecialPage::getTitleFor( 'MobileDiff', $newRevId )->getFullURL() );
+ }
+ }
+ } else {
+ $output->redirect( SpecialPage::getTitleFor(
'MobileDiff', $newRevId )->getFullURL() );
+ }
+ }
+
+ return true;
+ }
+
+ /**
* ResourceLoaderTestModules hook handler
* @see
https://www.mediawiki.org/wiki/Manual:Hooks/ResourceLoaderTestModules
*
--
To view, visit https://gerrit.wikimedia.org/r/148613
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ice81bc32479a3313baf2b09b6a53fbfb34a338ba
Gerrit-PatchSet: 8
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Florianschmidtwelzow <[email protected]>
Gerrit-Reviewer: Awjrichards <[email protected]>
Gerrit-Reviewer: Florianschmidtwelzow <[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