42 if ( !is_resource( $sink ) || get_resource_type( $sink ) !==
'stream' ) {
43 throw new InvalidArgumentException(
'$sink must be a file handle' );
58 'xmlns' =>
'http://www.mediawiki.org/xml/sitelist-1.0/',
63 foreach ( $sites as $site ) {
64 $this->exportSite( $site );
68 fflush( $this->sink );
76 private function exportSite(
Site $site ) {
78 $siteAttr = [
'type' => $site->
getType() ];
96 fwrite( $this->sink,
"\t\t" .
Xml::element(
'forward',
null,
'' ) .
"\n" );
100 fwrite( $this->sink,
"\t\t" .
Xml::element(
'path', [
'type' => $type ],
$path ) .
"\n" );
103 foreach ( $site->
getLocalIds() as $type => $ids ) {
104 foreach ( $ids as $id ) {
105 fwrite( $this->sink,
"\t\t" .
Xml::element(
'localid', [
'type' => $type ], $id ) .
"\n" );
Utility for exporting site entries to XML.
exportSites( $sites)
Writes a <site> tag for each Site object in $sites, and encloses the entire list between <sites> tags...
Represents a single site.
shouldForward()
Gets if site.tld/path/key:pageTitle should forward users to the page on the actual site,...
getSource()
Returns the source of the site data (ie 'local', 'wikidata', 'my-magical-repo').
getType()
Returns the type of the site (ie mediawiki).
getGlobalId()
Returns the global site identifier (ie enwiktionary).
getAllPaths()
Returns the paths as associative array.
getLocalIds()
Returns all local ids.
getGroup()
Gets the group of the site (ie wikipedia).
static closeElement( $element)
Shortcut to close an XML element.
static openElement( $element, $attribs=null)
This opens an XML element.
static element( $element, $attribs=null, $contents='', $allowShortTag=true)
Format an XML element with given attributes and, optionally, text content.