sink = $sink; } /** * Writes a tag for each Site object in $sites, and encloses the entire list * between tags. * * @param Site[]|SiteList $sites */ public function exportSites( $sites ) { $attributes = array( 'version' => '1.0', 'xmlns' => 'http://www.mediawiki.org/xml/sitelist-1.0/', ); fwrite( $this->sink, Xml::openElement( 'sites', $attributes ) . "\n" ); foreach ( $sites as $site ) { $this->exportSite( $site ); } fwrite( $this->sink, Xml::closeElement( 'sites' ) . "\n" ); fflush( $this->sink ); } /** * Writes a tag representing the given Site object. * * @param Site $site */ private function exportSite( Site $site ) { if ( $site->getType() !== Site::TYPE_UNKNOWN ) { $siteAttr = array( 'type' => $site->getType() ); } else { $siteAttr = null; } fwrite( $this->sink, "\t" . Xml::openElement( 'site', $siteAttr ) . "\n" ); fwrite( $this->sink, "\t\t" . Xml::element( 'globalid', null, $site->getGlobalId() ) . "\n" ); if ( $site->getGroup() !== Site::GROUP_NONE ) { fwrite( $this->sink, "\t\t" . Xml::element( 'group', null, $site->getGroup() ) . "\n" ); } if ( $site->getSource() !== Site::SOURCE_LOCAL ) { fwrite( $this->sink, "\t\t" . Xml::element( 'source', null, $site->getSource() ) . "\n" ); } if ( $site->shouldForward() ) { fwrite( $this->sink, "\t\t" . Xml::element( 'forward', null, '' ) . "\n" ); } foreach ( $site->getAllPaths() as $type => $path ) { fwrite( $this->sink, "\t\t" . Xml::element( 'path', array( 'type' => $type ), $path ) . "\n" ); } foreach ( $site->getLocalIds() as $type => $ids ) { foreach ( $ids as $id ) { fwrite( $this->sink, "\t\t" . Xml::element( 'localid', array( 'type' => $type ), $id ) . "\n" ); } } //@todo: export //@todo: export fwrite( $this->sink, "\t" . Xml::closeElement( 'site' ) . "\n" ); } }