}
/**
+ * Decides whether two Content objects are equal.
+ * Two Content objects MUST not be considered equal if they do not share the same content model.
+ * Two Content objects that are equal SHOULD have the same serialization.
+ *
+ * This default implementation relies on equalsInternal() to determin whether the
+ * Content objects are logically equivalent. Subclasses that need to implement a custom
+ * equality check should consider overriding equalsInternal(). Subclasses that override
+ * equals() itself MUST make sure that the implementation returns false for $that === null,
+ * and true for $that === this. It MUST also return false if $that does not have the same
+ * content model.
+ *
* @since 1.21
*
* @param Content|null $that
return false;
}
- return $this->getNativeData() === $that->getNativeData();
+ // For type safety. Needed for odd cases like MessageContent using CONTENT_MODEL_WIKITEXT
+ if ( get_class( $that ) !== get_class( $this ) ) {
+ return false;
+ }
+
+ return $this->equalsInternal( $that );
+ }
+
+ /**
+ * Checks whether $that is logically equal to this Content object.
+ *
+ * This method can be overwritten by subclasses that need to implement custom
+ * equality checks.
+ *
+ * This default implementation checks whether the serializations
+ * of $this and $that are the same: $this->serialize() === $that->serialize()
+ *
+ * Implementors can assume that $that is an instance of the same class
+ * as the present Content object, as long as equalsInternal() is only called
+ * by the standard implementation of equals().
+ *
+ * @note Do not call this method directly, call equals() instead.
+ *
+ * @param Content $that
+ * @return bool
+ */
+ protected function equalsInternal( Content $that ) {
+ return $this->serialize() === $that->serialize();
}
/**
ParserOptions $options = null, $generateHtml = true
) {
if ( $options === null ) {
- $options = $this->getContentHandler()->makeParserOptions( 'canonical' );
+ $options = ParserOptions::newCanonical( 'canonical' );
}
$po = new ParserOutput();
+ $options->registerWatcher( [ $po, 'recordOption' ] );
if ( Hooks::run( 'ContentGetParserOutput',
[ $this, $title, $revId, $options, $generateHtml, &$po ] )
}
Hooks::run( 'ContentAlterParserOutput', [ $this, $title, $po ] );
+ $options->registerWatcher( null );
return $po;
}