Don't record transclusion of current page from title methods

When the content or categories fields are accessed for the title object
of the current page, skip adding an entry in templatelinks.

* Cuts 5.9 million rows from enwiki templatelinks, where citation
templates use :getContent() to know what date format to use while
formatting citations.
* Prevents confusion about why a page is shown to transclude itself,
frequently brought up on technical support forums.

Change-Id: Id6a5e00572031f4a7258c99c6dc0f802385ee5fe
This commit is contained in:
Siddharth VP 2024-09-22 00:15:05 +05:30 committed by jenkins-bot
parent a630e3d129
commit 286add50b5

View file

@ -295,11 +295,6 @@ class TitleLibrary extends LibraryBase {
return null; return null;
} }
// Record in templatelinks, so edits cause the page to be refreshed
$this->getParser()->getOutput()->addTemplate(
$title, $title->getArticleID(), $title->getLatestRevID()
);
$rev = $this->getParser()->fetchCurrentRevisionRecordOfTitle( $title ); $rev = $this->getParser()->fetchCurrentRevisionRecordOfTitle( $title );
if ( $title->equals( $this->getTitle() ) ) { if ( $title->equals( $this->getTitle() ) ) {
@ -307,6 +302,11 @@ class TitleLibrary extends LibraryBase {
$parserOutput->setOutputFlag( ParserOutputFlags::VARY_REVISION_SHA1 ); $parserOutput->setOutputFlag( ParserOutputFlags::VARY_REVISION_SHA1 );
$parserOutput->setRevisionUsedSha1Base36( $rev ? $rev->getSha1() : '' ); $parserOutput->setRevisionUsedSha1Base36( $rev ? $rev->getSha1() : '' );
wfDebug( __METHOD__ . ": set vary-revision-sha1 for '$title'" ); wfDebug( __METHOD__ . ": set vary-revision-sha1 for '$title'" );
} else {
// Record in templatelinks, so edits cause the page to be refreshed
$this->getParser()->getOutput()->addTemplate(
$title, $title->getArticleID(), $title->getLatestRevID()
);
} }
if ( !$rev ) { if ( !$rev ) {
@ -355,9 +355,10 @@ class TitleLibrary extends LibraryBase {
$parserOutput = $this->getParser()->getOutput(); $parserOutput = $this->getParser()->getOutput();
if ( $title->equals( $this->getTitle() ) ) { if ( $title->equals( $this->getTitle() ) ) {
$parserOutput->setOutputFlag( ParserOutputFlags::VARY_REVISION ); $parserOutput->setOutputFlag( ParserOutputFlags::VARY_REVISION );
} } else {
// Record in templatelinks, so edits cause the page to be refreshed // Record in templatelinks, so edits cause the page to be refreshed
$parserOutput->addTemplate( $title, $title->getArticleID(), $title->getLatestRevID() ); $parserOutput->addTemplate( $title, $title->getArticleID(), $title->getLatestRevID() );
}
$categoryTitles = $page->getCategories(); $categoryTitles = $page->getCategories();
$categoryNames = []; $categoryNames = [];