Merge "Document that IContextSource::getTitle can return null"
[lhc/web/wiklou.git] / includes / Export.php
index 56fe452..7295a76 100644 (file)
@@ -73,15 +73,14 @@ class WikiExporter {
         * make additional queries to pull source data while the
         * main query is still running.
         *
-        * @param $db DatabaseBase
-        * @param $history Mixed: one of WikiExporter::FULL, WikiExporter::CURRENT,
-        *                 WikiExporter::RANGE or WikiExporter::STABLE,
-        *                 or an associative array:
-        *                   offset: non-inclusive offset at which to start the query
-        *                   limit: maximum number of rows to return
-        *                   dir: "asc" or "desc" timestamp order
-        * @param int $buffer one of WikiExporter::BUFFER or WikiExporter::STREAM
-        * @param int $text one of WikiExporter::TEXT or WikiExporter::STUB
+        * @param DatabaseBase $db
+        * @param int|array $history One of WikiExporter::FULL, WikiExporter::CURRENT,
+        *   WikiExporter::RANGE or WikiExporter::STABLE, or an associative array:
+        *   - offset: non-inclusive offset at which to start the query
+        *   - limit: maximum number of rows to return
+        *   - dir: "asc" or "desc" timestamp order
+        * @param int $buffer One of WikiExporter::BUFFER or WikiExporter::STREAM
+        * @param int $text One of WikiExporter::TEXT or WikiExporter::STUB
         */
        function __construct( $db, $history = WikiExporter::CURRENT,
                        $buffer = WikiExporter::BUFFER, $text = WikiExporter::TEXT ) {
@@ -98,7 +97,7 @@ class WikiExporter {
         * various row objects and XML output for filtering. Filters
         * can be chained or used as callbacks.
         *
-        * @param $sink mixed
+        * @param DumpOutput $sink
         */
        public function setOutputSink( &$sink ) {
                $this->sink =& $sink;
@@ -126,9 +125,9 @@ class WikiExporter {
        /**
         * Dumps a series of page and revision records for those pages
         * in the database falling within the page_id range given.
-        * @param int $start inclusive lower limit (this id is included)
-        * @param $end   Int: Exclusive upper limit (this id is not included)
-        *                   If 0, no upper limit.
+        * @param int $start Inclusive lower limit (this id is included)
+        * @param int $end Exclusive upper limit (this id is not included)
+        *   If 0, no upper limit.
         */
        public function pagesByRange( $start, $end ) {
                $condition = 'page_id >= ' . intval( $start );
@@ -141,9 +140,9 @@ class WikiExporter {
        /**
         * Dumps a series of page and revision records for those pages
         * in the database with revisions falling within the rev_id range given.
-        * @param int $start inclusive lower limit (this id is included)
-        * @param $end   Int: Exclusive upper limit (this id is not included)
-        *                   If 0, no upper limit.
+        * @param int $start Inclusive lower limit (this id is included)
+        * @param int $end Exclusive upper limit (this id is not included)
+        *   If 0, no upper limit.
         */
        public function revsByRange( $start, $end ) {
                $condition = 'rev_id >= ' . intval( $start );
@@ -154,7 +153,7 @@ class WikiExporter {
        }
 
        /**
-        * @param $title Title
+        * @param Title $title
         */
        public function pageByTitle( $title ) {
                $this->dumpFrom(
@@ -163,7 +162,7 @@ class WikiExporter {
        }
 
        /**
-        * @param $name string
+        * @param string $name
         * @throws MWException
         */
        public function pageByName( $name ) {
@@ -176,7 +175,7 @@ class WikiExporter {
        }
 
        /**
-        * @param $names array
+        * @param array $names
         */
        public function pagesByName( $names ) {
                foreach ( $names as $name ) {
@@ -189,8 +188,8 @@ class WikiExporter {
        }
 
        /**
-        * @param $start int
-        * @param $end int
+        * @param int $start
+        * @param int $end
         */
        public function logsByRange( $start, $end ) {
                $condition = 'log_id >= ' . intval( $start );
@@ -205,7 +204,7 @@ class WikiExporter {
         * Not called by default (depends on $this->list_authors)
         * Can be set by Special:Export when not exporting whole history
         *
-        * @param $cond
+        * @param array $cond
         */
        protected function do_list_authors( $cond ) {
                wfProfileIn( __METHOD__ );
@@ -238,7 +237,7 @@ class WikiExporter {
        }
 
        /**
-        * @param $cond string
+        * @param string $cond
         * @throws MWException
         * @throws Exception
         */
@@ -427,7 +426,7 @@ class WikiExporter {
         * separate database connection not managed by LoadBalancer; some
         * blob storage types will make queries to pull source data.
         *
-        * @param $resultset ResultWrapper
+        * @param ResultWrapper $resultset
         */
        protected function outputPageStream( $resultset ) {
                $last = null;
@@ -462,7 +461,7 @@ class WikiExporter {
        }
 
        /**
-        * @param $resultset array
+        * @param array $resultset
         */
        protected function outputLogStream( $resultset ) {
                foreach ( $resultset as $row ) {
@@ -478,7 +477,7 @@ class WikiExporter {
 class XmlDumpWriter {
        /**
         * Returns the export schema version.
-        * @deprecated in 1.20; use WikiExporter::schemaVersion() instead
+        * @deprecated since 1.20; use WikiExporter::schemaVersion() instead
         * @return string
         */
        function schemaVersion() {
@@ -592,11 +591,10 @@ class XmlDumpWriter {
         * Opens a "<page>" section on the output stream, with data
         * from the given database row.
         *
-        * @param $row object
+        * @param object $row
         * @return string
-        * @access private
         */
-       function openPage( $row ) {
+       public function openPage( $row ) {
                $out = "  <page>\n";
                $title = Title::makeTitle( $row->page_namespace, $row->page_title );
                $out .= '    ' . Xml::elementClean( 'title', array(), self::canonicalTitle( $title ) ) . "\n";
@@ -606,7 +604,9 @@ class XmlDumpWriter {
                        $page = WikiPage::factory( $title );
                        $redirect = $page->getRedirectTarget();
                        if ( $redirect instanceof Title && $redirect->isValidRedirectTarget() ) {
-                               $out .= '    ' . Xml::element( 'redirect', array( 'title' => self::canonicalTitle( $redirect ) ) ) . "\n";
+                               $out .= '    ';
+                               $out .= Xml::element( 'redirect', array( 'title' => self::canonicalTitle( $redirect ) ) );
+                               $out .= "\n";
                        }
                }
 
@@ -634,7 +634,7 @@ class XmlDumpWriter {
         * Dumps a "<revision>" section on the output stream, with
         * data filled in from the given database row.
         *
-        * @param $row object
+        * @param object $row
         * @return string
         * @access private
         */
@@ -680,7 +680,10 @@ class XmlDumpWriter {
                                "" ) . "\n";
                }
 
-               if ( isset( $row->rev_sha1 ) && $row->rev_sha1 && !( $row->rev_deleted & Revision::DELETED_TEXT ) ) {
+               if ( isset( $row->rev_sha1 )
+                       && $row->rev_sha1
+                       && !( $row->rev_deleted & Revision::DELETED_TEXT )
+               ) {
                        $out .= "      " . Xml::element( 'sha1', null, strval( $row->rev_sha1 ) ) . "\n";
                } else {
                        $out .= "      <sha1/>\n";
@@ -720,7 +723,7 @@ class XmlDumpWriter {
         * Dumps a "<logitem>" section on the output stream, with
         * data filled in from the given database row.
         *
-        * @param $row object
+        * @param object $row
         * @return string
         * @access private
         */
@@ -764,7 +767,7 @@ class XmlDumpWriter {
        }
 
        /**
-        * @param $timestamp string
+        * @param string $timestamp
         * @param string $indent Default to six spaces
         * @return string
         */
@@ -774,8 +777,8 @@ class XmlDumpWriter {
        }
 
        /**
-        * @param $id
-        * @param $text string
+        * @param int $id
+        * @param string $text
         * @param string $indent Default to six spaces
         * @return string
         */
@@ -793,8 +796,8 @@ class XmlDumpWriter {
 
        /**
         * Warning! This data is potentially inconsistent. :(
-        * @param $row
-        * @param $dumpContents bool
+        * @param object $row
+        * @param bool $dumpContents
         * @return string
         */
        function writeUploads( $row, $dumpContents = false ) {
@@ -813,8 +816,8 @@ class XmlDumpWriter {
        }
 
        /**
-        * @param $file File
-        * @param $dumpContents bool
+        * @param File $file
+        * @param bool $dumpContents
         * @return string
         */
        function writeUpload( $file, $dumpContents = false ) {
@@ -828,7 +831,7 @@ class XmlDumpWriter {
                        $be = $file->getRepo()->getBackend();
                        # Dump file as base64
                        # Uses only XML-safe characters, so does not need escaping
-                       # @TODO: too bad this loads the contents into memory (script might swap)
+                       # @todo Too bad this loads the contents into memory (script might swap)
                        $contents = '      <contents encoding="base64">' .
                                chunk_split( base64_encode(
                                        $be->getFileContents( array( 'src' => $file->getPath() ) ) ) ) .
@@ -888,45 +891,45 @@ class XmlDumpWriter {
 class DumpOutput {
 
        /**
-        * @param $string string
+        * @param string $string
         */
        function writeOpenStream( $string ) {
                $this->write( $string );
        }
 
        /**
-        * @param $string string
+        * @param string $string
         */
        function writeCloseStream( $string ) {
                $this->write( $string );
        }
 
        /**
-        * @param $page
-        * @param $string string
+        * @param object $page
+        * @param string $string
         */
        function writeOpenPage( $page, $string ) {
                $this->write( $string );
        }
 
        /**
-        * @param $string string
+        * @param string $string
         */
        function writeClosePage( $string ) {
                $this->write( $string );
        }
 
        /**
-        * @param $rev
-        * @param $string string
+        * @param object $rev
+        * @param string $string
         */
        function writeRevision( $rev, $string ) {
                $this->write( $string );
        }
 
        /**
-        * @param $rev
-        * @param $string string
+        * @param object $rev
+        * @param string $string
         */
        function writeLogItem( $rev, $string ) {
                $this->write( $string );
@@ -934,7 +937,7 @@ class DumpOutput {
 
        /**
         * Override to write to a different stream type.
-        * @param $string string
+        * @param string $string
         * @return bool
         */
        function write( $string ) {
@@ -946,7 +949,7 @@ class DumpOutput {
         * and reopen new file with the old name. Use this
         * for writing out a file in multiple pieces
         * at specified checkpoints (e.g. every n hours).
-        * @param $newname mixed File name. May be a string or an array with one element
+        * @param string|array $newname File name. May be a string or an array with one element
         */
        function closeRenameAndReopen( $newname ) {
        }
@@ -955,8 +958,9 @@ class DumpOutput {
         * Close the old file, and move it to a specified name.
         * Use this for the last piece of a file written out
         * at specified checkpoints (e.g. every n hours).
-        * @param $newname mixed File name. May be a string or an array with one element
-        * @param bool $open If true, a new file with the old filename will be opened again for writing (default: false)
+        * @param string|array $newname File name. May be a string or an array with one element
+        * @param bool $open If true, a new file with the old filename will be opened
+        *   again for writing (default: false)
         */
        function closeAndRename( $newname, $open = false ) {
        }
@@ -979,7 +983,7 @@ class DumpFileOutput extends DumpOutput {
        protected $handle = false, $filename;
 
        /**
-        * @param $file
+        * @param string $file
         */
        function __construct( $file ) {
                $this->handle = fopen( $file, "wt" );
@@ -987,7 +991,7 @@ class DumpFileOutput extends DumpOutput {
        }
 
        /**
-        * @param $string string
+        * @param string $string
         */
        function writeCloseStream( $string ) {
                parent::writeCloseStream( $string );
@@ -998,21 +1002,21 @@ class DumpFileOutput extends DumpOutput {
        }
 
        /**
-        * @param $string string
+        * @param string $string
         */
        function write( $string ) {
                fputs( $this->handle, $string );
        }
 
        /**
-        * @param $newname
+        * @param string $newname
         */
        function closeRenameAndReopen( $newname ) {
                $this->closeAndRename( $newname, true );
        }
 
        /**
-        * @param $newname
+        * @param string $newname
         * @throws MWException
         */
        function renameOrException( $newname ) {
@@ -1022,8 +1026,8 @@ class DumpFileOutput extends DumpOutput {
        }
 
        /**
-        * @param $newname array
-        * @return mixed
+        * @param array $newname
+        * @return string
         * @throws MWException
         */
        function checkRenameArgCount( $newname ) {
@@ -1038,8 +1042,8 @@ class DumpFileOutput extends DumpOutput {
        }
 
        /**
-        * @param $newname mixed
-        * @param $open bool
+        * @param string $newname
+        * @param bool $open
         */
        function closeAndRename( $newname, $open = false ) {
                $newname = $this->checkRenameArgCount( $newname );
@@ -1074,8 +1078,8 @@ class DumpPipeOutput extends DumpFileOutput {
        protected $procOpenResource = false;
 
        /**
-        * @param $command
-        * @param $file null
+        * @param string $command
+        * @param string $file
         */
        function __construct( $command, $file = null ) {
                if ( !is_null( $file ) ) {
@@ -1088,7 +1092,7 @@ class DumpPipeOutput extends DumpFileOutput {
        }
 
        /**
-        * @param $string string
+        * @param string $string
         */
        function writeCloseStream( $string ) {
                parent::writeCloseStream( $string );
@@ -1099,7 +1103,7 @@ class DumpPipeOutput extends DumpFileOutput {
        }
 
        /**
-        * @param $command
+        * @param string $command
         */
        function startCommand( $command ) {
                $spec = array(
@@ -1111,15 +1115,15 @@ class DumpPipeOutput extends DumpFileOutput {
        }
 
        /**
-        * @param mixed $newname
+        * @param string $newname
         */
        function closeRenameAndReopen( $newname ) {
                $this->closeAndRename( $newname, true );
        }
 
        /**
-        * @param $newname mixed
-        * @param $open bool
+        * @param string $newname
+        * @param bool $open
         */
        function closeAndRename( $newname, $open = false ) {
                $newname = $this->checkRenameArgCount( $newname );
@@ -1150,7 +1154,7 @@ class DumpPipeOutput extends DumpFileOutput {
 class DumpGZipOutput extends DumpPipeOutput {
 
        /**
-        * @param $file string
+        * @param string $file
         */
        function __construct( $file ) {
                parent::__construct( "gzip", $file );
@@ -1164,7 +1168,7 @@ class DumpGZipOutput extends DumpPipeOutput {
 class DumpBZip2Output extends DumpPipeOutput {
 
        /**
-        * @param $file string
+        * @param string $file
         */
        function __construct( $file ) {
                parent::__construct( "bzip2", $file );
@@ -1178,7 +1182,7 @@ class DumpBZip2Output extends DumpPipeOutput {
 class Dump7ZipOutput extends DumpPipeOutput {
 
        /**
-        * @param $file string
+        * @param string $file
         */
        function __construct( $file ) {
                $command = $this->setup7zCommand( $file );
@@ -1187,7 +1191,7 @@ class Dump7ZipOutput extends DumpPipeOutput {
        }
 
        /**
-        * @param $file string
+        * @param string $file
         * @return string
         */
        function setup7zCommand( $file ) {
@@ -1199,8 +1203,8 @@ class Dump7ZipOutput extends DumpPipeOutput {
        }
 
        /**
-        * @param $newname string
-        * @param $open bool
+        * @param string $newname
+        * @param bool $open
         */
        function closeAndRename( $newname, $open = false ) {
                $newname = $this->checkRenameArgCount( $newname );
@@ -1237,29 +1241,29 @@ class DumpFilter {
        protected $sendingThisPage;
 
        /**
-        * @param $sink DumpOutput
+        * @param DumpOutput $sink
         */
        function __construct( &$sink ) {
                $this->sink =& $sink;
        }
 
        /**
-        * @param $string string
+        * @param string $string
         */
        function writeOpenStream( $string ) {
                $this->sink->writeOpenStream( $string );
        }
 
        /**
-        * @param $string string
+        * @param string $string
         */
        function writeCloseStream( $string ) {
                $this->sink->writeCloseStream( $string );
        }
 
        /**
-        * @param $page
-        * @param $string string
+        * @param object $page
+        * @param string $string
         */
        function writeOpenPage( $page, $string ) {
                $this->sendingThisPage = $this->pass( $page, $string );
@@ -1269,7 +1273,7 @@ class DumpFilter {
        }
 
        /**
-        * @param $string string
+        * @param string $string
         */
        function writeClosePage( $string ) {
                if ( $this->sendingThisPage ) {
@@ -1279,8 +1283,8 @@ class DumpFilter {
        }
 
        /**
-        * @param $rev
-        * @param $string string
+        * @param object $rev
+        * @param string $string
         */
        function writeRevision( $rev, $string ) {
                if ( $this->sendingThisPage ) {
@@ -1289,23 +1293,23 @@ class DumpFilter {
        }
 
        /**
-        * @param $rev
-        * @param $string string
+        * @param object $rev
+        * @param string $string
         */
        function writeLogItem( $rev, $string ) {
                $this->sink->writeRevision( $rev, $string );
        }
 
        /**
-        * @param $newname string
+        * @param string $newname
         */
        function closeRenameAndReopen( $newname ) {
                $this->sink->closeRenameAndReopen( $newname );
        }
 
        /**
-        * @param $newname string
-        * @param $open bool
+        * @param string $newname
+        * @param bool $open
         */
        function closeAndRename( $newname, $open = false ) {
                $this->sink->closeAndRename( $newname, $open );
@@ -1320,7 +1324,7 @@ class DumpFilter {
 
        /**
         * Override for page-based filter types.
-        * @param $page
+        * @param object $page
         * @return bool
         */
        function pass( $page ) {
@@ -1335,7 +1339,7 @@ class DumpFilter {
 class DumpNotalkFilter extends DumpFilter {
 
        /**
-        * @param $page
+        * @param object $page
         * @return bool
         */
        function pass( $page ) {
@@ -1352,8 +1356,8 @@ class DumpNamespaceFilter extends DumpFilter {
        var $namespaces = array();
 
        /**
-        * @param $sink DumpOutput
-        * @param $param
+        * @param DumpOutput $sink
+        * @param array $param
         * @throws MWException
         */
        function __construct( &$sink, $param ) {
@@ -1399,7 +1403,7 @@ class DumpNamespaceFilter extends DumpFilter {
        }
 
        /**
-        * @param $page
+        * @param object $page
         * @return bool
         */
        function pass( $page ) {
@@ -1416,8 +1420,8 @@ class DumpLatestFilter extends DumpFilter {
        var $page, $pageString, $rev, $revString;
 
        /**
-        * @param $page
-        * @param $string string
+        * @param object $page
+        * @param string $string
         */
        function writeOpenPage( $page, $string ) {
                $this->page = $page;
@@ -1425,7 +1429,7 @@ class DumpLatestFilter extends DumpFilter {
        }
 
        /**
-        * @param $string string
+        * @param string $string
         */
        function writeClosePage( $string ) {
                if ( $this->rev ) {
@@ -1440,8 +1444,8 @@ class DumpLatestFilter extends DumpFilter {
        }
 
        /**
-        * @param $rev
-        * @param $string string
+        * @param object $rev
+        * @param string $string
         */
        function writeRevision( $rev, $string ) {
                if ( $rev->rev_id == $this->page->page_latest ) {
@@ -1458,7 +1462,7 @@ class DumpLatestFilter extends DumpFilter {
 class DumpMultiWriter {
 
        /**
-        * @param $sinks
+        * @param array $sinks
         */
        function __construct( $sinks ) {
                $this->sinks = $sinks;
@@ -1466,7 +1470,7 @@ class DumpMultiWriter {
        }
 
        /**
-        * @param $string string
+        * @param string $string
         */
        function writeOpenStream( $string ) {
                for ( $i = 0; $i < $this->count; $i++ ) {
@@ -1475,7 +1479,7 @@ class DumpMultiWriter {
        }
 
        /**
-        * @param $string string
+        * @param string $string
         */
        function writeCloseStream( $string ) {
                for ( $i = 0; $i < $this->count; $i++ ) {
@@ -1484,8 +1488,8 @@ class DumpMultiWriter {
        }
 
        /**
-        * @param $page
-        * @param $string string
+        * @param object $page
+        * @param string $string
         */
        function writeOpenPage( $page, $string ) {
                for ( $i = 0; $i < $this->count; $i++ ) {
@@ -1494,7 +1498,7 @@ class DumpMultiWriter {
        }
 
        /**
-        * @param $string
+        * @param string $string
         */
        function writeClosePage( $string ) {
                for ( $i = 0; $i < $this->count; $i++ ) {
@@ -1503,8 +1507,8 @@ class DumpMultiWriter {
        }
 
        /**
-        * @param $rev
-        * @param $string
+        * @param object $rev
+        * @param string $string
         */
        function writeRevision( $rev, $string ) {
                for ( $i = 0; $i < $this->count; $i++ ) {
@@ -1513,14 +1517,14 @@ class DumpMultiWriter {
        }
 
        /**
-        * @param $newnames
+        * @param array $newnames
         */
        function closeRenameAndReopen( $newnames ) {
                $this->closeAndRename( $newnames, true );
        }
 
        /**
-        * @param $newnames array
+        * @param array $newnames
         * @param bool $open
         */
        function closeAndRename( $newnames, $open = false ) {
@@ -1543,7 +1547,7 @@ class DumpMultiWriter {
 }
 
 /**
- * @param $string string
+ * @param string $string
  * @return string
  */
 function xmlsafe( $string ) {