MediaWiki  master
Go to the documentation of this file.
1 <?php
28  const ONTOLOGY_PREFIX = 'mediawiki';
32  const ONTOLOGY_URL = '';
36  const OWL_URL = '';
40  const FORMAT_VERSION = "1.1";
46  const SPECIAL_DUMP = 'Special:CategoryDump';
50  private $rdfWriter;
52  public function __construct( RdfWriter $writer ) {
53  $this->rdfWriter = $writer;
54  }
59  public function setupPrefixes() {
60  $this->rdfWriter->prefix( self::ONTOLOGY_PREFIX, self::ONTOLOGY_URL );
61  $this->rdfWriter->prefix( 'rdfs', '' );
62  $this->rdfWriter->prefix( 'owl', '' );
63  $this->rdfWriter->prefix( 'schema', '' );
64  $this->rdfWriter->prefix( 'cc', '' );
65  }
72  public function writeCategoryLinkData( $fromName, $toName ) {
73  $titleFrom = Title::makeTitle( NS_CATEGORY, $fromName );
74  $titleTo = Title::makeTitle( NS_CATEGORY, $toName );
75  $this->rdfWriter->about( $this->titleToUrl( $titleFrom ) )
76  ->say( self::ONTOLOGY_PREFIX, 'isInCategory' )
77  ->is( $this->titleToUrl( $titleTo ) );
78  }
87  public function writeCategoryData( $categoryName, $isHidden, $pages, $subcategories ) {
88  if ( $pages < 0 ) {
89  // Bugfix for T201119
90  $pages = 0;
91  }
92  $title = Title::makeTitle( NS_CATEGORY, $categoryName );
93  $this->rdfWriter->about( $this->titleToUrl( $title ) )
94  ->say( 'a' )
95  ->is( self::ONTOLOGY_PREFIX, 'Category' );
96  if ( $isHidden ) {
97  $this->rdfWriter->is( self::ONTOLOGY_PREFIX, 'HiddenCategory' );
98  }
99  $titletext = $title->getText();
100  $this->rdfWriter->say( 'rdfs', 'label' )->value( $titletext );
101  $this->rdfWriter->say( self::ONTOLOGY_PREFIX, 'pages' )->value( $pages );
102  $this->rdfWriter->say( self::ONTOLOGY_PREFIX, 'subcategories' )->value( $subcategories );
103  // TODO: do we want files too here? Easy to add, but don't have use case so far.
104  }
111  public function labelToUrl( $titleLabel ) {
112  return $this->titleToUrl( Title::makeTitle( NS_CATEGORY, $titleLabel ) );
113  }
120  private function titleToUrl( Title $title ) {
121  return $title->getFullURL( '', false, PROTO_CANONICAL );
122  }
128  public function getDumpURI() {
129  return $this->titleToUrl( Title::makeTitle( NS_MAIN, self::SPECIAL_DUMP ) );
130  }
132 }
titleToUrl(Title $title)
Convert Title to link to target page.
__construct(RdfWriter $writer)
const NS_MAIN
Definition: Defines.php:60
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
Helper class to produce RDF representation of categories.
Special page for Dump identification.
Base URL for Mediawiki ontology.
Setup prefixes relevant for the dump.
Definition: Defines.php:74
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:912
getFullURL( $query='', $query2=false, $proto=PROTO_RELATIVE)
Get a real URL referring to this title, with interwiki link and fragment.
Definition: Title.php:1974
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:592
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:35
Definition: Defines.php:203
labelToUrl( $titleLabel)
Make URL from title label.
RdfWriter $rdfWriter
Current version of the dump format.
writeCategoryData( $categoryName, $isHidden, $pages, $subcategories)
Write out the data for single category.
Prefix used for Mediawiki ontology in the dump.
Get URI of the dump for this particular wiki.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU Ge...
writeCategoryLinkData( $fromName, $toName)
Write RDF data for link between categories.
const OWL_URL
OWL description of the ontology.