}
// Parse the new revision and get the categories
- $categoryChanges = $this->getExplicitCategoriesChanges( $title, $newRev, $oldRev );
+ $categoryChanges = $this->getExplicitCategoriesChanges( $page, $newRev, $oldRev );
list( $categoryInserts, $categoryDeletes ) = $categoryChanges;
if ( !$categoryInserts && !$categoryDeletes ) {
return; // nothing to do
}
private function getExplicitCategoriesChanges(
- Title $title, Revision $newRev, Revision $oldRev = null
+ WikiPage $page, Revision $newRev, Revision $oldRev = null
) {
// Inject the same timestamp for both revision parses to avoid seeing category changes
// due to time-based parser functions. Inject the same page title for the parses too.
// assumes these updates are perfectly FIFO and that link tables are always
// up to date, neither of which are true.
$oldCategories = $oldRev
- ? $this->getCategoriesAtRev( $title, $oldRev, $parseTimestamp )
+ ? $this->getCategoriesAtRev( $page, $oldRev, $parseTimestamp )
: [];
// Parse the new revision and get the categories
- $newCategories = $this->getCategoriesAtRev( $title, $newRev, $parseTimestamp );
+ $newCategories = $this->getCategoriesAtRev( $page, $newRev, $parseTimestamp );
$categoryInserts = array_values( array_diff( $newCategories, $oldCategories ) );
$categoryDeletes = array_values( array_diff( $oldCategories, $newCategories ) );
}
/**
- * @param Title $title
+ * @param WikiPage $page
* @param Revision $rev
* @param string $parseTimestamp TS_MW
*
* @return string[] category names
*/
- private function getCategoriesAtRev( Title $title, Revision $rev, $parseTimestamp ) {
- $content = $rev->getContent();
- $options = $content->getContentHandler()->makeParserOptions( 'canonical' );
+ private function getCategoriesAtRev( WikiPage $page, Revision $rev, $parseTimestamp ) {
+ $renderer = MediaWikiServices::getInstance()->getRevisionRenderer();
+ $options = $page->makeParserOptions( 'canonical' );
$options->setTimestamp( $parseTimestamp );
+
// This could possibly use the parser cache if it checked the revision ID,
// but that's more complicated than it's worth.
- $output = $content->getParserOutput( $title, $rev->getId(), $options );
+ $output = $renderer->getRenderedRevision( $rev->getRevisionRecord(), $options )
+ ->getRevisionParserOutput();
// array keys will cast numeric category names to ints
// so we need to cast them back to strings to avoid breaking things!