From bb2453fa7c50e45b39c0788be594d277d6bb901a Mon Sep 17 00:00:00 2001 From: Stanislav Malyshev Date: Fri, 17 Nov 2017 16:17:09 -0800 Subject: [PATCH] Port categories dump header fix This fix is ported from https://gerrit.wikimedia.org/r/#/c/372905 since it does not belong to SPARQL updates really. It changes main node for category dump to thus allowing to support multiple wikis living on the same domain.w Change-Id: Ie1ac5ddf6b3b73f3966274f90abc1db50061b494 --- includes/CategoriesRdf.php | 28 +++++++++++++++++-- maintenance/dumpCategoriesAsRdf.php | 2 +- .../data/categoriesrdf/categoriesRdf-out.nt | 14 +++++----- .../phpunit/maintenance/categoriesRdfTest.php | 4 +-- 4 files changed, 36 insertions(+), 12 deletions(-) diff --git a/includes/CategoriesRdf.php b/includes/CategoriesRdf.php index e19dc2aadb..463f6e846b 100644 --- a/includes/CategoriesRdf.php +++ b/includes/CategoriesRdf.php @@ -37,7 +37,13 @@ class CategoriesRdf { /** * Current version of the dump format. */ - const FORMAT_VERSION = "1.0"; + const FORMAT_VERSION = "1.1"; + /** + * Special page for Dump identification. + * Used as head URI for each wiki's category dump, e.g.: + * https://en.wikipedia.org/wiki/Special:CategoryDump + */ + const SPECIAL_DUMP = 'Special:CategoryDump'; /** * @var RdfWriter */ @@ -84,12 +90,30 @@ class CategoriesRdf { $this->rdfWriter->say( 'rdfs', 'label' )->value( $titletext ); } + /** + * Make URL from title label + * @param string $titleLabel Short label (without namespace) of the category + * @return string URL for the category + */ + public function labelToUrl( $titleLabel ) { + return $this->titleToUrl( Title::makeTitle( NS_CATEGORY, $titleLabel ) ); + } + /** * Convert Title to link to target page. * @param Title $title - * @return string + * @return string URL for the category */ private function titleToUrl( Title $title ) { return $title->getFullURL( '', false, PROTO_CANONICAL ); } + + /** + * Get URI of the dump for this particular wiki. + * @return false|string + */ + public function getDumpURI() { + return $this->titleToUrl( Title::makeTitle( NS_MAIN, self::SPECIAL_DUMP ) ); + } + } diff --git a/maintenance/dumpCategoriesAsRdf.php b/maintenance/dumpCategoriesAsRdf.php index 282a04b0c3..c1835d05d1 100644 --- a/maintenance/dumpCategoriesAsRdf.php +++ b/maintenance/dumpCategoriesAsRdf.php @@ -96,7 +96,7 @@ class DumpCategoriesAsRdf extends Maintenance { if ( substr( $licenseUrl, 0, 2 ) == '//' ) { $licenseUrl = 'https:' . $licenseUrl; } - $this->rdfWriter->about( wfExpandUrl( '/categoriesDump', PROTO_CANONICAL ) ) + $this->rdfWriter->about( $this->categoriesRdf->getDumpURI() ) ->a( 'schema', 'Dataset' ) ->a( 'owl', 'Ontology' ) ->say( 'cc', 'license' )->is( $licenseUrl ) diff --git a/tests/phpunit/data/categoriesrdf/categoriesRdf-out.nt b/tests/phpunit/data/categoriesrdf/categoriesRdf-out.nt index d2d7ea81f1..b8bd8e02e2 100644 --- a/tests/phpunit/data/categoriesrdf/categoriesRdf-out.nt +++ b/tests/phpunit/data/categoriesrdf/categoriesRdf-out.nt @@ -1,10 +1,10 @@ - . - . - . - "1.0" . - "{DATE}"^^ . - . - . + . + . + . + "1.1" . + "{DATE}"^^ . + . + . . "Category One" . . diff --git a/tests/phpunit/maintenance/categoriesRdfTest.php b/tests/phpunit/maintenance/categoriesRdfTest.php index ec2746e8ee..9026bd9e1b 100644 --- a/tests/phpunit/maintenance/categoriesRdfTest.php +++ b/tests/phpunit/maintenance/categoriesRdfTest.php @@ -60,8 +60,8 @@ class CategoriesRdfTest extends MediaWikiLangTestCase { $dumpScript->execute(); $actualOut = file_get_contents( $outFileName ); $actualOut = preg_replace( - '| "[^"]+?"|', - ' "{DATE}"', + '| "[^"]+?"|', + ' "{DATE}"', $actualOut ); -- 2.20.1