Update hooks to use DifferenceEngineViewHeader, require MW 1.35+

Bug: T255769
Change-Id: I0d64099dd4caffc5b9631fc743bfe229868f46a8
This commit is contained in:
DannyS712 2020-06-24 01:02:22 +00:00
parent 2f14374d0a
commit 8e1ed89152
2 changed files with 17 additions and 13 deletions

View file

@ -15,7 +15,7 @@
"type": "other",
"manifest_version": 2,
"requires": {
"MediaWiki": ">= 1.34.0"
"MediaWiki": ">= 1.35.0"
},
"ConfigRegistry": {
"revisionslider": "GlobalVarConfig::newInstance"
@ -216,7 +216,7 @@
"remoteExtPath": "RevisionSlider"
},
"Hooks": {
"DiffViewHeader": "MediaWiki\\Extensions\\RevisionSlider\\RevisionSliderHooks::onDiffViewHeader",
"DifferenceEngineViewHeader": "MediaWiki\\Extensions\\RevisionSlider\\RevisionSliderHooks::onDifferenceEngineViewHeader",
"GetPreferences": "MediaWiki\\Extensions\\RevisionSlider\\RevisionSliderHooks::onGetPreferences"
}
}

View file

@ -9,7 +9,6 @@ use MediaWiki\MediaWikiServices;
use Message;
use OOUI\ButtonWidget;
use RequestContext;
use Revision;
use User;
/**
@ -42,17 +41,15 @@ class RevisionSliderHooks {
/**
* @param DifferenceEngine $diff
* @param Revision|null $oldRev
* @param Revision|null $newRev
* @suppress SecurityCheck-XSS Issue with OOUI, see T193837 for more information
*/
public static function onDiffViewHeader(
DifferenceEngine $diff,
Revision $oldRev = null,
Revision $newRev = null
) {
// sometimes $oldRev can be null (e.g. missing rev), and perhaps also $newRev (T167359)
if ( !( $oldRev instanceof Revision ) || !( $newRev instanceof Revision ) ) {
public static function onDifferenceEngineViewHeader( DifferenceEngine $diff ) {
$oldRevRecord = $diff->getOldRevision();
$newRevRecord = $diff->getNewRevision();
// sometimes the old revision can be null (e.g. missing rev), and perhaps also the
// new one (T167359)
if ( $oldRevRecord === null || $newRevRecord === null ) {
return;
}
@ -73,8 +70,15 @@ class RevisionSliderHooks {
/**
* Do not show the RevisionSlider when revisions from two different pages are being compared
*
* Since RevisionRecord::getPageAsLinkTarget only returns a LinkTarget, which doesn't
* have an equals method, compare manually by namespace and text
*/
if ( !$oldRev->getTitle()->equals( $newRev->getTitle() ) ) {
$oldTitle = $oldRevRecord->getPageAsLinkTarget();
$newTitle = $newRevRecord->getPageAsLinkTarget();
if ( $oldTitle->getNamespace() !== $newTitle->getNamespace() ||
$oldTitle->getDBKey() !== $newTitle->getDBKey()
) {
return;
}