export.php
来自「php 开发的内容管理系统」· PHP 代码 · 共 737 行 · 第 1/2 页
PHP
737 行
/** * Closes a <page> section on the output stream. * * @access private */ function closePage() { return " </page>\n"; } /** * Dumps a <revision> section on the output stream, with * data filled in from the given database row. * * @param object $row * @return string * @access private */ function writeRevision( $row ) { $fname = 'WikiExporter::dumpRev'; wfProfileIn( $fname ); $out = " <revision>\n"; $out .= " " . wfElement( 'id', null, strval( $row->rev_id ) ) . "\n"; $ts = wfTimestamp( TS_ISO_8601, $row->rev_timestamp ); $out .= " " . wfElement( 'timestamp', null, $ts ) . "\n"; if( $row->rev_deleted & Revision::DELETED_USER ) { $out .= " " . wfElement( 'contributor', array( 'deleted' => 'deleted' ) ) . "\n"; } else { $out .= " <contributor>\n"; if( $row->rev_user ) { $out .= " " . wfElementClean( 'username', null, strval( $row->rev_user_text ) ) . "\n"; $out .= " " . wfElement( 'id', null, strval( $row->rev_user ) ) . "\n"; } else { $out .= " " . wfElementClean( 'ip', null, strval( $row->rev_user_text ) ) . "\n"; } $out .= " </contributor>\n"; } if( $row->rev_minor_edit ) { $out .= " <minor/>\n"; } if( $row->rev_deleted & Revision::DELETED_COMMENT ) { $out .= " " . wfElement( 'comment', array( 'deleted' => 'deleted' ) ) . "\n"; } elseif( $row->rev_comment != '' ) { $out .= " " . wfElementClean( 'comment', null, strval( $row->rev_comment ) ) . "\n"; } if( $row->rev_deleted & Revision::DELETED_TEXT ) { $out .= " " . wfElement( 'text', array( 'deleted' => 'deleted' ) ) . "\n"; } elseif( isset( $row->old_text ) ) { // Raw text from the database may have invalid chars $text = strval( Revision::getRevisionText( $row ) ); $out .= " " . wfElementClean( 'text', array( 'xml:space' => 'preserve' ), strval( $text ) ) . "\n"; } else { // Stub output $out .= " " . wfElement( 'text', array( 'id' => $row->rev_text_id ), "" ) . "\n"; } $out .= " </revision>\n"; wfProfileOut( $fname ); return $out; }}/** * Base class for output stream; prints to stdout or buffer or whereever. */class DumpOutput { function writeOpenStream( $string ) { $this->write( $string ); } function writeCloseStream( $string ) { $this->write( $string ); } function writeOpenPage( $page, $string ) { $this->write( $string ); } function writeClosePage( $string ) { $this->write( $string ); } function writeRevision( $rev, $string ) { $this->write( $string ); } /** * Override to write to a different stream type. * @return bool */ function write( $string ) { print $string; }}/** * Stream outputter to send data to a file. */class DumpFileOutput extends DumpOutput { var $handle; function DumpFileOutput( $file ) { $this->handle = fopen( $file, "wt" ); } function write( $string ) { fputs( $this->handle, $string ); }}/** * Stream outputter to send data to a file via some filter program. * Even if compression is available in a library, using a separate * program can allow us to make use of a multi-processor system. */class DumpPipeOutput extends DumpFileOutput { function DumpPipeOutput( $command, $file = null ) { if( !is_null( $file ) ) { $command .= " > " . wfEscapeShellArg( $file ); } $this->handle = popen( $command, "w" ); }}/** * Sends dump output via the gzip compressor. */class DumpGZipOutput extends DumpPipeOutput { function DumpGZipOutput( $file ) { parent::DumpPipeOutput( "gzip", $file ); }}/** * Sends dump output via the bgzip2 compressor. */class DumpBZip2Output extends DumpPipeOutput { function DumpBZip2Output( $file ) { parent::DumpPipeOutput( "bzip2", $file ); }}/** * Sends dump output via the p7zip compressor. */class Dump7ZipOutput extends DumpPipeOutput { function Dump7ZipOutput( $file ) { $command = "7za a -bd -si " . wfEscapeShellArg( $file ); // Suppress annoying useless crap from p7zip // Unfortunately this could suppress real error messages too $command .= " >/dev/null 2>&1"; parent::DumpPipeOutput( $command ); }}/** * Dump output filter class. * This just does output filtering and streaming; XML formatting is done * higher up, so be careful in what you do. */class DumpFilter { function DumpFilter( &$sink ) { $this->sink =& $sink; } function writeOpenStream( $string ) { $this->sink->writeOpenStream( $string ); } function writeCloseStream( $string ) { $this->sink->writeCloseStream( $string ); } function writeOpenPage( $page, $string ) { $this->sendingThisPage = $this->pass( $page, $string ); if( $this->sendingThisPage ) { $this->sink->writeOpenPage( $page, $string ); } } function writeClosePage( $string ) { if( $this->sendingThisPage ) { $this->sink->writeClosePage( $string ); $this->sendingThisPage = false; } } function writeRevision( $rev, $string ) { if( $this->sendingThisPage ) { $this->sink->writeRevision( $rev, $string ); } } /** * Override for page-based filter types. * @return bool */ function pass( $page, $string ) { return true; }}/** * Simple dump output filter to exclude all talk pages. */class DumpNotalkFilter extends DumpFilter { function pass( $page ) { return !Namespace::isTalk( $page->page_namespace ); }}/** * Dump output filter to include or exclude pages in a given set of namespaces. */class DumpNamespaceFilter extends DumpFilter { var $invert = false; var $namespaces = array(); function DumpNamespaceFilter( &$sink, $param ) { parent::DumpFilter( $sink ); $constants = array( "NS_MAIN" => NS_MAIN, "NS_TALK" => NS_TALK, "NS_USER" => NS_USER, "NS_USER_TALK" => NS_USER_TALK, "NS_PROJECT" => NS_PROJECT, "NS_PROJECT_TALK" => NS_PROJECT_TALK, "NS_IMAGE" => NS_IMAGE, "NS_IMAGE_TALK" => NS_IMAGE_TALK, "NS_MEDIAWIKI" => NS_MEDIAWIKI, "NS_MEDIAWIKI_TALK" => NS_MEDIAWIKI_TALK, "NS_TEMPLATE" => NS_TEMPLATE, "NS_TEMPLATE_TALK" => NS_TEMPLATE_TALK, "NS_HELP" => NS_HELP, "NS_HELP_TALK" => NS_HELP_TALK, "NS_CATEGORY" => NS_CATEGORY, "NS_CATEGORY_TALK" => NS_CATEGORY_TALK ); if( $param{0} == '!' ) { $this->invert = true; $param = substr( $param, 1 ); } foreach( explode( ',', $param ) as $key ) { $key = trim( $key ); if( isset( $constants[$key] ) ) { $ns = $constants[$key]; $this->namespaces[$ns] = true; } elseif( is_numeric( $key ) ) { $ns = intval( $key ); $this->namespaces[$ns] = true; } else { throw new MWException( "Unrecognized namespace key '$key'\n" ); } } } function pass( $page ) { $match = isset( $this->namespaces[$page->page_namespace] ); return $this->invert xor $match; }}/** * Dump output filter to include only the last revision in each page sequence. */class DumpLatestFilter extends DumpFilter { var $page, $pageString, $rev, $revString; function writeOpenPage( $page, $string ) { $this->page = $page; $this->pageString = $string; } function writeClosePage( $string ) { if( $this->rev ) { $this->sink->writeOpenPage( $this->page, $this->pageString ); $this->sink->writeRevision( $this->rev, $this->revString ); $this->sink->writeClosePage( $string ); } $this->rev = null; $this->revString = null; $this->page = null; $this->pageString = null; } function writeRevision( $rev, $string ) { if( $rev->rev_id == $this->page->page_latest ) { $this->rev = $rev; $this->revString = $string; } }}/** * Base class for output stream; prints to stdout or buffer or whereever. */class DumpMultiWriter { function DumpMultiWriter( $sinks ) { $this->sinks = $sinks; $this->count = count( $sinks ); } function writeOpenStream( $string ) { for( $i = 0; $i < $this->count; $i++ ) { $this->sinks[$i]->writeOpenStream( $string ); } } function writeCloseStream( $string ) { for( $i = 0; $i < $this->count; $i++ ) { $this->sinks[$i]->writeCloseStream( $string ); } } function writeOpenPage( $page, $string ) { for( $i = 0; $i < $this->count; $i++ ) { $this->sinks[$i]->writeOpenPage( $page, $string ); } } function writeClosePage( $string ) { for( $i = 0; $i < $this->count; $i++ ) { $this->sinks[$i]->writeClosePage( $string ); } } function writeRevision( $rev, $string ) { for( $i = 0; $i < $this->count; $i++ ) { $this->sinks[$i]->writeRevision( $rev, $string ); } }}function xmlsafe( $string ) { $fname = 'xmlsafe'; wfProfileIn( $fname ); /** * The page may contain old data which has not been properly normalized. * Invalid UTF-8 sequences or forbidden control characters will make our * XML output invalid, so be sure to strip them out. */ $string = UtfNormal::cleanUp( $string ); $string = htmlspecialchars( $string ); wfProfileOut( $fname ); return $string;}?>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?