Param documentation
Explicitly define member variables Change-Id: I028bcfd40cf7a402b040694ad7dacaab8da45e45
This commit is contained in:
parent
801ede3a9b
commit
ab6e54e084
1 changed files with 258 additions and 6 deletions
|
|
@ -49,6 +49,15 @@ class WikiExporter {
|
|||
const TEXT = 0;
|
||||
const STUB = 1;
|
||||
|
||||
var $buffer;
|
||||
|
||||
var $text;
|
||||
|
||||
/**
|
||||
* @var DumpOutput
|
||||
*/
|
||||
var $sink;
|
||||
|
||||
/**
|
||||
* If using WikiExporter::STREAM to stream a large amount of data,
|
||||
* provide a database connection which is not managed by
|
||||
|
|
@ -145,6 +154,10 @@ class WikiExporter {
|
|||
' AND page_title=' . $this->db->addQuotes( $title->getDBkey() ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name string
|
||||
* @throws MWException
|
||||
*/
|
||||
public function pageByName( $name ) {
|
||||
$title = Title::newFromText( $name );
|
||||
if ( is_null( $title ) ) {
|
||||
|
|
@ -154,6 +167,9 @@ class WikiExporter {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $names array
|
||||
*/
|
||||
public function pagesByName( $names ) {
|
||||
foreach ( $names as $name ) {
|
||||
$this->pageByName( $name );
|
||||
|
|
@ -164,6 +180,10 @@ class WikiExporter {
|
|||
$this->dumpFrom( '' );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $start int
|
||||
* @param $end int
|
||||
*/
|
||||
public function logsByRange( $start, $end ) {
|
||||
$condition = 'log_id >= ' . intval( $start );
|
||||
if ( $end ) {
|
||||
|
|
@ -172,9 +192,13 @@ class WikiExporter {
|
|||
$this->dumpFrom( $condition );
|
||||
}
|
||||
|
||||
# Generates the distinct list of authors of an article
|
||||
# Not called by default (depends on $this->list_authors)
|
||||
# Can be set by Special:Export when not exporting whole history
|
||||
/**
|
||||
* Generates the distinct list of authors of an article
|
||||
* Not called by default (depends on $this->list_authors)
|
||||
* Can be set by Special:Export when not exporting whole history
|
||||
*
|
||||
* @param $cond
|
||||
*/
|
||||
protected function do_list_authors( $cond ) {
|
||||
wfProfileIn( __METHOD__ );
|
||||
$this->author_list = "<contributors>";
|
||||
|
|
@ -205,6 +229,11 @@ class WikiExporter {
|
|||
wfProfileOut( __METHOD__ );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $cond string
|
||||
* @throws MWException
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function dumpFrom( $cond = '' ) {
|
||||
wfProfileIn( __METHOD__ );
|
||||
# For logging dumps...
|
||||
|
|
@ -419,6 +448,9 @@ class WikiExporter {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $resultset array
|
||||
*/
|
||||
protected function outputLogStream( $resultset ) {
|
||||
foreach ( $resultset as $row ) {
|
||||
$output = $this->writer->writeLogItem( $row );
|
||||
|
|
@ -464,6 +496,9 @@ class XmlDumpWriter {
|
|||
$this->siteInfo();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
function siteInfo() {
|
||||
$info = array(
|
||||
$this->sitename(),
|
||||
|
|
@ -476,20 +511,32 @@ class XmlDumpWriter {
|
|||
"\n </siteinfo>\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
function sitename() {
|
||||
global $wgSitename;
|
||||
return Xml::element( 'sitename', array(), $wgSitename );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
function generator() {
|
||||
global $wgVersion;
|
||||
return Xml::element( 'generator', array(), "MediaWiki $wgVersion" );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
function homelink() {
|
||||
return Xml::element( 'base', array(), Title::newMainPage()->getCanonicalUrl() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
function caseSetting() {
|
||||
global $wgCapitalLinks;
|
||||
// "case-insensitive" option is reserved for future
|
||||
|
|
@ -497,6 +544,9 @@ class XmlDumpWriter {
|
|||
return Xml::element( 'case', array(), $sensitivity );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
function namespaces() {
|
||||
global $wgContLang;
|
||||
$spaces = "<namespaces>\n";
|
||||
|
|
@ -591,7 +641,7 @@ class XmlDumpWriter {
|
|||
if ( $row->rev_deleted & Revision::DELETED_COMMENT ) {
|
||||
$out .= " " . Xml::element( 'comment', array( 'deleted' => 'deleted' ) ) . "\n";
|
||||
} elseif ( $row->rev_comment != '' ) {
|
||||
$out .= " " . Xml::elementClean( 'comment', null, strval( $row->rev_comment ) ) . "\n";
|
||||
$out .= " " . Xml::elementClean( 'comment', array(), strval( $row->rev_comment ) ) . "\n";
|
||||
}
|
||||
|
||||
$text = '';
|
||||
|
|
@ -671,11 +721,20 @@ class XmlDumpWriter {
|
|||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $timestamp string
|
||||
* @return string
|
||||
*/
|
||||
function writeTimestamp( $timestamp ) {
|
||||
$ts = wfTimestamp( TS_ISO_8601, $timestamp );
|
||||
return " " . Xml::element( 'timestamp', null, $ts ) . "\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @param $text string
|
||||
* @return string
|
||||
*/
|
||||
function writeContributor( $id, $text ) {
|
||||
$out = " <contributor>\n";
|
||||
if ( $id || !IP::isValid( $text ) ) {
|
||||
|
|
@ -690,6 +749,8 @@ class XmlDumpWriter {
|
|||
|
||||
/**
|
||||
* Warning! This data is potentially inconsistent. :(
|
||||
* @param $row
|
||||
* @param $dumpContents bool
|
||||
* @return string
|
||||
*/
|
||||
function writeUploads( $row, $dumpContents = false ) {
|
||||
|
|
@ -774,32 +835,55 @@ class XmlDumpWriter {
|
|||
* @ingroup Dump
|
||||
*/
|
||||
class DumpOutput {
|
||||
|
||||
/**
|
||||
* @param $string string
|
||||
*/
|
||||
function writeOpenStream( $string ) {
|
||||
$this->write( $string );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $string string
|
||||
*/
|
||||
function writeCloseStream( $string ) {
|
||||
$this->write( $string );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $page
|
||||
* @param $string string
|
||||
*/
|
||||
function writeOpenPage( $page, $string ) {
|
||||
$this->write( $string );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $string string
|
||||
*/
|
||||
function writeClosePage( $string ) {
|
||||
$this->write( $string );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $rev
|
||||
* @param $string string
|
||||
*/
|
||||
function writeRevision( $rev, $string ) {
|
||||
$this->write( $string );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $rev
|
||||
* @param $string string
|
||||
*/
|
||||
function writeLogItem( $rev, $string ) {
|
||||
$this->write( $string );
|
||||
}
|
||||
|
||||
/**
|
||||
* Override to write to a different stream type.
|
||||
* @param $string string
|
||||
* @return bool
|
||||
*/
|
||||
function write( $string ) {
|
||||
|
|
@ -845,11 +929,17 @@ class DumpOutput {
|
|||
class DumpFileOutput extends DumpOutput {
|
||||
protected $handle = false, $filename;
|
||||
|
||||
/**
|
||||
* @param $file
|
||||
*/
|
||||
function __construct( $file ) {
|
||||
$this->handle = fopen( $file, "wt" );
|
||||
$this->filename = $file;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $string string
|
||||
*/
|
||||
function writeCloseStream( $string ) {
|
||||
parent::writeCloseStream( $string );
|
||||
if ( $this->handle ) {
|
||||
|
|
@ -858,20 +948,35 @@ class DumpFileOutput extends DumpOutput {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $string string
|
||||
*/
|
||||
function write( $string ) {
|
||||
fputs( $this->handle, $string );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $newname
|
||||
*/
|
||||
function closeRenameAndReopen( $newname ) {
|
||||
$this->closeAndRename( $newname, true );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $newname
|
||||
* @throws MWException
|
||||
*/
|
||||
function renameOrException( $newname ) {
|
||||
if (! rename( $this->filename, $newname ) ) {
|
||||
throw new MWException( __METHOD__ . ": rename of file {$this->filename} to $newname failed\n" );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $newname array
|
||||
* @return mixed
|
||||
* @throws MWException
|
||||
*/
|
||||
function checkRenameArgCount( $newname ) {
|
||||
if ( is_array( $newname ) ) {
|
||||
if ( count( $newname ) > 1 ) {
|
||||
|
|
@ -883,6 +988,10 @@ class DumpFileOutput extends DumpOutput {
|
|||
return $newname;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $newname mixed
|
||||
* @param $open bool
|
||||
*/
|
||||
function closeAndRename( $newname, $open = false ) {
|
||||
$newname = $this->checkRenameArgCount( $newname );
|
||||
if ( $newname ) {
|
||||
|
|
@ -897,6 +1006,9 @@ class DumpFileOutput extends DumpOutput {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
function getFilenames() {
|
||||
return $this->filename;
|
||||
}
|
||||
|
|
@ -912,6 +1024,10 @@ class DumpPipeOutput extends DumpFileOutput {
|
|||
protected $command, $filename;
|
||||
protected $procOpenResource = false;
|
||||
|
||||
/**
|
||||
* @param $command
|
||||
* @param $file null
|
||||
*/
|
||||
function __construct( $command, $file = null ) {
|
||||
if ( !is_null( $file ) ) {
|
||||
$command .= " > " . wfEscapeShellArg( $file );
|
||||
|
|
@ -922,6 +1038,9 @@ class DumpPipeOutput extends DumpFileOutput {
|
|||
$this->filename = $file;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $string string
|
||||
*/
|
||||
function writeCloseStream( $string ) {
|
||||
parent::writeCloseStream( $string );
|
||||
if ( $this->procOpenResource ) {
|
||||
|
|
@ -930,6 +1049,9 @@ class DumpPipeOutput extends DumpFileOutput {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $command
|
||||
*/
|
||||
function startCommand( $command ) {
|
||||
$spec = array(
|
||||
0 => array( "pipe", "r" ),
|
||||
|
|
@ -939,10 +1061,17 @@ class DumpPipeOutput extends DumpFileOutput {
|
|||
$this->handle = $pipes[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $newname
|
||||
*/
|
||||
function closeRenameAndReopen( $newname ) {
|
||||
$this->closeAndRename( $newname, true );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $newname mixed
|
||||
* @param $open bool
|
||||
*/
|
||||
function closeAndRename( $newname, $open = false ) {
|
||||
$newname = $this->checkRenameArgCount( $newname );
|
||||
if ( $newname ) {
|
||||
|
|
@ -970,6 +1099,10 @@ class DumpPipeOutput extends DumpFileOutput {
|
|||
* @ingroup Dump
|
||||
*/
|
||||
class DumpGZipOutput extends DumpPipeOutput {
|
||||
|
||||
/**
|
||||
* @param $file string
|
||||
*/
|
||||
function __construct( $file ) {
|
||||
parent::__construct( "gzip", $file );
|
||||
}
|
||||
|
|
@ -980,6 +1113,10 @@ class DumpGZipOutput extends DumpPipeOutput {
|
|||
* @ingroup Dump
|
||||
*/
|
||||
class DumpBZip2Output extends DumpPipeOutput {
|
||||
|
||||
/**
|
||||
* @param $file string
|
||||
*/
|
||||
function __construct( $file ) {
|
||||
parent::__construct( "bzip2", $file );
|
||||
}
|
||||
|
|
@ -990,12 +1127,20 @@ class DumpBZip2Output extends DumpPipeOutput {
|
|||
* @ingroup Dump
|
||||
*/
|
||||
class Dump7ZipOutput extends DumpPipeOutput {
|
||||
|
||||
/**
|
||||
* @param $file string
|
||||
*/
|
||||
function __construct( $file ) {
|
||||
$command = $this->setup7zCommand( $file );
|
||||
parent::__construct( $command );
|
||||
$this->filename = $file;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $file string
|
||||
* @return string
|
||||
*/
|
||||
function setup7zCommand( $file ) {
|
||||
$command = "7za a -bd -si " . wfEscapeShellArg( $file );
|
||||
// Suppress annoying useless crap from p7zip
|
||||
|
|
@ -1004,6 +1149,10 @@ class Dump7ZipOutput extends DumpPipeOutput {
|
|||
return( $command );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $newname string
|
||||
* @param $open bool
|
||||
*/
|
||||
function closeAndRename( $newname, $open = false ) {
|
||||
$newname = $this->checkRenameArgCount( $newname );
|
||||
if ( $newname ) {
|
||||
|
|
@ -1018,8 +1167,6 @@ class Dump7ZipOutput extends DumpPipeOutput {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Dump output filter class.
|
||||
* This just does output filtering and streaming; XML formatting is done
|
||||
|
|
@ -1027,18 +1174,42 @@ class Dump7ZipOutput extends DumpPipeOutput {
|
|||
* @ingroup Dump
|
||||
*/
|
||||
class DumpFilter {
|
||||
|
||||
/**
|
||||
* @var DumpOutput
|
||||
*/
|
||||
protected $sink;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $sendingThisPage;
|
||||
|
||||
/**
|
||||
* @param $sink DumpOutput
|
||||
*/
|
||||
function __construct( &$sink ) {
|
||||
$this->sink =& $sink;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $string string
|
||||
*/
|
||||
function writeOpenStream( $string ) {
|
||||
$this->sink->writeOpenStream( $string );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $string string
|
||||
*/
|
||||
function writeCloseStream( $string ) {
|
||||
$this->sink->writeCloseStream( $string );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $page
|
||||
* @param $string string
|
||||
*/
|
||||
function writeOpenPage( $page, $string ) {
|
||||
$this->sendingThisPage = $this->pass( $page, $string );
|
||||
if ( $this->sendingThisPage ) {
|
||||
|
|
@ -1046,6 +1217,9 @@ class DumpFilter {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $string string
|
||||
*/
|
||||
function writeClosePage( $string ) {
|
||||
if ( $this->sendingThisPage ) {
|
||||
$this->sink->writeClosePage( $string );
|
||||
|
|
@ -1053,30 +1227,49 @@ class DumpFilter {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $rev
|
||||
* @param $string string
|
||||
*/
|
||||
function writeRevision( $rev, $string ) {
|
||||
if ( $this->sendingThisPage ) {
|
||||
$this->sink->writeRevision( $rev, $string );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $rev
|
||||
* @param $string string
|
||||
*/
|
||||
function writeLogItem( $rev, $string ) {
|
||||
$this->sink->writeRevision( $rev, $string );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $newname string
|
||||
*/
|
||||
function closeRenameAndReopen( $newname ) {
|
||||
$this->sink->closeRenameAndReopen( $newname );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $newname string
|
||||
* @param $open bool
|
||||
*/
|
||||
function closeAndRename( $newname, $open = false ) {
|
||||
$this->sink->closeAndRename( $newname, $open );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
function getFilenames() {
|
||||
return $this->sink->getFilenames();
|
||||
}
|
||||
|
||||
/**
|
||||
* Override for page-based filter types.
|
||||
* @param $page
|
||||
* @return bool
|
||||
*/
|
||||
function pass( $page ) {
|
||||
|
|
@ -1089,6 +1282,11 @@ class DumpFilter {
|
|||
* @ingroup Dump
|
||||
*/
|
||||
class DumpNotalkFilter extends DumpFilter {
|
||||
|
||||
/**
|
||||
* @param $page
|
||||
* @return bool
|
||||
*/
|
||||
function pass( $page ) {
|
||||
return !MWNamespace::isTalk( $page->page_namespace );
|
||||
}
|
||||
|
|
@ -1102,6 +1300,10 @@ class DumpNamespaceFilter extends DumpFilter {
|
|||
var $invert = false;
|
||||
var $namespaces = array();
|
||||
|
||||
/**
|
||||
* @param $sink DumpOutput
|
||||
* @param $param
|
||||
*/
|
||||
function __construct( &$sink, $param ) {
|
||||
parent::__construct( $sink );
|
||||
|
||||
|
|
@ -1144,6 +1346,10 @@ class DumpNamespaceFilter extends DumpFilter {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $page
|
||||
* @return bool
|
||||
*/
|
||||
function pass( $page ) {
|
||||
$match = isset( $this->namespaces[$page->page_namespace] );
|
||||
return $this->invert xor $match;
|
||||
|
|
@ -1158,11 +1364,18 @@ class DumpNamespaceFilter extends DumpFilter {
|
|||
class DumpLatestFilter extends DumpFilter {
|
||||
var $page, $pageString, $rev, $revString;
|
||||
|
||||
/**
|
||||
* @param $page
|
||||
* @param $string string
|
||||
*/
|
||||
function writeOpenPage( $page, $string ) {
|
||||
$this->page = $page;
|
||||
$this->pageString = $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $string string
|
||||
*/
|
||||
function writeClosePage( $string ) {
|
||||
if ( $this->rev ) {
|
||||
$this->sink->writeOpenPage( $this->page, $this->pageString );
|
||||
|
|
@ -1175,6 +1388,10 @@ class DumpLatestFilter extends DumpFilter {
|
|||
$this->pageString = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $rev
|
||||
* @param $string string
|
||||
*/
|
||||
function writeRevision( $rev, $string ) {
|
||||
if ( $rev->rev_id == $this->page->page_latest ) {
|
||||
$this->rev = $rev;
|
||||
|
|
@ -1188,51 +1405,82 @@ class DumpLatestFilter extends DumpFilter {
|
|||
* @ingroup Dump
|
||||
*/
|
||||
class DumpMultiWriter {
|
||||
|
||||
/**
|
||||
* @param $sinks
|
||||
*/
|
||||
function __construct( $sinks ) {
|
||||
$this->sinks = $sinks;
|
||||
$this->count = count( $sinks );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $string string
|
||||
*/
|
||||
function writeOpenStream( $string ) {
|
||||
for ( $i = 0; $i < $this->count; $i++ ) {
|
||||
$this->sinks[$i]->writeOpenStream( $string );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $string string
|
||||
*/
|
||||
function writeCloseStream( $string ) {
|
||||
for ( $i = 0; $i < $this->count; $i++ ) {
|
||||
$this->sinks[$i]->writeCloseStream( $string );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $page
|
||||
* @param $string string
|
||||
*/
|
||||
function writeOpenPage( $page, $string ) {
|
||||
for ( $i = 0; $i < $this->count; $i++ ) {
|
||||
$this->sinks[$i]->writeOpenPage( $page, $string );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $string
|
||||
*/
|
||||
function writeClosePage( $string ) {
|
||||
for ( $i = 0; $i < $this->count; $i++ ) {
|
||||
$this->sinks[$i]->writeClosePage( $string );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $rev
|
||||
* @param $string
|
||||
*/
|
||||
function writeRevision( $rev, $string ) {
|
||||
for ( $i = 0; $i < $this->count; $i++ ) {
|
||||
$this->sinks[$i]->writeRevision( $rev, $string );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $newnames
|
||||
*/
|
||||
function closeRenameAndReopen( $newnames ) {
|
||||
$this->closeAndRename( $newnames, true );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $newnames array
|
||||
* @param bool $open
|
||||
*/
|
||||
function closeAndRename( $newnames, $open = false ) {
|
||||
for ( $i = 0; $i < $this->count; $i++ ) {
|
||||
$this->sinks[$i]->closeAndRename( $newnames[$i], $open );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
function getFilenames() {
|
||||
$filenames = array();
|
||||
for ( $i = 0; $i < $this->count; $i++ ) {
|
||||
|
|
@ -1243,6 +1491,10 @@ class DumpMultiWriter {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $string string
|
||||
* @return string
|
||||
*/
|
||||
function xmlsafe( $string ) {
|
||||
wfProfileIn( __FUNCTION__ );
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue