19use Wikimedia\Purtle\RdfWriter;
20use Wikimedia\Purtle\RdfWriterFactory;
23require_once __DIR__ .
'/Maintenance.php';
43 parent::__construct();
45 $this->
addDescription(
"Generate RDF dump of categories in a wiki." );
48 $this->
addOption(
'output',
"Output file (default is stdout). Will be overwritten.",
50 $this->
addOption(
'format',
"Set the dump format.",
false,
true );
68 $it->setFetchColumns( [
'page_title',
'page_id' ] );
82 [
'cl_from',
'cl_to' ],
86 'cl_type' =>
'subcat',
89 $it->setFetchColumns( [
'cl_from',
'cl_to' ] );
90 return new RecursiveIteratorIterator( $it );
96 if ( substr( $licenseUrl, 0, 2 ) ==
'//' ) {
97 $licenseUrl =
'https:' . $licenseUrl;
100 ->a(
'schema',
'Dataset' )
101 ->a(
'owl',
'Ontology' )
102 ->say(
'cc',
'license' )->is( $licenseUrl )
104 ->say(
'schema',
'dateModified' )
105 ->value(
wfTimestamp( TS_ISO_8601, $timestamp ),
'xsd',
'dateTime' )
111 $outFile = $this->
getOption(
'output',
'php://stdout' );
113 if ( $outFile ===
'-' ) {
114 $outFile =
'php://stdout';
117 $output = fopen( $outFile,
'w' );
119 $this->categoriesRdf =
new CategoriesRdf( $this->rdfWriter );
121 $this->categoriesRdf->setupPrefixes();
122 $this->rdfWriter->start();
125 fwrite(
$output, $this->rdfWriter->drain() );
131 foreach (
$batch as $row ) {
132 $this->categoriesRdf->writeCategoryData( $row->page_title );
133 $pages[$row->page_id] = $row->page_title;
137 $this->categoriesRdf->writeCategoryLinkData( $pages[$row->cl_from], $row->cl_to );
139 fwrite(
$output, $this->rdfWriter->drain() );
142 if ( $outFile !==
'-' ) {
152 $factory =
new RdfWriterFactory();
153 return $factory->getWriter( $factory->getFormatName( $format ) );
$wgRightsUrl
Set this to specify an external URL containing details about the content license used on your wiki.
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Helper class to produce RDF representation of categories.
const FORMAT_VERSION
Current version of the dump format.
const OWL_URL
OWL description of the ontology.
Maintenance script to provide RDF representation of the category tree.
getCategoryIterator(IDatabase $dbr)
Produce row iterator for categories.
getCategoryLinksIterator(IDatabase $dbr, array $ids)
Get iterator for links for categories.
execute()
Do the actual work.
addDumpHeader( $timestamp)
CategoriesRdf $categoriesRdf
Categories RDF helper.
__construct()
Default constructor.
createRdfWriter( $format)
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
getDB( $db, $groups=[], $wiki=false)
Returns a database to be used by current maintenance script.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
setBatchSize( $s=0)
Set the batch size.
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title after the basic globals have been set but before ordinary actions take place $output
require_once RUN_MAINTENANCE_IF_MAIN