Re-arrange getHistoryLink method for readability

Most notably: Bail out as early as possible.

Change-Id: Ibd22bd41e6d38a807edf45acdcd72c29537a0c06
This commit is contained in:
Thiemo Kreuz 2022-03-31 11:01:04 +02:00 committed by Jdlrobson
parent 53331f749a
commit 73749969d6

View file

@ -491,21 +491,28 @@ class SkinMinerva extends SkinMustache {
* @return array|null
*/
protected function getHistoryLink( Title $title ) {
$out = $this->getOutput();
$isLatestRevision = $out->getRevisionId() === $title->getLatestRevID();
// Get rev_timestamp of current revision (preloaded by MediaWiki core)
$timestamp = $out->getRevisionTimestamp();
# No cached timestamp, load it from the database
if ( $timestamp === null ) {
$timestamp = MediaWikiServices::getInstance()
->getRevisionLookup()
->getTimestampFromId( $out->getRevisionId() );
if ( !$title->exists() ||
Action::getActionName( RequestContext::getMain() ) !== 'view'
) {
return null;
}
// Create history link and corresponding icons.
$historyLinkAndIcons = [];
if ( Action::getActionName( RequestContext::getMain() ) === 'view' ) {
$historyIconClasses = [
$out = $this->getOutput();
if ( !$out->isRevisionCurrent() || $title->isMainPage() ) {
$historyLink = $this->getGenericHistoryLink( $title );
} else {
// Get rev_timestamp of current revision (preloaded by MediaWiki core)
$timestamp = $out->getRevisionTimestamp();
if ( !$timestamp ) {
# No cached timestamp, load it from the database
$revisionLookup = MediaWikiServices::getInstance()->getRevisionLookup();
$timestamp = $revisionLookup->getTimestampFromId( $out->getRevisionId() );
}
$historyLink = $this->getRelativeHistoryLink( $title, $timestamp );
}
return $historyLink + [
'historyIconClass' => MinervaUI::iconClass(
'history-base20', 'mw-ui-icon-small', '', 'wikimedia'
),
@ -521,17 +528,6 @@ class SkinMinerva extends SkinMustache {
'mf'
),
];
$historyLink = !$isLatestRevision || $title->isMainPage() ?
$this->getGenericHistoryLink( $title ) :
$this->getRelativeHistoryLink( $title, $timestamp );
$historyLinkAndIcons = $historyLink + $historyIconClasses;
}
$title = $this->getTitle();
return $title->canExist() && $title->exists() && !empty( $historyLinkAndIcons )
? $historyLinkAndIcons
: null;
}
/**