Param documentation

Explicitly define member variables

Change-Id: I028bcfd40cf7a402b040694ad7dacaab8da45e45
This commit is contained in:
Reedy 2012-04-28 23:47:23 +01:00
parent 801ede3a9b
commit ab6e54e084

View file

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