Daniel Kinzler has uploaded a new change for review.
https://gerrit.wikimedia.org/r/66245
Change subject: Handle If-Modified-Since in Special:EntityData
......................................................................
Handle If-Modified-Since in Special:EntityData
Change-Id: I23fcd3996b858383e41d0bb67980334eb35ae820
---
M repo/includes/specials/EntityDataRequestHandler.php
M repo/tests/phpunit/includes/specials/EntityDataRequestHandlerTest.php
M repo/tests/phpunit/includes/specials/SpecialEntityDataTest.php
3 files changed, 49 insertions(+), 29 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/45/66245/1
diff --git a/repo/includes/specials/EntityDataRequestHandler.php
b/repo/includes/specials/EntityDataRequestHandler.php
index 46f5990..4b86b59 100644
--- a/repo/includes/specials/EntityDataRequestHandler.php
+++ b/repo/includes/specials/EntityDataRequestHandler.php
@@ -412,8 +412,6 @@
*/
public function showData( WebRequest $request, OutputPage $output,
$format, EntityId $id, $revision ) {
- //TODO: handle IfModifiedSince!
-
$prefixedId = $this->entityIdFormatter->format( $id );
$entity = $this->entityContentFactory->getFromId( $id );
@@ -452,6 +450,18 @@
$rev = $page->getRevision();
}
+ // handle If-Modified-Since
+ $imsHeader = $request->getHeader( 'IF-MODIFIED-SINCE' );
+ if ( $imsHeader !== false ) {
+ $ims = wfTimestamp( TS_MW, $imsHeader );
+
+ if ( $rev->getTimestamp() <= $ims ) {
+ $response = $output->getRequest()->response();
+ $response->header( 'Status: 304', true, 304 );
+ return;
+ }
+ }
+
list( $data, $contentType ) =
$this->serializationService->getSerializedData(
$format, $entity->getEntity(), $rev
);
diff --git
a/repo/tests/phpunit/includes/specials/EntityDataRequestHandlerTest.php
b/repo/tests/phpunit/includes/specials/EntityDataRequestHandlerTest.php
index 431b534..6bf64e1 100644
--- a/repo/tests/phpunit/includes/specials/EntityDataRequestHandlerTest.php
+++ b/repo/tests/phpunit/includes/specials/EntityDataRequestHandlerTest.php
@@ -6,6 +6,7 @@
use Title;
use ValueFormatters\FormatterOptions;
use ValueParsers\ParserOptions;
+use Wikibase\Entity;
use Wikibase\EntityContentFactory;
use Wikibase\EntityDataSerializationService;
use \Wikibase\Item;
@@ -491,10 +492,34 @@
)
);
+ // If-Modified-Since handling
+
+ // #35: IMS from the deep bast should return a 200
+ $cases[] = array(
+ '{testitemid}.xml', // subpage
+ array(), // parameters
+ array( // headers
+ 'If-Modified-Since' => wfTimestamp( TS_RFC2822,
'20000101000000' )
+ ),
+ '!!', // output regex
+ 200, // http code
+ );
+
+ // #36: IMS from now should return a 304
+ $cases[] = array(
+ '{testitemid}.json', // subpage
+ array(), // parameters
+ array( // headers
+ 'If-Modified-Since' => '{testitemtimestamp}'
+ ),
+ '!!', // output regex
+ 304, // http code
+ );
+
return $cases;
}
- protected static function injectIds( &$data, \Wikibase\Entity $entity )
{
+ public static function injectIds( &$data, Entity $entity ) {
if ( is_array( $data ) ) {
foreach ( $data as $k => &$v ) {
self::injectIds( $v, $entity );
@@ -503,10 +528,11 @@
$data = str_replace( '{testitemid}', strtoupper(
$entity->getId()->getPrefixedId() ), $data );
$data = str_replace( '{lowertestitemid}', strtolower(
$entity->getId()->getPrefixedId() ), $data );
- if ( strpos( $data, '{testitemrev}' ) >= 0 ) {
- $content =
\Wikibase\EntityContentFactory::singleton()->getFromId( $entity->getId() );
- $data = str_replace( '{testitemrev}',
$content->getWikiPage()->getLatest(), $data );
- }
+ $content =
EntityContentFactory::singleton()->getFromId( $entity->getId() );
+ $data = str_replace( '{testitemrev}',
$content->getWikiPage()->getLatest(), $data );
+
+ $ts = wfTimestamp( TS_RFC2822,
$content->getWikiPage()->getTimestamp() );
+ $data = str_replace( '{testitemtimestamp}', $ts, $data
);
}
}
@@ -555,6 +581,7 @@
// inject actual ID of test items
self::injectIds( $subpage, $item );
self::injectIds( $params, $item );
+ self::injectIds( $headers, $item );
self::injectIds( $expRegExp, $item );
self::injectIds( $expHeaders, $item );
diff --git a/repo/tests/phpunit/includes/specials/SpecialEntityDataTest.php
b/repo/tests/phpunit/includes/specials/SpecialEntityDataTest.php
index 98b8136..0d6b3e0 100644
--- a/repo/tests/phpunit/includes/specials/SpecialEntityDataTest.php
+++ b/repo/tests/phpunit/includes/specials/SpecialEntityDataTest.php
@@ -84,24 +84,6 @@
return $cases;
}
- protected static function injectIds( &$data, \Wikibase\Entity $entity )
{
- //TODO: Same as in EntityDataRequestHandlerTest. Factor out.
-
- if ( is_array( $data ) ) {
- foreach ( $data as $k => &$v ) {
- self::injectIds( $v, $entity );
- }
- } else if ( is_string( $data ) ) {
- $data = str_replace( '{testitemid}', strtoupper(
$entity->getId()->getPrefixedId() ), $data );
- $data = str_replace( '{lowertestitemid}', strtolower(
$entity->getId()->getPrefixedId() ), $data );
-
- if ( strpos( $data, '{testitemrev}' ) >= 0 ) {
- $content =
\Wikibase\EntityContentFactory::singleton()->getFromId( $entity->getId() );
- $data = str_replace( '{testitemrev}',
$content->getWikiPage()->getLatest(), $data );
- }
- }
- }
-
/**
* @dataProvider provideExecute
*
@@ -115,10 +97,11 @@
public function testExecute( $subpage, $params, $headers, $expRegExp,
$expCode = 200, $expHeaders = array() ) {
$item = $this->getTestItem();
- self::injectIds( $subpage, $item );
- self::injectIds( $params, $item );
- self::injectIds( $expRegExp, $item );
- self::injectIds( $expHeaders, $item );
+ EntityDataRequestHandlerTest::injectIds( $subpage, $item );
+ EntityDataRequestHandlerTest::injectIds( $params, $item );
+ EntityDataRequestHandlerTest::injectIds( $headers, $item );
+ EntityDataRequestHandlerTest::injectIds( $expRegExp, $item );
+ EntityDataRequestHandlerTest::injectIds( $expHeaders, $item );
$request = new \FauxRequest( $params );
$request->response()->header( 'Status: 200 OK', true, 200 ); //
init/reset
--
To view, visit https://gerrit.wikimedia.org/r/66245
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I23fcd3996b858383e41d0bb67980334eb35ae820
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits