jenkins-bot has submitted this change and it was merged. Change subject: Remove canonical URL from Special:MobileCite ......................................................................
Remove canonical URL from Special:MobileCite * Special:MobileCite is only available on the mobile site * The page is not being indexed by robots since Ifaef5114ff0ae8d6955fb7c09bc561535c622822 Bug: T136617 Change-Id: I65051d198b0916b1968d1a8d2f5a6583ad983461 --- M includes/MobileFrontend.hooks.php M tests/phpunit/MobileFrontend.hooksTest.php 2 files changed, 39 insertions(+), 6 deletions(-) Approvals: Jdlrobson: Looks good to me, but someone else must approve Phuedx: Looks good to me, approved jenkins-bot: Verified diff --git a/includes/MobileFrontend.hooks.php b/includes/MobileFrontend.hooks.php index 8883d52..05e9c63 100644 --- a/includes/MobileFrontend.hooks.php +++ b/includes/MobileFrontend.hooks.php @@ -809,6 +809,8 @@ // an canonical/alternate link is only useful, if the mobile and desktop URL are different // and $wgMFNoindexPages needs to be true if ( $mfMobileUrlTemplate && $mfNoIndexPages ) { + $link = false; + if ( !$context->shouldDisplayMobileView() ) { // add alternate link to desktop sites - bug T91183 $desktopUrl = $title->getFullUrl(); @@ -817,14 +819,21 @@ 'media' => 'only screen and (max-width: ' . $lessVars['deviceWidthTablet'] . ')', 'href' => $context->getMobileUrl( $desktopUrl ), ]; - } else { - // add canonical link to mobile pages, instead of noindex - bug T91183 + } elseif ( + !Title::makeTitleSafe( $title->getNamespace(), strtok( $title->getText(), '/' ) ) + ->equals( SpecialPage::getTitleFor( 'MobileCite' ) ) + ) { + // Add canonical link to mobile pages (except for Special:MobileCite), + // instead of noindex - bug T91183. $link = [ 'rel' => 'canonical', 'href' => $title->getFullUrl(), ]; } - $out->addLink( $link ); + + if ( $link !== false ) { + $out->addLink( $link ); + } } // set the vary header to User-Agent, if mobile frontend auto detects, if the mobile diff --git a/tests/phpunit/MobileFrontend.hooksTest.php b/tests/phpunit/MobileFrontend.hooksTest.php index 04f3e3c..b5b5d8a 100644 --- a/tests/phpunit/MobileFrontend.hooksTest.php +++ b/tests/phpunit/MobileFrontend.hooksTest.php @@ -5,6 +5,26 @@ */ class MobileFrontendHooksTest extends MediaWikiTestCase { /** + * Test no alternate/canonical link is set on Special:MobileCite + * + * @covers MobileFrontendHooks::OnBeforePageDisplay + */ + public function testSpecialMobileCiteOnBeforePageDisplay() { + $this->setMwGlobals( [ + 'wgMobileUrlTemplate' => true, + 'wgMFNoindexPages' => true + ] ); + $param = $this->getContextSetup( 'mobile', [], SpecialPage::getTitleFor( 'MobileCite' ) ); + $out = $param['out']; + $sk = $param['sk']; + + MobileFrontendHooks::onBeforePageDisplay( $out, $sk ); + + $links = $out->getLinkTags(); + $this->assertEquals( 0, count( $links ), + 'test, no alternate or canonical link is added' ); + } + /** * Test headers and alternate/canonical links to be set or not * * @dataProvider onBeforePageDisplayDataProvider @@ -82,10 +102,12 @@ * outputpage and skintemplate. * * @param string $mode The mode for the test cases (desktop, mobile) + * @param array $mfXAnalyticsItems + * @param Title $title * @return array Array of objects, including MobileContext (context), * SkinTemplate (sk) and OutputPage (out) */ - protected function getContextSetup( $mode, $mfXAnalyticsItems ) { + protected function getContextSetup( $mode, $mfXAnalyticsItems, $title = null ) { // Create a new MobileContext object for this test MobileContext::setInstance( null ); // create a new instance of MobileContext @@ -96,8 +118,10 @@ $out = new OutputPage( $context ); // create a new, empty SkinTemplate $sk = new SkinTemplate(); - // create a new Title (main page) - $title = Title::newMainPage(); + if ( is_null( $title ) ) { + // create a new Title (main page) + $title = Title::newMainPage(); + } // create a FauxRequest to use instead of a WebRequest object (FauxRequest forces // the creation of a FauxResponse, which allows to investigate sent header values) $request = new FauxRequest(); -- To view, visit https://gerrit.wikimedia.org/r/295379 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I65051d198b0916b1968d1a8d2f5a6583ad983461 Gerrit-PatchSet: 6 Gerrit-Project: mediawiki/extensions/MobileFrontend Gerrit-Branch: master Gerrit-Owner: Bmansurov <bmansu...@wikimedia.org> Gerrit-Reviewer: Bmansurov <bmansu...@wikimedia.org> Gerrit-Reviewer: Jdlrobson <jrob...@wikimedia.org> Gerrit-Reviewer: Jhobs <jhob...@wikimedia.org> Gerrit-Reviewer: Legoktm <legoktm.wikipe...@gmail.com> Gerrit-Reviewer: Phuedx <g...@samsmith.io> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits