From: Kunal Mehta Date: Tue, 15 Aug 2017 20:34:55 +0000 (-0700) Subject: Support AJAX watch in skins that use a different class structure X-Git-Tag: 1.31.0-rc.0~2373^2 X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=30cfcd39a574fe82842e002be93fdf6f8cdd81c2 Support AJAX watch in skins that use a different class structure Skipping links that are in #bodyContent or #content doesn't work for skins like Timeless. Instead of trying to filter based on those classes, have SkinTemplate set a data-mw=interface attribute on the element, and filter based on that. The Sanitizer prevents any data-mw attributes being set by users, so it must have been created by MediaWiki, and therefore safe to use. If no link meets that criteria, then it will fallback to trying to find a link using the old criteria of not being in #bodyContent or #content. Bug: T173279 Change-Id: I1688a499dda40428dd514230b78ccded0d228ca3 --- diff --git a/includes/skins/SkinTemplate.php b/includes/skins/SkinTemplate.php index f49d46c2fd..5ad1b116f7 100644 --- a/includes/skins/SkinTemplate.php +++ b/includes/skins/SkinTemplate.php @@ -1080,7 +1080,12 @@ class SkinTemplate extends Skin { ), // uses 'watch' or 'unwatch' message 'text' => $this->msg( $mode )->text(), - 'href' => $title->getLocalURL( [ 'action' => $mode ] ) + 'href' => $title->getLocalURL( [ 'action' => $mode ] ), + // Set a data-mw=interface attribute, which the mediawiki.page.ajax + // module will look for to make sure it's a trusted link + 'data' => [ + 'mw' => 'interface', + ], ]; } } diff --git a/resources/src/mediawiki/page/watch.js b/resources/src/mediawiki/page/watch.js index 6322ccd29d..e56e807899 100644 --- a/resources/src/mediawiki/page/watch.js +++ b/resources/src/mediawiki/page/watch.js @@ -110,9 +110,13 @@ ); $( function () { - var $links = $( '.mw-watchlink a, a.mw-watchlink' ); - // Restrict to core interfaces, ignore user-generated content - $links = $links.filter( ':not( #bodyContent *, #content * )' ); + var $links = $( '.mw-watchlink a[data-mw="interface"], a.mw-watchlink[data-mw="interface"]' ); + if ( !$links.length ) { + // Fallback to the class-based exclusion method for backwards-compatibility + $links = $( '.mw-watchlink a, a.mw-watchlink' ); + // Restrict to core interfaces, ignore user-generated content + $links = $links.filter( ':not( #bodyContent *, #content * )' ); + } $links.click( function ( e ) { var mwTitle, action, api, $link;