Merge "Split classes in Import.php into separate files"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Wed, 30 Dec 2015 00:16:39 +0000 (00:16 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Wed, 30 Dec 2015 00:16:39 +0000 (00:16 +0000)
41 files changed:
autoload.php
includes/DefaultSettings.php
includes/Export.php [deleted file]
includes/api/ApiMain.php
includes/changes/ChangesList.php
includes/changes/EnhancedChangesList.php
includes/changes/OldChangesList.php
includes/db/DBConnRef.php
includes/db/Database.php
includes/db/IDatabase.php
includes/export/Dump7ZipOutput.php [new file with mode: 0644]
includes/export/DumpBZip2Output.php [new file with mode: 0644]
includes/export/DumpFileOutput.php [new file with mode: 0644]
includes/export/DumpFilter.php [new file with mode: 0644]
includes/export/DumpGZipOutput.php [new file with mode: 0644]
includes/export/DumpLatestFilter.php [new file with mode: 0644]
includes/export/DumpMultiWriter.php [new file with mode: 0644]
includes/export/DumpNamespaceFilter.php [new file with mode: 0644]
includes/export/DumpNotalkFilter.php [new file with mode: 0644]
includes/export/DumpOutput.php [new file with mode: 0644]
includes/export/DumpPipeOutput.php [new file with mode: 0644]
includes/export/WikiExporter.php [new file with mode: 0644]
includes/export/XmlDumpWriter.php [new file with mode: 0644]
includes/specialpage/QueryPage.php
includes/specials/SpecialBlock.php
includes/specials/SpecialContributions.php
includes/specials/SpecialDeletedContributions.php
includes/specials/SpecialEmailuser.php
includes/specials/SpecialFileDuplicateSearch.php
includes/specials/SpecialListfiles.php
includes/specials/SpecialMediaStatistics.php
includes/specials/SpecialPreferences.php
includes/specials/SpecialUnblock.php
includes/specials/SpecialUserrights.php
includes/templates/EnhancedChangesListGroup.mustache [new file with mode: 0644]
includes/user/UserNamePrefixSearch.php [new file with mode: 0644]
languages/i18n/en.json
languages/i18n/qqq.json
maintenance/benchmarks/Benchmarker.php
resources/src/mediawiki.less/mediawiki.ui/variables.less
tests/parser/parserTests.txt

index 75466f5..ac38fa5 100644 (file)
@@ -352,21 +352,21 @@ $wgAutoloadLocalClasses = array(
        'DoubleReplacer' => __DIR__ . '/includes/libs/replacers/DoubleReplacer.php',
        'DummyLinker' => __DIR__ . '/includes/Linker.php',
        'DummyTermColorer' => __DIR__ . '/maintenance/term/MWTerm.php',
-       'Dump7ZipOutput' => __DIR__ . '/includes/Export.php',
-       'DumpBZip2Output' => __DIR__ . '/includes/Export.php',
+       'Dump7ZipOutput' => __DIR__ . '/includes/export/Dump7ZipOutput.php',
+       'DumpBZip2Output' => __DIR__ . '/includes/export/DumpBZip2Output.php',
        'DumpDBZip2Output' => __DIR__ . '/maintenance/backup.inc',
-       'DumpFileOutput' => __DIR__ . '/includes/Export.php',
-       'DumpFilter' => __DIR__ . '/includes/Export.php',
-       'DumpGZipOutput' => __DIR__ . '/includes/Export.php',
+       'DumpFileOutput' => __DIR__ . '/includes/export/DumpFileOutput.php',
+       'DumpFilter' => __DIR__ . '/includes/export/DumpFilter.php',
+       'DumpGZipOutput' => __DIR__ . '/includes/export/DumpGZipOutput.php',
        'DumpIterator' => __DIR__ . '/maintenance/dumpIterator.php',
-       'DumpLatestFilter' => __DIR__ . '/includes/Export.php',
+       'DumpLatestFilter' => __DIR__ . '/includes/export/DumpLatestFilter.php',
        'DumpLinks' => __DIR__ . '/maintenance/dumpLinks.php',
        'DumpMessages' => __DIR__ . '/maintenance/language/dumpMessages.php',
-       'DumpMultiWriter' => __DIR__ . '/includes/Export.php',
-       'DumpNamespaceFilter' => __DIR__ . '/includes/Export.php',
-       'DumpNotalkFilter' => __DIR__ . '/includes/Export.php',
-       'DumpOutput' => __DIR__ . '/includes/Export.php',
-       'DumpPipeOutput' => __DIR__ . '/includes/Export.php',
+       'DumpMultiWriter' => __DIR__ . '/includes/export/DumpMultiWriter.php',
+       'DumpNamespaceFilter' => __DIR__ . '/includes/export/DumpNamespaceFilter.php',
+       'DumpNotalkFilter' => __DIR__ . '/includes/export/DumpNotalkFilter.php',
+       'DumpOutput' => __DIR__ . '/includes/export/DumpOutput.php',
+       'DumpPipeOutput' => __DIR__ . '/includes/export/DumpPipeOutput.php',
        'DumpRenderer' => __DIR__ . '/maintenance/renderDump.php',
        'DumpRev' => __DIR__ . '/maintenance/storage/dumpRev.php',
        'DuplicateJob' => __DIR__ . '/includes/jobqueue/jobs/DuplicateJob.php',
@@ -1336,6 +1336,7 @@ $wgAutoloadLocalClasses = array(
        'UserCache' => __DIR__ . '/includes/cache/UserCache.php',
        'UserDupes' => __DIR__ . '/maintenance/userDupes.inc',
        'UserMailer' => __DIR__ . '/includes/mail/UserMailer.php',
+       'UserNamePrefixSearch' => __DIR__ . '/includes/user/UserNamePrefixSearch.php',
        'UserNotLoggedIn' => __DIR__ . '/includes/exception/UserNotLoggedIn.php',
        'UserOptions' => __DIR__ . '/maintenance/userOptions.inc',
        'UserPasswordPolicy' => __DIR__ . '/includes/password/UserPasswordPolicy.php',
@@ -1386,7 +1387,7 @@ $wgAutoloadLocalClasses = array(
        'WebResponse' => __DIR__ . '/includes/WebResponse.php',
        'WikiCategoryPage' => __DIR__ . '/includes/page/WikiCategoryPage.php',
        'WikiDiff3' => __DIR__ . '/includes/diff/WikiDiff3.php',
-       'WikiExporter' => __DIR__ . '/includes/Export.php',
+       'WikiExporter' => __DIR__ . '/includes/export/WikiExporter.php',
        'WikiFilePage' => __DIR__ . '/includes/page/WikiFilePage.php',
        'WikiImporter' => __DIR__ . '/includes/import/WikiImporter.php',
        'WikiMap' => __DIR__ . '/includes/WikiMap.php',
@@ -1408,7 +1409,7 @@ $wgAutoloadLocalClasses = array(
        'XMPValidate' => __DIR__ . '/includes/media/XMPValidate.php',
        'Xhprof' => __DIR__ . '/includes/libs/Xhprof.php',
        'Xml' => __DIR__ . '/includes/Xml.php',
-       'XmlDumpWriter' => __DIR__ . '/includes/Export.php',
+       'XmlDumpWriter' => __DIR__ . '/includes/export/XmlDumpWriter.php',
        'XmlJsCode' => __DIR__ . '/includes/Xml.php',
        'XmlSelect' => __DIR__ . '/includes/XmlSelect.php',
        'XmlTypeCheck' => __DIR__ . '/includes/libs/XmlTypeCheck.php',
index 0d4ecac..a6d34b0 100644 (file)
@@ -5556,6 +5556,11 @@ $wgTrxProfilerLimits = array(
                'writeQueryTime' => 1,
                'maxAffected' => 500
        ),
+       'POST-nonwrite' => array(
+               'masterConns' => 0,
+               'writes' => 0,
+               'readQueryTime' => 5
+       ),
        // Background job runner
        'JobRunner' => array(
                'readQueryTime' => 30,
diff --git a/includes/Export.php b/includes/Export.php
deleted file mode 100644 (file)
index b4d7737..0000000
+++ /dev/null
@@ -1,1549 +0,0 @@
-<?php
-/**
- * Base classes for dumps and export
- *
- * Copyright © 2003, 2005, 2006 Brion Vibber <brion@pobox.com>
- * https://www.mediawiki.org/
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- * http://www.gnu.org/copyleft/gpl.html
- *
- * @file
- */
-
-/**
- * @defgroup Dump Dump
- */
-
-/**
- * @ingroup SpecialPage Dump
- */
-class WikiExporter {
-       /** @var bool Return distinct author list (when not returning full history) */
-       public $list_authors = false;
-
-       /** @var bool */
-       public $dumpUploads = false;
-
-       /** @var bool */
-       public $dumpUploadFileContents = false;
-
-       /** @var string */
-       public $author_list = "";
-
-       const FULL = 1;
-       const CURRENT = 2;
-       const STABLE = 4; // extension defined
-       const LOGS = 8;
-       const RANGE = 16;
-
-       const BUFFER = 0;
-       const STREAM = 1;
-
-       const TEXT = 0;
-       const STUB = 1;
-
-       /** @var int */
-       public $buffer;
-
-       /** @var int */
-       public $text;
-
-       /** @var DumpOutput */
-       public $sink;
-
-       /**
-        * Returns the export schema version.
-        * @return string
-        */
-       public static function schemaVersion() {
-               return "0.10";
-       }
-
-       /**
-        * If using WikiExporter::STREAM to stream a large amount of data,
-        * provide a database connection which is not managed by
-        * LoadBalancer to read from: some history blob types will
-        * make additional queries to pull source data while the
-        * main query is still running.
-        *
-        * @param IDatabase $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 ) {
-               $this->db = $db;
-               $this->history = $history;
-               $this->buffer = $buffer;
-               $this->writer = new XmlDumpWriter();
-               $this->sink = new DumpOutput();
-               $this->text = $text;
-       }
-
-       /**
-        * Set the DumpOutput or DumpFilter object which will receive
-        * various row objects and XML output for filtering. Filters
-        * can be chained or used as callbacks.
-        *
-        * @param DumpOutput $sink
-        */
-       public function setOutputSink( &$sink ) {
-               $this->sink =& $sink;
-       }
-
-       public function openStream() {
-               $output = $this->writer->openStream();
-               $this->sink->writeOpenStream( $output );
-       }
-
-       public function closeStream() {
-               $output = $this->writer->closeStream();
-               $this->sink->writeCloseStream( $output );
-       }
-
-       /**
-        * Dumps a series of page and revision records for all pages
-        * in the database, either including complete history or only
-        * the most recent version.
-        */
-       public function allPages() {
-               $this->dumpFrom( '' );
-       }
-
-       /**
-        * 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 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 );
-               if ( $end ) {
-                       $condition .= ' AND page_id < ' . intval( $end );
-               }
-               $this->dumpFrom( $condition );
-       }
-
-       /**
-        * 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 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 );
-               if ( $end ) {
-                       $condition .= ' AND rev_id < ' . intval( $end );
-               }
-               $this->dumpFrom( $condition );
-       }
-
-       /**
-        * @param Title $title
-        */
-       public function pageByTitle( $title ) {
-               $this->dumpFrom(
-                       'page_namespace=' . $title->getNamespace() .
-                       ' AND page_title=' . $this->db->addQuotes( $title->getDBkey() ) );
-       }
-
-       /**
-        * @param string $name
-        * @throws MWException
-        */
-       public function pageByName( $name ) {
-               $title = Title::newFromText( $name );
-               if ( is_null( $title ) ) {
-                       throw new MWException( "Can't export invalid title" );
-               } else {
-                       $this->pageByTitle( $title );
-               }
-       }
-
-       /**
-        * @param array $names
-        */
-       public function pagesByName( $names ) {
-               foreach ( $names as $name ) {
-                       $this->pageByName( $name );
-               }
-       }
-
-       public function allLogs() {
-               $this->dumpFrom( '' );
-       }
-
-       /**
-        * @param int $start
-        * @param int $end
-        */
-       public function logsByRange( $start, $end ) {
-               $condition = 'log_id >= ' . intval( $start );
-               if ( $end ) {
-                       $condition .= ' AND log_id < ' . intval( $end );
-               }
-               $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
-        *
-        * @param array $cond
-        */
-       protected function do_list_authors( $cond ) {
-               $this->author_list = "<contributors>";
-               // rev_deleted
-
-               $res = $this->db->select(
-                       array( 'page', 'revision' ),
-                       array( 'DISTINCT rev_user_text', 'rev_user' ),
-                       array(
-                               $this->db->bitAnd( 'rev_deleted', Revision::DELETED_USER ) . ' = 0',
-                               $cond,
-                               'page_id = rev_id',
-                       ),
-                       __METHOD__
-               );
-
-               foreach ( $res as $row ) {
-                       $this->author_list .= "<contributor>" .
-                               "<username>" .
-                               htmlentities( $row->rev_user_text ) .
-                               "</username>" .
-                               "<id>" .
-                               $row->rev_user .
-                               "</id>" .
-                               "</contributor>";
-               }
-               $this->author_list .= "</contributors>";
-       }
-
-       /**
-        * @param string $cond
-        * @throws MWException
-        * @throws Exception
-        */
-       protected function dumpFrom( $cond = '' ) {
-               # For logging dumps...
-               if ( $this->history & self::LOGS ) {
-                       $where = array( 'user_id = log_user' );
-                       # Hide private logs
-                       $hideLogs = LogEventsList::getExcludeClause( $this->db );
-                       if ( $hideLogs ) {
-                               $where[] = $hideLogs;
-                       }
-                       # Add on any caller specified conditions
-                       if ( $cond ) {
-                               $where[] = $cond;
-                       }
-                       # Get logging table name for logging.* clause
-                       $logging = $this->db->tableName( 'logging' );
-
-                       if ( $this->buffer == WikiExporter::STREAM ) {
-                               $prev = $this->db->bufferResults( false );
-                       }
-                       $result = null; // Assuring $result is not undefined, if exception occurs early
-                       try {
-                               $result = $this->db->select( array( 'logging', 'user' ),
-                                       array( "{$logging}.*", 'user_name' ), // grab the user name
-                                       $where,
-                                       __METHOD__,
-                                       array( 'ORDER BY' => 'log_id', 'USE INDEX' => array( 'logging' => 'PRIMARY' ) )
-                               );
-                               $this->outputLogStream( $result );
-                               if ( $this->buffer == WikiExporter::STREAM ) {
-                                       $this->db->bufferResults( $prev );
-                               }
-                       } catch ( Exception $e ) {
-                               // Throwing the exception does not reliably free the resultset, and
-                               // would also leave the connection in unbuffered mode.
-
-                               // Freeing result
-                               try {
-                                       if ( $result ) {
-                                               $result->free();
-                                       }
-                               } catch ( Exception $e2 ) {
-                                       // Already in panic mode -> ignoring $e2 as $e has
-                                       // higher priority
-                               }
-
-                               // Putting database back in previous buffer mode
-                               try {
-                                       if ( $this->buffer == WikiExporter::STREAM ) {
-                                               $this->db->bufferResults( $prev );
-                                       }
-                               } catch ( Exception $e2 ) {
-                                       // Already in panic mode -> ignoring $e2 as $e has
-                                       // higher priority
-                               }
-
-                               // Inform caller about problem
-                               throw $e;
-                       }
-               # For page dumps...
-               } else {
-                       $tables = array( 'page', 'revision' );
-                       $opts = array( 'ORDER BY' => 'page_id ASC' );
-                       $opts['USE INDEX'] = array();
-                       $join = array();
-                       if ( is_array( $this->history ) ) {
-                               # Time offset/limit for all pages/history...
-                               $revJoin = 'page_id=rev_page';
-                               # Set time order
-                               if ( $this->history['dir'] == 'asc' ) {
-                                       $op = '>';
-                                       $opts['ORDER BY'] = 'rev_timestamp ASC';
-                               } else {
-                                       $op = '<';
-                                       $opts['ORDER BY'] = 'rev_timestamp DESC';
-                               }
-                               # Set offset
-                               if ( !empty( $this->history['offset'] ) ) {
-                                       $revJoin .= " AND rev_timestamp $op " .
-                                               $this->db->addQuotes( $this->db->timestamp( $this->history['offset'] ) );
-                               }
-                               $join['revision'] = array( 'INNER JOIN', $revJoin );
-                               # Set query limit
-                               if ( !empty( $this->history['limit'] ) ) {
-                                       $opts['LIMIT'] = intval( $this->history['limit'] );
-                               }
-                       } elseif ( $this->history & WikiExporter::FULL ) {
-                               # Full history dumps...
-                               $join['revision'] = array( 'INNER JOIN', 'page_id=rev_page' );
-                       } elseif ( $this->history & WikiExporter::CURRENT ) {
-                               # Latest revision dumps...
-                               if ( $this->list_authors && $cond != '' ) { // List authors, if so desired
-                                       $this->do_list_authors( $cond );
-                               }
-                               $join['revision'] = array( 'INNER JOIN', 'page_id=rev_page AND page_latest=rev_id' );
-                       } elseif ( $this->history & WikiExporter::STABLE ) {
-                               # "Stable" revision dumps...
-                               # Default JOIN, to be overridden...
-                               $join['revision'] = array( 'INNER JOIN', 'page_id=rev_page AND page_latest=rev_id' );
-                               # One, and only one hook should set this, and return false
-                               if ( Hooks::run( 'WikiExporter::dumpStableQuery', array( &$tables, &$opts, &$join ) ) ) {
-                                       throw new MWException( __METHOD__ . " given invalid history dump type." );
-                               }
-                       } elseif ( $this->history & WikiExporter::RANGE ) {
-                               # Dump of revisions within a specified range
-                               $join['revision'] = array( 'INNER JOIN', 'page_id=rev_page' );
-                               $opts['ORDER BY'] = array( 'rev_page ASC', 'rev_id ASC' );
-                       } else {
-                               # Unknown history specification parameter?
-                               throw new MWException( __METHOD__ . " given invalid history dump type." );
-                       }
-                       # Query optimization hacks
-                       if ( $cond == '' ) {
-                               $opts[] = 'STRAIGHT_JOIN';
-                               $opts['USE INDEX']['page'] = 'PRIMARY';
-                       }
-                       # Build text join options
-                       if ( $this->text != WikiExporter::STUB ) { // 1-pass
-                               $tables[] = 'text';
-                               $join['text'] = array( 'INNER JOIN', 'rev_text_id=old_id' );
-                       }
-
-                       if ( $this->buffer == WikiExporter::STREAM ) {
-                               $prev = $this->db->bufferResults( false );
-                       }
-
-                       $result = null; // Assuring $result is not undefined, if exception occurs early
-                       try {
-                               Hooks::run( 'ModifyExportQuery',
-                                               array( $this->db, &$tables, &$cond, &$opts, &$join ) );
-
-                               # Do the query!
-                               $result = $this->db->select( $tables, '*', $cond, __METHOD__, $opts, $join );
-                               # Output dump results
-                               $this->outputPageStream( $result );
-
-                               if ( $this->buffer == WikiExporter::STREAM ) {
-                                       $this->db->bufferResults( $prev );
-                               }
-                       } catch ( Exception $e ) {
-                               // Throwing the exception does not reliably free the resultset, and
-                               // would also leave the connection in unbuffered mode.
-
-                               // Freeing result
-                               try {
-                                       if ( $result ) {
-                                               $result->free();
-                                       }
-                               } catch ( Exception $e2 ) {
-                                       // Already in panic mode -> ignoring $e2 as $e has
-                                       // higher priority
-                               }
-
-                               // Putting database back in previous buffer mode
-                               try {
-                                       if ( $this->buffer == WikiExporter::STREAM ) {
-                                               $this->db->bufferResults( $prev );
-                                       }
-                               } catch ( Exception $e2 ) {
-                                       // Already in panic mode -> ignoring $e2 as $e has
-                                       // higher priority
-                               }
-
-                               // Inform caller about problem
-                               throw $e;
-                       }
-               }
-       }
-
-       /**
-        * Runs through a query result set dumping page and revision records.
-        * The result set should be sorted/grouped by page to avoid duplicate
-        * page records in the output.
-        *
-        * Should be safe for
-        * streaming (non-buffered) queries, as long as it was made on a
-        * separate database connection not managed by LoadBalancer; some
-        * blob storage types will make queries to pull source data.
-        *
-        * @param ResultWrapper $resultset
-        */
-       protected function outputPageStream( $resultset ) {
-               $last = null;
-               foreach ( $resultset as $row ) {
-                       if ( $last === null ||
-                               $last->page_namespace != $row->page_namespace ||
-                               $last->page_title != $row->page_title ) {
-                               if ( $last !== null ) {
-                                       $output = '';
-                                       if ( $this->dumpUploads ) {
-                                               $output .= $this->writer->writeUploads( $last, $this->dumpUploadFileContents );
-                                       }
-                                       $output .= $this->writer->closePage();
-                                       $this->sink->writeClosePage( $output );
-                               }
-                               $output = $this->writer->openPage( $row );
-                               $this->sink->writeOpenPage( $row, $output );
-                               $last = $row;
-                       }
-                       $output = $this->writer->writeRevision( $row );
-                       $this->sink->writeRevision( $row, $output );
-               }
-               if ( $last !== null ) {
-                       $output = '';
-                       if ( $this->dumpUploads ) {
-                               $output .= $this->writer->writeUploads( $last, $this->dumpUploadFileContents );
-                       }
-                       $output .= $this->author_list;
-                       $output .= $this->writer->closePage();
-                       $this->sink->writeClosePage( $output );
-               }
-       }
-
-       /**
-        * @param ResultWrapper $resultset
-        */
-       protected function outputLogStream( $resultset ) {
-               foreach ( $resultset as $row ) {
-                       $output = $this->writer->writeLogItem( $row );
-                       $this->sink->writeLogItem( $row, $output );
-               }
-       }
-}
-
-/**
- * @ingroup Dump
- */
-class XmlDumpWriter {
-       /**
-        * Opens the XML output stream's root "<mediawiki>" element.
-        * This does not include an xml directive, so is safe to include
-        * as a subelement in a larger XML stream. Namespace and XML Schema
-        * references are included.
-        *
-        * Output will be encoded in UTF-8.
-        *
-        * @return string
-        */
-       function openStream() {
-               global $wgLanguageCode;
-               $ver = WikiExporter::schemaVersion();
-               return Xml::element( 'mediawiki', array(
-                       'xmlns'              => "http://www.mediawiki.org/xml/export-$ver/",
-                       'xmlns:xsi'          => "http://www.w3.org/2001/XMLSchema-instance",
-                       /*
-                        * When a new version of the schema is created, it needs staging on mediawiki.org.
-                        * This requires a change in the operations/mediawiki-config git repo.
-                        *
-                        * Create a changeset like https://gerrit.wikimedia.org/r/#/c/149643/ in which
-                        * you copy in the new xsd file.
-                        *
-                        * After it is reviewed, merged and deployed (sync-docroot), the index.html needs purging.
-                        * echo "http://www.mediawiki.org/xml/index.html" | mwscript purgeList.php --wiki=aawiki
-                        */
-                       'xsi:schemaLocation' => "http://www.mediawiki.org/xml/export-$ver/ " .
-                               "http://www.mediawiki.org/xml/export-$ver.xsd",
-                       'version'            => $ver,
-                       'xml:lang'           => $wgLanguageCode ),
-                       null ) .
-                       "\n" .
-                       $this->siteInfo();
-       }
-
-       /**
-        * @return string
-        */
-       function siteInfo() {
-               $info = array(
-                       $this->sitename(),
-                       $this->dbname(),
-                       $this->homelink(),
-                       $this->generator(),
-                       $this->caseSetting(),
-                       $this->namespaces() );
-               return "  <siteinfo>\n    " .
-                       implode( "\n    ", $info ) .
-                       "\n  </siteinfo>\n";
-       }
-
-       /**
-        * @return string
-        */
-       function sitename() {
-               global $wgSitename;
-               return Xml::element( 'sitename', array(), $wgSitename );
-       }
-
-       /**
-        * @return string
-        */
-       function dbname() {
-               global $wgDBname;
-               return Xml::element( 'dbname', array(), $wgDBname );
-       }
-
-       /**
-        * @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
-               $sensitivity = $wgCapitalLinks ? 'first-letter' : 'case-sensitive';
-               return Xml::element( 'case', array(), $sensitivity );
-       }
-
-       /**
-        * @return string
-        */
-       function namespaces() {
-               global $wgContLang;
-               $spaces = "<namespaces>\n";
-               foreach ( $wgContLang->getFormattedNamespaces() as $ns => $title ) {
-                       $spaces .= '      ' .
-                               Xml::element( 'namespace',
-                                       array(
-                                               'key' => $ns,
-                                               'case' => MWNamespace::isCapitalized( $ns ) ? 'first-letter' : 'case-sensitive',
-                                       ), $title ) . "\n";
-               }
-               $spaces .= "    </namespaces>";
-               return $spaces;
-       }
-
-       /**
-        * Closes the output stream with the closing root element.
-        * Call when finished dumping things.
-        *
-        * @return string
-        */
-       function closeStream() {
-               return "</mediawiki>\n";
-       }
-
-       /**
-        * Opens a "<page>" section on the output stream, with data
-        * from the given database row.
-        *
-        * @param object $row
-        * @return string
-        */
-       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";
-               $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 ) {
-                       $page = WikiPage::factory( $title );
-                       $redirect = $page->getRedirectTarget();
-                       if ( $redirect instanceof Title && $redirect->isValidRedirectTarget() ) {
-                               $out .= '    ';
-                               $out .= Xml::element( 'redirect', array( 'title' => self::canonicalTitle( $redirect ) ) );
-                               $out .= "\n";
-                       }
-               }
-
-               if ( $row->page_restrictions != '' ) {
-                       $out .= '    ' . Xml::element( 'restrictions', array(),
-                               strval( $row->page_restrictions ) ) . "\n";
-               }
-
-               Hooks::run( 'XmlDumpWriterOpenPage', array( $this, &$out, $row, $title ) );
-
-               return $out;
-       }
-
-       /**
-        * Closes a "<page>" section on the output stream.
-        *
-        * @access private
-        * @return string
-        */
-       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 ) {
-
-               $out = "    <revision>\n";
-               $out .= "      " . Xml::element( 'id', null, strval( $row->rev_id ) ) . "\n";
-               if ( isset( $row->rev_parent_id ) && $row->rev_parent_id ) {
-                       $out .= "      " . Xml::element( 'parentid', null, strval( $row->rev_parent_id ) ) . "\n";
-               }
-
-               $out .= $this->writeTimestamp( $row->rev_timestamp );
-
-               if ( isset( $row->rev_deleted ) && ( $row->rev_deleted & Revision::DELETED_USER ) ) {
-                       $out .= "      " . Xml::element( 'contributor', array( 'deleted' => 'deleted' ) ) . "\n";
-               } else {
-                       $out .= $this->writeContributor( $row->rev_user, $row->rev_user_text );
-               }
-
-               if ( isset( $row->rev_minor_edit ) && $row->rev_minor_edit ) {
-                       $out .= "      <minor/>\n";
-               }
-               if ( isset( $row->rev_deleted ) && ( $row->rev_deleted & Revision::DELETED_COMMENT ) ) {
-                       $out .= "      " . Xml::element( 'comment', array( 'deleted' => 'deleted' ) ) . "\n";
-               } elseif ( $row->rev_comment != '' ) {
-                       $out .= "      " . Xml::elementClean( 'comment', array(), strval( $row->rev_comment ) ) . "\n";
-               }
-
-               if ( isset( $row->rev_content_model ) && !is_null( $row->rev_content_model ) ) {
-                       $content_model = strval( $row->rev_content_model );
-               } else {
-                       // probably using $wgContentHandlerUseDB = false;
-                       $title = Title::makeTitle( $row->page_namespace, $row->page_title );
-                       $content_model = ContentHandler::getDefaultModelFor( $title );
-               }
-
-               $content_handler = ContentHandler::getForModelID( $content_model );
-
-               if ( isset( $row->rev_content_format ) && !is_null( $row->rev_content_format ) ) {
-                       $content_format = strval( $row->rev_content_format );
-               } else {
-                       // probably using $wgContentHandlerUseDB = false;
-                       $content_format = $content_handler->getDefaultFormat();
-               }
-
-               $out .= "      " . Xml::element( 'model', null, strval( $content_model ) ) . "\n";
-               $out .= "      " . Xml::element( 'format', null, strval( $content_format ) ) . "\n";
-
-               $text = '';
-               if ( isset( $row->rev_deleted ) && ( $row->rev_deleted & Revision::DELETED_TEXT ) ) {
-                       $out .= "      " . Xml::element( 'text', array( 'deleted' => 'deleted' ) ) . "\n";
-               } elseif ( isset( $row->old_text ) ) {
-                       // Raw text from the database may have invalid chars
-                       $text = strval( Revision::getRevisionText( $row ) );
-                       $text = $content_handler->exportTransform( $text, $content_format );
-                       $out .= "      " . Xml::elementClean( 'text',
-                               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' => intval( $row->rev_len ) ),
-                               "" ) . "\n";
-               }
-
-               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";
-               }
-
-               Hooks::run( 'XmlDumpWriterWriteRevision', array( &$this, &$out, $row, $text ) );
-
-               $out .= "    </revision>\n";
-
-               return $out;
-       }
-
-       /**
-        * Dumps a "<logitem>" section on the output stream, with
-        * data filled in from the given database row.
-        *
-        * @param object $row
-        * @return string
-        * @access private
-        */
-       function writeLogItem( $row ) {
-
-               $out = "  <logitem>\n";
-               $out .= "    " . Xml::element( 'id', null, strval( $row->log_id ) ) . "\n";
-
-               $out .= $this->writeTimestamp( $row->log_timestamp, "    " );
-
-               if ( $row->log_deleted & LogPage::DELETED_USER ) {
-                       $out .= "    " . Xml::element( 'contributor', array( 'deleted' => 'deleted' ) ) . "\n";
-               } else {
-                       $out .= $this->writeContributor( $row->log_user, $row->user_name, "    " );
-               }
-
-               if ( $row->log_deleted & LogPage::DELETED_COMMENT ) {
-                       $out .= "    " . Xml::element( 'comment', array( 'deleted' => 'deleted' ) ) . "\n";
-               } elseif ( $row->log_comment != '' ) {
-                       $out .= "    " . Xml::elementClean( 'comment', null, strval( $row->log_comment ) ) . "\n";
-               }
-
-               $out .= "    " . Xml::element( 'type', null, strval( $row->log_type ) ) . "\n";
-               $out .= "    " . Xml::element( 'action', null, strval( $row->log_action ) ) . "\n";
-
-               if ( $row->log_deleted & LogPage::DELETED_ACTION ) {
-                       $out .= "    " . Xml::element( 'text', array( 'deleted' => 'deleted' ) ) . "\n";
-               } else {
-                       $title = Title::makeTitle( $row->log_namespace, $row->log_title );
-                       $out .= "    " . Xml::elementClean( 'logtitle', null, self::canonicalTitle( $title ) ) . "\n";
-                       $out .= "    " . Xml::elementClean( 'params',
-                               array( 'xml:space' => 'preserve' ),
-                               strval( $row->log_params ) ) . "\n";
-               }
-
-               $out .= "  </logitem>\n";
-
-               return $out;
-       }
-
-       /**
-        * @param string $timestamp
-        * @param string $indent Default to six spaces
-        * @return string
-        */
-       function writeTimestamp( $timestamp, $indent = "      " ) {
-               $ts = wfTimestamp( TS_ISO_8601, $timestamp );
-               return $indent . Xml::element( 'timestamp', null, $ts ) . "\n";
-       }
-
-       /**
-        * @param int $id
-        * @param string $text
-        * @param string $indent Default to six spaces
-        * @return string
-        */
-       function writeContributor( $id, $text, $indent = "      " ) {
-               $out = $indent . "<contributor>\n";
-               if ( $id || !IP::isValid( $text ) ) {
-                       $out .= $indent . "  " . Xml::elementClean( 'username', null, strval( $text ) ) . "\n";
-                       $out .= $indent . "  " . Xml::element( 'id', null, strval( $id ) ) . "\n";
-               } else {
-                       $out .= $indent . "  " . Xml::elementClean( 'ip', null, strval( $text ) ) . "\n";
-               }
-               $out .= $indent . "</contributor>\n";
-               return $out;
-       }
-
-       /**
-        * Warning! This data is potentially inconsistent. :(
-        * @param object $row
-        * @param bool $dumpContents
-        * @return string
-        */
-       function writeUploads( $row, $dumpContents = false ) {
-               if ( $row->page_namespace == NS_FILE ) {
-                       $img = wfLocalFile( $row->page_title );
-                       if ( $img && $img->exists() ) {
-                               $out = '';
-                               foreach ( array_reverse( $img->getHistory() ) as $ver ) {
-                                       $out .= $this->writeUpload( $ver, $dumpContents );
-                               }
-                               $out .= $this->writeUpload( $img, $dumpContents );
-                               return $out;
-                       }
-               }
-               return '';
-       }
-
-       /**
-        * @param File $file
-        * @param bool $dumpContents
-        * @return string
-        */
-       function writeUpload( $file, $dumpContents = false ) {
-               if ( $file->isOld() ) {
-                       $archiveName = "      " .
-                               Xml::element( 'archivename', null, $file->getArchiveName() ) . "\n";
-               } else {
-                       $archiveName = '';
-               }
-               if ( $dumpContents ) {
-                       $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)
-                       $contents = '      <contents encoding="base64">' .
-                               chunk_split( base64_encode(
-                                       $be->getFileContents( array( 'src' => $file->getPath() ) ) ) ) .
-                               "      </contents>\n";
-               } else {
-                       $contents = '';
-               }
-               if ( $file->isDeleted( File::DELETED_COMMENT ) ) {
-                       $comment = Xml::element( 'comment', array( 'deleted' => 'deleted' ) );
-               } else {
-                       $comment = Xml::elementClean( 'comment', null, $file->getDescription() );
-               }
-               return "    <upload>\n" .
-                       $this->writeTimestamp( $file->getTimestamp() ) .
-                       $this->writeContributor( $file->getUser( 'id' ), $file->getUser( 'text' ) ) .
-                       "      " . $comment . "\n" .
-                       "      " . Xml::element( 'filename', null, $file->getName() ) . "\n" .
-                       $archiveName .
-                       "      " . Xml::element( 'src', null, $file->getCanonicalURL() ) . "\n" .
-                       "      " . Xml::element( 'size', null, $file->getSize() ) . "\n" .
-                       "      " . Xml::element( 'sha1base36', null, $file->getSha1() ) . "\n" .
-                       "      " . Xml::element( 'rel', null, $file->getRel() ) . "\n" .
-                       $contents .
-                       "    </upload>\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 "<siteinfo>" data so are unsafe in export.
-        *
-        * @param Title $title
-        * @return string
-        * @since 1.18
-        */
-       public static function canonicalTitle( Title $title ) {
-               if ( $title->isExternal() ) {
-                       return $title->getPrefixedText();
-               }
-
-               global $wgContLang;
-               $prefix = $wgContLang->getFormattedNsText( $title->getNamespace() );
-
-               if ( $prefix !== '' ) {
-                       $prefix .= ':';
-               }
-
-               return $prefix . $title->getText();
-       }
-}
-
-/**
- * Base class for output stream; prints to stdout or buffer or wherever.
- * @ingroup Dump
- */
-class DumpOutput {
-
-       /**
-        * @param string $string
-        */
-       function writeOpenStream( $string ) {
-               $this->write( $string );
-       }
-
-       /**
-        * @param string $string
-        */
-       function writeCloseStream( $string ) {
-               $this->write( $string );
-       }
-
-       /**
-        * @param object $page
-        * @param string $string
-        */
-       function writeOpenPage( $page, $string ) {
-               $this->write( $string );
-       }
-
-       /**
-        * @param string $string
-        */
-       function writeClosePage( $string ) {
-               $this->write( $string );
-       }
-
-       /**
-        * @param object $rev
-        * @param string $string
-        */
-       function writeRevision( $rev, $string ) {
-               $this->write( $string );
-       }
-
-       /**
-        * @param object $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 ) {
-               print $string;
-       }
-
-       /**
-        * Close the old file, move it to a specified name,
-        * 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 string|array $newname File name. May be a string or an array with one element
-        */
-       function closeRenameAndReopen( $newname ) {
-       }
-
-       /**
-        * 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 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 ) {
-       }
-
-       /**
-        * Returns the name of the file or files which are
-        * being written to, if there are any.
-        * @return null
-        */
-       function getFilenames() {
-               return null;
-       }
-}
-
-/**
- * Stream outputter to send data to a file.
- * @ingroup Dump
- */
-class DumpFileOutput extends DumpOutput {
-       protected $handle = false, $filename;
-
-       /**
-        * @param string $file
-        */
-       function __construct( $file ) {
-               $this->handle = fopen( $file, "wt" );
-               $this->filename = $file;
-       }
-
-       /**
-        * @param string $string
-        */
-       function writeCloseStream( $string ) {
-               parent::writeCloseStream( $string );
-               if ( $this->handle ) {
-                       fclose( $this->handle );
-                       $this->handle = false;
-               }
-       }
-
-       /**
-        * @param string $string
-        */
-       function write( $string ) {
-               fputs( $this->handle, $string );
-       }
-
-       /**
-        * @param string $newname
-        */
-       function closeRenameAndReopen( $newname ) {
-               $this->closeAndRename( $newname, true );
-       }
-
-       /**
-        * @param string $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 array $newname
-        * @return string
-        * @throws MWException
-        */
-       function checkRenameArgCount( $newname ) {
-               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];
-                       }
-               }
-               return $newname;
-       }
-
-       /**
-        * @param string $newname
-        * @param bool $open
-        */
-       function closeAndRename( $newname, $open = false ) {
-               $newname = $this->checkRenameArgCount( $newname );
-               if ( $newname ) {
-                       if ( $this->handle ) {
-                               fclose( $this->handle );
-                               $this->handle = false;
-                       }
-                       $this->renameOrException( $newname );
-                       if ( $open ) {
-                               $this->handle = fopen( $this->filename, "wt" );
-                       }
-               }
-       }
-
-       /**
-        * @return string|null
-        */
-       function getFilenames() {
-               return $this->filename;
-       }
-}
-
-/**
- * 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.
- * @ingroup Dump
- */
-class DumpPipeOutput extends DumpFileOutput {
-       protected $command, $filename;
-       protected $procOpenResource = false;
-
-       /**
-        * @param string $command
-        * @param string $file
-        */
-       function __construct( $command, $file = null ) {
-               if ( !is_null( $file ) ) {
-                       $command .= " > " . wfEscapeShellArg( $file );
-               }
-
-               $this->startCommand( $command );
-               $this->command = $command;
-               $this->filename = $file;
-       }
-
-       /**
-        * @param string $string
-        */
-       function writeCloseStream( $string ) {
-               parent::writeCloseStream( $string );
-               if ( $this->procOpenResource ) {
-                       proc_close( $this->procOpenResource );
-                       $this->procOpenResource = false;
-               }
-       }
-
-       /**
-        * @param string $command
-        */
-       function startCommand( $command ) {
-               $spec = array(
-                       0 => array( "pipe", "r" ),
-               );
-               $pipes = array();
-               $this->procOpenResource = proc_open( $command, $spec, $pipes );
-               $this->handle = $pipes[0];
-       }
-
-       /**
-        * @param string $newname
-        */
-       function closeRenameAndReopen( $newname ) {
-               $this->closeAndRename( $newname, true );
-       }
-
-       /**
-        * @param string $newname
-        * @param bool $open
-        */
-       function closeAndRename( $newname, $open = false ) {
-               $newname = $this->checkRenameArgCount( $newname );
-               if ( $newname ) {
-                       if ( $this->handle ) {
-                               fclose( $this->handle );
-                               $this->handle = false;
-                       }
-                       if ( $this->procOpenResource ) {
-                               proc_close( $this->procOpenResource );
-                               $this->procOpenResource = false;
-                       }
-                       $this->renameOrException( $newname );
-                       if ( $open ) {
-                               $command = $this->command;
-                               $command .= " > " . wfEscapeShellArg( $this->filename );
-                               $this->startCommand( $command );
-                       }
-               }
-       }
-}
-
-/**
- * Sends dump output via the gzip compressor.
- * @ingroup Dump
- */
-class DumpGZipOutput extends DumpPipeOutput {
-       /**
-        * @param string $file
-        */
-       function __construct( $file ) {
-               parent::__construct( "gzip", $file );
-       }
-}
-
-/**
- * Sends dump output via the bgzip2 compressor.
- * @ingroup Dump
- */
-class DumpBZip2Output extends DumpPipeOutput {
-       /**
-        * @param string $file
-        */
-       function __construct( $file ) {
-               parent::__construct( "bzip2", $file );
-       }
-}
-
-/**
- * Sends dump output via the p7zip compressor.
- * @ingroup Dump
- */
-class Dump7ZipOutput extends DumpPipeOutput {
-       /**
-        * @param string $file
-        */
-       function __construct( $file ) {
-               $command = $this->setup7zCommand( $file );
-               parent::__construct( $command );
-               $this->filename = $file;
-       }
-
-       /**
-        * @param string $file
-        * @return string
-        */
-       function setup7zCommand( $file ) {
-               $command = "7za a -bd -si -mx=4 " . wfEscapeShellArg( $file );
-               // Suppress annoying useless crap from p7zip
-               // Unfortunately this could suppress real error messages too
-               $command .= ' >' . wfGetNull() . ' 2>&1';
-               return $command;
-       }
-
-       /**
-        * @param string $newname
-        * @param bool $open
-        */
-       function closeAndRename( $newname, $open = false ) {
-               $newname = $this->checkRenameArgCount( $newname );
-               if ( $newname ) {
-                       fclose( $this->handle );
-                       proc_close( $this->procOpenResource );
-                       $this->renameOrException( $newname );
-                       if ( $open ) {
-                               $command = $this->setup7zCommand( $this->filename );
-                               $this->startCommand( $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.
- * @ingroup Dump
- */
-class DumpFilter {
-       /**
-        * @var DumpOutput
-        * FIXME will need to be made protected whenever legacy code
-        * is updated.
-        */
-       public $sink;
-
-       /**
-        * @var bool
-        */
-       protected $sendingThisPage;
-
-       /**
-        * @param DumpOutput $sink
-        */
-       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 object $page
-        * @param string $string
-        */
-       function writeOpenPage( $page, $string ) {
-               $this->sendingThisPage = $this->pass( $page, $string );
-               if ( $this->sendingThisPage ) {
-                       $this->sink->writeOpenPage( $page, $string );
-               }
-       }
-
-       /**
-        * @param string $string
-        */
-       function writeClosePage( $string ) {
-               if ( $this->sendingThisPage ) {
-                       $this->sink->writeClosePage( $string );
-                       $this->sendingThisPage = false;
-               }
-       }
-
-       /**
-        * @param object $rev
-        * @param string $string
-        */
-       function writeRevision( $rev, $string ) {
-               if ( $this->sendingThisPage ) {
-                       $this->sink->writeRevision( $rev, $string );
-               }
-       }
-
-       /**
-        * @param object $rev
-        * @param string $string
-        */
-       function writeLogItem( $rev, $string ) {
-               $this->sink->writeRevision( $rev, $string );
-       }
-
-       /**
-        * @param string $newname
-        */
-       function closeRenameAndReopen( $newname ) {
-               $this->sink->closeRenameAndReopen( $newname );
-       }
-
-       /**
-        * @param string $newname
-        * @param bool $open
-        */
-       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 object $page
-        * @return bool
-        */
-       function pass( $page ) {
-               return true;
-       }
-}
-
-/**
- * Simple dump output filter to exclude all talk pages.
- * @ingroup Dump
- */
-class DumpNotalkFilter extends DumpFilter {
-       /**
-        * @param object $page
-        * @return bool
-        */
-       function pass( $page ) {
-               return !MWNamespace::isTalk( $page->page_namespace );
-       }
-}
-
-/**
- * Dump output filter to include or exclude pages in a given set of namespaces.
- * @ingroup Dump
- */
-class DumpNamespaceFilter extends DumpFilter {
-       /** @var bool */
-       public $invert = false;
-
-       /** @var array */
-       public $namespaces = array();
-
-       /**
-        * @param DumpOutput $sink
-        * @param array $param
-        * @throws MWException
-        */
-       function __construct( &$sink, $param ) {
-               parent::__construct( $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_FILE"           => NS_FILE,
-                       "NS_FILE_TALK"      => NS_FILE_TALK,
-                       "NS_IMAGE"          => NS_IMAGE, // NS_IMAGE is an alias for NS_FILE
-                       "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" );
-                       }
-               }
-       }
-
-       /**
-        * @param object $page
-        * @return bool
-        */
-       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.
- * @ingroup Dump
- */
-class DumpLatestFilter extends DumpFilter {
-       public $page;
-
-       public $pageString;
-
-       public $rev;
-
-       public $revString;
-
-       /**
-        * @param object $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 );
-                       $this->sink->writeRevision( $this->rev, $this->revString );
-                       $this->sink->writeClosePage( $string );
-               }
-               $this->rev = null;
-               $this->revString = null;
-               $this->page = null;
-               $this->pageString = null;
-       }
-
-       /**
-        * @param object $rev
-        * @param string $string
-        */
-       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 wherever.
- * @ingroup Dump
- */
-class DumpMultiWriter {
-
-       /**
-        * @param array $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 object $page
-        * @param string $string
-        */
-       function writeOpenPage( $page, $string ) {
-               for ( $i = 0; $i < $this->count; $i++ ) {
-                       $this->sinks[$i]->writeOpenPage( $page, $string );
-               }
-       }
-
-       /**
-        * @param string $string
-        */
-       function writeClosePage( $string ) {
-               for ( $i = 0; $i < $this->count; $i++ ) {
-                       $this->sinks[$i]->writeClosePage( $string );
-               }
-       }
-
-       /**
-        * @param object $rev
-        * @param string $string
-        */
-       function writeRevision( $rev, $string ) {
-               for ( $i = 0; $i < $this->count; $i++ ) {
-                       $this->sinks[$i]->writeRevision( $rev, $string );
-               }
-       }
-
-       /**
-        * @param array $newnames
-        */
-       function closeRenameAndReopen( $newnames ) {
-               $this->closeAndRename( $newnames, true );
-       }
-
-       /**
-        * @param array $newnames
-        * @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++ ) {
-                       $filenames[] = $this->sinks[$i]->getFilenames();
-               }
-               return $filenames;
-       }
-}
index 49b9786..89ff19a 100644 (file)
@@ -1253,6 +1253,8 @@ class ApiMain extends ApiBase {
                $module = $this->setupModule();
                $this->mModule = $module;
 
+               $this->setRequestExpectations( $module );
+
                $this->checkExecutePermissions( $module );
 
                if ( !$this->checkMaxLag( $module, $params ) ) {
@@ -1284,6 +1286,24 @@ class ApiMain extends ApiBase {
                }
        }
 
+       /**
+        * Set database connection, query, and write expectations given this module request
+        * @param ApiBase $module
+        */
+       protected function setRequestExpectations( ApiBase $module ) {
+               $limits = $this->getConfig()->get( 'TrxProfilerLimits' );
+               $trxProfiler = Profiler::instance()->getTransactionProfiler();
+               if ( $this->getRequest()->wasPosted() ) {
+                       if ( $module->isWriteMode() ) {
+                               $trxProfiler->setExpectations( $limits['POST'], __METHOD__ );
+                       } else {
+                               $trxProfiler->setExpectations( $limits['POST-nonwrite'], __METHOD__ );
+                       }
+               } else {
+                       $trxProfiler->setExpectations( $limits['GET'], __METHOD__ );
+               }
+       }
+
        /**
         * Log the preceding request
         * @param float $time Time in seconds
index 2494ef1..9567700 100644 (file)
@@ -364,12 +364,24 @@ class ChangesList extends ContextSource {
        }
 
        /**
-        * @param string $s HTML to update
+        * @param string $s Article link will be appended to this string, in place.
         * @param RecentChange $rc
         * @param bool $unpatrolled
         * @param bool $watched
+        * @deprecated since 1.27, use getArticleLink instead.
         */
-       public function insertArticleLink( &$s, &$rc, $unpatrolled, $watched ) {
+       public function insertArticleLink( &$s, RecentChange $rc, $unpatrolled, $watched ) {
+               $s .= $this->getArticleLink( $rc, $unpatrolled, $watched );
+       }
+
+       /**
+        * @param RecentChange $rc
+        * @param bool $unpatrolled
+        * @param bool $watched
+        * @return string HTML
+        * @since 1.26
+        */
+       public function getArticleLink( &$rc, $unpatrolled, $watched ) {
                $params = array();
                if ( $rc->getTitle()->isRedirect() ) {
                        $params = array( 'redirect' => 'no' );
@@ -389,23 +401,12 @@ class ChangesList extends ContextSource {
                # RTL/LTR marker
                $articlelink .= $this->getLanguage()->getDirMark();
 
+               # TODO: Deprecate the $s argument, it seems happily unused.
+               $s = '';
                Hooks::run( 'ChangesListInsertArticleLink',
                        array( &$this, &$articlelink, &$s, &$rc, $unpatrolled, $watched ) );
 
-               $s .= " $articlelink";
-       }
-
-       /**
-        * @param RecentChange $rc
-        * @param bool $unpatrolled
-        * @param bool $watched
-        * @return string
-        * @since 1.26
-        */
-       public function getArticleLink( RecentChange $rc, $unpatrolled, $watched ) {
-               $s = '';
-               $this->insertArticleLink( $s, $rc, $unpatrolled, $watched );
-               return $s;
+               return "{$s} {$articlelink}";
        }
 
        /**
index ed374b0..1c49545 100644 (file)
@@ -161,19 +161,22 @@ class EnhancedChangesList extends ChangesList {
        protected function recentChangesBlockGroup( $block ) {
 
                # Add the namespace and title of the block as part of the class
-               $classes = array( 'mw-collapsible', 'mw-collapsed', 'mw-enhanced-rc' );
+               $tableClasses = array( 'mw-collapsible', 'mw-collapsed', 'mw-enhanced-rc' );
                if ( $block[0]->mAttribs['rc_log_type'] ) {
                        # Log entry
-                       $classes[] = Sanitizer::escapeClass( 'mw-changeslist-log-'
+                       $tableClasses[] = Sanitizer::escapeClass( 'mw-changeslist-log-'
                                . $block[0]->mAttribs['rc_log_type'] );
                } else {
-                       $classes[] = Sanitizer::escapeClass( 'mw-changeslist-ns'
+                       $tableClasses[] = Sanitizer::escapeClass( 'mw-changeslist-ns'
                                . $block[0]->mAttribs['rc_namespace'] . '-' . $block[0]->mAttribs['rc_title'] );
                }
-               $classes[] = $block[0]->watched && $block[0]->mAttribs['rc_timestamp'] >= $block[0]->watched
-                       ? 'mw-changeslist-line-watched' : 'mw-changeslist-line-not-watched';
-               $r = Html::openElement( 'table', array( 'class' => $classes ) ) .
-                       Html::openElement( 'tr' );
+               if ( $block[0]->watched
+                       && $block[0]->mAttribs['rc_timestamp'] >= $block[0]->watched
+               ) {
+                       $tableClasses[] = 'mw-changeslist-line-watched';
+               } else {
+                       $tableClasses[] = 'mw-changeslist-line-not-watched';
+               }
 
                # Collate list of users
                $userlinks = array();
@@ -243,61 +246,44 @@ class EnhancedChangesList extends ChangesList {
                        array_push( $users, $text );
                }
 
-               $users = ' <span class="changedby">'
-                       . $this->msg( 'brackets' )->rawParams(
-                               implode( $this->message['semicolon-separator'], $users )
-                       )->escaped() . '</span>';
-
-               $tl = '<span class="mw-collapsible-toggle mw-collapsible-arrow ' .
-                       'mw-enhancedchanges-arrow mw-enhancedchanges-arrow-space"></span>';
-               $r .= "<td>$tl</td>";
-
-               # Main line
-               $r .= '<td class="mw-enhanced-rc">' . $this->recentChangesFlags(
-                       $collectedRcFlags
-               );
-
-               # Timestamp
-               $r .= '&#160;' . $block[0]->timestamp . '&#160;</td><td>';
-
                # Article link
+               $articleLink = '';
+               $revDeletedMsg = false;
                if ( $namehidden ) {
-                       $r .= ' <span class="history-deleted">' .
-                               $this->msg( 'rev-deleted-event' )->escaped() . '</span>';
+                       $revDeletedMsg = $this->msg( 'rev-deleted-event' )->escaped();
                } elseif ( $allLogs ) {
-                       $r .= $this->maybeWatchedLink( $block[0]->link, $block[0]->watched );
+                       $articleLink = $this->maybeWatchedLink( $block[0]->link, $block[0]->watched );
                } else {
-                       $this->insertArticleLink( $r, $block[0], $block[0]->unpatrolled, $block[0]->watched );
+                       $articleLink = $this->getArticleLink( $block[0], $block[0]->unpatrolled, $block[0]->watched );
                }
 
-               $r .= $this->getLanguage()->getDirMark();
-
                $queryParams['curid'] = $curId;
 
                # Sub-entries
-               $lines = '';
+               $lines = array();
                foreach ( $block as $i => $rcObj ) {
                        $line = $this->getLineData( $block, $rcObj, $queryParams );
-                       $lines .= $line;
                        if ( !$line ) {
                                // completely ignore this RC entry if we don't want to render it
                                unset( $block[$i] );
                        }
+                       $lines[] = $line;
                }
                // Further down are some assumptions that $block is a 0-indexed array
                // with (count-1) as last key. Let's make sure it is.
                $block = array_values( $block );
-               if ( empty( $block ) ) {
+
+               if ( empty( $block ) || !$lines ) {
                        // if we can't show anything, don't display this block altogether
                        return '';
                }
 
-               $r .= $this->getLogText( $block, $queryParams, $allLogs,
-                       $collectedRcFlags['newpage'], $namehidden );
-
-               $r .= ' <span class="mw-changeslist-separator">. .</span> ';
+               $logText = $this->getLogText( $block, $queryParams, $allLogs,
+                       $collectedRcFlags['newpage'], $namehidden
+               );
 
                # Character difference (does not apply if only log items)
+               $charDifference = false;
                if ( $RCShowChangedSize && !$allLogs ) {
                        $last = 0;
                        $first = count( $block ) - 1;
@@ -309,37 +295,42 @@ class EnhancedChangesList extends ChangesList {
                                $first--;
                        }
                        # Get net change
-                       $chardiff = $this->formatCharacterDifference( $block[$first], $block[$last] );
-
-                       if ( $chardiff == '' ) {
-                               $r .= ' ';
-                       } else {
-                               $r .= ' ' . $chardiff . ' <span class="mw-changeslist-separator">. .</span> ';
-                       }
-               }
-
-               $r .= $users;
-               $r .= $this->numberofWatchingusers( $block[0]->numberofWatchingusers );
-               $r .= '</td></tr>';
-
-               if ( !$lines ) {
-                       // if there are no lines to be rendered (all aborted by hook), don't render the block
-                       return '';
-               }
-
-               $r .= $lines;
-               $r .= "</table>\n";
+                       $charDifference = $this->formatCharacterDifference( $block[$first], $block[$last] );
+               }
+
+               $numberofWatchingusers = $this->numberofWatchingusers( $block[0]->numberofWatchingusers );
+               $usersList = $this->msg( 'brackets' )->rawParams(
+                       implode( $this->message['semicolon-separator'], $users )
+               )->escaped();
+
+               $templateParams = array(
+                       'articleLink' => $articleLink,
+                       'charDifference' => $charDifference,
+                       'collectedRcFlags' => $this->recentChangesFlags( $collectedRcFlags ),
+                       'languageDirMark' => $this->getLanguage()->getDirMark(),
+                       'lines' => $lines,
+                       'logText' => $logText,
+                       'numberofWatchingusers' => $numberofWatchingusers,
+                       'rev-deleted-event' => $revDeletedMsg,
+                       'tableClasses' => $tableClasses,
+                       'timestamp' => $block[0]->timestamp,
+                       'users' => $usersList,
+               );
 
                $this->rcCacheIndex++;
 
-               return $r;
+               $templateParser = new TemplateParser();
+               return $templateParser->processTemplate(
+                       'EnhancedChangesListGroup',
+                       $templateParams
+               );
        }
 
        /**
         * @param RCCacheEntry[] $block
         * @param RCCacheEntry $rcObj
         * @param array $queryParams
-        * @return string
+        * @return array
         * @throws Exception
         * @throws FatalError
         * @throws MWException
@@ -351,9 +342,13 @@ class EnhancedChangesList extends ChangesList {
                $classes = array();
                $type = $rcObj->mAttribs['rc_type'];
                $data = array();
+               $lineParams = array();
 
-               $trClass = $rcObj->watched && $rcObj->mAttribs['rc_timestamp'] >= $rcObj->watched
-                       ? ' class="mw-enhanced-watched"' : '';
+               if ( $rcObj->watched
+                       && $rcObj->mAttribs['rc_timestamp'] >= $rcObj->watched
+               ) {
+                       $lineParams['classes'] = array( 'mw-enhanced-watched' );
+               }
                $separator = ' <span class="mw-changeslist-separator">. .</span> ';
 
                $data['recentChangesFlags'] = array(
@@ -430,27 +425,23 @@ class EnhancedChangesList extends ChangesList {
                        array( $this, &$data, $block, $rcObj ) );
                if ( !$success ) {
                        // skip entry if hook aborted it
-                       return '';
+                       return array();
                }
 
-               $line = '<tr' . $trClass . '><td></td><td class="mw-enhanced-rc">';
                if ( isset( $data['recentChangesFlags'] ) ) {
-                       $line .= $this->recentChangesFlags( $data['recentChangesFlags'] );
+                       $lineParams['recentChangesFlags'] = $this->recentChangesFlags( $data['recentChangesFlags'] );
                        unset( $data['recentChangesFlags'] );
                }
-               $line .= '&#160;</td><td class="mw-enhanced-rc-nested">';
 
                if ( isset( $data['timestampLink'] ) ) {
-                       $line .= '<span class="mw-enhanced-rc-time">' . $data['timestampLink'] . '</span>';
+                       $lineParams['timestampLink'] = $data['timestampLink'];
                        unset( $data['timestampLink'] );
                }
 
                // everything else: makes it easier for extensions to add or remove data
-               $line .= implode( '', $data );
+               $lineParams['data'] = array_values( $data );
 
-               $line .= "</td></tr>\n";
-
-               return $line;
+               return $lineParams;
        }
 
        /**
index 31b355d..58a57a4 100644 (file)
@@ -98,7 +98,7 @@ class OldChangesList extends ChangesList {
                                ),
                                ''
                        );
-                       $this->insertArticleLink( $html, $rc, $unpatrolled, $watched );
+                       $html .= $this->getArticleLink( $rc, $unpatrolled, $watched );
                }
                # Edit/log timestamp
                $this->insertTimestamp( $html, $rc );
index 5443eeb..3cac22a 100644 (file)
@@ -429,6 +429,10 @@ class DBConnRef implements IDatabase {
                return $this->__call( __FUNCTION__, func_get_args() );
        }
 
+       public function doAtomicSection( $fname, $callback ) {
+               return $this->__call( __FUNCTION__, func_get_args() );
+       }
+
        public function begin( $fname = __METHOD__ ) {
                return $this->__call( __FUNCTION__, func_get_args() );
        }
index 31e2653..3fec522 100644 (file)
@@ -1286,13 +1286,14 @@ abstract class DatabaseBase implements IDatabase {
         * @param string|array $cond The condition array. See DatabaseBase::select() for details.
         * @param string $fname The function name of the caller.
         * @param string|array $options The query options. See DatabaseBase::select() for details.
+        * @param string|array $join_conds The join conditions. See DatabaseBase::select() for details.
         *
         * @return bool|array The values from the field, or false on failure
         * @throws DBUnexpectedError
         * @since 1.25
         */
        public function selectFieldValues(
-               $table, $var, $cond = '', $fname = __METHOD__, $options = array()
+               $table, $var, $cond = '', $fname = __METHOD__, $options = array(), $join_conds = array()
        ) {
                if ( $var === '*' ) { // sanity
                        throw new DBUnexpectedError( $this, "Cannot use a * field: got '$var'" );
@@ -1302,7 +1303,7 @@ abstract class DatabaseBase implements IDatabase {
                        $options = array( $options );
                }
 
-               $res = $this->select( $table, $var, $cond, $fname, $options );
+               $res = $this->select( $table, $var, $cond, $fname, $options, $join_conds );
                if ( $res === false ) {
                        return false;
                }
@@ -3446,6 +3447,21 @@ abstract class DatabaseBase implements IDatabase {
                }
        }
 
+       final public function doAtomicSection( $fname, $callback ) {
+               if ( !is_callable( $callback ) ) {
+                       throw new UnexpectedValueException( "Invalid callback." );
+               };
+
+               $this->startAtomic( $fname );
+               try {
+                       call_user_func_array( $callback, array( $this, $fname ) );
+               } catch ( Exception $e ) {
+                       $this->rollback( $fname );
+                       throw $e;
+               }
+               $this->endAtomic( $fname );
+       }
+
        /**
         * Begin a transaction. If a transaction is already in progress,
         * that transaction will be committed before the new transaction is started.
index 4674c17..31b2758 100644 (file)
@@ -1268,6 +1268,34 @@ interface IDatabase {
         */
        public function endAtomic( $fname = __METHOD__ );
 
+       /**
+        * Run a callback to do an atomic set of updates for this database
+        *
+        * The $callback takes the following arguments:
+        *   - This database object
+        *   - The value of $fname
+        *
+        * If any exception occurs in the callback, then rollback() will be called and the error will
+        * be re-thrown. It may also be that the rollback itself fails with an exception before then.
+        * In any case, such errors are expected to terminate the request, without any outside caller
+        * attempting to catch errors and commit anyway. Note that any rollback undoes all prior
+        * atomic section and uncommitted updates, which trashes the current request, requiring an
+        * error to be displayed.
+        *
+        * This can be an alternative to explicit startAtomic()/endAtomic() calls.
+        *
+        * @see DatabaseBase::startAtomic
+        * @see DatabaseBase::endAtomic
+        *
+        * @param string $fname Caller name (usually __METHOD__)
+        * @param callable $callback Callback that issues DB updates
+        * @throws DBError
+        * @throws RuntimeException
+        * @throws UnexpectedValueException
+        * @since 1.27
+        */
+       public function doAtomicSection( $fname, $callback );
+
        /**
         * Begin a transaction. If a transaction is already in progress,
         * that transaction will be committed before the new transaction is started.
diff --git a/includes/export/Dump7ZipOutput.php b/includes/export/Dump7ZipOutput.php
new file mode 100644 (file)
index 0000000..ec7a6b2
--- /dev/null
@@ -0,0 +1,67 @@
+<?php
+/**
+ * Sends dump output via the p7zip compressor.
+ *
+ * Copyright © 2003, 2005, 2006 Brion Vibber <brion@pobox.com>
+ * https://www.mediawiki.org/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
+/**
+ * @ingroup Dump
+ */
+class Dump7ZipOutput extends DumpPipeOutput {
+       /**
+        * @param string $file
+        */
+       function __construct( $file ) {
+               $command = $this->setup7zCommand( $file );
+               parent::__construct( $command );
+               $this->filename = $file;
+       }
+
+       /**
+        * @param string $file
+        * @return string
+        */
+       function setup7zCommand( $file ) {
+               $command = "7za a -bd -si -mx=4 " . wfEscapeShellArg( $file );
+               // Suppress annoying useless crap from p7zip
+               // Unfortunately this could suppress real error messages too
+               $command .= ' >' . wfGetNull() . ' 2>&1';
+               return $command;
+       }
+
+       /**
+        * @param string $newname
+        * @param bool $open
+        */
+       function closeAndRename( $newname, $open = false ) {
+               $newname = $this->checkRenameArgCount( $newname );
+               if ( $newname ) {
+                       fclose( $this->handle );
+                       proc_close( $this->procOpenResource );
+                       $this->renameOrException( $newname );
+                       if ( $open ) {
+                               $command = $this->setup7zCommand( $this->filename );
+                               $this->startCommand( $command );
+                       }
+               }
+       }
+}
diff --git a/includes/export/DumpBZip2Output.php b/includes/export/DumpBZip2Output.php
new file mode 100644 (file)
index 0000000..8767b92
--- /dev/null
@@ -0,0 +1,36 @@
+<?php
+/**
+ * Sends dump output via the bgzip2 compressor.
+ *
+ * Copyright © 2003, 2005, 2006 Brion Vibber <brion@pobox.com>
+ * https://www.mediawiki.org/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
+/**
+ * @ingroup Dump
+ */
+class DumpBZip2Output extends DumpPipeOutput {
+       /**
+        * @param string $file
+        */
+       function __construct( $file ) {
+               parent::__construct( "bzip2", $file );
+       }
+}
diff --git a/includes/export/DumpFileOutput.php b/includes/export/DumpFileOutput.php
new file mode 100644 (file)
index 0000000..de1c0a5
--- /dev/null
@@ -0,0 +1,115 @@
+<?php
+/**
+ * Stream outputter to send data to a file.
+ *
+ * Copyright © 2003, 2005, 2006 Brion Vibber <brion@pobox.com>
+ * https://www.mediawiki.org/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
+/**
+ * @ingroup Dump
+ */
+class DumpFileOutput extends DumpOutput {
+       protected $handle = false, $filename;
+
+       /**
+        * @param string $file
+        */
+       function __construct( $file ) {
+               $this->handle = fopen( $file, "wt" );
+               $this->filename = $file;
+       }
+
+       /**
+        * @param string $string
+        */
+       function writeCloseStream( $string ) {
+               parent::writeCloseStream( $string );
+               if ( $this->handle ) {
+                       fclose( $this->handle );
+                       $this->handle = false;
+               }
+       }
+
+       /**
+        * @param string $string
+        */
+       function write( $string ) {
+               fputs( $this->handle, $string );
+       }
+
+       /**
+        * @param string $newname
+        */
+       function closeRenameAndReopen( $newname ) {
+               $this->closeAndRename( $newname, true );
+       }
+
+       /**
+        * @param string $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 array $newname
+        * @return string
+        * @throws MWException
+        */
+       function checkRenameArgCount( $newname ) {
+               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];
+                       }
+               }
+               return $newname;
+       }
+
+       /**
+        * @param string $newname
+        * @param bool $open
+        */
+       function closeAndRename( $newname, $open = false ) {
+               $newname = $this->checkRenameArgCount( $newname );
+               if ( $newname ) {
+                       if ( $this->handle ) {
+                               fclose( $this->handle );
+                               $this->handle = false;
+                       }
+                       $this->renameOrException( $newname );
+                       if ( $open ) {
+                               $this->handle = fopen( $this->filename, "wt" );
+                       }
+               }
+       }
+
+       /**
+        * @return string|null
+        */
+       function getFilenames() {
+               return $this->filename;
+       }
+}
diff --git a/includes/export/DumpFilter.php b/includes/export/DumpFilter.php
new file mode 100644 (file)
index 0000000..224262d
--- /dev/null
@@ -0,0 +1,134 @@
+<?php
+/**
+ * Dump output filter class.
+ * This just does output filtering and streaming; XML formatting is done
+ * higher up, so be careful in what you do.
+ *
+ * Copyright © 2003, 2005, 2006 Brion Vibber <brion@pobox.com>
+ * https://www.mediawiki.org/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
+/**
+ * @ingroup Dump
+ */
+class DumpFilter {
+       /**
+        * @var DumpOutput
+        * FIXME will need to be made protected whenever legacy code
+        * is updated.
+        */
+       public $sink;
+
+       /**
+        * @var bool
+        */
+       protected $sendingThisPage;
+
+       /**
+        * @param DumpOutput $sink
+        */
+       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 object $page
+        * @param string $string
+        */
+       function writeOpenPage( $page, $string ) {
+               $this->sendingThisPage = $this->pass( $page, $string );
+               if ( $this->sendingThisPage ) {
+                       $this->sink->writeOpenPage( $page, $string );
+               }
+       }
+
+       /**
+        * @param string $string
+        */
+       function writeClosePage( $string ) {
+               if ( $this->sendingThisPage ) {
+                       $this->sink->writeClosePage( $string );
+                       $this->sendingThisPage = false;
+               }
+       }
+
+       /**
+        * @param object $rev
+        * @param string $string
+        */
+       function writeRevision( $rev, $string ) {
+               if ( $this->sendingThisPage ) {
+                       $this->sink->writeRevision( $rev, $string );
+               }
+       }
+
+       /**
+        * @param object $rev
+        * @param string $string
+        */
+       function writeLogItem( $rev, $string ) {
+               $this->sink->writeRevision( $rev, $string );
+       }
+
+       /**
+        * @param string $newname
+        */
+       function closeRenameAndReopen( $newname ) {
+               $this->sink->closeRenameAndReopen( $newname );
+       }
+
+       /**
+        * @param string $newname
+        * @param bool $open
+        */
+       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 object $page
+        * @return bool
+        */
+       function pass( $page ) {
+               return true;
+       }
+}
diff --git a/includes/export/DumpGZipOutput.php b/includes/export/DumpGZipOutput.php
new file mode 100644 (file)
index 0000000..3f0333e
--- /dev/null
@@ -0,0 +1,36 @@
+<?php
+/**
+ * Sends dump output via the gzip compressor.
+ *
+ * Copyright © 2003, 2005, 2006 Brion Vibber <brion@pobox.com>
+ * https://www.mediawiki.org/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
+/**
+ * @ingroup Dump
+ */
+class DumpGZipOutput extends DumpPipeOutput {
+       /**
+        * @param string $file
+        */
+       function __construct( $file ) {
+               parent::__construct( "gzip", $file );
+       }
+}
diff --git a/includes/export/DumpLatestFilter.php b/includes/export/DumpLatestFilter.php
new file mode 100644 (file)
index 0000000..d21dfa9
--- /dev/null
@@ -0,0 +1,72 @@
+<?php
+/**
+ * Dump output filter to include only the last revision in each page sequence.
+ *
+ * Copyright © 2003, 2005, 2006 Brion Vibber <brion@pobox.com>
+ * https://www.mediawiki.org/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
+/**
+ * @ingroup Dump
+ */
+class DumpLatestFilter extends DumpFilter {
+       public $page;
+
+       public $pageString;
+
+       public $rev;
+
+       public $revString;
+
+       /**
+        * @param object $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 );
+                       $this->sink->writeRevision( $this->rev, $this->revString );
+                       $this->sink->writeClosePage( $string );
+               }
+               $this->rev = null;
+               $this->revString = null;
+               $this->page = null;
+               $this->pageString = null;
+       }
+
+       /**
+        * @param object $rev
+        * @param string $string
+        */
+       function writeRevision( $rev, $string ) {
+               if ( $rev->rev_id == $this->page->page_latest ) {
+                       $this->rev = $rev;
+                       $this->revString = $string;
+               }
+       }
+}
diff --git a/includes/export/DumpMultiWriter.php b/includes/export/DumpMultiWriter.php
new file mode 100644 (file)
index 0000000..2f5a782
--- /dev/null
@@ -0,0 +1,113 @@
+<?php
+/**
+ * Base class for output stream; prints to stdout or buffer or wherever.
+ *
+ * Copyright © 2003, 2005, 2006 Brion Vibber <brion@pobox.com>
+ * https://www.mediawiki.org/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
+/**
+ * @ingroup Dump
+ */
+class DumpMultiWriter {
+
+       /**
+        * @param array $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 object $page
+        * @param string $string
+        */
+       function writeOpenPage( $page, $string ) {
+               for ( $i = 0; $i < $this->count; $i++ ) {
+                       $this->sinks[$i]->writeOpenPage( $page, $string );
+               }
+       }
+
+       /**
+        * @param string $string
+        */
+       function writeClosePage( $string ) {
+               for ( $i = 0; $i < $this->count; $i++ ) {
+                       $this->sinks[$i]->writeClosePage( $string );
+               }
+       }
+
+       /**
+        * @param object $rev
+        * @param string $string
+        */
+       function writeRevision( $rev, $string ) {
+               for ( $i = 0; $i < $this->count; $i++ ) {
+                       $this->sinks[$i]->writeRevision( $rev, $string );
+               }
+       }
+
+       /**
+        * @param array $newnames
+        */
+       function closeRenameAndReopen( $newnames ) {
+               $this->closeAndRename( $newnames, true );
+       }
+
+       /**
+        * @param array $newnames
+        * @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++ ) {
+                       $filenames[] = $this->sinks[$i]->getFilenames();
+               }
+               return $filenames;
+       }
+}
diff --git a/includes/export/DumpNamespaceFilter.php b/includes/export/DumpNamespaceFilter.php
new file mode 100644 (file)
index 0000000..c7d1b2e
--- /dev/null
@@ -0,0 +1,91 @@
+<?php
+/**
+ * Dump output filter to include or exclude pages in a given set of namespaces.
+ *
+ * Copyright © 2003, 2005, 2006 Brion Vibber <brion@pobox.com>
+ * https://www.mediawiki.org/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
+/**
+ * @ingroup Dump
+ */
+class DumpNamespaceFilter extends DumpFilter {
+       /** @var bool */
+       public $invert = false;
+
+       /** @var array */
+       public $namespaces = array();
+
+       /**
+        * @param DumpOutput $sink
+        * @param array $param
+        * @throws MWException
+        */
+       function __construct( &$sink, $param ) {
+               parent::__construct( $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_FILE"           => NS_FILE,
+                       "NS_FILE_TALK"      => NS_FILE_TALK,
+                       "NS_IMAGE"          => NS_IMAGE, // NS_IMAGE is an alias for NS_FILE
+                       "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" );
+                       }
+               }
+       }
+
+       /**
+        * @param object $page
+        * @return bool
+        */
+       function pass( $page ) {
+               $match = isset( $this->namespaces[$page->page_namespace] );
+               return $this->invert xor $match;
+       }
+}
diff --git a/includes/export/DumpNotalkFilter.php b/includes/export/DumpNotalkFilter.php
new file mode 100644 (file)
index 0000000..9974d67
--- /dev/null
@@ -0,0 +1,37 @@
+<?php
+/**
+ * Simple dump output filter to exclude all talk pages.
+ *
+ * Copyright © 2003, 2005, 2006 Brion Vibber <brion@pobox.com>
+ * https://www.mediawiki.org/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
+/**
+ * @ingroup Dump
+ */
+class DumpNotalkFilter extends DumpFilter {
+       /**
+        * @param object $page
+        * @return bool
+        */
+       function pass( $page ) {
+               return !MWNamespace::isTalk( $page->page_namespace );
+       }
+}
diff --git a/includes/export/DumpOutput.php b/includes/export/DumpOutput.php
new file mode 100644 (file)
index 0000000..bdcaf35
--- /dev/null
@@ -0,0 +1,114 @@
+<?php
+/**
+ * Base class for output stream; prints to stdout or buffer or wherever.
+ *
+ * Copyright © 2003, 2005, 2006 Brion Vibber <brion@pobox.com>
+ * https://www.mediawiki.org/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
+/**
+ * @ingroup Dump
+ */
+class DumpOutput {
+
+       /**
+        * @param string $string
+        */
+       function writeOpenStream( $string ) {
+               $this->write( $string );
+       }
+
+       /**
+        * @param string $string
+        */
+       function writeCloseStream( $string ) {
+               $this->write( $string );
+       }
+
+       /**
+        * @param object $page
+        * @param string $string
+        */
+       function writeOpenPage( $page, $string ) {
+               $this->write( $string );
+       }
+
+       /**
+        * @param string $string
+        */
+       function writeClosePage( $string ) {
+               $this->write( $string );
+       }
+
+       /**
+        * @param object $rev
+        * @param string $string
+        */
+       function writeRevision( $rev, $string ) {
+               $this->write( $string );
+       }
+
+       /**
+        * @param object $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 ) {
+               print $string;
+       }
+
+       /**
+        * Close the old file, move it to a specified name,
+        * 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 string|array $newname File name. May be a string or an array with one element
+        */
+       function closeRenameAndReopen( $newname ) {
+       }
+
+       /**
+        * 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 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 ) {
+       }
+
+       /**
+        * Returns the name of the file or files which are
+        * being written to, if there are any.
+        * @return null
+        */
+       function getFilenames() {
+               return null;
+       }
+}
diff --git a/includes/export/DumpPipeOutput.php b/includes/export/DumpPipeOutput.php
new file mode 100644 (file)
index 0000000..b4ad672
--- /dev/null
@@ -0,0 +1,102 @@
+<?php
+/**
+ * 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.
+ *
+ * Copyright © 2003, 2005, 2006 Brion Vibber <brion@pobox.com>
+ * https://www.mediawiki.org/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
+/**
+ * @ingroup Dump
+ */
+class DumpPipeOutput extends DumpFileOutput {
+       protected $command, $filename;
+       protected $procOpenResource = false;
+
+       /**
+        * @param string $command
+        * @param string $file
+        */
+       function __construct( $command, $file = null ) {
+               if ( !is_null( $file ) ) {
+                       $command .= " > " . wfEscapeShellArg( $file );
+               }
+
+               $this->startCommand( $command );
+               $this->command = $command;
+               $this->filename = $file;
+       }
+
+       /**
+        * @param string $string
+        */
+       function writeCloseStream( $string ) {
+               parent::writeCloseStream( $string );
+               if ( $this->procOpenResource ) {
+                       proc_close( $this->procOpenResource );
+                       $this->procOpenResource = false;
+               }
+       }
+
+       /**
+        * @param string $command
+        */
+       function startCommand( $command ) {
+               $spec = array(
+                       0 => array( "pipe", "r" ),
+               );
+               $pipes = array();
+               $this->procOpenResource = proc_open( $command, $spec, $pipes );
+               $this->handle = $pipes[0];
+       }
+
+       /**
+        * @param string $newname
+        */
+       function closeRenameAndReopen( $newname ) {
+               $this->closeAndRename( $newname, true );
+       }
+
+       /**
+        * @param string $newname
+        * @param bool $open
+        */
+       function closeAndRename( $newname, $open = false ) {
+               $newname = $this->checkRenameArgCount( $newname );
+               if ( $newname ) {
+                       if ( $this->handle ) {
+                               fclose( $this->handle );
+                               $this->handle = false;
+                       }
+                       if ( $this->procOpenResource ) {
+                               proc_close( $this->procOpenResource );
+                               $this->procOpenResource = false;
+                       }
+                       $this->renameOrException( $newname );
+                       if ( $open ) {
+                               $command = $this->command;
+                               $command .= " > " . wfEscapeShellArg( $this->filename );
+                               $this->startCommand( $command );
+                       }
+               }
+       }
+}
diff --git a/includes/export/WikiExporter.php b/includes/export/WikiExporter.php
new file mode 100644 (file)
index 0000000..a24418c
--- /dev/null
@@ -0,0 +1,469 @@
+<?php
+/**
+ * Base class for exporting
+ *
+ * Copyright © 2003, 2005, 2006 Brion Vibber <brion@pobox.com>
+ * https://www.mediawiki.org/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
+/**
+ * @defgroup Dump Dump
+ */
+
+/**
+ * @ingroup SpecialPage Dump
+ */
+class WikiExporter {
+       /** @var bool Return distinct author list (when not returning full history) */
+       public $list_authors = false;
+
+       /** @var bool */
+       public $dumpUploads = false;
+
+       /** @var bool */
+       public $dumpUploadFileContents = false;
+
+       /** @var string */
+       public $author_list = "";
+
+       const FULL = 1;
+       const CURRENT = 2;
+       const STABLE = 4; // extension defined
+       const LOGS = 8;
+       const RANGE = 16;
+
+       const BUFFER = 0;
+       const STREAM = 1;
+
+       const TEXT = 0;
+       const STUB = 1;
+
+       /** @var int */
+       public $buffer;
+
+       /** @var int */
+       public $text;
+
+       /** @var DumpOutput */
+       public $sink;
+
+       /**
+        * Returns the export schema version.
+        * @return string
+        */
+       public static function schemaVersion() {
+               return "0.10";
+       }
+
+       /**
+        * If using WikiExporter::STREAM to stream a large amount of data,
+        * provide a database connection which is not managed by
+        * LoadBalancer to read from: some history blob types will
+        * make additional queries to pull source data while the
+        * main query is still running.
+        *
+        * @param IDatabase $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 ) {
+               $this->db = $db;
+               $this->history = $history;
+               $this->buffer = $buffer;
+               $this->writer = new XmlDumpWriter();
+               $this->sink = new DumpOutput();
+               $this->text = $text;
+       }
+
+       /**
+        * Set the DumpOutput or DumpFilter object which will receive
+        * various row objects and XML output for filtering. Filters
+        * can be chained or used as callbacks.
+        *
+        * @param DumpOutput $sink
+        */
+       public function setOutputSink( &$sink ) {
+               $this->sink =& $sink;
+       }
+
+       public function openStream() {
+               $output = $this->writer->openStream();
+               $this->sink->writeOpenStream( $output );
+       }
+
+       public function closeStream() {
+               $output = $this->writer->closeStream();
+               $this->sink->writeCloseStream( $output );
+       }
+
+       /**
+        * Dumps a series of page and revision records for all pages
+        * in the database, either including complete history or only
+        * the most recent version.
+        */
+       public function allPages() {
+               $this->dumpFrom( '' );
+       }
+
+       /**
+        * 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 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 );
+               if ( $end ) {
+                       $condition .= ' AND page_id < ' . intval( $end );
+               }
+               $this->dumpFrom( $condition );
+       }
+
+       /**
+        * 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 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 );
+               if ( $end ) {
+                       $condition .= ' AND rev_id < ' . intval( $end );
+               }
+               $this->dumpFrom( $condition );
+       }
+
+       /**
+        * @param Title $title
+        */
+       public function pageByTitle( $title ) {
+               $this->dumpFrom(
+                       'page_namespace=' . $title->getNamespace() .
+                       ' AND page_title=' . $this->db->addQuotes( $title->getDBkey() ) );
+       }
+
+       /**
+        * @param string $name
+        * @throws MWException
+        */
+       public function pageByName( $name ) {
+               $title = Title::newFromText( $name );
+               if ( is_null( $title ) ) {
+                       throw new MWException( "Can't export invalid title" );
+               } else {
+                       $this->pageByTitle( $title );
+               }
+       }
+
+       /**
+        * @param array $names
+        */
+       public function pagesByName( $names ) {
+               foreach ( $names as $name ) {
+                       $this->pageByName( $name );
+               }
+       }
+
+       public function allLogs() {
+               $this->dumpFrom( '' );
+       }
+
+       /**
+        * @param int $start
+        * @param int $end
+        */
+       public function logsByRange( $start, $end ) {
+               $condition = 'log_id >= ' . intval( $start );
+               if ( $end ) {
+                       $condition .= ' AND log_id < ' . intval( $end );
+               }
+               $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
+        *
+        * @param array $cond
+        */
+       protected function do_list_authors( $cond ) {
+               $this->author_list = "<contributors>";
+               // rev_deleted
+
+               $res = $this->db->select(
+                       array( 'page', 'revision' ),
+                       array( 'DISTINCT rev_user_text', 'rev_user' ),
+                       array(
+                               $this->db->bitAnd( 'rev_deleted', Revision::DELETED_USER ) . ' = 0',
+                               $cond,
+                               'page_id = rev_id',
+                       ),
+                       __METHOD__
+               );
+
+               foreach ( $res as $row ) {
+                       $this->author_list .= "<contributor>" .
+                               "<username>" .
+                               htmlentities( $row->rev_user_text ) .
+                               "</username>" .
+                               "<id>" .
+                               $row->rev_user .
+                               "</id>" .
+                               "</contributor>";
+               }
+               $this->author_list .= "</contributors>";
+       }
+
+       /**
+        * @param string $cond
+        * @throws MWException
+        * @throws Exception
+        */
+       protected function dumpFrom( $cond = '' ) {
+               # For logging dumps...
+               if ( $this->history & self::LOGS ) {
+                       $where = array( 'user_id = log_user' );
+                       # Hide private logs
+                       $hideLogs = LogEventsList::getExcludeClause( $this->db );
+                       if ( $hideLogs ) {
+                               $where[] = $hideLogs;
+                       }
+                       # Add on any caller specified conditions
+                       if ( $cond ) {
+                               $where[] = $cond;
+                       }
+                       # Get logging table name for logging.* clause
+                       $logging = $this->db->tableName( 'logging' );
+
+                       if ( $this->buffer == WikiExporter::STREAM ) {
+                               $prev = $this->db->bufferResults( false );
+                       }
+                       $result = null; // Assuring $result is not undefined, if exception occurs early
+                       try {
+                               $result = $this->db->select( array( 'logging', 'user' ),
+                                       array( "{$logging}.*", 'user_name' ), // grab the user name
+                                       $where,
+                                       __METHOD__,
+                                       array( 'ORDER BY' => 'log_id', 'USE INDEX' => array( 'logging' => 'PRIMARY' ) )
+                               );
+                               $this->outputLogStream( $result );
+                               if ( $this->buffer == WikiExporter::STREAM ) {
+                                       $this->db->bufferResults( $prev );
+                               }
+                       } catch ( Exception $e ) {
+                               // Throwing the exception does not reliably free the resultset, and
+                               // would also leave the connection in unbuffered mode.
+
+                               // Freeing result
+                               try {
+                                       if ( $result ) {
+                                               $result->free();
+                                       }
+                               } catch ( Exception $e2 ) {
+                                       // Already in panic mode -> ignoring $e2 as $e has
+                                       // higher priority
+                               }
+
+                               // Putting database back in previous buffer mode
+                               try {
+                                       if ( $this->buffer == WikiExporter::STREAM ) {
+                                               $this->db->bufferResults( $prev );
+                                       }
+                               } catch ( Exception $e2 ) {
+                                       // Already in panic mode -> ignoring $e2 as $e has
+                                       // higher priority
+                               }
+
+                               // Inform caller about problem
+                               throw $e;
+                       }
+               # For page dumps...
+               } else {
+                       $tables = array( 'page', 'revision' );
+                       $opts = array( 'ORDER BY' => 'page_id ASC' );
+                       $opts['USE INDEX'] = array();
+                       $join = array();
+                       if ( is_array( $this->history ) ) {
+                               # Time offset/limit for all pages/history...
+                               $revJoin = 'page_id=rev_page';
+                               # Set time order
+                               if ( $this->history['dir'] == 'asc' ) {
+                                       $op = '>';
+                                       $opts['ORDER BY'] = 'rev_timestamp ASC';
+                               } else {
+                                       $op = '<';
+                                       $opts['ORDER BY'] = 'rev_timestamp DESC';
+                               }
+                               # Set offset
+                               if ( !empty( $this->history['offset'] ) ) {
+                                       $revJoin .= " AND rev_timestamp $op " .
+                                               $this->db->addQuotes( $this->db->timestamp( $this->history['offset'] ) );
+                               }
+                               $join['revision'] = array( 'INNER JOIN', $revJoin );
+                               # Set query limit
+                               if ( !empty( $this->history['limit'] ) ) {
+                                       $opts['LIMIT'] = intval( $this->history['limit'] );
+                               }
+                       } elseif ( $this->history & WikiExporter::FULL ) {
+                               # Full history dumps...
+                               $join['revision'] = array( 'INNER JOIN', 'page_id=rev_page' );
+                       } elseif ( $this->history & WikiExporter::CURRENT ) {
+                               # Latest revision dumps...
+                               if ( $this->list_authors && $cond != '' ) { // List authors, if so desired
+                                       $this->do_list_authors( $cond );
+                               }
+                               $join['revision'] = array( 'INNER JOIN', 'page_id=rev_page AND page_latest=rev_id' );
+                       } elseif ( $this->history & WikiExporter::STABLE ) {
+                               # "Stable" revision dumps...
+                               # Default JOIN, to be overridden...
+                               $join['revision'] = array( 'INNER JOIN', 'page_id=rev_page AND page_latest=rev_id' );
+                               # One, and only one hook should set this, and return false
+                               if ( Hooks::run( 'WikiExporter::dumpStableQuery', array( &$tables, &$opts, &$join ) ) ) {
+                                       throw new MWException( __METHOD__ . " given invalid history dump type." );
+                               }
+                       } elseif ( $this->history & WikiExporter::RANGE ) {
+                               # Dump of revisions within a specified range
+                               $join['revision'] = array( 'INNER JOIN', 'page_id=rev_page' );
+                               $opts['ORDER BY'] = array( 'rev_page ASC', 'rev_id ASC' );
+                       } else {
+                               # Unknown history specification parameter?
+                               throw new MWException( __METHOD__ . " given invalid history dump type." );
+                       }
+                       # Query optimization hacks
+                       if ( $cond == '' ) {
+                               $opts[] = 'STRAIGHT_JOIN';
+                               $opts['USE INDEX']['page'] = 'PRIMARY';
+                       }
+                       # Build text join options
+                       if ( $this->text != WikiExporter::STUB ) { // 1-pass
+                               $tables[] = 'text';
+                               $join['text'] = array( 'INNER JOIN', 'rev_text_id=old_id' );
+                       }
+
+                       if ( $this->buffer == WikiExporter::STREAM ) {
+                               $prev = $this->db->bufferResults( false );
+                       }
+
+                       $result = null; // Assuring $result is not undefined, if exception occurs early
+                       try {
+                               Hooks::run( 'ModifyExportQuery',
+                                               array( $this->db, &$tables, &$cond, &$opts, &$join ) );
+
+                               # Do the query!
+                               $result = $this->db->select( $tables, '*', $cond, __METHOD__, $opts, $join );
+                               # Output dump results
+                               $this->outputPageStream( $result );
+
+                               if ( $this->buffer == WikiExporter::STREAM ) {
+                                       $this->db->bufferResults( $prev );
+                               }
+                       } catch ( Exception $e ) {
+                               // Throwing the exception does not reliably free the resultset, and
+                               // would also leave the connection in unbuffered mode.
+
+                               // Freeing result
+                               try {
+                                       if ( $result ) {
+                                               $result->free();
+                                       }
+                               } catch ( Exception $e2 ) {
+                                       // Already in panic mode -> ignoring $e2 as $e has
+                                       // higher priority
+                               }
+
+                               // Putting database back in previous buffer mode
+                               try {
+                                       if ( $this->buffer == WikiExporter::STREAM ) {
+                                               $this->db->bufferResults( $prev );
+                                       }
+                               } catch ( Exception $e2 ) {
+                                       // Already in panic mode -> ignoring $e2 as $e has
+                                       // higher priority
+                               }
+
+                               // Inform caller about problem
+                               throw $e;
+                       }
+               }
+       }
+
+       /**
+        * Runs through a query result set dumping page and revision records.
+        * The result set should be sorted/grouped by page to avoid duplicate
+        * page records in the output.
+        *
+        * Should be safe for
+        * streaming (non-buffered) queries, as long as it was made on a
+        * separate database connection not managed by LoadBalancer; some
+        * blob storage types will make queries to pull source data.
+        *
+        * @param ResultWrapper $resultset
+        */
+       protected function outputPageStream( $resultset ) {
+               $last = null;
+               foreach ( $resultset as $row ) {
+                       if ( $last === null ||
+                               $last->page_namespace != $row->page_namespace ||
+                               $last->page_title != $row->page_title ) {
+                               if ( $last !== null ) {
+                                       $output = '';
+                                       if ( $this->dumpUploads ) {
+                                               $output .= $this->writer->writeUploads( $last, $this->dumpUploadFileContents );
+                                       }
+                                       $output .= $this->writer->closePage();
+                                       $this->sink->writeClosePage( $output );
+                               }
+                               $output = $this->writer->openPage( $row );
+                               $this->sink->writeOpenPage( $row, $output );
+                               $last = $row;
+                       }
+                       $output = $this->writer->writeRevision( $row );
+                       $this->sink->writeRevision( $row, $output );
+               }
+               if ( $last !== null ) {
+                       $output = '';
+                       if ( $this->dumpUploads ) {
+                               $output .= $this->writer->writeUploads( $last, $this->dumpUploadFileContents );
+                       }
+                       $output .= $this->author_list;
+                       $output .= $this->writer->closePage();
+                       $this->sink->writeClosePage( $output );
+               }
+       }
+
+       /**
+        * @param ResultWrapper $resultset
+        */
+       protected function outputLogStream( $resultset ) {
+               foreach ( $resultset as $row ) {
+                       $output = $this->writer->writeLogItem( $row );
+                       $this->sink->writeLogItem( $row, $output );
+               }
+       }
+}
diff --git a/includes/export/XmlDumpWriter.php b/includes/export/XmlDumpWriter.php
new file mode 100644 (file)
index 0000000..3bd4c96
--- /dev/null
@@ -0,0 +1,440 @@
+<?php
+/**
+ * XmlDumpWriter
+ *
+ * Copyright © 2003, 2005, 2006 Brion Vibber <brion@pobox.com>
+ * https://www.mediawiki.org/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
+/**
+ * @ingroup Dump
+ */
+class XmlDumpWriter {
+       /**
+        * Opens the XML output stream's root "<mediawiki>" element.
+        * This does not include an xml directive, so is safe to include
+        * as a subelement in a larger XML stream. Namespace and XML Schema
+        * references are included.
+        *
+        * Output will be encoded in UTF-8.
+        *
+        * @return string
+        */
+       function openStream() {
+               global $wgLanguageCode;
+               $ver = WikiExporter::schemaVersion();
+               return Xml::element( 'mediawiki', array(
+                       'xmlns'              => "http://www.mediawiki.org/xml/export-$ver/",
+                       'xmlns:xsi'          => "http://www.w3.org/2001/XMLSchema-instance",
+                       /*
+                        * When a new version of the schema is created, it needs staging on mediawiki.org.
+                        * This requires a change in the operations/mediawiki-config git repo.
+                        *
+                        * Create a changeset like https://gerrit.wikimedia.org/r/#/c/149643/ in which
+                        * you copy in the new xsd file.
+                        *
+                        * After it is reviewed, merged and deployed (sync-docroot), the index.html needs purging.
+                        * echo "http://www.mediawiki.org/xml/index.html" | mwscript purgeList.php --wiki=aawiki
+                        */
+                       'xsi:schemaLocation' => "http://www.mediawiki.org/xml/export-$ver/ " .
+                               "http://www.mediawiki.org/xml/export-$ver.xsd",
+                       'version'            => $ver,
+                       'xml:lang'           => $wgLanguageCode ),
+                       null ) .
+                       "\n" .
+                       $this->siteInfo();
+       }
+
+       /**
+        * @return string
+        */
+       function siteInfo() {
+               $info = array(
+                       $this->sitename(),
+                       $this->dbname(),
+                       $this->homelink(),
+                       $this->generator(),
+                       $this->caseSetting(),
+                       $this->namespaces() );
+               return "  <siteinfo>\n    " .
+                       implode( "\n    ", $info ) .
+                       "\n  </siteinfo>\n";
+       }
+
+       /**
+        * @return string
+        */
+       function sitename() {
+               global $wgSitename;
+               return Xml::element( 'sitename', array(), $wgSitename );
+       }
+
+       /**
+        * @return string
+        */
+       function dbname() {
+               global $wgDBname;
+               return Xml::element( 'dbname', array(), $wgDBname );
+       }
+
+       /**
+        * @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
+               $sensitivity = $wgCapitalLinks ? 'first-letter' : 'case-sensitive';
+               return Xml::element( 'case', array(), $sensitivity );
+       }
+
+       /**
+        * @return string
+        */
+       function namespaces() {
+               global $wgContLang;
+               $spaces = "<namespaces>\n";
+               foreach ( $wgContLang->getFormattedNamespaces() as $ns => $title ) {
+                       $spaces .= '      ' .
+                               Xml::element( 'namespace',
+                                       array(
+                                               'key' => $ns,
+                                               'case' => MWNamespace::isCapitalized( $ns ) ? 'first-letter' : 'case-sensitive',
+                                       ), $title ) . "\n";
+               }
+               $spaces .= "    </namespaces>";
+               return $spaces;
+       }
+
+       /**
+        * Closes the output stream with the closing root element.
+        * Call when finished dumping things.
+        *
+        * @return string
+        */
+       function closeStream() {
+               return "</mediawiki>\n";
+       }
+
+       /**
+        * Opens a "<page>" section on the output stream, with data
+        * from the given database row.
+        *
+        * @param object $row
+        * @return string
+        */
+       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";
+               $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 ) {
+                       $page = WikiPage::factory( $title );
+                       $redirect = $page->getRedirectTarget();
+                       if ( $redirect instanceof Title && $redirect->isValidRedirectTarget() ) {
+                               $out .= '    ';
+                               $out .= Xml::element( 'redirect', array( 'title' => self::canonicalTitle( $redirect ) ) );
+                               $out .= "\n";
+                       }
+               }
+
+               if ( $row->page_restrictions != '' ) {
+                       $out .= '    ' . Xml::element( 'restrictions', array(),
+                               strval( $row->page_restrictions ) ) . "\n";
+               }
+
+               Hooks::run( 'XmlDumpWriterOpenPage', array( $this, &$out, $row, $title ) );
+
+               return $out;
+       }
+
+       /**
+        * Closes a "<page>" section on the output stream.
+        *
+        * @access private
+        * @return string
+        */
+       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 ) {
+
+               $out = "    <revision>\n";
+               $out .= "      " . Xml::element( 'id', null, strval( $row->rev_id ) ) . "\n";
+               if ( isset( $row->rev_parent_id ) && $row->rev_parent_id ) {
+                       $out .= "      " . Xml::element( 'parentid', null, strval( $row->rev_parent_id ) ) . "\n";
+               }
+
+               $out .= $this->writeTimestamp( $row->rev_timestamp );
+
+               if ( isset( $row->rev_deleted ) && ( $row->rev_deleted & Revision::DELETED_USER ) ) {
+                       $out .= "      " . Xml::element( 'contributor', array( 'deleted' => 'deleted' ) ) . "\n";
+               } else {
+                       $out .= $this->writeContributor( $row->rev_user, $row->rev_user_text );
+               }
+
+               if ( isset( $row->rev_minor_edit ) && $row->rev_minor_edit ) {
+                       $out .= "      <minor/>\n";
+               }
+               if ( isset( $row->rev_deleted ) && ( $row->rev_deleted & Revision::DELETED_COMMENT ) ) {
+                       $out .= "      " . Xml::element( 'comment', array( 'deleted' => 'deleted' ) ) . "\n";
+               } elseif ( $row->rev_comment != '' ) {
+                       $out .= "      " . Xml::elementClean( 'comment', array(), strval( $row->rev_comment ) ) . "\n";
+               }
+
+               if ( isset( $row->rev_content_model ) && !is_null( $row->rev_content_model ) ) {
+                       $content_model = strval( $row->rev_content_model );
+               } else {
+                       // probably using $wgContentHandlerUseDB = false;
+                       $title = Title::makeTitle( $row->page_namespace, $row->page_title );
+                       $content_model = ContentHandler::getDefaultModelFor( $title );
+               }
+
+               $content_handler = ContentHandler::getForModelID( $content_model );
+
+               if ( isset( $row->rev_content_format ) && !is_null( $row->rev_content_format ) ) {
+                       $content_format = strval( $row->rev_content_format );
+               } else {
+                       // probably using $wgContentHandlerUseDB = false;
+                       $content_format = $content_handler->getDefaultFormat();
+               }
+
+               $out .= "      " . Xml::element( 'model', null, strval( $content_model ) ) . "\n";
+               $out .= "      " . Xml::element( 'format', null, strval( $content_format ) ) . "\n";
+
+               $text = '';
+               if ( isset( $row->rev_deleted ) && ( $row->rev_deleted & Revision::DELETED_TEXT ) ) {
+                       $out .= "      " . Xml::element( 'text', array( 'deleted' => 'deleted' ) ) . "\n";
+               } elseif ( isset( $row->old_text ) ) {
+                       // Raw text from the database may have invalid chars
+                       $text = strval( Revision::getRevisionText( $row ) );
+                       $text = $content_handler->exportTransform( $text, $content_format );
+                       $out .= "      " . Xml::elementClean( 'text',
+                               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' => intval( $row->rev_len ) ),
+                               "" ) . "\n";
+               }
+
+               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";
+               }
+
+               Hooks::run( 'XmlDumpWriterWriteRevision', array( &$this, &$out, $row, $text ) );
+
+               $out .= "    </revision>\n";
+
+               return $out;
+       }
+
+       /**
+        * Dumps a "<logitem>" section on the output stream, with
+        * data filled in from the given database row.
+        *
+        * @param object $row
+        * @return string
+        * @access private
+        */
+       function writeLogItem( $row ) {
+
+               $out = "  <logitem>\n";
+               $out .= "    " . Xml::element( 'id', null, strval( $row->log_id ) ) . "\n";
+
+               $out .= $this->writeTimestamp( $row->log_timestamp, "    " );
+
+               if ( $row->log_deleted & LogPage::DELETED_USER ) {
+                       $out .= "    " . Xml::element( 'contributor', array( 'deleted' => 'deleted' ) ) . "\n";
+               } else {
+                       $out .= $this->writeContributor( $row->log_user, $row->user_name, "    " );
+               }
+
+               if ( $row->log_deleted & LogPage::DELETED_COMMENT ) {
+                       $out .= "    " . Xml::element( 'comment', array( 'deleted' => 'deleted' ) ) . "\n";
+               } elseif ( $row->log_comment != '' ) {
+                       $out .= "    " . Xml::elementClean( 'comment', null, strval( $row->log_comment ) ) . "\n";
+               }
+
+               $out .= "    " . Xml::element( 'type', null, strval( $row->log_type ) ) . "\n";
+               $out .= "    " . Xml::element( 'action', null, strval( $row->log_action ) ) . "\n";
+
+               if ( $row->log_deleted & LogPage::DELETED_ACTION ) {
+                       $out .= "    " . Xml::element( 'text', array( 'deleted' => 'deleted' ) ) . "\n";
+               } else {
+                       $title = Title::makeTitle( $row->log_namespace, $row->log_title );
+                       $out .= "    " . Xml::elementClean( 'logtitle', null, self::canonicalTitle( $title ) ) . "\n";
+                       $out .= "    " . Xml::elementClean( 'params',
+                               array( 'xml:space' => 'preserve' ),
+                               strval( $row->log_params ) ) . "\n";
+               }
+
+               $out .= "  </logitem>\n";
+
+               return $out;
+       }
+
+       /**
+        * @param string $timestamp
+        * @param string $indent Default to six spaces
+        * @return string
+        */
+       function writeTimestamp( $timestamp, $indent = "      " ) {
+               $ts = wfTimestamp( TS_ISO_8601, $timestamp );
+               return $indent . Xml::element( 'timestamp', null, $ts ) . "\n";
+       }
+
+       /**
+        * @param int $id
+        * @param string $text
+        * @param string $indent Default to six spaces
+        * @return string
+        */
+       function writeContributor( $id, $text, $indent = "      " ) {
+               $out = $indent . "<contributor>\n";
+               if ( $id || !IP::isValid( $text ) ) {
+                       $out .= $indent . "  " . Xml::elementClean( 'username', null, strval( $text ) ) . "\n";
+                       $out .= $indent . "  " . Xml::element( 'id', null, strval( $id ) ) . "\n";
+               } else {
+                       $out .= $indent . "  " . Xml::elementClean( 'ip', null, strval( $text ) ) . "\n";
+               }
+               $out .= $indent . "</contributor>\n";
+               return $out;
+       }
+
+       /**
+        * Warning! This data is potentially inconsistent. :(
+        * @param object $row
+        * @param bool $dumpContents
+        * @return string
+        */
+       function writeUploads( $row, $dumpContents = false ) {
+               if ( $row->page_namespace == NS_FILE ) {
+                       $img = wfLocalFile( $row->page_title );
+                       if ( $img && $img->exists() ) {
+                               $out = '';
+                               foreach ( array_reverse( $img->getHistory() ) as $ver ) {
+                                       $out .= $this->writeUpload( $ver, $dumpContents );
+                               }
+                               $out .= $this->writeUpload( $img, $dumpContents );
+                               return $out;
+                       }
+               }
+               return '';
+       }
+
+       /**
+        * @param File $file
+        * @param bool $dumpContents
+        * @return string
+        */
+       function writeUpload( $file, $dumpContents = false ) {
+               if ( $file->isOld() ) {
+                       $archiveName = "      " .
+                               Xml::element( 'archivename', null, $file->getArchiveName() ) . "\n";
+               } else {
+                       $archiveName = '';
+               }
+               if ( $dumpContents ) {
+                       $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)
+                       $contents = '      <contents encoding="base64">' .
+                               chunk_split( base64_encode(
+                                       $be->getFileContents( array( 'src' => $file->getPath() ) ) ) ) .
+                               "      </contents>\n";
+               } else {
+                       $contents = '';
+               }
+               if ( $file->isDeleted( File::DELETED_COMMENT ) ) {
+                       $comment = Xml::element( 'comment', array( 'deleted' => 'deleted' ) );
+               } else {
+                       $comment = Xml::elementClean( 'comment', null, $file->getDescription() );
+               }
+               return "    <upload>\n" .
+                       $this->writeTimestamp( $file->getTimestamp() ) .
+                       $this->writeContributor( $file->getUser( 'id' ), $file->getUser( 'text' ) ) .
+                       "      " . $comment . "\n" .
+                       "      " . Xml::element( 'filename', null, $file->getName() ) . "\n" .
+                       $archiveName .
+                       "      " . Xml::element( 'src', null, $file->getCanonicalURL() ) . "\n" .
+                       "      " . Xml::element( 'size', null, $file->getSize() ) . "\n" .
+                       "      " . Xml::element( 'sha1base36', null, $file->getSha1() ) . "\n" .
+                       "      " . Xml::element( 'rel', null, $file->getRel() ) . "\n" .
+                       $contents .
+                       "    </upload>\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 "<siteinfo>" data so are unsafe in export.
+        *
+        * @param Title $title
+        * @return string
+        * @since 1.18
+        */
+       public static function canonicalTitle( Title $title ) {
+               if ( $title->isExternal() ) {
+                       return $title->getPrefixedText();
+               }
+
+               global $wgContLang;
+               $prefix = $wgContLang->getFormattedNsText( $title->getNamespace() );
+
+               if ( $prefix !== '' ) {
+                       $prefix .= ':';
+               }
+
+               return $prefix . $title->getText();
+       }
+}
index 9755e8e..2d25710 100644 (file)
@@ -325,25 +325,39 @@ abstract class QueryPage extends SpecialPage {
                                                $value = 0;
                                        }
 
-                                       $vals[] = array( 'qc_type' => $this->getName(),
-                                                       'qc_namespace' => $row->namespace,
-                                                       'qc_title' => $row->title,
-                                                       'qc_value' => $value );
+                                       $vals[] = array(
+                                               'qc_type' => $this->getName(),
+                                               'qc_namespace' => $row->namespace,
+                                               'qc_title' => $row->title,
+                                               'qc_value' => $value
+                                       );
                                }
 
-                               $dbw->startAtomic( __METHOD__ );
-                               # Clear out any old cached data
-                               $dbw->delete( 'querycache', array( 'qc_type' => $this->getName() ), $fname );
-                               # Save results into the querycache table on the master
-                               if ( count( $vals ) ) {
-                                       $dbw->insert( 'querycache', $vals, __METHOD__ );
-                               }
-                               # Update the querycache_info record for the page
-                               $dbw->delete( 'querycache_info', array( 'qci_type' => $this->getName() ), $fname );
-                               $dbw->insert( 'querycache_info',
-                                       array( 'qci_type' => $this->getName(), 'qci_timestamp' => $dbw->timestamp() ),
-                                       $fname );
-                               $dbw->endAtomic( __METHOD__ );
+                               $that = $this;
+                               $dbw->doAtomicSection(
+                                       __METHOD__,
+                                       function ( IDatabase $dbw, $fname ) use ( $that, $vals ) {
+                                               # Clear out any old cached data
+                                               $dbw->delete( 'querycache',
+                                                       array( 'qc_type' => $that->getName() ),
+                                                       $fname
+                                               );
+                                               # Save results into the querycache table on the master
+                                               if ( count( $vals ) ) {
+                                                       $dbw->insert( 'querycache', $vals, $fname );
+                                               }
+                                               # Update the querycache_info record for the page
+                                               $dbw->delete( 'querycache_info',
+                                                       array( 'qci_type' => $that->getName() ),
+                                                       $fname
+                                               );
+                                               $dbw->insert( 'querycache_info',
+                                                       array( 'qci_type' => $that->getName(),
+                                                               'qci_timestamp' => $dbw->timestamp() ),
+                                                       $fname
+                                               );
+                                       }
+                               );
                        }
                } catch ( DBError $e ) {
                        if ( !$ignoreErrors ) {
index e125d94..db50bd8 100644 (file)
@@ -971,6 +971,24 @@ class SpecialBlock extends FormSpecialPage {
                $out->addWikiMsg( 'blockipsuccesstext', wfEscapeWikiText( $this->target ) );
        }
 
+       /**
+        * Return an array of subpages beginning with $search that this special page will accept.
+        *
+        * @param string $search Prefix to search for
+        * @param int $limit Maximum number of results to return (usually 10)
+        * @param int $offset Number of results to skip (usually 0)
+        * @return string[] Matching subpages
+        */
+       public function prefixSearchSubpages( $search, $limit, $offset ) {
+               $user = User::newFromName( $search );
+               if ( !$user ) {
+                       // No prefix suggestion for invalid user
+                       return array();
+               }
+               // Autocomplete subpage as user list - public to allow caching
+               return UserNamePrefixSearch::search( 'public', $search, $limit, $offset );
+       }
+
        protected function getGroupName() {
                return 'users';
        }
index bf3ab90..ab6614b 100644 (file)
@@ -645,6 +645,24 @@ class SpecialContributions extends IncludableSpecialPage {
                return $form;
        }
 
+       /**
+        * Return an array of subpages beginning with $search that this special page will accept.
+        *
+        * @param string $search Prefix to search for
+        * @param int $limit Maximum number of results to return (usually 10)
+        * @param int $offset Number of results to skip (usually 0)
+        * @return string[] Matching subpages
+        */
+       public function prefixSearchSubpages( $search, $limit, $offset ) {
+               $user = User::newFromName( $search );
+               if ( !$user ) {
+                       // No prefix suggestion for invalid user
+                       return array();
+               }
+               // Autocomplete subpage as user list - public to allow caching
+               return UserNamePrefixSearch::search( 'public', $search, $limit, $offset );
+       }
+
        protected function getGroupName() {
                return 'users';
        }
index 6f8e786..f6d560f 100644 (file)
@@ -658,6 +658,24 @@ class DeletedContributionsPage extends SpecialPage {
                return $f;
        }
 
+       /**
+        * Return an array of subpages beginning with $search that this special page will accept.
+        *
+        * @param string $search Prefix to search for
+        * @param int $limit Maximum number of results to return (usually 10)
+        * @param int $offset Number of results to skip (usually 0)
+        * @return string[] Matching subpages
+        */
+       public function prefixSearchSubpages( $search, $limit, $offset ) {
+               $user = User::newFromName( $search );
+               if ( !$user ) {
+                       // No prefix suggestion for invalid user
+                       return array();
+               }
+               // Autocomplete subpage as user list - public to allow caching
+               return UserNamePrefixSearch::search( 'public', $search, $limit, $offset );
+       }
+
        protected function getGroupName() {
                return 'users';
        }
index 3b31530..618e700 100644 (file)
@@ -392,6 +392,24 @@ class SpecialEmailUser extends UnlistedSpecialPage {
                }
        }
 
+       /**
+        * Return an array of subpages beginning with $search that this special page will accept.
+        *
+        * @param string $search Prefix to search for
+        * @param int $limit Maximum number of results to return (usually 10)
+        * @param int $offset Number of results to skip (usually 0)
+        * @return string[] Matching subpages
+        */
+       public function prefixSearchSubpages( $search, $limit, $offset ) {
+               $user = User::newFromName( $search );
+               if ( !$user ) {
+                       // No prefix suggestion for invalid user
+                       return array();
+               }
+               // Autocomplete subpage as user list - public to allow caching
+               return UserNamePrefixSearch::search( 'public', $search, $limit, $offset );
+       }
+
        protected function getGroupName() {
                return 'users';
        }
index bb57ee0..323903e 100644 (file)
@@ -241,7 +241,7 @@ class FileDuplicateSearchPage extends QueryPage {
         * @return string[] Matching subpages
         */
        public function prefixSearchSubpages( $search, $limit, $offset ) {
-               $title = Title::newFromText( $search );
+               $title = Title::newFromText( $search, NS_FILE );
                if ( !$title || $title->getNamespace() !== NS_FILE ) {
                        // No prefix suggestion outside of file namespace
                        return array();
index 8de4e2f..9a73a25 100644 (file)
@@ -57,6 +57,24 @@ class SpecialListFiles extends IncludableSpecialPage {
                }
        }
 
+       /**
+        * Return an array of subpages beginning with $search that this special page will accept.
+        *
+        * @param string $search Prefix to search for
+        * @param int $limit Maximum number of results to return (usually 10)
+        * @param int $offset Number of results to skip (usually 0)
+        * @return string[] Matching subpages
+        */
+       public function prefixSearchSubpages( $search, $limit, $offset ) {
+               $user = User::newFromName( $search );
+               if ( !$user ) {
+                       // No prefix suggestion for invalid user
+                       return array();
+               }
+               // Autocomplete subpage as user list - public to allow caching
+               return UserNamePrefixSearch::search( 'public', $search, $limit, $offset );
+       }
+
        protected function getGroupName() {
                return 'media';
        }
index 6e67df0..fb78a40 100644 (file)
@@ -144,6 +144,7 @@ class MediaStatisticsPage extends QueryPage {
                        $this->getOutput()->addWikiText(
                                $this->msg( 'mediastatistics-allbytes' )
                                        ->numParams( $this->totalSize )
+                                       ->sizeParams( $this->totalSize )
                                        ->text()
                        );
                }
@@ -157,6 +158,8 @@ class MediaStatisticsPage extends QueryPage {
                $this->getOutput()->addWikiText(
                                $this->msg( 'mediastatistics-bytespertype' )
                                        ->numParams( $this->totalPerType )
+                                       ->sizeParams( $this->totalPerType )
+                                       ->numParams( $this->makePercentPretty( $this->totalPerType / $this->totalBytes ) )
                                        ->text()
                );
                $this->totalSize += $this->totalPerType;
index 49ab6d5..b45946f 100644 (file)
@@ -128,7 +128,7 @@ class SpecialPreferences extends SpecialPage {
                        throw new PermissionsError( 'editmyoptions' );
                }
 
-               $user = $this->getUser();
+               $user = $this->getUser()->getInstanceForUpdate();
                $user->resetOptions( 'all', $this->getContext() );
                $user->saveSettings();
 
index f81f1c3..f776832 100644 (file)
@@ -237,6 +237,24 @@ class SpecialUnblock extends SpecialPage {
                return true;
        }
 
+       /**
+        * Return an array of subpages beginning with $search that this special page will accept.
+        *
+        * @param string $search Prefix to search for
+        * @param int $limit Maximum number of results to return (usually 10)
+        * @param int $offset Number of results to skip (usually 0)
+        * @return string[] Matching subpages
+        */
+       public function prefixSearchSubpages( $search, $limit, $offset ) {
+               $user = User::newFromName( $search );
+               if ( !$user ) {
+                       // No prefix suggestion for invalid user
+                       return array();
+               }
+               // Autocomplete subpage as user list - public to allow caching
+               return UserNamePrefixSearch::search( 'public', $search, $limit, $offset );
+       }
+
        protected function getGroupName() {
                return 'users';
        }
index ea22274..cf94e50 100644 (file)
@@ -776,6 +776,24 @@ class UserrightsPage extends SpecialPage {
                LogEventsList::showLogExtract( $output, 'rights', $user->getUserPage() );
        }
 
+       /**
+        * Return an array of subpages beginning with $search that this special page will accept.
+        *
+        * @param string $search Prefix to search for
+        * @param int $limit Maximum number of results to return (usually 10)
+        * @param int $offset Number of results to skip (usually 0)
+        * @return string[] Matching subpages
+        */
+       public function prefixSearchSubpages( $search, $limit, $offset ) {
+               $user = User::newFromName( $search );
+               if ( !$user ) {
+                       // No prefix suggestion for invalid user
+                       return array();
+               }
+               // Autocomplete subpage as user list - public to allow caching
+               return UserNamePrefixSearch::search( 'public', $search, $limit, $offset );
+       }
+
        protected function getGroupName() {
                return 'users';
        }
diff --git a/includes/templates/EnhancedChangesListGroup.mustache b/includes/templates/EnhancedChangesListGroup.mustache
new file mode 100644 (file)
index 0000000..352eb17
--- /dev/null
@@ -0,0 +1,28 @@
+<table class="{{# tableClasses }}{{ . }} {{/ tableClasses }}">
+       <tr>
+               <td>
+                       <span class="mw-collapsible-toggle mw-collapsible-arrow mw-enhancedchanges-arrow mw-enhancedchanges-arrow-space"></span>
+               </td>
+               <td class="mw-enhanced-rc">{{{ collectedRcFlags }}}&#160;{{ timestamp }}&#160;</td>
+               <td>
+                       {{# rev-deleted-event }}<span class="history-deleted">{{{ . }}}</span>{{/ rev-deleted-event }}
+                       {{{ articleLink }}}{{{ languageDirMark }}}{{{ logText }}}
+                       <span class="mw-changeslist-separator">. .</span>
+                       {{# charDifference }}{{{ . }}} <span class="mw-changeslist-separator">. .</span>{{/ charDifference }}
+                       <span class="changedby">{{{ users }}}</span>
+                       {{ numberofWatchingusers }}
+               </td>
+       </tr>
+       {{# lines }}
+       <tr class="{{# classes }}{{ . }} {{/ classes }}">
+               <td></td>
+               <td class="mw-enhanced-rc">{{{ recentChangesFlags }}}&#160;</td>
+               <td class="mw-enhanced-rc-nested">
+                       {{# timestampLink }}
+                       <span class="mw-enhanced-rc-time">{{{ . }}}</span>
+                       {{/ timestampLink }}
+                       {{# data }}{{{ . }}}{{/ data }}
+               </td>
+       </tr>
+       {{/ lines }}
+</table>
diff --git a/includes/user/UserNamePrefixSearch.php b/includes/user/UserNamePrefixSearch.php
new file mode 100644 (file)
index 0000000..f565266
--- /dev/null
@@ -0,0 +1,70 @@
+<?php
+/**
+ * Prefix search of user names.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
+/**
+ * Handles searching prefixes of user names
+ *
+ * @since 1.27
+ */
+class UserNamePrefixSearch {
+
+       /**
+        * Do a prefix search of user names and return a list of matching user names.
+        *
+        * @param string|User $audience The string 'public' or a user object to show the search for
+        * @param string $search
+        * @param int $limit
+        * @param int $offset How many results to offset from the beginning
+        * @return array Array of strings
+        */
+       public static function search( $audience, $search, $limit, $offset = 0 ) {
+               $user = User::newFromName( $search );
+
+               $dbr = wfGetDB( DB_SLAVE );
+               $prefix = $user ? $user->getName() : '';
+               $tables = array( 'user' );
+               $cond = array( 'user_name ' . $dbr->buildLike( $prefix, $dbr->anyString() ) );
+               $joinConds = array();
+
+               // Filter out hidden user names
+               if ( $audience === 'public' || !$audience->isAllowed( 'hideuser' ) ) {
+                       $tables[] = 'ipblocks';
+                       $cond['ipb_deleted'] = array( 0, null );
+                       $joinConds['ipblocks'] = array( 'LEFT JOIN', 'user_id=ipb_user' );
+               }
+
+               $res = $dbr->selectFieldValues(
+                       $tables,
+                       'user_name',
+                       $cond,
+                       __METHOD__,
+                       array(
+                               'LIMIT' => $limit,
+                               'ORDER BY' => 'user_name',
+                               'OFFSET' => $offset
+                       ),
+                       $joinConds
+               );
+
+               return $res === false ? array() : $res;
+       }
+}
index 349cac6..688e9b8 100644 (file)
        "mediastatistics-summary": "Statistics about uploaded file types. This only includes the most recent version of a file. Old or deleted versions of files are excluded.",
        "mediastatistics-nfiles": "$1 ($2%)",
        "mediastatistics-nbytes": "{{PLURAL:$1|$1 byte|$1 bytes}} ($2; $3%)",
-       "mediastatistics-bytespertype": "Total file size for this section: $1 bytes.",
-       "mediastatistics-allbytes": "Total file size for all files: $1 bytes.",
+       "mediastatistics-bytespertype": "Total file size for this section: {{PLURAL:$1|$1 byte|$1 bytes}} ($2; $3%).",
+       "mediastatistics-allbytes": "Total file size for all files: {{PLURAL:$1|$1 byte|$1 bytes}} ($2).",
        "mediastatistics-table-mimetype": "MIME type",
        "mediastatistics-table-extensions": "Possible extensions",
        "mediastatistics-table-count": "Number of files",
index 87470bf..0d02549 100644 (file)
        "mediastatistics-summary": "Used to explain that this page only does statistics over current versions of files. \"Old\" versions of files and deleted files are not counted.",
        "mediastatistics-nfiles": "{{optional}}\nEntry in table on [[Special:MediaStatistics]] that gives total number of files. $1 - number of files. $2 - percentage of total files that is this type (percent will be formatted to have about 3 interesting digits. e.g. 0.121 or 10.2)",
        "mediastatistics-nbytes": "Combined space of this type of file. Bytes and \"human units\" are shown so that users can better get a sense of magnitude when making comparisons.\n*$1 - total space in bytes.\n*$2 - total space in \"human units\" (i.e. KB, MB, GB, etc)\n*$3 - What percentage of the space all uploads take up does this file take up.",
-       "mediastatistics-bytespertype": "Combined space of one section of [[Special:MediaStatistics]]. \n*$1 - total space in bytes",
-       "mediastatistics-allbytes": "Combined space of all uploaded files. \n*$1 - total space in bytes",
+       "mediastatistics-bytespertype": "Combined space of one section of [[Special:MediaStatistics]]. \n*$1 - total space in bytes\n*$2 - total space in \"human units\" (i.e. KB, MB, GB, etc)\n*$3 - What percentage of the space all uploads take up does this file take up.",
+       "mediastatistics-allbytes": "Combined space of all uploaded files. \n*$1 - total space in bytes\n*$2 - total space in \"human units\" (i.e. KB, MB, GB, etc)",
        "mediastatistics-table-mimetype": "Header for table on Special:MediaStatistics. Column that lists MIME types (The values in this column will look like 'image/jpeg', and be linked to Special:MIMESearch).",
        "mediastatistics-table-extensions": "Header for column in tables on [[Special:MediaStatistics]] that lists possible extensions for a given file type. (The values in this column will be a comma separated list of file extensions, such as '.webm' or '.png, .apng').",
        "mediastatistics-table-count": "Column header on Special:MediaStatistics for the number of files column. The headers in this column use {{msg-mw|mediastatistics-nfiles}}.",
index 3f8a899..f3e2db0 100644 (file)
@@ -22,7 +22,6 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  * http://www.gnu.org/copyleft/gpl.html
  *
- * @todo Report PHP version, OS ..
  * @file
  * @ingroup Benchmark
  */
@@ -39,7 +38,7 @@ abstract class Benchmarker extends Maintenance {
 
        public function __construct() {
                parent::__construct();
-               $this->addOption( 'count', "How many time to run a benchmark", false, true );
+               $this->addOption( 'count', "How many times to run a benchmark", false, true );
        }
 
        public function bench( array $benchs ) {
@@ -76,7 +75,13 @@ abstract class Benchmarker extends Maintenance {
        }
 
        public function getFormattedResults() {
-               $ret = '';
+               $ret = sprintf( "Running PHP version %s (%s) on %s %s %s\n\n",
+                       phpversion(),
+                       php_uname( 'm' ),
+                       php_uname( 's' ),
+                       php_uname( 'r' ),
+                       php_uname( 'v' )
+               );
                foreach ( $this->results as $res ) {
                        // show function with args
                        $ret .= sprintf( "%s times: function %s(%s) :\n",
index d87e117..3b4a403 100644 (file)
 @colorGray7: #777;
 @colorGray8: #888;
 @colorGray9: #999;
-@colorGray10: #AAA;
-@colorGray11: #BBB;
-@colorGray12: #CCC;
-@colorGray13: #DDD;
-@colorGray14: #EEE;
-@colorGray15: #F9F9F9; // lightest
+@colorGray10: #aaa;
+@colorGray11: #bbb;
+@colorGray12: #ccc;
+@colorGray13: #ddd;
+@colorGray14: #eee;
+@colorGray15: #f9f9f9; // lightest
 
 // Semantic background colors
 // Blue; for contextual use of a continuing action
 @colorProgressive: #347bff;
-@colorProgressiveHighlight: #2962CC;
-@colorProgressiveActive: #2962CC;
+@colorProgressiveHighlight: #2962cc;
+@colorProgressiveActive: #2962cc;
 // Green; for contextual use of a positive finalizing action
 @colorConstructive: #00af89;
-@colorConstructiveHighlight: #008C6D;
-@colorConstructiveActive: #008C6D;
+@colorConstructiveHighlight: #008c6d;
+@colorConstructiveActive: #008c6d;
 // Orange; for contextual use of returning to a past action
-@colorRegressive: #FF5D00;
+@colorRegressive: #ff5d00;
 // Red; for contextual use of a negative action of high severity
 @colorDestructive: #d11d13;
-@colorDestructiveHighlight: #A7170F;
-@colorDestructiveActive: #A7170F;
+@colorDestructiveHighlight: #a7170f;
+@colorDestructiveActive: #a7170f;
 // Orange; for contextual use of a potentially negative action of medium severity
-@colorMediumSevere: #FF5D00;
+@colorMediumSevere: #ff5d00;
 // Yellow; for contextual use of a potentially negative action of low severity
-@colorLowSevere: #FFB50D;
+@colorLowSevere: #ffb50d;
 
 // Used in mixins to darken contextual colors by the same amount (eg. focus)
 @colorDarkenPercentage: 13.5%;
@@ -50,7 +50,7 @@
 @colorButtonTextHighlight: @colorGray7;
 @colorButtonTextActive: @colorGray7;
 @colorDisabledText: @colorGray12;
-@colorErrorText: #CC0000;
+@colorErrorText: #c00;
 
 // UI colors
 @colorFieldBorder: @colorGray12;
index 0ed8270..7437a8c 100644 (file)
@@ -14,6 +14,7 @@
 # Plus any combination of these:
 #
 # cat           add category links
+#               (ignored by Parsoid, since it emits <link>s)
 # ill           add inter-language links
 #               (ignored by Parsoid, since it emits <link>s)
 # subpage       enable subpages (disabled by default)
@@ -1335,6 +1336,8 @@ array (
 )
 </pre>
 
+!! html/parsoid
+<pre typeof="mw:Extension/tåg" data-mw='{"name":"tåg","attrs":{},"body":{"extsrc":"tåg"}}' data-parsoid='{}' about="#mwt2"></pre>
 !! end
 
 !! test
@@ -3329,14 +3332,18 @@ parsoid=wt2html,wt2wt
 <span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":" [[Category:foo]]"}},"i":0}}]}'> </span><link rel="mw:PageProp/Category" href="./Category:Foo" about="#mwt1"> <!-- No pre&#x2D;wrapping -->
 !! end
 
+## We used to, but no longer wt2wt this test since the default serializer
+## will normalize all categories to serialize on their own line.
+## This wikitext usage is going to be fairly uncommon in production and
+## selser will take care of preserving formatting in those scenarios.
 !! test
 7b. Indent-pre and category links
 !! options
-parsoid=wt2html,wt2wt
+parsoid=wt2html
 !! wikitext
  [[Category:foo]] a
  [[Category:foo]] {{echo|b}}
-!! html
+!! html/parsoid
 <pre><link rel="mw:PageProp/Category" href="./Category:Foo"> a
  <link rel="mw:PageProp/Category" href="./Category:Foo"> <span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"b"}},"i":0}}]}'>b</span></pre>
 !! end
@@ -7119,6 +7126,17 @@ Piped link with multiple pipe characters in link text
 <p><a rel="mw:WikiLink" href="Main_Page" title="Main Page">|The|Main|Page|</a></p>
 !! end
 
+!! test
+Piped link with no link text
+!! wikitext
+[[Thomas Bek (bishop of St David's)|]]
+!! html/php
+<p>[[Thomas Bek (bishop of St David's)|]]
+</p>
+!! html/parsoid
+<p>[[Thomas Bek (bishop of St David's)|]]</p>
+!! end
+
 !! test
 Broken link
 !! wikitext
@@ -10860,8 +10878,14 @@ Un-closed <includeonly>
 !! html
 !! end
 
+## We used to, but no longer wt2wt this test since the default serializer
+## will normalize the include directives to serialize on their own line.
+## Selser will take care of preserving formatting in scenarios where they
+## intermingled with other wikitext.
 !! test
 Includes and comments at SOL
+!! options
+parsoid=wt2html,html2html
 !! wikitext
 <!-- comment --><noinclude><!-- comment --></noinclude><!-- comment -->== hu ==
 
@@ -11042,10 +11066,14 @@ parsoid=wt2html,wt2wt
 </tbody></table>
 !!end
 
+## We used to, but no longer wt2wt this test since the default serializer
+## will normalize the include directives to serialize on their own line.
+## Selser will take care of preserving formatting in scenarios where they
+## intermingled with other wikitext.
 !!test
 2. Table tag in SOL posn. should get reparsed correctly with valid TSR
 !!options
-parsoid=wt2html,wt2wt
+parsoid=wt2html
 !!wikitext
 <includeonly>a</includeonly>{| {{{b}}}
 |c
@@ -14245,7 +14273,7 @@ cat
 pst
 !! wikitext
 [[Category:MediaWiki User's Guide|]]
-!! html
+!! html/php
 [[Category:MediaWiki User's Guide|MediaWiki User's Guide]]
 !! end
 
@@ -14256,19 +14284,26 @@ cat
 pst
 !! wikitext
 [[Category:Foo (bar)|]]
-!! html
+!! html/php
 [[Category:Foo (bar)|Foo]]
 !! end
 
+## We used to, but no longer wt2wt this test since the default serializer
+## will normalize all categories to serialize on their own line.
+## This wikitext usage is going to be fairly uncommon in production and
+## selser will take care of preserving formatting in those scenarios.
 !! test
 Category with link tail
 !! options
 cat
 pst
+parsoid=wt2html
 !! wikitext
 123[[Category:Foo]]456
-!! html
+!! html/php
 123[[Category:Foo]]456
+!! html/parsoid
+<p>123<link rel="mw:PageProp/Category" href="Category:Foo"/>456</p>
 !! end
 
 !! test
@@ -14278,7 +14313,7 @@ cat
 pst
 !! wikitext
 [[Category:{{echo|Foo}}]]
-!! html
+!! html/php
 [[Category:{{echo|Foo}}]]
 !! end
 
@@ -14289,7 +14324,7 @@ cat
 pst
 !! wikitext
 [[Category:Foo|{{echo|Bar}}]]
-!! html
+!! html/php
 [[Category:Foo|{{echo|Bar}}]]
 !! end
 
@@ -14300,12 +14335,18 @@ cat
 pst
 !! wikitext
 [[Category:{{echo|Foo}}|{{echo|Bar}}]]
-!! html
+!! html/php
 [[Category:{{echo|Foo}}|{{echo|Bar}}]]
 !! end
 
+## We used to, but no longer wt2wt this test since the default serializer
+## will normalize all categories to serialize on their own line.
+## This wikitext usage is going to be fairly uncommon in production and
+## selser will take care of preserving formatting in those scenarios.
 !! test
 Category / paragraph interactions
+!! options
+parsoid=wt2html
 !! wikitext
 Foo [[Category:Baz]] Bar
 
@@ -14332,7 +14373,7 @@ Bar
 [[Category:Baz]]
  {{echo|[[Category:Baz]]}}
 [[Category:Baz]]
-!! html
+!! html/php
 <p>Foo Bar
 </p><p>Foo
 Bar
@@ -14342,20 +14383,32 @@ Bar
 </p><p>Foo
 Bar
 </p>
+!! html/parsoid
+<p>Foo <link rel="mw:PageProp/Category" href="Category:Baz"/> Bar</p>
+<p>Foo <link rel="mw:PageProp/Category" href="Category:Baz"/> Bar</p>
+<p>Foo <link rel="mw:PageProp/Category" href="Category:Baz"/> Bar</p>
+<p>Foo <link rel="mw:PageProp/Category" href="Category:Baz"/> Bar</p>
+<p>Foo <link rel="mw:PageProp/Category" href="Category:Baz"/> <link rel="mw:PageProp/Category" href="Category:Baz"/> <link rel="mw:PageProp/Category" href="Category:Baz"/> Bar <link rel="mw:PageProp/Category" href="Category:Baz"/> <link rel="mw:PageProp/Category" href="Category:Baz"/> <link rel="mw:PageProp/Category" href="Category:Baz"/> <link rel="mw:PageProp/Category" href="Category:Baz"/> <link rel="mw:PageProp/Category" href="Category:Baz" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"[[Category:Baz]]"}},"i":0}}]}'/></p>
+<link rel="mw:PageProp/Category" href="Category:Baz"/>
 !! end
 
+## We used to, but no longer wt2wt this test since the default serializer
+## will normalize all categories to serialize on their own line.
+## This wikitext usage is going to be fairly uncommon in production and
+## selser will take care of preserving formatting in those scenarios.
+##
 ## The whitespace on the empty line is part of the test. Please do not delete
 !! test
 1. Categories and newlines: All preceding newlines should be suppressed (courtesy bug 87)
 !! options
-parsoid=wt2html,wt2wt
+parsoid=wt2html
 !! wikitext
 This
    
 [[Category:Foo]] and this should be part of same paragraph (not an indent-pre)
    
 {{echo|[[Category:Foo]] and so should this!}}
-!! html
+!! html/php
 <p>This and this should be part of same paragraph (not an indent-pre) and so should this!
 </p>
 !! html/parsoid
@@ -14453,8 +14506,14 @@ parsoid=wt2html
 <link rel="mw:PageProp/Category" href="./Category:Foo" data-parsoid='{"stx":"simple","a":{"href":"./Category:Foo"},"sa":{"href":"Category:Foo"}}'/>
 !! end
 
+## We used to, but no longer wt2wt this test since the default serializer
+## will normalize all categories to serialize on their own line.
+## This wikitext usage is going to be fairly uncommon in production and
+## selser will take care of preserving formatting in those scenarios.
 !! test
 6. Categories and newlines: migrateTrailingCategories dom pass should not migrate categories not preceded by newlines
+!! options
+parsoid=wt2html
 !! wikitext
 * a [[Category:Foo]]
 !! html/parsoid
@@ -14505,13 +14564,20 @@ parsoid
 </p>
 !! end
 
-# html2wt localizes the "Category" namespace.
-# XXX the <link> element needs an empty data-parsoid attribute, or
-# else the html2html test fails because spaces are inserted.
+# We used to, but no longer wt2wt this test since the default serializer
+# will normalize all categories to serialize on their own line.
+# This wikitext usage is going to be fairly uncommon in production and
+# selser will take care of preventing whitespace insertion if this
+# occurs in an article.
+#
+# html2html disabled for the same reason (whitespace insertion between
+# x and y).
+#
+# html2wt disabled because it localizes the "Category" namespace.
 !! test
 Link prefix/suffixes aren't applied to category links
 !! options
-parsoid=wt2html,wt2wt,html2html
+parsoid=wt2html
 language=is
 !! wikitext
 x[[Category:Foo]]y
@@ -16152,10 +16218,15 @@ array (
 )
 </pre>
 
+!! html/parsoid
+<pre typeof="mw:Extension/tag" data-mw='{"name":"tag","attrs":{},"body":{"extsrc":""}}' data-parsoid='{}' about="#mwt2"></pre>
 !! end
 
+## Don't expect parsoid to rt this form.
 !! test
 Parser hook: empty input using terminated empty elements
+!! options
+parsoid=wt2html,html2html
 !! wikitext
 <tag/>
 !! html/php
@@ -16165,6 +16236,8 @@ array (
 )
 </pre>
 
+!! html/parsoid
+<pre typeof="mw:Extension/tag" data-mw='{"name":"tag","attrs":{},"body":null}' data-parsoid='{}' about="#mwt2"></pre>
 !! end
 
 !! test
@@ -16178,6 +16251,8 @@ array (
 )
 </pre>
 
+!! html/parsoid
+<pre typeof="mw:Extension/tag" data-mw='{"name":"tag","attrs":{},"body":null}' data-parsoid='{}' about="#mwt2"></pre>
 !! end
 
 !! test
@@ -16191,11 +16266,15 @@ array (
 )
 </pre>
 
+!! html/parsoid
+<pre typeof="mw:Extension/tag" data-mw='{"name":"tag","attrs":{},"body":{"extsrc":"input"}}' data-parsoid='{}' about="#mwt2"></pre>
 !! end
 
-
+## Don't expect parsoid to rt this form.
 !! test
 Parser hook: case insensitive
+!! options
+parsoid=wt2html,html2html
 !! wikitext
 <TAG>input</TAG>
 !! html/php
@@ -16205,11 +16284,15 @@ array (
 )
 </pre>
 
+!! html/parsoid
+<pre typeof="mw:Extension/tag" data-mw='{"name":"tag","attrs":{},"body":{"extsrc":"input"}}' data-parsoid='{}' about="#mwt2"></pre>
 !! end
 
-
+## Don't expect parsoid to rt this form.
 !! test
 Parser hook: case insensitive, redux
+!! options
+parsoid=wt2html,html2html
 !! wikitext
 <TaG>input</TAg>
 !! html/php
@@ -16219,6 +16302,8 @@ array (
 )
 </pre>
 
+!! html/parsoid
+<pre typeof="mw:Extension/tag" data-mw='{"name":"tag","attrs":{},"body":{"extsrc":"input"}}' data-parsoid='{}' about="#mwt2"></pre>
 !! end
 
 !! test
@@ -16234,11 +16319,35 @@ array (
 )
 </pre>&lt;/tag&gt;
 
+!! html/parsoid
+<pre typeof="mw:Extension/tag" data-mw='{"name":"tag","attrs":{},"body":{"extsrc":"&lt;tag>"}}' data-parsoid='{}' about="#mwt2"></pre>&lt;/tag>
 !! end
 
 !! test
 Parser hook: basic arguments
 !! wikitext
+<tag width="200" height="100" depth="50" square=""></tag>
+!! html/php
+<pre>
+''
+array (
+  'width' => '200',
+  'height' => '100',
+  'depth' => '50',
+  'square' => '',
+)
+</pre>
+
+!! html/parsoid
+<pre typeof="mw:Extension/tag" data-mw='{"name":"tag","attrs":{"width":"200","height":"100","depth":"50","square":""},"body":{"extsrc":""}}' data-parsoid='{}' about="#mwt2"></pre>
+!! end
+
+## Don't expect parsoid to rt this form.
+!! test
+Parser hook: basic arguments, variations
+!! options
+parsoid=wt2html,html2html
+!! wikitext
 <tag width=200 height = "100" depth = '50' square></tag>
 !! html/php
 <pre>
@@ -16251,12 +16360,14 @@ array (
 )
 </pre>
 
+!! html/parsoid
+<pre typeof="mw:Extension/tag" data-mw='{"name":"tag","attrs":{"width":"200","height":"100","depth":"50","square":""},"body":{"extsrc":""}}' data-parsoid='{}' about="#mwt2"></pre>
 !! end
 
 !! test
 Parser hook: argument containing a forward slash (bug 5344)
 !! wikitext
-<tag filename='/tmp/bla'></tag>
+<tag filename="/tmp/bla"></tag>
 !! html/php
 <pre>
 ''
@@ -16265,10 +16376,15 @@ array (
 )
 </pre>
 
+!! html/parsoid
+<pre typeof="mw:Extension/tag" data-mw='{"name":"tag","attrs":{"filename":"/tmp/bla"},"body":{"extsrc":""}}' data-parsoid='{}' about="#mwt2"></pre>
 !! end
 
+## Don't expect parsoid to rt this form.
 !! test
 Parser hook: empty input using terminated empty elements (bug 2374)
+!! options
+parsoid=wt2html,html2html
 !! wikitext
 <tag foo=bar/>text
 !! html/php
@@ -16279,6 +16395,8 @@ array (
 )
 </pre>text
 
+!! html/parsoid
+<pre typeof="mw:Extension/tag" data-mw='{"name":"tag","attrs":{"foo":"bar"},"body":null}' data-parsoid='{}' about="#mwt2"></pre>text
 !! end
 
 # </tag> should be output literally since there is no matching tag that begins it
@@ -16311,21 +16429,28 @@ array (
 Parser hook: static parser hook not inside a comment
 !! wikitext
 <statictag>hello, world</statictag>
-<statictag action=flush/>
+
+<statictag action="flush" />
 !! html/php
-<p>hello, world
+<p><br />
+hello, world
 </p>
+!! html/parsoid
+<p><span typeof="mw:Extension/statictag" data-mw='{"name":"statictag","attrs":{},"body":{"extsrc":"hello, world"}}' data-parsoid='{}' about="#mwt2"></span></p>
+<p typeof="mw:Extension/statictag" data-mw='{"name":"statictag","attrs":{"action":"flush"},"body":null}' data-parsoid='{}' about="#mwt4">hello, world</p>
 !! end
 
-
 !! test
 Parser hook: static parser hook inside a comment
 !! wikitext
 <!-- <statictag>hello, world</statictag> -->
-<statictag action=flush/>
+<statictag action="flush" />
 !! html/php
 <p><br />
 </p>
+!! html/parsoid
+<!-- <statictag&#x3E;hello, world</statictag&#x3E; -->
+<p typeof="mw:Extension/statictag" data-mw='{"name":"statictag","attrs":{"action":"flush"},"body":null}' data-parsoid='{}' about="#mwt2"></p>
 !! end
 
 # Nested template calls; this case was broken by Parser.php rev 1.506,
@@ -19211,17 +19336,25 @@ Category:分類
 blah
 !! endarticle
 
+## We used to, but no longer wt2wt this test since the default serializer
+## will normalize all categories to serialize on their own line.
+## This wikitext usage is going to be fairly uncommon in production and
+## selser will take care of preserving formatting in those scenarios.
 !! test
 Don't convert blue categorylinks to another variant (bug 33210)
 !! options
-language=zh cat
+cat
+language=zh
+parsoid=wt2html
 !! wikitext
 [[A]][[Category:分类]]
-!! html
+!! html/php
 <a href="/wiki/Category:%E5%88%86%E7%B1%BB" title="Category:分类">分类</a>
+!! html/parsoid
+<p><a rel="mw:WikiLink" href="A" title="A">A</a></p>
+<link rel="mw:PageProp/Category" href="Category:分类"/>
 !! end
 
-
 !! test
 Stripping -{}- tags (language variants)
 !! options
@@ -19756,7 +19889,7 @@ Tildes in comments
 pst
 !! wikitext
 <!-- ~~~~ -->
-!! html
+!! html/php
 <!-- ~~~~ -->
 !! end
 
@@ -20078,7 +20211,7 @@ Edit comment with link
 comment
 !! wikitext
 I like the [[Main Page]] a lot
-!! html
+!! html/php
 I like the <a href="/wiki/Main_Page" title="Main Page">Main Page</a> a lot
 !!end
 
@@ -20088,7 +20221,7 @@ Edit comment with link and link text
 comment
 !! wikitext
 I like the [[Main Page|best pages]] a lot
-!! html
+!! html/php
 I like the <a href="/wiki/Main_Page" title="Main Page">best pages</a> a lot
 !!end
 
@@ -20098,7 +20231,7 @@ Edit comment with link and link text with suffix
 comment
 !! wikitext
 I like the [[Main Page|best page]]s a lot
-!! html
+!! html/php
 I like the <a href="/wiki/Main_Page" title="Main Page">best pages</a> a lot
 !!end
 
@@ -20108,7 +20241,7 @@ Edit comment with section link (non-local, eg in history list)
 comment title=[[Main Page]]
 !! wikitext
 /* External links */ removed bogus entries
-!! html
+!! html/php
 <a href="/wiki/Main_Page#External_links" title="Main Page">→</a>‎<span dir="auto"><span class="autocomment">External links: </span> removed bogus entries</span>
 !!end
 
@@ -20118,7 +20251,7 @@ Edit comment with section link and text before it (non-local, eg in history list
 comment title=[[Main Page]]
 !! wikitext
 pre-comment text /* External links */ removed bogus entries
-!! html
+!! html/php
 pre-comment text <a href="/wiki/Main_Page#External_links" title="Main Page">→</a>‎<span dir="auto"><span class="autocomment">External links: </span> removed bogus entries</span>
 !!end
 
@@ -20128,7 +20261,7 @@ Edit comment with section link (local, eg in diff view)
 comment local title=[[Main Page]]
 !! wikitext
 /* External links */ removed bogus entries
-!! html
+!! html/php
 <a href="#External_links">→</a>‎<span dir="auto"><span class="autocomment">External links: </span> removed bogus entries</span>
 !!end
 
@@ -20140,7 +20273,7 @@ subpage
 title=[[Subpage test]]
 !! wikitext
 Poked at a [[/subpage]] here...
-!! html
+!! html/php
 Poked at a <a href="/wiki/Subpage_test/subpage" title="Subpage test/subpage">/subpage</a> here...
 !!end
 
@@ -20152,7 +20285,7 @@ subpage
 title=[[Subpage test]]
 !! wikitext
 Poked at a [[/subpage|neat little page]] here...
-!! html
+!! html/php
 Poked at a <a href="/wiki/Subpage_test/subpage" title="Subpage test/subpage">neat little page</a> here...
 !!end
 
@@ -20163,7 +20296,7 @@ comment
 title=[[Subpage test]]
 !! wikitext
 Poked at a [[/subpage]] here...
-!! html
+!! html/php
 Poked at a <a href="/index.php?title=/subpage&amp;action=edit&amp;redlink=1" class="new" title="/subpage (page does not exist)">/subpage</a> here...
 !!end
 
@@ -20175,7 +20308,7 @@ local
 title=[[Main Page]]
 !! wikitext
 [[#section]]
-!! html
+!! html/php
 <a href="#section">#section</a>
 !! end
 
@@ -20186,24 +20319,28 @@ comment
 title=[[Main Page]]
 !! wikitext
 [[#section]]
-!! html
+!! html/php
 <a href="/wiki/Main_Page#section" title="Main Page">#section</a>
 !! end
 
 !! test
 Anchor starting with underscore
+!! options
+title=[[Foo]]
 !! wikitext
 [[#_ref|One]]
-!! html
+!! html/php
 <p><a href="#_ref">One</a>
 </p>
+!! html/parsoid
+<p><a rel="mw:WikiLink" href="./Foo#_ref" data-parsoid='{"stx":"piped","a":{"href":"./Foo#_ref"},"sa":{"href":"#_ref"}}'>One</a></p>
 !! end
 
 !! test
 Id starting with underscore
 !! wikitext
 <div id="_ref"></div>
-!! html
+!! html/*
 <div id="_ref"></div>
 
 !! end
@@ -20215,7 +20352,7 @@ comment
 title=[[Main Page]]
 !! wikitext
 /* __hello__world__ */
-!! html
+!! html/php
 <a href="/wiki/Main_Page#hello_world" title="Main Page">→</a>‎<span dir="auto"><span class="autocomment">__hello__world__</span></span>
 !! end
 
@@ -20534,20 +20671,14 @@ HTML5 data attributes
 !! wikitext
 <span data-foo="bar">Baz</span>
 <p data-abc-def_hij="">Quuz</p>
-!! html
+!! html/php
 <p><span data-foo="bar">Baz</span>
 </p>
 <p data-abc-def_hij="">Quuz</p>
 
-!! end
-
-!! test
-Strip reserved data attributes
-!! wikitext
-<div data-mw="foo" data-parsoid="bar" data-mw-someext="baz" data-ok="fred" data-ooui="xyzzy" data-bad:ns="ns">d</div>
-!! html
-<div data-ok="fred">d</div>
-
+!! html/parsoid
+<p><span data-foo="bar" data-parsoid='{"stx":"html"}'>Baz</span></p>
+<p data-abc-def_hij="" data-parsoid='{"stx":"html"}'>Quuz</p>
 !! end
 
 !! test
@@ -21386,14 +21517,12 @@ parsoid=wt2html,wt2wt
 
 !!test
 Ref: 1. ref-location should be replaced with an index span
-!!options
-parsoid
 !! wikitext
 A <ref>foo</ref>
 B <ref name="x">foo</ref>
 C <ref name="y" />
 <references />
-!! html
+!! html/parsoid
 <p>A <span about="#mwt2" class="mw-ref" id="cite_ref-1" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-1"},"attrs":{}}'><a href="#cite_note-1"><span class="mw-reflink-text">[1]</span></a></span>
 B <span about="#mwt4" class="mw-ref" id="cite_ref-x_2-0" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-x-2"},"attrs":{"name":"x"}}'><a href="#cite_note-x-2"><span class="mw-reflink-text">[2]</span></a></span>
 C <span about="#mwt6" class="mw-ref" id="cite_ref-y_3-0" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","attrs":{"name":"y"}}'><a href="#cite_note-y-3"><span class="mw-reflink-text">[3]</span></a></span></p>
@@ -21406,13 +21535,11 @@ C <span about="#mwt6" class="mw-ref" id="cite_ref-y_3-0" rel="dc:references" typ
 
 !!test
 Ref: 2. ref-tags with identical names should all get the same index
-!!options
-parsoid
 !! wikitext
 A <ref name="x">foo</ref>
 B <ref name="x" />
 <references />
-!! html
+!! html/parsoid
 <p>A <span about="#mwt2" class="mw-ref" id="cite_ref-x_1-0" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-x-1"},"attrs":{"name":"x"}}'><a href="#cite_note-x-1"><span class="mw-reflink-text">[1]</span></a></span>
 B <span about="#mwt4" class="mw-ref" id="cite_ref-x_1-1" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","attrs":{"name":"x"}}'><a href="#cite_note-x-1"><span class="mw-reflink-text">[1]</span></a></span></p>
 <ol class="mw-references" typeof="mw:Extension/references" about="#mwt6" data-mw='{"name":"references","attrs":{}}'>
@@ -21422,14 +21549,12 @@ B <span about="#mwt4" class="mw-ref" id="cite_ref-x_1-1" rel="dc:references" typ
 
 !!test
 Ref: 3. spaces in ref-names should be ignored
-!!options
-parsoid
 !! wikitext
 A <ref name="x">foo</ref>
 B <ref name=" x " />
 C <ref name= x  />
 <references />
-!! html
+!! html/parsoid
 <p>A <span about="#mwt2" class="mw-ref" id="cite_ref-x_1-0" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-x-1"},"attrs":{"name":"x"}}'><a href="#cite_note-x-1"><span class="mw-reflink-text">[1]</span></a></span>
 B <span about="#mwt4" class="mw-ref" id="cite_ref-x_1-1" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","attrs":{"name":"x"}}'><a href="#cite_note-x-1"><span class="mw-reflink-text">[1]</span></a></span>
 C <span about="#mwt6" class="mw-ref" id="cite_ref-x_1-2" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","attrs":{"name":"x"}}'><a href="#cite_note-x-1"><span class="mw-reflink-text">[1]</span></a></span></p>
@@ -21441,12 +21566,10 @@ C <span about="#mwt6" class="mw-ref" id="cite_ref-x_1-2" rel="dc:references" typ
 # NOTE: constructor is a predefined property in JS and constructor as a ref-name can clash with it if not handled properly)
 !!test
 Ref: 4. 'constructor' should be accepted as a valid ref-name
-!!options
-parsoid
 !! wikitext
 A <ref name="constructor">foo</ref>
 <references />
-!! html
+!! html/parsoid
 <p>A <span about="#mwt2" class="mw-ref" id="cite_ref-constructor_1-0" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-constructor-1"},"attrs":{"name":"constructor"}}'><a href="#cite_note-constructor-1"><span class="mw-reflink-text">[1]</span></a></span></p>
 <ol class="mw-references" typeof="mw:Extension/references" about="#mwt4" data-mw='{"name":"references","attrs":{}}'>
 <li about="#cite_note-constructor-1" id="cite_note-constructor-1"><a href="#cite_ref-constructor_1-0" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-constructor-1" class="mw-reference-text">foo</span></li>
@@ -21455,15 +21578,13 @@ A <ref name="constructor">foo</ref>
 
 !!test
 Ref: 5. body should accept generic wikitext
-!!options
-parsoid
 !! wikitext
 A <ref>
  This is a '''[[bolded link]]''' and this is a {{echo|transclusion}}
 </ref>
 
 <references />
-!! html
+!! html/parsoid
 <p>A <span about="#mwt2" class="mw-ref" id="cite_ref-1" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-1"},"attrs":{}}'><a href="#cite_note-1"><span class="mw-reflink-text">[1]</span></a></span></p>
 
 <ol class="mw-references" typeof="mw:Extension/references" about="#mwt5" data-mw='{"name":"references","attrs":{}}'>
@@ -21474,8 +21595,6 @@ A <ref>
 
 !!test
 Ref: 6. indent-pres should not be output in ref-body
-!!options
-parsoid
 !! wikitext
 A <ref>
  foo
@@ -21484,7 +21603,7 @@ A <ref>
 </ref>
 
 <references />
-!! html
+!! html/parsoid
 <p>A <span about="#mwt2" class="mw-ref" id="cite_ref-1" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-1"},"attrs":{}}'><a href="#cite_note-1"><span class="mw-reflink-text">[1]</span></a></span></p>
 
 <ol class="mw-references" typeof="mw:Extension/references" about="#mwt4" data-mw='{"name":"references","attrs":{}}'>
@@ -21497,8 +21616,6 @@ A <ref>
 
 !!test
 Ref: 7. No p-wrapping in ref-body
-!!options
-parsoid
 !! wikitext
 A <ref>
 foo
@@ -21514,7 +21631,7 @@ booz
 </ref>
 
 <references />
-!! html
+!! html/parsoid
 <p>A <span about="#mwt2" class="mw-ref" id="cite_ref-1" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-1"},"attrs":{}}'><a href="#cite_note-1"><span class="mw-reflink-text">[1]</span></a></span></p>
 
 <ol class="mw-references" typeof="mw:Extension/references" about="#mwt4" data-mw='{"name":"references","attrs":{}}'>
@@ -21534,27 +21651,23 @@ booz
 
 !!test
 Ref: 8. transclusion wikitext has lower precedence
-!!options
-parsoid
 !! wikitext
 A <ref> foo {{echo|</ref> B C}}
 
 <references />
-!! html
+!! html/parsoid
 <p>A <span about="#mwt2" class="mw-ref" id="cite_ref-1" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-1"},"attrs":{}}'><a href="#cite_note-1"><span class="mw-reflink-text">[1]</span></a></span> B C<span typeof="mw:Nowiki">}}</span></p>
 <ol class="mw-references" typeof="mw:Extension/references" about="#mwt4" data-mw='{"name":"references","attrs":{}}'>
-<li about="#cite_note-1" id="cite_note-1"><a href="#cite_ref-1" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-1" class="mw-reference-text">foo <span typeof="mw:Nowiki" data-parsoid='{"src":"{{","dsr":[12,14,0,0]}'>{{</span>echo|</span></li>
+<li about="#cite_note-1" id="cite_note-1"><a href="#cite_ref-1" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-1" class="mw-reference-text">foo {{echo|</span></li>
 </ol>
 !!end
 
 !!test
 Ref: 9. unclosed comments should not leak out of ref-body
-!!options
-parsoid
 !! wikitext
 A <ref> foo <!--</ref> B C
 <references />
-!! html
+!! html/parsoid
 <p>A <span about="#mwt2" class="mw-ref" id="cite_ref-1" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-1"},"attrs":{}}'><a href="#cite_note-1"><span class="mw-reflink-text">[1]</span></a></span> B C</p>
 <ol class="mw-references" typeof="mw:Extension/references" about="#mwt4" data-mw='{"name":"references","attrs":{}}'>
 <li about="#cite_note-1" id="cite_note-1"><a href="#cite_ref-1" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-1" class="mw-reference-text">foo <!----></span></li>
@@ -21563,13 +21676,11 @@ A <ref> foo <!--</ref> B C
 
 !!test
 Ref: 10. Unclosed HTML tags should not leak out of ref-body
-!!options
-parsoid
 !! wikitext
 A <ref> <b> foo </ref> B C
 
 <references />
-!! html
+!! html/parsoid
 <p>A <span about="#mwt2" class="mw-ref" id="cite_ref-1" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-1"},"attrs":{}}'><a href="#cite_note-1"><span class="mw-reflink-text">[1]</span></a></span> B C</p>
 
 
@@ -21580,13 +21691,11 @@ A <ref> <b> foo </ref> B C
 
 !!test
 Ref: 11. ref-tags acts like an inline element wrt P-wrapping
-!!options
-parsoid
 !! wikitext
 A <ref>foo</ref> B
 C <ref>bar</ref> D
 <references />
-!! html
+!! html/parsoid
 <p>A <span about="#mwt2" class="mw-ref" id="cite_ref-1" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-1"},"attrs":{}}'><a href="#cite_note-1"><span class="mw-reflink-text">[1]</span></a></span> B
 C <span about="#mwt4" class="mw-ref" id="cite_ref-2" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-2"},"attrs":{}}'><a href="#cite_note-2"><span class="mw-reflink-text">[2]</span></a></span> D</p>
 <ol class="mw-references" typeof="mw:Extension/references" about="#mwt6" data-mw='{"name":"references","attrs":{}}'>
 
 !!test
 Ref: 13. ref-tags are not SOL-transparent and block indent-pres
-!!options
-parsoid
 !! wikitext
 <ref>foo</ref> A
 <ref>bar
 </ref> B
 <references />
-!! html
+!! html/parsoid
 <p><span about="#mwt2" class="mw-ref" id="cite_ref-1" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-1"},"attrs":{}}'><a href="#cite_note-1"><span class="mw-reflink-text">[1]</span></a></span> A
 <span about="#mwt4" class="mw-ref" id="cite_ref-2" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-2"},"attrs":{}}'><a href="#cite_note-2"><span class="mw-reflink-text">[2]</span></a></span> B</p>
 <ol class="mw-references" typeof="mw:Extension/references" about="#mwt6" data-mw='{"name":"references","attrs":{}}'>
@@ -21639,13 +21746,11 @@ parsoid
 
 !!test
 Ref: 14. A nested ref-tag should be emitted as plain text
-!!options
-parsoid
 !! wikitext
 <ref>foo <ref>bar</ref> baz</ref>
 
 <references />
-!! html
+!! html/parsoid
 <p><span about="#mwt2" class="mw-ref" id="cite_ref-1" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-1"},"attrs":{}}'><a href="#cite_note-1"><span class="mw-reflink-text">[1]</span></a></span>
 </p>
 <ol class="mw-references" typeof="mw:Extension/references" about="#mwt5" data-mw='{"name":"references","attrs":{}}'>
@@ -21655,14 +21760,12 @@ parsoid
 
 !!test
 Ref: 15. ref-tags with identical names should get identical indexes
-!!options
-parsoid
 !! wikitext
 A1 <ref name="a">foo</ref> A2 <ref name="a" />
 B1 <ref name="b" /> B2 <ref name="b">bar</ref>
 
 <references />
-!! html
+!! html/parsoid
 <p>A1 <span about="#mwt3" class="mw-ref" id="cite_ref-a_1-0" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-a-1"},"attrs":{"name":"a"}}'><a href="#cite_note-a-1"><span class="mw-reflink-text">[1]</span></a></span> A2 <span about="#mwt4" class="mw-ref" id="cite_ref-a_1-1" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","attrs":{"name":"a"}}'><a href="#cite_note-a-1"><span class="mw-reflink-text">[1]</span></a></span>
 B1 <span about="#mwt7" class="mw-ref" id="cite_ref-b_2-0" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","attrs":{"name":"b"}}'><a href="#cite_note-b-2"><span class="mw-reflink-text">[2]</span></a></span> B2 <span about="#mwt8" class="mw-ref" id="cite_ref-b_2-1" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-b-2"},"attrs":{"name":"b"}}'><a href="#cite_note-b-2"><span class="mw-reflink-text">[2]</span></a></span></p>
 
@@ -21679,7 +21782,7 @@ parsoid=wt2html
 A <ref >foo</ref >
 
 <references />
-!! html
+!! html/parsoid
 <p>A <span about="#mwt2" class="mw-ref" id="cite_ref-1" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-1"},"attrs":{}}'><a href="#cite_note-1"><span class="mw-reflink-text">[1]</span></a></span></p>
 <ol class="mw-references" typeof="mw:Extension/references" about="#mwt4" data-mw='{"name":"references","attrs":{}}'>
 <li about="#cite_note-1" id="cite_note-1"><a href="#cite_ref-1" rel="mw:referencedBy"><span class="mw-linkback-text">↑ </span></a> <span id="mw-reference-text-cite_note-1" class="mw-reference-text">foo</span></li></ol>
@@ -21687,13 +21790,11 @@ A <ref >foo</ref >
 
 !!test
 Ref: 17. Generate valid HTML5 id/about attributes
-!!options
-parsoid
 !!wikitext
 <ref name="a b">foo</ref>
 
 <references />
-!!html
+!!html/parsoid
 <p><span class="mw-ref" id="cite_ref-a_b_1-0" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-a_b-1"},"attrs":{"name":"a b"}}'><a href="#cite_note-a_b-1"><span class="mw-reflink-text">[1]</span></a></span>
 </p>
 
@@ -21704,13 +21805,11 @@ parsoid
 
 !!test
 Ref: 18. T58916: Extension attributes should be parsed as plain text
-!!options
-parsoid
 !!wikitext
 <ref name="{{echo|a}}">foo</ref>
 
 <references />
-!!html
+!!html/parsoid
 <p><span class="mw-ref" id="cite_ref-.7B.7Becho.7Ca.7D.7D_1-0" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-.7B.7Becho.7Ca.7D.7D-1"},"attrs":{"name":"{{echo|a}}"}}'><a href="#cite_note-.7B.7Becho.7Ca.7D.7D-1"><span class="mw-reflink-text">[1]</span></a></span>
 </p>
 
@@ -21721,13 +21820,11 @@ parsoid
 
 !!test
 Ref: 19. ref-tags with identical name encodings should get identical indexes
-!!options
-parsoid
 !! wikitext
 1 <ref name="a & b">foo</ref> 2 <ref name="a &amp; b" />
 
 <references />
-!! html
+!! html/parsoid
 <p>1 <span about="#mwt3" class="mw-ref" id="cite_ref-a_.26_b_1-0" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-a_.26_b-1"},"attrs":{"name":"a &amp; b"}}'><a href="#cite_note-a_.26_b-1"><span class="mw-reflink-text">[1]</span></a></span> 2 <span about="#mwt4" class="mw-ref" id="cite_ref-a_.26_b_1-1" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","attrs":{"name":"a &amp;amp; b"}}'><a href="#cite_note-a_.26_b-1"><span class="mw-reflink-text">[1]</span></a></span>
 </p>
 <ol class="mw-references" typeof="mw:Extension/references" about="#mwt6" data-mw='{"name":"references","attrs":{}}'>
@@ -21737,15 +21834,13 @@ parsoid
 
 !!test
 Ref: 20. ref-tags with identical names but different content should keep it
-!!options
-parsoid
 !! wikitext
 A <ref name="foo">Foo one</ref>
 B <ref name="foo">Foo two</ref>
 C <ref name="foo" />
 
 <references />
-!! html
+!! html/parsoid
 <p>A <span about="#mwt2" class="mw-ref" id="cite_ref-foo_1-0" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"id":"mw-reference-text-cite_note-foo-1"},"attrs":{"name":"foo"}}'><a href="#cite_note-foo-1"><span class="mw-reflink-text">[1]</span></a></span>
 B <span about="#mwt4" class="mw-ref" id="cite_ref-foo_1-1" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","body":{"html":"Foo two"},"attrs":{"name":"foo"}}'><a href="#cite_note-foo-1"><span class="mw-reflink-text">[1]</span></a></span>
 C <span about="#mwt6" class="mw-ref" id="cite_ref-foo_1-2" rel="dc:references" typeof="mw:Extension/ref" data-mw='{"name":"ref","attrs":{"name":"foo"}}'><a href="#cite_note-foo-1"><span class="mw-reflink-text">[1]</span></a></span></p>
@@ -21979,8 +22074,10 @@ foo<ol class="mw-references" typeof="mw:Extension/references" about="#mwt2" data
 #### https://www.mediawiki.org/wiki/Parsoid/HTML_based_LST
 #### ----------------------------------------------------------------
 
-!!test
+!! test
 LST Sections: 1. Simple section start and end
+!! options
+parsoid={ "suppressErrors": true }
 !! wikitext
 <section begin="2011-05-16" />
 <section end="2014-04-10 (MW 1.23wmf22)" />
@@ -23574,7 +23671,8 @@ parsoid=html2wt
 
  __TOC__ foo
 
-__TOC__ bar
+__TOC__
+ bar
 !! end
 
 #### --------------- HTML tags ---------------
@@ -23723,6 +23821,19 @@ HTML tag with broken attribute value quoting
 </p>
 !! end
 
+!! test
+Self-closed tag with broken attribute value quoting
+!! options
+parsoid=wt2html,html2html
+!! wikitext
+<div title="Hello world />Foo
+!! html/php+tidy
+<div title="Hello world"></div>
+<p>Foo</p>
+!! html/parsoid
+<div title="Hello world " data-parsoid='{"stx":"html","selfClose":true}'></div><p>Foo</p>
+!! end
+
 !! test
 Table with broken attribute value quoting
 !! wikitext
@@ -24351,6 +24462,19 @@ Properly encapsulate empty-content transclusions in fosterable positions
 </table>
 !! end
 
+!! test
+Always encapsulate foster box when template range is expanded to table
+!! options
+parsoid=wt2wt
+!! wikitext
+{|
+hello
+{{OpenTable}}
+|}
+!! html/parsoid
+
+!! end
+
 !!test
 Support <object> element with .data attribute
 !!options
@@ -24785,7 +24909,8 @@ parsoid=html2wt
 </div>
 !! wikitext
 foo
-<nowiki> </nowiki><span>bar</span>
+<span>bar</span>
 
 <span>foo2
 <nowiki> </nowiki></span>bar2
@@ -24827,15 +24952,15 @@ parsoid={
 
 <h2><meta property="mw:PageProp/toc" /> ok</h2>
 !! wikitext
-== hello there [[Category:A1]]  ==
+== hello there [[Category:A1]] ==
 
-==  [[Category:A2]] hi pal ==
+== [[Category:A2]] hi pal ==
 
-==  <!--foo-->  [[Category:A3]]    how goes it ==
+== <!--foo-->  [[Category:A3]]    how goes it ==
 
-== it goes well    [[Category:A4]]  <!--bar-->  ==
+== it goes well    [[Category:A4]]  <!--bar--> ==
 
-==howdy [[Category:A5]] ==
+==howdy [[Category:A5]]==
 
 ==  __TOC__  ok ==
 !! end
@@ -25620,7 +25745,7 @@ parsoid={ "modes": ["html2wt"], "suppressErrors": true }
 # shown to sneak through on occasion. See T101768.
 # The original wikitext here is: [http://test.com [[one]] two three]
 !! test
-Strip span tags added to mark as misnested
+Strip span tags added to mark misnested links
 !! options
 parsoid=html2wt
 !! html/parsoid
@@ -25629,10 +25754,112 @@ parsoid=html2wt
 [http://test.com][[one]] two three
 !! end
 
+!! test
+Use data-parsoid.firstWikitextNode to compute newline constraints for template content
+!! options
+parsoid=html2wt
+!! html/parsoid
+<span about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1","spc":["","","",""]}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"a"}},"i":0}}]}'>a</span><table about="#mwt2" typeof="mw:Transclusion mw:ExpandedAttrs" data-parsoid='{"a":{"{{echo|c\n{{!}}d\n}}":null},"sa":{"{{echo|c\n{{!}}d\n}}":""},"firstWikitextNode":"table","pi":[[{"k":"1","spc":["","","",""]}]]}' data-mw='{"parts":["{|",{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"c\n{{!}}d\n"}},"i":0}},"\n|}"]}'>
+<tbody><tr><td>d
+</td></tr>
+</tbody></table>
+!! wikitext
+{{echo|a}}
+{|{{echo|c
+{{!}}d
+}}
+|}
+!! end
+
+## This test verifies the presence and computation of this attribute indirectly
+## by making an edit and ensuring that the serialization is correct (which it would be
+## only if firstWikitextNode is properly set).
+!! test
+data-parsoid.firstWikitextNode should be computed properly in the presence of fostered content
+!! options
+parsoid= {
+  "modes": ["wt2wt"],
+  "changes": [
+    [ "div#x", "remove" ],
+    [ "div", "before", "<div>new</div>" ]
+  ]
+}
+!! wikitext
+<div id="x">foo</div>
+{|
+{{echo|<div>boo</div>
+{{!}}b}}
+|c
+|}
+!! wikitext/edited
+
+<div>new</div>
+{|
+{{echo|<div>boo</div>
+{{!}}b}}
+|c
+|}
+!! end
+
 # --------------------------------------------
 # Tests spec'ing wikitext serialization norms |
 # --------------------------------------------
 
+!! test
+1. Categories should always be serialized on their own line
+!! options
+parsoid=html2wt
+!! html/parsoid
+foo<link rel="mw:PageProp/Category" href="./Category:Foo">bar
+!! wikitext
+foo
+[[Category:Foo]]
+bar
+!! end
+
+!! test
+2. Categories that are part of templates should not introduce a line break
+!! wikitext
+foo {{echo|<span>bar</span> [[Category:baz]]}} bar
+!! html/parsoid
+<p>foo <span about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"&lt;span>bar&lt;/span> [[Category:baz]]"}},"i":0}}]}'>bar</span><span about="#mwt1"> </span><link rel="mw:PageProp/Category" href="./Category:Baz" about="#mwt1" data-parsoid='{"stx":"simple","a":{"href":"./Category:Baz"},"sa":{"href":"Category:baz"}}'/> bar</p>
+!! end
+
+# Careful while editing these next 2 tests. There are \u200f characters
+# before and after the <link> tags in the HTML and following some
+# of the categories in wikitext
+# Do not remove these characters in edits.
+#
+# As part of the serialization, these bidi characters will get stripped.
+!! test
+RTL (\u200f) and LTR (\u200e) markers around category tags should be stripped
+!! options
+parsoid={
+  "modes": ["html2wt"],
+  "scrubWikitext": true
+}
+!! html/parsoid
+<p>‏<link rel="mw:PageProp/Category" href="./קטגוריה:טקסים" />‏
+‏<link rel="mw:PageProp/Category" href="./קטגוריה:_שיטות_משפט" />‏</p>
+!! wikitext
+[[קטגוריה:טקסים]]
+[[קטגוריה: שיטות משפט]]
+!! end
+
+!! test
+RTL (\u200f) and LTR (\u200e) markers should not be stripped if followed by a text node
+!! options
+parsoid={
+  "modes": ["html2wt"],
+  "scrubWikitext": true
+}
+!! html/parsoid
+<p>‏<link rel="mw:PageProp/Category" href="./קטגוריה:טקסים" />‏y</p>
+!! wikitext
+[[קטגוריה:טקסים]]
+‏y
+!! end
+
 !! test
 Lists: Add space after bullets
 !! options
@@ -25720,6 +25947,35 @@ parsoid={
 !! wikitext/edited
 !! end
 
+!! test
+Headings: Replace <br/> with a single whitespace char (when scrubWikitext = true)
+!! options
+parsoid={
+  "modes": ["html2wt"],
+  "scrubWikitext": true
+}
+!! html/parsoid
+<h2>foo<br/>bar</h2>
+<h2>foo <span><br/>bar</span> baz</h2>
+!! wikitext
+== foo bar ==
+
+== foo <span> bar</span> baz ==
+!! end
+
+!! test
+Headings: Replace <br/> with a single whitespace char (when scrubWikitext = false)
+!! options
+parsoid={
+  "modes": ["html2wt"],
+  "scrubWikitext": false
+}
+!! html/parsoid
+<h2>foo<br/>bar</h2>
+!! wikitext
+== foo<br> bar ==
+!! end
+
 !! test
 1. WT Quote Tags: suppress newly created empty style tags
 !! options
@@ -26225,10 +26481,61 @@ parsoid=html2wt
 &lt;nowiki&gt;''foo''&lt;/nowiki&gt;
 !! end
 
+# This is meant to be an interim fix while we go about figuring out
+# how to not introduce these trailing <nowiki/>s in the first place.
+!! test
+T115717: Strip trailing <nowiki/>s (without affecting valid uses)
+!! options
+parsoid=html2wt
+!! html/parsoid
+<p>x<meta typeof="mw:Placeholder" data-parsoid='{"src":"&lt;nowiki/>"}'/><meta typeof="mw:Placeholder" data-parsoid='{"src":"&lt;nowiki/>"}'/>
+y</p>
+<p><span about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"dsr":[0,23,null,null],"pi":[[{"k":"1","named":true,"spc":["\n"," "," ",""]}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"&lt;nowiki/>"}},"i":0}}]}'></span></p>
+<p><span about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"dsr":[0,24,null,null],"pi":[[{"k":"1","named":true,"spc":["\n"," "," ","\n"]}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"echo","href":"./Template:Echo"},"params":{"1":{"wt":"&lt;nowiki/>"}},"i":0}}]}'></span></p>
+!! wikitext
+x
+y
+
+{{echo|
+1 = <nowiki/>}}
+
+{{echo|
+1 = <nowiki/>
+}}
+!! end
+
 # ---------------------------------------------------
 # End of tests spec'ing wikitext serialization norms |
 # ---------------------------------------------------
 
+# T104032
+!! test
+Bare inline nodes not wrapped inside p-tags should be treated as p-wrapped
+!! options
+parsoid=html2wt
+!! html/parsoid
+a<p>b</p>
+<b>c</b><p>d</p>
+<table><tr>
+<td>a<p>b</p></td>
+<td><b>c</b><p>d</p></td>
+</tr></table>
+!! wikitext
+a
+
+b
+
+'''c'''
+
+d
+{|
+|a
+b
+|'''c'''
+d
+|}
+!! end
+
 # -----------------------------------------------------------------
 # End of section for Parsoid-only html2wt tests for serialization
 # of new content