23use InvalidArgumentException;
47 if ( !is_resource( $sink ) || get_resource_type( $sink ) !==
'stream' ) {
48 throw new InvalidArgumentException(
'$sink must be a file handle' );
63 'xmlns' =>
'http://www.mediawiki.org/xml/sitelist-1.0/',
66 fwrite( $this->sink, Xml::openElement(
'sites', $attributes ) .
"\n" );
68 foreach ( $sites as $site ) {
69 $this->exportSite( $site );
72 fwrite( $this->sink, Xml::closeElement(
'sites' ) .
"\n" );
73 fflush( $this->sink );
81 private function exportSite(
Site $site ) {
83 $siteAttr = [
'type' => $site->
getType() ];
88 fwrite( $this->sink,
"\t" . Xml::openElement(
'site', $siteAttr ) .
"\n" );
90 fwrite( $this->sink,
"\t\t" . Xml::element(
'globalid',
null, $site->
getGlobalId() ) .
"\n" );
93 fwrite( $this->sink,
"\t\t" . Xml::element(
'group',
null, $site->
getGroup() ) .
"\n" );
97 fwrite( $this->sink,
"\t\t" . Xml::element(
'source',
null, $site->
getSource() ) .
"\n" );
101 fwrite( $this->sink,
"\t\t" . Xml::element(
'forward',
null,
'' ) .
"\n" );
105 fwrite( $this->sink,
"\t\t" . Xml::element(
'path', [
'type' => $type ],
$path ) .
"\n" );
108 foreach ( $site->
getLocalIds() as $type => $ids ) {
109 foreach ( $ids as $id ) {
110 fwrite( $this->sink,
"\t\t" . Xml::element(
'localid', [
'type' => $type ], $id ) .
"\n" );
117 fwrite( $this->sink,
"\t" . Xml::closeElement(
'site' ) .
"\n" );
123class_alias( SiteExporter::class,
'SiteExporter' );
Module of static functions for generating XML.