mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/RevisionSlider
synced 2024-11-24 07:23:41 +00:00
Update hooks to use DifferenceEngineViewHeader
, require MW 1.35+
Bug: T255769 Change-Id: I0d64099dd4caffc5b9631fc743bfe229868f46a8
This commit is contained in:
parent
2f14374d0a
commit
8e1ed89152
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue