MediaWiki  1.30.0
SiteExporter.php
Go to the documentation of this file.
1 <?php
2 
30 class SiteExporter {
31 
35  private $sink;
36 
40  public function __construct( $sink ) {
41  if ( !is_resource( $sink ) || get_resource_type( $sink ) !== 'stream' ) {
42  throw new InvalidArgumentException( '$sink must be a file handle' );
43  }
44 
45  $this->sink = $sink;
46  }
47 
54  public function exportSites( $sites ) {
55  $attributes = [
56  'version' => '1.0',
57  'xmlns' => 'http://www.mediawiki.org/xml/sitelist-1.0/',
58  ];
59 
60  fwrite( $this->sink, Xml::openElement( 'sites', $attributes ) . "\n" );
61 
62  foreach ( $sites as $site ) {
63  $this->exportSite( $site );
64  }
65 
66  fwrite( $this->sink, Xml::closeElement( 'sites' ) . "\n" );
67  fflush( $this->sink );
68  }
69 
75  private function exportSite( Site $site ) {
76  if ( $site->getType() !== Site::TYPE_UNKNOWN ) {
77  $siteAttr = [ 'type' => $site->getType() ];
78  } else {
79  $siteAttr = null;
80  }
81 
82  fwrite( $this->sink, "\t" . Xml::openElement( 'site', $siteAttr ) . "\n" );
83 
84  fwrite( $this->sink, "\t\t" . Xml::element( 'globalid', null, $site->getGlobalId() ) . "\n" );
85 
86  if ( $site->getGroup() !== Site::GROUP_NONE ) {
87  fwrite( $this->sink, "\t\t" . Xml::element( 'group', null, $site->getGroup() ) . "\n" );
88  }
89 
90  if ( $site->getSource() !== Site::SOURCE_LOCAL ) {
91  fwrite( $this->sink, "\t\t" . Xml::element( 'source', null, $site->getSource() ) . "\n" );
92  }
93 
94  if ( $site->shouldForward() ) {
95  fwrite( $this->sink, "\t\t" . Xml::element( 'forward', null, '' ) . "\n" );
96  }
97 
98  foreach ( $site->getAllPaths() as $type => $path ) {
99  fwrite( $this->sink, "\t\t" . Xml::element( 'path', [ 'type' => $type ], $path ) . "\n" );
100  }
101 
102  foreach ( $site->getLocalIds() as $type => $ids ) {
103  foreach ( $ids as $id ) {
104  fwrite( $this->sink, "\t\t" . Xml::element( 'localid', [ 'type' => $type ], $id ) . "\n" );
105  }
106  }
107 
108  // @todo: export <data>
109  // @todo: export <config>
110 
111  fwrite( $this->sink, "\t" . Xml::closeElement( 'site' ) . "\n" );
112  }
113 
114 }
Site\getType
getType()
Returns the type of the site (ie mediawiki).
Definition: Site.php:168
SiteExporter\__construct
__construct( $sink)
Definition: SiteExporter.php:40
Xml\openElement
static openElement( $element, $attribs=null)
This opens an XML element.
Definition: Xml.php:109
php
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
Site\TYPE_UNKNOWN
const TYPE_UNKNOWN
Definition: Site.php:30
Site\getGlobalId
getGlobalId()
Returns the global site identifier (ie enwiktionary).
Definition: Site.php:140
Site\getSource
getSource()
Returns the source of the site data (ie 'local', 'wikidata', 'my-magical-repo').
Definition: Site.php:207
Xml\element
static element( $element, $attribs=null, $contents='', $allowShortTag=true)
Format an XML element with given attributes and, optionally, text content.
Definition: Xml.php:39
Site\getGroup
getGroup()
Gets the group of the site (ie wikipedia).
Definition: Site.php:179
SiteExporter\exportSite
exportSite(Site $site)
Writes a <site> tag representing the given Site object.
Definition: SiteExporter.php:75
Site
Definition: Site.php:29
SiteExporter\exportSites
exportSites( $sites)
Writes a <site> tag for each Site object in $sites, and encloses the entire list between <sites> tags...
Definition: SiteExporter.php:54
Site\getAllPaths
getAllPaths()
Returns the paths as associative array.
Definition: Site.php:620
SiteExporter
Definition: SiteExporter.php:30
Xml\closeElement
static closeElement( $element)
Shortcut to close an XML element.
Definition: Xml.php:118
$path
$path
Definition: NoLocalSettings.php:26
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
Site\shouldForward
shouldForward()
Gets if site.tld/path/key:pageTitle should forward users to the page on the actual site,...
Definition: Site.php:236
Site\GROUP_NONE
const GROUP_NONE
Definition: Site.php:33
Site\SOURCE_LOCAL
const SOURCE_LOCAL
Definition: Site.php:38
SiteExporter\$sink
resource $sink
Definition: SiteExporter.php:35
Site\getLocalIds
getLocalIds()
Returns all local ids.
Definition: Site.php:571
$type
$type
Definition: testCompression.php:48