X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FExport.php;h=35a1b5b51e58822ddfc53883a6f240eb72a0cac1;hb=8441c854aaadca54bc9a5c8d728ff80dcf3745cc;hp=3dcd3baeb5f1420d9b07940d12a69dcb55bdaf45;hpb=669e5b9318af2906214834db4904b3c57693229f;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Export.php b/includes/Export.php index 3dcd3baeb5..35a1b5b51e 100644 --- a/includes/Export.php +++ b/includes/Export.php @@ -56,7 +56,7 @@ class WikiExporter { * make additional queries to pull source data while the * main query is still running. * - * @param $db Database + * @param $db DatabaseBase * @param $history Mixed: one of WikiExporter::FULL, WikiExporter::CURRENT, * WikiExporter::RANGE or WikiExporter::STABLE, * or an associative array: @@ -380,7 +380,7 @@ class XmlDumpWriter { * @return string */ function schemaVersion() { - return "0.5"; + return "0.6"; } /** @@ -476,11 +476,23 @@ class XmlDumpWriter { function openPage( $row ) { $out = " \n"; $title = Title::makeTitle( $row->page_namespace, $row->page_title ); - $out .= ' ' . Xml::elementClean( 'title', array(), $title->getPrefixedText() ) . "\n"; + $out .= ' ' . Xml::elementClean( 'title', array(), self::canonicalTitle( $title ) ) . "\n"; + $out .= ' ' . Xml::element( 'ns', array(), strval( $row->page_namespace) ) . "\n"; $out .= ' ' . Xml::element( 'id', array(), strval( $row->page_id ) ) . "\n"; if ( $row->page_is_redirect ) { - $out .= ' ' . Xml::element( 'redirect', array() ) . "\n"; + $page = WikiPage::factory( $title ); + $redirect = $page->getRedirectTarget(); + if ( $redirect instanceOf Title && $redirect->isValidRedirectTarget() ) { + $out .= ' ' . Xml::element( 'redirect', array( 'title' => self::canonicalTitle( $redirect ) ) ) . "\n"; + } + } + + if ( $row->rev_sha1 ) { + $out .= " " . Xml::element('sha1', null, strval( $row->rev_sha1 ) ) . "\n"; + } else { + $out .= " \n"; } + if ( $row->page_restrictions != '' ) { $out .= ' ' . Xml::element( 'restrictions', array(), strval( $row->page_restrictions ) ) . "\n"; @@ -495,6 +507,7 @@ class XmlDumpWriter { * Closes a section on the output stream. * * @access private + * @return string */ function closePage() { return " \n"; @@ -538,12 +551,12 @@ class XmlDumpWriter { // Raw text from the database may have invalid chars $text = strval( Revision::getRevisionText( $row ) ); $out .= " " . Xml::elementClean( 'text', - array( 'xml:space' => 'preserve', 'bytes' => $row->rev_len ), + array( 'xml:space' => 'preserve', 'bytes' => intval( $row->rev_len ) ), strval( $text ) ) . "\n"; } else { // Stub output $out .= " " . Xml::element( 'text', - array( 'id' => $row->rev_text_id, 'bytes' => $row->rev_len ), + array( 'id' => $row->rev_text_id, 'bytes' => intval( $row->rev_len ) ), "" ) . "\n"; } @@ -590,7 +603,7 @@ class XmlDumpWriter { $out .= " " . Xml::element( 'text', array( 'deleted' => 'deleted' ) ) . "\n"; } else { $title = Title::makeTitle( $row->log_namespace, $row->log_title ); - $out .= " " . Xml::elementClean( 'logtitle', null, $title->getPrefixedText() ) . "\n"; + $out .= " " . Xml::elementClean( 'logtitle', null, self::canonicalTitle( $title ) ) . "\n"; $out .= " " . Xml::elementClean( 'params', array( 'xml:space' => 'preserve' ), strval( $row->log_params ) ) . "\n"; @@ -609,7 +622,7 @@ class XmlDumpWriter { function writeContributor( $id, $text ) { $out = " \n"; - if ( $id ) { + if ( $id || !IP::isValid( $text ) ) { $out .= " " . Xml::elementClean( 'username', null, strval( $text ) ) . "\n"; $out .= " " . Xml::element( 'id', null, strval( $id ) ) . "\n"; } else { @@ -621,6 +634,7 @@ class XmlDumpWriter { /** * Warning! This data is potentially inconsistent. :( + * @return string */ function writeUploads( $row, $dumpContents = false ) { if ( $row->page_namespace == NS_IMAGE ) { @@ -672,6 +686,30 @@ class XmlDumpWriter { " \n"; } + /** + * Return prefixed text form of title, but using the content language's + * canonical namespace. This skips any special-casing such as gendered + * user namespaces -- which while useful, are not yet listed in the + * XML data so are unsafe in export. + * + * @param Title $title + * @return string + * @since 1.18 + */ + public static function canonicalTitle( Title $title ) { + if ( $title->getInterwiki() ) { + return $title->getPrefixedText(); + } + + global $wgContLang; + $prefix = str_replace( '_', ' ', $wgContLang->getNsText( $title->getNamespace() ) ); + + if ( $prefix !== '' ) { + $prefix .= ':'; + } + + return $prefix . $title->getText(); + } } @@ -737,6 +775,7 @@ class DumpOutput { /** * Returns the name of the file or files which are * being written to, if there are any. + * @return null */ function getFilenames() { return NULL; @@ -763,7 +802,13 @@ class DumpFileOutput extends DumpOutput { $this->closeAndRename( $newname, true ); } - function closeAndRename( $newname, $open = false ) { + function renameOrException( $newname ) { + if (! rename( $this->filename, $newname ) ) { + throw new MWException( __METHOD__ . ": rename of file {$this->filename} to $newname failed\n" ); + } + } + + function checkRenameArgCount( $newname ) { if ( is_array( $newname ) ) { if ( count( $newname ) > 1 ) { throw new MWException( __METHOD__ . ": passed multiple arguments for rename of single file\n" ); @@ -771,12 +816,15 @@ class DumpFileOutput extends DumpOutput { $newname = $newname[0]; } } + return $newname; + } + + function closeAndRename( $newname, $open = false ) { + $newname = $this->checkRenameArgCount( $newname ); if ( $newname ) { fclose( $this->handle ); - if (! rename( $this->filename, $newname ) ) { - throw new MWException( __METHOD__ . ": rename of file {$this->filename} to $newname failed\n" ); - } - elseif ( $open ) { + $this->renameOrException( $newname ); + if ( $open ) { $this->handle = fopen( $this->filename, "wt" ); } } @@ -820,20 +868,12 @@ class DumpPipeOutput extends DumpFileOutput { } function closeAndRename( $newname, $open = false ) { - if ( is_array( $newname ) ) { - if ( count( $newname ) > 1 ) { - throw new MWException( __METHOD__ . ": passed multiple arguments for rename of single file\n" ); - } else { - $newname = $newname[0]; - } - } + $newname = $this->checkRenameArgCount( $newname ); if ( $newname ) { fclose( $this->handle ); proc_close( $this->procOpenResource ); - if (! rename( $this->filename, $newname ) ) { - throw new MWException( __METHOD__ . ": rename of file {$this->filename} to $newname failed\n" ); - } - elseif ( $open ) { + $this->renameOrException( $newname ); + if ( $open ) { $command = $this->command; $command .= " > " . wfEscapeShellArg( $this->filename ); $this->startCommand( $command ); @@ -868,37 +908,28 @@ class DumpBZip2Output extends DumpPipeOutput { * @ingroup Dump */ class Dump7ZipOutput extends DumpPipeOutput { - protected $filename; - function __construct( $file ) { - $command = setup7zCommand( $file ); + $command = $this->setup7zCommand( $file ); parent::__construct( $command ); $this->filename = $file; } - function closeRenameAndReopen( $newname ) { - $this->closeAndRename( $newname, true ); + function setup7zCommand( $file ) { + $command = "7za a -bd -si " . wfEscapeShellArg( $file ); + // Suppress annoying useless crap from p7zip + // Unfortunately this could suppress real error messages too + $command .= ' >' . wfGetNull() . ' 2>&1'; + return( $command ); } function closeAndRename( $newname, $open = false ) { - if ( is_array( $newname ) ) { - if ( count( $newname ) > 1 ) { - throw new MWException( __METHOD__ . ": passed multiple arguments for rename of single file\n" ); - } else { - $newname = $newname[0]; - } - } + $newname = $this->checkRenameArgCount( $newname ); if ( $newname ) { fclose( $this->handle ); proc_close( $this->procOpenResource ); - if (! rename( $this->filename, $newname ) ) { - throw new MWException( __METHOD__ . ": rename of file {$this->filename} to $newname failed\n" ); - } - elseif ( $open ) { - $command = "7za a -bd -si " . wfEscapeShellArg( $file ); - // Suppress annoying useless crap from p7zip - // Unfortunately this could suppress real error messages too - $command .= ' >' . wfGetNull() . ' 2>&1'; + $this->renameOrException( $newname ); + if ( $open ) { + $command = $this->setup7zCommand( $this->filename ); $this->startCommand( $command ); } }