Rename ParserOutput::{get,set,unset}Property to {get,set,unset}PageProperty
The ::getProperty() naming is too generic and doesn't clearly indicate that these are "page properties" (which have their own table in the DB). As part of refactoring a clean API out of ParserOutput which can be used by Parsoid, clean up the naming here. Soft-deprecation in this patch, there are a handful of external users which need to be cleaned up before we hard-deprecate. Bug: T287216 Change-Id: Ie963eea5aa0f0e984ced7c4dfa0fd65d57313cfa
This commit is contained in:
parent
aead92cf86
commit
af5d13c5de
11 changed files with 118 additions and 62 deletions
|
|
@ -181,6 +181,11 @@ because of Phabricator reports.
|
|||
* The following methods from the ParserOutput class were hard deprecated:
|
||||
- ::hideNewSection() - use ::setHideNewSection()
|
||||
- ::preventClickjacking() - use ::{get,set}PreventClickjacking()
|
||||
* The following methods from the ParserOutput class were soft deprecated:
|
||||
- ::getProperty() - use ::getPageProperty()
|
||||
- ::setProperty() - use ::setPageProperty()
|
||||
- ::unsetProperty() - use ::unsetPageProperties()
|
||||
- ::getProperties() - use ::getPageProperties()
|
||||
* The following methods were soft-deprecated; use ::setPreventClickjacking(..)
|
||||
instead:
|
||||
- OutputPage::preventClickjacking()
|
||||
|
|
|
|||
|
|
@ -163,7 +163,7 @@ class ApiExpandTemplates extends ApiBase {
|
|||
}
|
||||
}
|
||||
if ( isset( $prop['properties'] ) ) {
|
||||
$properties = $p_output->getProperties();
|
||||
$properties = $p_output->getPageProperties();
|
||||
if ( $properties ) {
|
||||
ApiResult::setArrayType( $properties, 'BCkvp', 'name' );
|
||||
ApiResult::setIndexedTagName( $properties, 'property' );
|
||||
|
|
|
|||
|
|
@ -631,7 +631,7 @@ class ApiParse extends ApiBase {
|
|||
}
|
||||
}
|
||||
if ( isset( $prop['properties'] ) ) {
|
||||
$result_array['properties'] = (array)$p_result->getProperties();
|
||||
$result_array['properties'] = $p_result->getPageProperties();
|
||||
ApiResult::setArrayType( $result_array['properties'], 'BCkvp', 'name' );
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -244,6 +244,6 @@ class WikiTextStructure {
|
|||
* @return string|null
|
||||
*/
|
||||
public function getDefaultSort() {
|
||||
return $this->parserOutput->getProperty( 'defaultsort' );
|
||||
return $this->parserOutput->getPageProperty( 'defaultsort' );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -141,7 +141,7 @@ class LinksUpdate extends DataUpdate {
|
|||
$this->mTemplates = $parserOutput->getTemplates();
|
||||
$this->mExternals = $parserOutput->getExternalLinks();
|
||||
$this->mCategories = $parserOutput->getCategories();
|
||||
$this->mProperties = $parserOutput->getProperties();
|
||||
$this->mProperties = $parserOutput->getPageProperties();
|
||||
$this->mInterwikis = $parserOutput->getInterwikiLinks();
|
||||
|
||||
# Convert the format of the interlanguage links
|
||||
|
|
|
|||
|
|
@ -482,7 +482,7 @@ class CoreParserFunctions {
|
|||
&& !$title->hasFragment()
|
||||
&& $title->equals( $parser->getTitle() ) )
|
||||
) {
|
||||
$old = $parser->getOutput()->getProperty( 'displaytitle' );
|
||||
$old = $parser->getOutput()->getPageProperty( 'displaytitle' );
|
||||
if ( $old === false || $arg !== 'displaytitle_noreplace' ) {
|
||||
$parser->getOutput()->setDisplayTitle( $text );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4072,7 +4072,7 @@ class Parser {
|
|||
|
||||
# Cache all double underscores in the database
|
||||
foreach ( $this->mDoubleUnderscores as $key => $val ) {
|
||||
$this->mOutput->setProperty( $key, '' );
|
||||
$this->mOutput->setPageProperty( $key, '' );
|
||||
}
|
||||
|
||||
return $text;
|
||||
|
|
@ -5978,7 +5978,7 @@ class Parser {
|
|||
*/
|
||||
public function setDefaultSort( $sort ) {
|
||||
$this->mDefaultSort = $sort;
|
||||
$this->mOutput->setProperty( 'defaultsort', $sort );
|
||||
$this->mOutput->setPageProperty( 'defaultsort', $sort );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1051,7 +1051,7 @@ class ParserOutput extends CacheTime {
|
|||
|
||||
$containerCategory = Title::makeTitleSafe( NS_CATEGORY, $cat );
|
||||
if ( $containerCategory ) {
|
||||
$this->addCategory( $containerCategory->getDBkey(), $this->getProperty( 'defaultsort' ) ?: '' );
|
||||
$this->addCategory( $containerCategory->getDBkey(), $this->getPageProperty( 'defaultsort' ) ?: '' );
|
||||
return true;
|
||||
} else {
|
||||
wfDebug( __METHOD__ . ": [[MediaWiki:$msg]] is not a valid title!" );
|
||||
|
|
@ -1072,7 +1072,7 @@ class ParserOutput extends CacheTime {
|
|||
*/
|
||||
public function setDisplayTitle( $text ) {
|
||||
$this->setTitleText( $text );
|
||||
$this->setProperty( 'displaytitle', $text );
|
||||
$this->setPageProperty( 'displaytitle', $text );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1117,7 +1117,46 @@ class ParserOutput extends CacheTime {
|
|||
}
|
||||
|
||||
/**
|
||||
* Set a property to be stored in the page_props database table.
|
||||
* Sets a page property to be stored in the page_props database table.
|
||||
* @param string $name
|
||||
* @param int|float|string|bool|null $value
|
||||
* @deprecated since 1.38, renamed to ::setPageProperty()
|
||||
*/
|
||||
public function setProperty( $name, $value ) {
|
||||
$this->setPageProperty( $name, $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name The property name to look up.
|
||||
*
|
||||
* @return mixed|bool The value previously set using setPageProperty(). False if null or no value
|
||||
* was set for the given property name.
|
||||
*
|
||||
* @note You need to use getPageProperties() to check for boolean and null properties.
|
||||
* @deprecated since 1.38, renamed to ::getPageProperty()
|
||||
*/
|
||||
public function getProperty( $name ) {
|
||||
return $this->getPageProperty( $name );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @deprecated since 1.38, renamed to ::unsetPageProperty()
|
||||
*/
|
||||
public function unsetProperty( $name ) {
|
||||
$this->unsetPageProperty( $name );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @deprecated since 1.38, renamed to ::getPageProperties()
|
||||
*/
|
||||
public function getProperties() {
|
||||
return $this->getPageProperties();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a page property to be stored in the page_props database table.
|
||||
*
|
||||
* page_props is a key value store indexed by the page ID. This allows
|
||||
* the parser to set a property on a page which can then be quickly
|
||||
|
|
@ -1127,14 +1166,14 @@ class ParserOutput extends CacheTime {
|
|||
* Since 1.23, page_props are also indexed by numeric value, to allow
|
||||
* for efficient "top k" queries of pages wrt a given property.
|
||||
*
|
||||
* setProperty() is thus used to propagate properties from the parsed
|
||||
* setPageProperty() is thus used to propagate properties from the parsed
|
||||
* page to request contexts other than a page view of the currently parsed
|
||||
* article.
|
||||
*
|
||||
* Some applications examples:
|
||||
*
|
||||
* * To implement hidden categories, hiding pages from category listings
|
||||
* by storing a property.
|
||||
* by storing a page property.
|
||||
*
|
||||
* * Overriding the displayed article title (ParserOutput::setDisplayTitle()).
|
||||
*
|
||||
|
|
@ -1143,7 +1182,7 @@ class ParserOutput extends CacheTime {
|
|||
* Wikimedia Commons.
|
||||
* This is not actually implemented, yet but would be pretty cool.
|
||||
*
|
||||
* @note Do not use setProperty() to set a property which is only used
|
||||
* @note Do not use setPageProperty() to set a property which is only used
|
||||
* in a context where the ParserOutput object itself is already available,
|
||||
* for example a normal page view. There is no need to save such a property
|
||||
* in the database since the text is already parsed. You can just hook
|
||||
|
|
@ -1180,28 +1219,40 @@ class ParserOutput extends CacheTime {
|
|||
*
|
||||
* @param string $name
|
||||
* @param int|float|string|bool|null $value
|
||||
* @since 1.38
|
||||
*/
|
||||
public function setProperty( $name, $value ) {
|
||||
public function setPageProperty( string $name, $value ): void {
|
||||
$this->mProperties[$name] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name The property name to look up.
|
||||
*
|
||||
* @return mixed|bool The value previously set using setProperty(). False if null or no value
|
||||
* Look up a page property.
|
||||
* @param string $name The page property name to look up.
|
||||
* @return int|float|string|bool The value previously set using setPageProperty(). False if null or no value
|
||||
* was set for the given property name.
|
||||
*
|
||||
* @note You need to use getProperties() to check for boolean and null properties.
|
||||
* @note You need to use getPageProperties() to check for boolean and null properties.
|
||||
* @since 1.38
|
||||
*/
|
||||
public function getProperty( $name ) {
|
||||
public function getPageProperty( string $name ) {
|
||||
return $this->mProperties[$name] ?? false;
|
||||
}
|
||||
|
||||
public function unsetProperty( $name ) {
|
||||
/**
|
||||
* Remove a page property.
|
||||
* @param string $name The page property name.
|
||||
* @since 1.38
|
||||
*/
|
||||
public function unsetPageProperty( string $name ): void {
|
||||
unset( $this->mProperties[$name] );
|
||||
}
|
||||
|
||||
public function getProperties() {
|
||||
/**
|
||||
* Return all the page properties set on this ParserOutput.
|
||||
* @return array<string,int|float|string|bool|null>
|
||||
* @since 1.38
|
||||
*/
|
||||
public function getPageProperties(): array {
|
||||
if ( !isset( $this->mProperties ) ) {
|
||||
$this->mProperties = [];
|
||||
}
|
||||
|
|
@ -1211,7 +1262,7 @@ class ParserOutput extends CacheTime {
|
|||
/**
|
||||
* Attaches arbitrary data to this ParserObject. This can be used to store some information in
|
||||
* the ParserOutput object for later use during page output. The data will be cached along with
|
||||
* the ParserOutput object, but unlike data set using setProperty(), it is not recorded in the
|
||||
* the ParserOutput object, but unlike data set using setPageProperty(), it is not recorded in the
|
||||
* database.
|
||||
*
|
||||
* This method is provided to overcome the unsafe practice of attaching extra information to a
|
||||
|
|
@ -1639,9 +1690,9 @@ class ParserOutput extends CacheTime {
|
|||
$source->getInterwikiLinks()
|
||||
);
|
||||
|
||||
// TODO: add a $mergeStrategy parameter to setProperty to allow different
|
||||
// TODO: add a $mergeStrategy parameter to setPageProperty to allow different
|
||||
// kinds of properties to be merged in different ways.
|
||||
$this->mProperties = self::mergeMap( $this->mProperties, $source->getProperties() );
|
||||
$this->mProperties = self::mergeMap( $this->mProperties, $source->getPageProperties() );
|
||||
|
||||
// NOTE: include extension data in "tracking meta data" as well as "html meta data"!
|
||||
// TODO: add a $mergeStrategy parameter to setExtensionData to allow different
|
||||
|
|
|
|||
|
|
@ -372,7 +372,7 @@ class LinksUpdateTest extends MediaWikiLangTestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* @covers ParserOutput::setProperty
|
||||
* @covers ParserOutput::setPageProperty
|
||||
*/
|
||||
public function testUpdate_page_props() {
|
||||
/** @var ParserOutput $po */
|
||||
|
|
@ -381,16 +381,16 @@ class LinksUpdateTest extends MediaWikiLangTestCase {
|
|||
$fields = [ 'pp_propname', 'pp_value', 'pp_sortkey' ];
|
||||
$expected = [];
|
||||
|
||||
$po->setProperty( "bool", true );
|
||||
$po->setPageProperty( "bool", true );
|
||||
$expected[] = [ "bool", true ];
|
||||
|
||||
$po->setProperty( "float", 4.0 + 1.0 / 4.0 );
|
||||
$po->setPageProperty( "float", 4.0 + 1.0 / 4.0 );
|
||||
$expected[] = [ "float", 4.0 + 1.0 / 4.0 ];
|
||||
|
||||
$po->setProperty( "int", -7 );
|
||||
$po->setPageProperty( "int", -7 );
|
||||
$expected[] = [ "int", -7 ];
|
||||
|
||||
$po->setProperty( "string", "33 bar" );
|
||||
$po->setPageProperty( "string", "33 bar" );
|
||||
$expected[] = [ "string", "33 bar" ];
|
||||
|
||||
// compute expected sortkey values
|
||||
|
|
|
|||
|
|
@ -146,12 +146,12 @@ abstract class ParserCacheSerializationTestCases {
|
|||
|
||||
$parserOutputWithProperties = new ParserOutput();
|
||||
foreach ( self::MOCK_EXT_DATA as $key => $value ) {
|
||||
$parserOutputWithProperties->setProperty( $key, $value );
|
||||
$parserOutputWithProperties->setPageProperty( $key, $value );
|
||||
}
|
||||
|
||||
$parserOutputWithBinaryProperties = new ParserOutput();
|
||||
foreach ( self::MOCK_BINARY_PROPERTIES as $key => $value ) {
|
||||
$parserOutputWithBinaryProperties->setProperty( $key, $value );
|
||||
$parserOutputWithBinaryProperties->setPageProperty( $key, $value );
|
||||
}
|
||||
|
||||
$parserOutputWithMetadata = new ParserOutput();
|
||||
|
|
@ -258,8 +258,8 @@ abstract class ParserCacheSerializationTestCases {
|
|||
$testCase->assertFalse( $object->getDisplayTitle() );
|
||||
$testCase->assertFalse( $object->getFlag( 'test' ) );
|
||||
$testCase->assertArrayEquals( [], $object->getAllFlags() );
|
||||
$testCase->assertFalse( $object->getProperty( 'test_prop' ) );
|
||||
$testCase->assertArrayEquals( [], $object->getProperties() );
|
||||
$testCase->assertFalse( $object->getPageProperty( 'test_prop' ) );
|
||||
$testCase->assertArrayEquals( [], $object->getPageProperties() );
|
||||
$testCase->assertArrayEquals( [], $object->getUsedOptions() );
|
||||
$testCase->assertNull( $object->getExtensionData( 'test_ext_data' ) );
|
||||
$testCase->assertNull( $object->getTimeSinceStart( 'wall' ) );
|
||||
|
|
@ -293,23 +293,23 @@ abstract class ParserCacheSerializationTestCases {
|
|||
'pageProperties' => [
|
||||
'instance' => $parserOutputWithProperties,
|
||||
'assertions' => static function ( MediaWikiIntegrationTestCase $testCase, ParserOutput $object ) {
|
||||
$testCase->assertSame( self::MOCK_EXT_DATA['boolean'], $object->getProperty( 'boolean' ) );
|
||||
$testCase->assertSame( self::MOCK_EXT_DATA['boolean'], $object->getPageProperty( 'boolean' ) );
|
||||
// Falsy properties return false even though null was given.
|
||||
$testCase->assertFalse( $object->getProperty( 'null' ) );
|
||||
$testCase->assertSame( self::MOCK_EXT_DATA['number'], $object->getProperty( 'number' ) );
|
||||
$testCase->assertSame( self::MOCK_EXT_DATA['string'], $object->getProperty( 'string' ) );
|
||||
$testCase->assertArrayEquals( self::MOCK_EXT_DATA['array'], $object->getProperty( 'array' ) );
|
||||
$testCase->assertSame( self::MOCK_EXT_DATA['map'], $object->getProperty( 'map' ) );
|
||||
$testCase->assertArrayEquals( self::MOCK_EXT_DATA, $object->getProperties() );
|
||||
$testCase->assertFalse( $object->getPageProperty( 'null' ) );
|
||||
$testCase->assertSame( self::MOCK_EXT_DATA['number'], $object->getPageProperty( 'number' ) );
|
||||
$testCase->assertSame( self::MOCK_EXT_DATA['string'], $object->getPageProperty( 'string' ) );
|
||||
$testCase->assertArrayEquals( self::MOCK_EXT_DATA['array'], $object->getPageProperty( 'array' ) );
|
||||
$testCase->assertSame( self::MOCK_EXT_DATA['map'], $object->getPageProperty( 'map' ) );
|
||||
$testCase->assertArrayEquals( self::MOCK_EXT_DATA, $object->getPageProperties() );
|
||||
}
|
||||
],
|
||||
'binaryPageProperties' => [
|
||||
'instance' => $parserOutputWithBinaryProperties,
|
||||
'assertions' => static function ( MediaWikiIntegrationTestCase $testCase, ParserOutput $object ) {
|
||||
$testCase->assertSame( self::MOCK_BINARY_PROPERTIES['empty'], $object->getProperty( 'empty' ) );
|
||||
$testCase->assertSame( self::MOCK_BINARY_PROPERTIES['\x00'], $object->getProperty( '\x00' ) );
|
||||
$testCase->assertSame( self::MOCK_BINARY_PROPERTIES['gzip'], $object->getProperty( 'gzip' ) );
|
||||
$testCase->assertArrayEquals( self::MOCK_BINARY_PROPERTIES, $object->getProperties() );
|
||||
$testCase->assertSame( self::MOCK_BINARY_PROPERTIES['empty'], $object->getPageProperty( 'empty' ) );
|
||||
$testCase->assertSame( self::MOCK_BINARY_PROPERTIES['\x00'], $object->getPageProperty( '\x00' ) );
|
||||
$testCase->assertSame( self::MOCK_BINARY_PROPERTIES['gzip'], $object->getPageProperty( 'gzip' ) );
|
||||
$testCase->assertArrayEquals( self::MOCK_BINARY_PROPERTIES, $object->getPageProperties() );
|
||||
}
|
||||
],
|
||||
'withMetadata' => [
|
||||
|
|
|
|||
|
|
@ -111,30 +111,30 @@ class ParserOutputTest extends MediaWikiLangTestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* @covers ParserOutput::setProperty
|
||||
* @covers ParserOutput::getProperty
|
||||
* @covers ParserOutput::unsetProperty
|
||||
* @covers ParserOutput::getProperties
|
||||
* @covers ParserOutput::setPageProperty
|
||||
* @covers ParserOutput::getPageProperty
|
||||
* @covers ParserOutput::unsetPageProperty
|
||||
* @covers ParserOutput::getPageProperties
|
||||
*/
|
||||
public function testProperties() {
|
||||
$po = new ParserOutput();
|
||||
|
||||
$po->setProperty( 'foo', 'val' );
|
||||
$po->setPageProperty( 'foo', 'val' );
|
||||
|
||||
$properties = $po->getProperties();
|
||||
$this->assertSame( 'val', $po->getProperty( 'foo' ) );
|
||||
$properties = $po->getPageProperties();
|
||||
$this->assertSame( 'val', $po->getPageProperty( 'foo' ) );
|
||||
$this->assertSame( 'val', $properties['foo'] );
|
||||
|
||||
$po->setProperty( 'foo', 'second val' );
|
||||
$po->setPageProperty( 'foo', 'second val' );
|
||||
|
||||
$properties = $po->getProperties();
|
||||
$this->assertSame( 'second val', $po->getProperty( 'foo' ) );
|
||||
$properties = $po->getPageProperties();
|
||||
$this->assertSame( 'second val', $po->getPageProperty( 'foo' ) );
|
||||
$this->assertSame( 'second val', $properties['foo'] );
|
||||
|
||||
$po->unsetProperty( 'foo' );
|
||||
$po->unsetPageProperty( 'foo' );
|
||||
|
||||
$properties = $po->getProperties();
|
||||
$this->assertSame( false, $po->getProperty( 'foo' ) );
|
||||
$properties = $po->getPageProperties();
|
||||
$this->assertSame( false, $po->getPageProperty( 'foo' ) );
|
||||
$this->assertArrayNotHasKey( 'foo', $properties );
|
||||
}
|
||||
|
||||
|
|
@ -726,22 +726,22 @@ EOF
|
|||
// properties ------------
|
||||
$a = new ParserOutput();
|
||||
|
||||
$a->setProperty( 'foo', 'Foo!' );
|
||||
$a->setProperty( 'bar', 'Bar!' );
|
||||
$a->setPageProperty( 'foo', 'Foo!' );
|
||||
$a->setPageProperty( 'bar', 'Bar!' );
|
||||
|
||||
$a->setExtensionData( 'foo', 'Foo!' );
|
||||
$a->setExtensionData( 'bar', 'Bar!' );
|
||||
|
||||
$b = new ParserOutput();
|
||||
|
||||
$b->setProperty( 'zoo', 'Zoo!' );
|
||||
$b->setProperty( 'bar', 'Barrr!' );
|
||||
$b->setPageProperty( 'zoo', 'Zoo!' );
|
||||
$b->setPageProperty( 'bar', 'Barrr!' );
|
||||
|
||||
$b->setExtensionData( 'zoo', 'Zoo!' );
|
||||
$b->setExtensionData( 'bar', 'Barrr!' );
|
||||
|
||||
yield 'properties' => [ $a, $b, [
|
||||
'getProperties' => [
|
||||
'getPageProperties' => [
|
||||
'foo' => 'Foo!',
|
||||
'bar' => 'Barrr!',
|
||||
'zoo' => 'Zoo!',
|
||||
|
|
|
|||
Loading…
Reference in a new issue