Skip to content

Commit

Permalink
Merge 6e7849a into 0a24a15
Browse files Browse the repository at this point in the history
  • Loading branch information
mwjames committed Dec 9, 2015
2 parents 0a24a15 + 6e7849a commit 1ed7382
Show file tree
Hide file tree
Showing 10 changed files with 206 additions and 22 deletions.
3 changes: 2 additions & 1 deletion i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -340,5 +340,6 @@
"smw-sp-types_dat": "\"$1\" is a datatype to represent points in time in a unified format.",
"smw-specials-browse-helplink": "https://www.semantic-mediawiki.org/wiki/Help:Special:Browse",
"smw-pa-property-predefined_errc": "\"$1\" is a predefined property representing a [https://www.semantic-mediawiki.org/wiki/Help:Container container] for errors that appeared in connection with improper value annotations or input processing.",
"smw-pa-property-predefined_errt": "\"$1\" is a predefined property containing a textual description of an error."
"smw-pa-property-predefined_errt": "\"$1\" is a predefined property containing a textual description of an error.",
"smw-subobject-parser-invalid-naming-scheme": "A user-defined subobject used an invalid naming scheme. The dot notation ($1) is reserved to be used exclusively by extensions."
}
3 changes: 2 additions & 1 deletion i18n/qqq.json
Original file line number Diff line number Diff line change
Expand Up @@ -347,5 +347,6 @@
"smw-sp-types_dat": "This is an informatory message shown to the user.",
"smw-specials-browse-helplink": "{{notranslate}}",
"smw-pa-property-predefined_errc": "This informatory message describes the [https://semantic-mediawiki.org/wiki/Help:Special_properties special property].",
"smw-pa-property-predefined_errt": "This informatory message describes the [https://semantic-mediawiki.org/wiki/Help:Special_properties special property]."
"smw-pa-property-predefined_errt": "This informatory message describes the [https://semantic-mediawiki.org/wiki/Help:Special_properties special property].",
"smw-subobject-parser-invalid-naming-scheme": "This is an error message shown to the user in case a named identifier contains a dot (foo.bar)."
}
10 changes: 6 additions & 4 deletions includes/parserhooks/RecurringEventsParserFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ public function parse( ParserParameterProcessor $parameters ) {
// @see SubobjectParserFunction::addDataValuesToSubobject
// Each new $parameters set will add an additional subobject
// to the instance
$this->addDataValuesToSubobject( $parameters );

$this->parserData->getSemanticData()->addSubobject( $this->subobject );
if ( $this->addDataValuesToSubobject( $parameters ) ) {
$this->parserData->getSemanticData()->addSubobject( $this->subobject );
}

// Collect errors that occurred during processing
$this->messageFormatter->addFromArray( $this->subobject->getErrors() );
Expand All @@ -82,7 +82,9 @@ public function parse( ParserParameterProcessor $parameters ) {
// Update ParserOutput
$this->parserData->pushSemanticDataToParserOutput();

return $this->messageFormatter->getHtml();
return $this->messageFormatter
->addFromArray( $this->parserData->getErrors() )
->getHtml();
}

}
40 changes: 35 additions & 5 deletions includes/parserhooks/SubobjectParserFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,12 @@ public function setFirstElementForPropertyLabel( $useFirstElementForPropertyLabe
*/
public function parse( ParserParameterProcessor $parameters ) {

$this->addDataValuesToSubobject( $parameters );

if ( !$this->subobject->getSemanticData()->isEmpty() ) {
if ( $this->addDataValuesToSubobject( $parameters ) && !$this->subobject->getSemanticData()->isEmpty() ) {
$this->parserData->getSemanticData()->addSubobject( $this->subobject );
$this->parserData->pushSemanticDataToParserOutput();
}

$this->parserData->pushSemanticDataToParserOutput();

return $this->messageFormatter
->addFromArray( $this->subobject->getErrors() )
->addFromArray( $this->parserData->getErrors() )
Expand All @@ -108,7 +107,19 @@ protected function addDataValuesToSubobject( ParserParameterProcessor $parameter

$subject = $this->parserData->getSemanticData()->getSubject();

$this->subobject->setEmptyContainerForId( $this->createSubobjectId( $parameters ) );
// Named subobjects that contain a "." are reserved to be used by extensions
// only in order to separate them from user land
// (i.e. different access restrictions etc.)
if ( strpos( $parameters->getFirst(), '.' ) !== false ) {
return $this->addErrorWithMsg(
$subject,
wfMessage( 'smw-subobject-parser-invalid-naming-scheme', $parameters->getFirst() )->escaped()
);
}

$this->subobject->setEmptyContainerForId(
$this->createSubobjectId( $parameters )
);

foreach ( $this->transformParametersToArray( $parameters ) as $property => $values ) {

Expand All @@ -132,6 +143,8 @@ protected function addDataValuesToSubobject( ParserParameterProcessor $parameter
$this->subobject->addDataValue( $dataValue );
}
}

return true;
}

private function createSubobjectId( ParserParameterProcessor $parameters ) {
Expand Down Expand Up @@ -159,4 +172,21 @@ private function transformParametersToArray( ParserParameterProcessor $parameter
return $parameters->toArray();
}

private function addErrorWithMsg( $subject, $errorMsg ) {

$error = new Error( $subject );

$this->parserData->getSemanticData()->addPropertyObjectValue(
$error->getProperty(),
$error->getContainerFor(
new DIProperty( '_SOBJ' ),
$errorMsg
)
);

$this->parserData->addError( $errorMsg );

return false;
}

}
15 changes: 10 additions & 5 deletions src/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,21 @@ public function getContainerFor( DIProperty $property = null, $errorMsg = '' ) {
$property = new DIProperty( $property->getKey() );
}

$subWikiPage = new DIWikiPage(
$errorMsg = is_array( $errorMsg ) ? implode( ' ', $errorMsg ) : $errorMsg;

$subject = new DIWikiPage(
$this->subject->getDBkey(),
$this->subject->getNamespace(),
$this->subject->getInterwiki(),
'_ERR' . md5( $property !== null ? $property->getKey() : 'UNKNOWN' )
'_ERR' . md5( ( $property !== null ? $property->getKey() : 'UNKNOWN' ) . $errorMsg )
);

$containerSemanticData = new ContainerSemanticData( $subWikiPage );
// Encode brackets to avoid an annotion is created/included
return $this->newDiContainer( $subject, $property, str_replace( '[', '[', $errorMsg ) );
}

private function newDiContainer( $subject, $property, $errorMsg ) {
$containerSemanticData = new ContainerSemanticData( $subject );

if ( $property !== null ) {
$containerSemanticData->addPropertyObjectValue(
Expand All @@ -67,8 +74,6 @@ public function getContainerFor( DIProperty $property = null, $errorMsg = '' ) {
);
}

$errorMsg = is_array( $errorMsg ) ? implode( ' ', $errorMsg ) : $errorMsg;

$containerSemanticData->addPropertyObjectValue(
new DIProperty( '_ERRT' ),
new DIBlob( $errorMsg )
Expand Down
2 changes: 1 addition & 1 deletion src/Query/Parser/DescriptionProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function addErrorWithMsgKey( $msgKey /*...*/ ) {
array_shift( $params );

$message = new \Message( $msgKey, $params );
$this->addError( str_replace( array( '[' ), array( ':' ), $message->inContentLanguage()->text() ) );
$this->addError( str_replace( array( '[' ), array( '[' ), $message->inContentLanguage()->text() ) );
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
{
"description": "Subobjects to fail, #1299",
"properties": [
{
"name": "Has page",
"contents": "[[Has type::Page]]"
}
],
"subjects": [
{
"name": "Example/P0302/1",
"contents": "{{#subobject:invalid.name |@category=ABC;123|+sep=;}}"
},
{
"name": "Example/P0302/2",
"contents": "{{#subobject:|Modification date= 1 Jan 1970 }}"
},
{
"name": "Example/P0302/3",
"contents": "{{#subobject:|Date= InvalidValue }}"
},
{
"name": "Example/P0302/4",
"contents": "{{#set_recurring_event:some.foo|property=Has date |start=June 8, 2010 |unit=day |period=1 |limit=10 }}"
}
],
"parser-testcases": [
{
"about": "#0 dot scheme not permitted for user-defined named identifiers",
"subject": "Example/P0302/1",
"store": {
"semantic-data": {
"strict-mode-valuematch": false,
"propertyCount": 3,
"propertyKeys": [ "_ERRC", "_SKEY", "_MDAT" ],
"propertyValues": []
}
}
},
{
"about": "#1 restricted property",
"subject": "Example/P0302/2#_a0017273b0d05dedf1e2ca22e2035490",
"store": {
"semantic-data": {
"strict-mode-valuematch": false,
"propertyCount": 2,
"propertyKeys": [ "_ERRC", "_SKEY" ],
"propertyValues": []
}
}
},
{
"about": "#2 invalid value",
"subject": "Example/P0302/3#_d1e1d8ef8b81b9275dee98ab6795b179",
"store": {
"semantic-data": {
"strict-mode-valuematch": false,
"propertyCount": 2,
"propertyKeys": [ "_ERRC", "_SKEY" ],
"propertyValues": []
}
}
},
{
"about": "#3 recurring events invalid name",
"subject": "Example/P0302/4",
"store": {
"semantic-data": {
"strict-mode-valuematch": false,
"propertyCount": 3,
"propertyKeys": [ "_ERRC", "_SKEY", "_MDAT" ],
"propertyValues": []
}
}
}
],
"settings": {
"wgContLang": "en",
"wgLang": "en",
"smwgPageSpecialProperties": [ "_MDAT" ]
},
"meta": {
"version": "0.1",
"is-incomplete": false,
"debug": false
}
}
32 changes: 32 additions & 0 deletions tests/phpunit/Unit/ErrorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,36 @@ public function testErrorContainerForInverseProperty() {
);
}

public function testErrorContainerForSamePropertyAndMsg() {

$instance = new Error( DIWikiPage::newFromText( 'Foo' ) );
$property = new DIProperty( 'Foo' );

$container = $instance->getContainerFor(
$property,
array( 'Some error' )
);

$this->assertSame(
$container->getHash(),
$instance->getContainerFor( $property, array( 'Some error' ) )->getHash()
);
}

public function testErrorContainerForSamePropertyButDifferentMsg() {

$instance = new Error( DIWikiPage::newFromText( 'Foo' ) );
$property = new DIProperty( 'Foo' );

$container = $instance->getContainerFor(
$property,
array( 'Some error' )
);

$this->assertNotSame(
$container->getHash(),
$instance->getContainerFor( $property, array( 'Different error' ) )->getHash()
);
}

}
11 changes: 10 additions & 1 deletion tests/phpunit/includes/parserhooks/ShowParserFunctionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,18 @@ public function testQueryWithErroneousData() {
'propertyKeys' => array( '_ERRP', '_ERRT' ),
);

$errorID = null;

foreach ( $parserData->getSemanticData()->getSubSemanticData() as $subSemanticData ) {
if ( strpos( $subSemanticData->getSubject()->getSubobjectName(), '_ERR' ) !== false ) {
$errorID = $subSemanticData->getSubject()->getSubobjectName();
break;
}
}

$this->semanticDataValidator->assertThatPropertiesAreSet(
$expected,
$parserData->getSemanticData()->findSubSemanticData( '_ERR6fd39e1d9c9c36a9cf917bdb3d80e0fb' )
$parserData->getSemanticData()->findSubSemanticData( $errorID )
);
}

Expand Down
25 changes: 21 additions & 4 deletions tests/phpunit/includes/parserhooks/SubobjectParserFunctionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,12 @@ public function testInstantiatedSubobject( array $parameters, array $expected )
$instance = $this->acquireInstance( $subobject );
$instance->parse( new ParserParameterFormatter( $parameters ) );

$this->assertContains(
$expected['identifier'],
$subobject->getSubobjectId()
);
if ( $expected['identifier'] !== null ) {
$this->assertContains(
$expected['identifier'],
$subobject->getSubobjectId()
);
}
}

/**
Expand Down Expand Up @@ -365,6 +367,21 @@ public function parameterDataProvider() {
)
);

#10 {{#subobject:foo.bar
// |Bar=foo Bar
// |Date=Foo
// }}
$provider[] = array(
array( 'foo.bar', 'Date=Foo' ),
array(
'hasErrors' => true,
'identifier' => null,
'strict-mode-valuematch' => false,
'propertyCount' => 1,
'propertyKeys' => array( '_ERRC' )
)
);

return $provider;
}

Expand Down

0 comments on commit 1ed7382

Please sign in to comment.