*/ public static function classify( Env $env, ?PageConfig $oldPage, ?PageBundle $oldPb, PageConfig $newPage, PageBundle $newPb ): array { // Default labels (ensure keys are consistent & in consistent order) $labels = [ 'type' => 'missing-prev', 'same-wt' => 'unknown', 'rev-diff' => 'unknown', 'changed-sections' => 'unknown', 'changed-template-sites' => 'unknown', 'changed-template-names' => 'unknown', ]; if ( $oldPage === null || $oldPb === null ) { return $labels; } $oldWt = self::pc2wt( $oldPage ); $newWt = self::pc2wt( $newPage ); // Compare wikitext in both revisions $labels['same-wt'] = self::bool2str( $oldWt == $newWt ); // Compare revision IDs $oldRev = $oldPage->getRevisionId(); $newRev = $newPage->getRevisionId(); if ( $oldRev === $newRev ) { // same revision (template update, most likely) $labels['rev-diff'] = '0'; } elseif ( $oldRev === $newPage->getParentRevisionId() ) { // "normal edit": new revision is the one after old revision $labels['rev-diff'] = '1'; } elseif ( $newRev === $oldPage->getParentRevisionId() ) { // new revision is the one *before* old revision // This is probably a render triggered from RevisionOutputCache // of the previous revision where the "oldRev" is coming from // the parser cache and is thus the latest. This may happen // during races, vandalism patrol, HTML diffing, etc. $labels['rev-diff'] = 'minus1'; } // Parse to DOM and diff $oldDoc = self::pb2doc( $env, $oldPb ); $newDoc = self::pb2doc( $env, $newPb ); $dd = new DOMDiff( $env ); // Don't skip over template content! $dd->skipEncapsulatedContent = false; // Ignore differences in data-parsoid 'dsr' and 'tmp' $cleanDP = static function ( $dp ) { $dp = $dp->clone(); foreach ( [ 'tmp', 'tsr', 'dsr', 'extTagOffsets', 'extLinkContentOffsets' ] as $prop ) { unset( $dp->$prop ); } return $dp; }; $dd->specializedAttribHandlers['data-parsoid'] = static function ( $nA, $vA, $nB, $vB ) use ( $cleanDP ) { return $cleanDP( $vA ) == $cleanDP( $vB ); }; // Ignore differences in 'id' attributes, since these are a side-effect // of data-parsoid/page bundle encapsulation. $dd->specializedAttribHandlers['id'] = static function ( $nA, $vA, $nB, $vB ) { // XXX we can't really tell synthethic ID attributes created by // DOMDataUtils::storeInPageBundle() from "real" ID attributes // in user wikitext. Hackishly ignore differences in any ID // attributes that begin with 'mw' even though technically you // could have a