MediaWiki REL1_30
CategoriesRdf.php
Go to the documentation of this file.
1<?php
19use Wikimedia\Purtle\RdfWriter;
20
28 const ONTOLOGY_PREFIX = 'mediawiki';
32 const ONTOLOGY_URL = 'https://www.mediawiki.org/ontology#';
36 const OWL_URL = 'https://www.mediawiki.org/ontology/ontology.owl';
40 const FORMAT_VERSION = "1.0";
44 private $rdfWriter;
45
46 public function __construct( RdfWriter $writer ) {
47 $this->rdfWriter = $writer;
48 }
49
53 public function setupPrefixes() {
54 $this->rdfWriter->prefix( self::ONTOLOGY_PREFIX, self::ONTOLOGY_URL );
55 $this->rdfWriter->prefix( 'rdfs', 'http://www.w3.org/2000/01/rdf-schema#' );
56 $this->rdfWriter->prefix( 'owl', 'http://www.w3.org/2002/07/owl#' );
57 $this->rdfWriter->prefix( 'schema', 'http://schema.org/' );
58 $this->rdfWriter->prefix( 'cc', 'http://creativecommons.org/ns#' );
59 }
60
66 public function writeCategoryLinkData( $fromName, $toName ) {
67 $titleFrom = Title::makeTitle( NS_CATEGORY, $fromName );
68 $titleTo = Title::makeTitle( NS_CATEGORY, $toName );
69 $this->rdfWriter->about( $this->titleToUrl( $titleFrom ) )
70 ->say( self::ONTOLOGY_PREFIX, 'isInCategory' )
71 ->is( $this->titleToUrl( $titleTo ) );
72 }
73
78 public function writeCategoryData( $categoryName ) {
79 $title = Title::makeTitle( NS_CATEGORY, $categoryName );
80 $this->rdfWriter->about( $this->titleToUrl( $title ) )
81 ->say( 'a' )
82 ->is( self::ONTOLOGY_PREFIX, 'Category' );
83 $titletext = $title->getText();
84 $this->rdfWriter->say( 'rdfs', 'label' )->value( $titletext );
85 }
86
92 private function titleToUrl( Title $title ) {
93 return $title->getFullURL( '', false, PROTO_CANONICAL );
94 }
95}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
Helper class to produce RDF representation of categories.
setupPrefixes()
Setup prefixes relevant for the dump.
const ONTOLOGY_URL
Base URL for Mediawiki ontology.
writeCategoryData( $categoryName)
Write out the data for single category.
writeCategoryLinkData( $fromName, $toName)
Write RDF data for link between categories.
__construct(RdfWriter $writer)
const ONTOLOGY_PREFIX
Prefix used for Mediawiki ontology in the dump.
RdfWriter $rdfWriter
const FORMAT_VERSION
Current version of the dump format.
titleToUrl(Title $title)
Convert Title to link to target page.
const OWL_URL
OWL description of the ontology.
Represents a title within MediaWiki.
Definition Title.php:39
const PROTO_CANONICAL
Definition Defines.php:224
const NS_CATEGORY
Definition Defines.php:79
namespace and then decline to actually register it file or subcat img or subcat $title
Definition hooks.txt:962
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37