2004-02-18 02:15:00 +00:00
|
|
|
<?php
|
2010-06-21 12:59:04 +00:00
|
|
|
/**
|
2010-08-14 19:19:41 +00:00
|
|
|
* Implements Special:Export
|
|
|
|
|
*
|
|
|
|
|
* Copyright © 2003-2008 Brion Vibber <brion@pobox.com>
|
2010-06-21 12:59:04 +00:00
|
|
|
*
|
|
|
|
|
* 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.,
|
2010-06-21 13:16:32 +00:00
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2010-06-21 12:59:04 +00:00
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
2010-08-14 19:19:41 +00:00
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
* @ingroup SpecialPage
|
2010-06-21 12:59:04 +00:00
|
|
|
*/
|
|
|
|
|
|
2018-09-20 14:54:06 +00:00
|
|
|
use MediaWiki\Logger\LoggerFactory;
|
2020-10-21 17:55:48 +00:00
|
|
|
use Wikimedia\Rdbms\ILoadBalancer;
|
2017-02-07 13:31:46 +00:00
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
2010-08-14 19:19:41 +00:00
|
|
|
* A special page that allows users to export pages in a XML file
|
|
|
|
|
*
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @ingroup SpecialPage
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2009-02-06 23:36:12 +00:00
|
|
|
class SpecialExport extends SpecialPage {
|
2019-10-21 16:29:06 +00:00
|
|
|
protected $curonly, $doExport, $pageLinkDepth, $templates;
|
2010-05-06 21:07:37 +00:00
|
|
|
|
2020-10-21 17:55:48 +00:00
|
|
|
/** @var ILoadBalancer */
|
|
|
|
|
private $loadBalancer;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param ILoadBalancer $loadBalancer
|
|
|
|
|
*/
|
|
|
|
|
public function __construct(
|
|
|
|
|
ILoadBalancer $loadBalancer
|
|
|
|
|
) {
|
2009-03-16 21:19:01 +00:00
|
|
|
parent::__construct( 'Export' );
|
2020-10-21 17:55:48 +00:00
|
|
|
$this->loadBalancer = $loadBalancer;
|
2009-03-16 21:19:01 +00:00
|
|
|
}
|
2010-05-06 21:07:37 +00:00
|
|
|
|
2009-03-16 21:19:01 +00:00
|
|
|
public function execute( $par ) {
|
|
|
|
|
$this->setHeaders();
|
|
|
|
|
$this->outputHeader();
|
2014-08-03 22:10:25 +00:00
|
|
|
$config = $this->getConfig();
|
2010-05-06 21:07:37 +00:00
|
|
|
|
2009-03-16 21:19:01 +00:00
|
|
|
// Set some variables
|
|
|
|
|
$this->curonly = true;
|
|
|
|
|
$this->doExport = false;
|
2011-09-02 16:59:01 +00:00
|
|
|
$request = $this->getRequest();
|
|
|
|
|
$this->templates = $request->getCheck( 'templates' );
|
2009-03-16 21:19:01 +00:00
|
|
|
$this->pageLinkDepth = $this->validateLinkDepth(
|
2011-09-02 16:59:01 +00:00
|
|
|
$request->getIntOrNull( 'pagelink-depth' )
|
2010-07-26 17:31:38 +00:00
|
|
|
);
|
2009-04-16 00:18:36 +00:00
|
|
|
$nsindex = '';
|
2012-01-14 14:18:56 +00:00
|
|
|
$exportall = false;
|
2010-05-06 21:07:37 +00:00
|
|
|
|
2011-09-02 16:59:01 +00:00
|
|
|
if ( $request->getCheck( 'addcat' ) ) {
|
|
|
|
|
$page = $request->getText( 'pages' );
|
|
|
|
|
$catname = $request->getText( 'catname' );
|
2010-05-06 21:07:37 +00:00
|
|
|
|
2009-12-11 21:07:27 +00:00
|
|
|
if ( $catname !== '' && $catname !== null && $catname !== false ) {
|
2009-03-16 21:19:01 +00:00
|
|
|
$t = Title::makeTitleSafe( NS_MAIN, $catname );
|
|
|
|
|
if ( $t ) {
|
|
|
|
|
/**
|
2011-05-17 22:03:20 +00:00
|
|
|
* @todo FIXME: This can lead to hitting memory limit for very large
|
2009-03-16 21:19:01 +00:00
|
|
|
* categories. Ideally we would do the lookup synchronously
|
|
|
|
|
* during the export in a single query.
|
|
|
|
|
*/
|
|
|
|
|
$catpages = $this->getPagesFromCategory( $t );
|
2010-12-22 18:25:40 +00:00
|
|
|
if ( $catpages ) {
|
2015-12-10 11:47:07 +00:00
|
|
|
if ( $page !== '' ) {
|
|
|
|
|
$page .= "\n";
|
|
|
|
|
}
|
|
|
|
|
$page .= implode( "\n", $catpages );
|
2010-12-22 18:25:40 +00:00
|
|
|
}
|
2009-03-16 21:19:01 +00:00
|
|
|
}
|
|
|
|
|
}
|
2014-08-03 22:10:25 +00:00
|
|
|
} elseif ( $request->getCheck( 'addns' ) && $config->get( 'ExportFromNamespaces' ) ) {
|
2011-09-02 16:59:01 +00:00
|
|
|
$page = $request->getText( 'pages' );
|
|
|
|
|
$nsindex = $request->getText( 'nsindex', '' );
|
2010-05-06 21:07:37 +00:00
|
|
|
|
2013-02-09 22:03:53 +00:00
|
|
|
if ( strval( $nsindex ) !== '' ) {
|
2009-03-16 21:19:01 +00:00
|
|
|
/**
|
2009-12-15 21:26:58 +00:00
|
|
|
* Same implementation as above, so same @todo
|
2009-03-16 21:19:01 +00:00
|
|
|
*/
|
|
|
|
|
$nspages = $this->getPagesFromNamespace( $nsindex );
|
2010-12-22 18:25:40 +00:00
|
|
|
if ( $nspages ) {
|
|
|
|
|
$page .= "\n" . implode( "\n", $nspages );
|
|
|
|
|
}
|
2009-08-04 08:54:31 +00:00
|
|
|
}
|
2014-08-03 22:10:25 +00:00
|
|
|
} elseif ( $request->getCheck( 'exportall' ) && $config->get( 'ExportAllowAll' ) ) {
|
2012-01-03 21:08:32 +00:00
|
|
|
$this->doExport = true;
|
|
|
|
|
$exportall = true;
|
2012-03-30 21:01:06 +00:00
|
|
|
|
|
|
|
|
/* Although $page and $history are not used later on, we
|
|
|
|
|
nevertheless set them to avoid that PHP notices about using
|
|
|
|
|
undefined variables foul up our XML output (see call to
|
|
|
|
|
doExport(...) further down) */
|
|
|
|
|
$page = '';
|
|
|
|
|
$history = '';
|
2013-04-14 17:27:14 +00:00
|
|
|
} elseif ( $request->wasPosted() && $par == '' ) {
|
2018-09-20 14:54:06 +00:00
|
|
|
// Log to see if certain parameters are actually used.
|
|
|
|
|
// If not, we could deprecate them and do some cleanup, here and in WikiExporter.
|
|
|
|
|
LoggerFactory::getInstance( 'export' )->debug(
|
|
|
|
|
'Special:Export POST, dir: [{dir}], offset: [{offset}], limit: [{limit}]', [
|
|
|
|
|
'dir' => $request->getRawVal( 'dir' ),
|
|
|
|
|
'offset' => $request->getRawVal( 'offset' ),
|
|
|
|
|
'limit' => $request->getRawVal( 'limit' ),
|
|
|
|
|
] );
|
|
|
|
|
|
2011-09-02 16:59:01 +00:00
|
|
|
$page = $request->getText( 'pages' );
|
|
|
|
|
$this->curonly = $request->getCheck( 'curonly' );
|
|
|
|
|
$rawOffset = $request->getVal( 'offset' );
|
2011-03-18 20:37:11 +00:00
|
|
|
|
2013-04-14 17:27:14 +00:00
|
|
|
if ( $rawOffset ) {
|
2009-03-16 21:19:01 +00:00
|
|
|
$offset = wfTimestamp( TS_MW, $rawOffset );
|
|
|
|
|
} else {
|
|
|
|
|
$offset = null;
|
|
|
|
|
}
|
2011-03-18 20:37:11 +00:00
|
|
|
|
2014-08-03 22:10:25 +00:00
|
|
|
$maxHistory = $config->get( 'ExportMaxHistory' );
|
2011-09-02 16:59:01 +00:00
|
|
|
$limit = $request->getInt( 'limit' );
|
|
|
|
|
$dir = $request->getVal( 'dir' );
|
2016-02-17 09:09:32 +00:00
|
|
|
$history = [
|
2009-08-04 08:54:31 +00:00
|
|
|
'dir' => 'asc',
|
|
|
|
|
'offset' => false,
|
2014-08-03 22:10:25 +00:00
|
|
|
'limit' => $maxHistory,
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2011-09-02 16:59:01 +00:00
|
|
|
$historyCheck = $request->getCheck( 'history' );
|
2011-03-18 20:37:11 +00:00
|
|
|
|
2009-03-16 21:19:01 +00:00
|
|
|
if ( $this->curonly ) {
|
|
|
|
|
$history = WikiExporter::CURRENT;
|
|
|
|
|
} elseif ( !$historyCheck ) {
|
2014-08-03 22:10:25 +00:00
|
|
|
if ( $limit > 0 && ( $maxHistory == 0 || $limit < $maxHistory ) ) {
|
2009-03-16 21:19:01 +00:00
|
|
|
$history['limit'] = $limit;
|
|
|
|
|
}
|
2013-04-14 17:27:14 +00:00
|
|
|
|
2020-01-09 23:48:34 +00:00
|
|
|
if ( $offset !== null ) {
|
2009-03-16 21:19:01 +00:00
|
|
|
$history['offset'] = $offset;
|
|
|
|
|
}
|
2013-04-14 17:27:14 +00:00
|
|
|
|
2009-03-16 21:19:01 +00:00
|
|
|
if ( strtolower( $dir ) == 'desc' ) {
|
|
|
|
|
$history['dir'] = 'desc';
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-05-06 21:07:37 +00:00
|
|
|
|
2013-04-14 17:27:14 +00:00
|
|
|
if ( $page != '' ) {
|
2010-12-22 18:25:40 +00:00
|
|
|
$this->doExport = true;
|
|
|
|
|
}
|
2009-03-16 21:19:01 +00:00
|
|
|
} else {
|
2010-07-26 17:31:38 +00:00
|
|
|
// Default to current-only for GET requests.
|
2011-09-02 16:59:01 +00:00
|
|
|
$page = $request->getText( 'pages', $par );
|
|
|
|
|
$historyCheck = $request->getCheck( 'history' );
|
2011-03-18 20:37:11 +00:00
|
|
|
|
2013-04-14 17:27:14 +00:00
|
|
|
if ( $historyCheck ) {
|
2009-03-16 21:19:01 +00:00
|
|
|
$history = WikiExporter::FULL;
|
|
|
|
|
} else {
|
|
|
|
|
$history = WikiExporter::CURRENT;
|
|
|
|
|
}
|
2010-05-06 21:07:37 +00:00
|
|
|
|
2013-04-14 17:27:14 +00:00
|
|
|
if ( $page != '' ) {
|
2010-12-22 18:25:40 +00:00
|
|
|
$this->doExport = true;
|
|
|
|
|
}
|
2009-03-16 21:19:01 +00:00
|
|
|
}
|
2010-05-06 21:07:37 +00:00
|
|
|
|
2014-08-03 22:10:25 +00:00
|
|
|
if ( !$config->get( 'ExportAllowHistory' ) ) {
|
2009-03-16 21:19:01 +00:00
|
|
|
// Override
|
|
|
|
|
$history = WikiExporter::CURRENT;
|
|
|
|
|
}
|
2010-05-06 21:07:37 +00:00
|
|
|
|
2011-09-02 16:59:01 +00:00
|
|
|
$list_authors = $request->getCheck( 'listauthors' );
|
2014-08-03 22:10:25 +00:00
|
|
|
if ( !$this->curonly || !$config->get( 'ExportAllowListContributors' ) ) {
|
2013-02-09 21:44:24 +00:00
|
|
|
$list_authors = false;
|
2010-12-22 18:25:40 +00:00
|
|
|
}
|
2010-05-06 21:07:37 +00:00
|
|
|
|
2009-03-16 21:19:01 +00:00
|
|
|
if ( $this->doExport ) {
|
2011-09-02 16:59:01 +00:00
|
|
|
$this->getOutput()->disable();
|
2011-03-18 20:37:11 +00:00
|
|
|
|
2009-03-16 21:19:01 +00:00
|
|
|
// Cancel output buffering and gzipping if set
|
|
|
|
|
// This should provide safer streaming for pages with history
|
|
|
|
|
wfResetOutputBuffers();
|
2019-10-21 16:29:06 +00:00
|
|
|
$request->response()->header( 'Content-type: application/xml; charset=utf-8' );
|
|
|
|
|
$request->response()->header( 'X-Robots-Tag: noindex,nofollow' );
|
2011-03-18 20:37:11 +00:00
|
|
|
|
2013-04-14 17:27:14 +00:00
|
|
|
if ( $request->getCheck( 'wpDownload' ) ) {
|
2009-03-16 21:19:01 +00:00
|
|
|
// Provide a sane filename suggestion
|
2014-08-03 22:10:25 +00:00
|
|
|
$filename = urlencode( $config->get( 'Sitename' ) . '-' . wfTimestampNow() . '.xml' );
|
2011-09-02 16:59:01 +00:00
|
|
|
$request->response()->header( "Content-disposition: attachment;filename={$filename}" );
|
2009-03-16 21:19:01 +00:00
|
|
|
}
|
2011-03-18 20:37:11 +00:00
|
|
|
|
2012-01-03 21:08:32 +00:00
|
|
|
$this->doExport( $page, $history, $list_authors, $exportall );
|
2011-03-18 20:37:11 +00:00
|
|
|
|
2009-03-16 21:19:01 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2010-05-06 21:07:37 +00:00
|
|
|
|
2011-09-02 16:59:01 +00:00
|
|
|
$out = $this->getOutput();
|
|
|
|
|
$out->addWikiMsg( 'exporttext' );
|
2010-05-06 21:07:37 +00:00
|
|
|
|
2015-02-11 11:13:26 +00:00
|
|
|
if ( $page == '' ) {
|
|
|
|
|
$categoryName = $request->getText( 'catname' );
|
|
|
|
|
} else {
|
|
|
|
|
$categoryName = '';
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$formDescriptor = [
|
|
|
|
|
'catname' => [
|
2015-04-17 16:56:32 +00:00
|
|
|
'type' => 'textwithbutton',
|
|
|
|
|
'name' => 'catname',
|
|
|
|
|
'horizontal-label' => true,
|
|
|
|
|
'label-message' => 'export-addcattext',
|
|
|
|
|
'default' => $categoryName,
|
|
|
|
|
'size' => 40,
|
|
|
|
|
'buttontype' => 'submit',
|
|
|
|
|
'buttonname' => 'addcat',
|
|
|
|
|
'buttondefault' => $this->msg( 'export-addcat' )->text(),
|
2016-07-31 14:35:59 +00:00
|
|
|
'hide-if' => [ '===', 'exportall', '1' ],
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
];
|
2014-08-03 22:10:25 +00:00
|
|
|
if ( $config->get( 'ExportFromNamespaces' ) ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$formDescriptor += [
|
|
|
|
|
'nsindex' => [
|
2015-04-17 16:56:32 +00:00
|
|
|
'type' => 'namespaceselectwithbutton',
|
|
|
|
|
'default' => $nsindex,
|
|
|
|
|
'label-message' => 'export-addnstext',
|
|
|
|
|
'horizontal-label' => true,
|
2013-04-14 17:27:14 +00:00
|
|
|
'name' => 'nsindex',
|
|
|
|
|
'id' => 'namespace',
|
2015-04-17 16:56:32 +00:00
|
|
|
'cssclass' => 'namespaceselector',
|
|
|
|
|
'buttontype' => 'submit',
|
|
|
|
|
'buttonname' => 'addns',
|
|
|
|
|
'buttondefault' => $this->msg( 'export-addns' )->text(),
|
2016-07-31 14:35:59 +00:00
|
|
|
'hide-if' => [ '===', 'exportall', '1' ],
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
];
|
2009-03-24 18:48:50 +00:00
|
|
|
}
|
2010-05-06 21:07:37 +00:00
|
|
|
|
2014-08-03 22:10:25 +00:00
|
|
|
if ( $config->get( 'ExportAllowAll' ) ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$formDescriptor += [
|
|
|
|
|
'exportall' => [
|
2015-04-17 16:56:32 +00:00
|
|
|
'type' => 'check',
|
|
|
|
|
'label-message' => 'exportall',
|
|
|
|
|
'name' => 'exportall',
|
|
|
|
|
'id' => 'exportall',
|
|
|
|
|
'default' => $request->wasPosted() ? $request->getCheck( 'exportall' ) : false,
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
];
|
2012-01-03 21:08:32 +00:00
|
|
|
}
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$formDescriptor += [
|
|
|
|
|
'textarea' => [
|
2018-01-13 00:02:09 +00:00
|
|
|
'class' => HTMLTextAreaField::class,
|
2015-04-17 16:56:32 +00:00
|
|
|
'name' => 'pages',
|
2015-11-25 20:20:16 +00:00
|
|
|
'label-message' => 'export-manual',
|
2015-04-17 16:56:32 +00:00
|
|
|
'nodata' => true,
|
|
|
|
|
'rows' => 10,
|
|
|
|
|
'default' => $page,
|
2016-07-31 14:35:59 +00:00
|
|
|
'hide-if' => [ '===', 'exportall', '1' ],
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
];
|
2010-05-06 21:07:37 +00:00
|
|
|
|
2014-08-03 22:10:25 +00:00
|
|
|
if ( $config->get( 'ExportAllowHistory' ) ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$formDescriptor += [
|
|
|
|
|
'curonly' => [
|
2015-04-17 16:56:32 +00:00
|
|
|
'type' => 'check',
|
|
|
|
|
'label-message' => 'exportcuronly',
|
|
|
|
|
'name' => 'curonly',
|
|
|
|
|
'id' => 'curonly',
|
|
|
|
|
'default' => $request->wasPosted() ? $request->getCheck( 'curonly' ) : true,
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
];
|
2009-03-16 21:19:01 +00:00
|
|
|
} else {
|
2012-02-23 19:57:42 +00:00
|
|
|
$out->addWikiMsg( 'exportnohistory' );
|
2009-03-16 21:19:01 +00:00
|
|
|
}
|
2011-03-18 20:37:11 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$formDescriptor += [
|
|
|
|
|
'templates' => [
|
2015-04-17 16:56:32 +00:00
|
|
|
'type' => 'check',
|
|
|
|
|
'label-message' => 'export-templates',
|
|
|
|
|
'name' => 'templates',
|
|
|
|
|
'id' => 'wpExportTemplates',
|
|
|
|
|
'default' => $request->wasPosted() ? $request->getCheck( 'templates' ) : false,
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
];
|
2011-03-18 20:37:11 +00:00
|
|
|
|
2014-08-03 22:10:25 +00:00
|
|
|
if ( $config->get( 'ExportMaxLinkDepth' ) || $this->userCanOverrideExportDepth() ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$formDescriptor += [
|
|
|
|
|
'pagelink-depth' => [
|
2015-04-17 16:56:32 +00:00
|
|
|
'type' => 'text',
|
|
|
|
|
'name' => 'pagelink-depth',
|
|
|
|
|
'id' => 'pagelink-depth',
|
|
|
|
|
'label-message' => 'export-pagelinks',
|
|
|
|
|
'default' => '0',
|
|
|
|
|
'size' => 20,
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
];
|
2009-03-16 21:19:01 +00:00
|
|
|
}
|
2013-04-14 17:27:14 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$formDescriptor += [
|
|
|
|
|
'wpDownload' => [
|
2015-04-17 16:56:32 +00:00
|
|
|
'type' => 'check',
|
2017-08-11 13:53:17 +00:00
|
|
|
'name' => 'wpDownload',
|
2015-04-17 16:56:32 +00:00
|
|
|
'id' => 'wpDownload',
|
|
|
|
|
'default' => $request->wasPosted() ? $request->getCheck( 'wpDownload' ) : true,
|
|
|
|
|
'label-message' => 'export-download',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
];
|
2010-05-06 21:07:37 +00:00
|
|
|
|
2014-08-03 22:10:25 +00:00
|
|
|
if ( $config->get( 'ExportAllowListContributors' ) ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$formDescriptor += [
|
|
|
|
|
'listauthors' => [
|
2015-04-17 16:56:32 +00:00
|
|
|
'type' => 'check',
|
|
|
|
|
'label-message' => 'exportlistauthors',
|
|
|
|
|
'default' => $request->wasPosted() ? $request->getCheck( 'listauthors' ) : false,
|
|
|
|
|
'name' => 'listauthors',
|
|
|
|
|
'id' => 'listauthors',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
];
|
2011-11-16 12:01:58 +00:00
|
|
|
}
|
|
|
|
|
|
2015-11-25 20:20:16 +00:00
|
|
|
$htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() );
|
2015-04-17 16:56:32 +00:00
|
|
|
$htmlForm->setSubmitTextMsg( 'export-submit' );
|
|
|
|
|
$htmlForm->prepareForm()->displayForm( false );
|
2015-03-04 23:58:14 +00:00
|
|
|
$this->addHelpLink( 'Help:Export' );
|
2009-03-16 21:19:01 +00:00
|
|
|
}
|
2010-05-06 21:07:37 +00:00
|
|
|
|
2011-12-11 20:57:57 +00:00
|
|
|
/**
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
2019-10-21 16:29:06 +00:00
|
|
|
protected function userCanOverrideExportDepth() {
|
2021-03-02 23:59:56 +00:00
|
|
|
return $this->getAuthority()->isAllowed( 'override-export-depth' );
|
2009-03-16 21:19:01 +00:00
|
|
|
}
|
2010-05-06 21:07:37 +00:00
|
|
|
|
2009-03-16 21:19:01 +00:00
|
|
|
/**
|
|
|
|
|
* Do the actual page exporting
|
2010-05-06 21:07:37 +00:00
|
|
|
*
|
2014-07-24 17:43:44 +00:00
|
|
|
* @param string $page User input on what page(s) to export
|
2014-04-19 08:16:52 +00:00
|
|
|
* @param int $history One of the WikiExporter history export constants
|
|
|
|
|
* @param bool $list_authors Whether to add distinct author list (when
|
|
|
|
|
* not returning full history)
|
|
|
|
|
* @param bool $exportall Whether to export everything
|
2009-03-16 21:19:01 +00:00
|
|
|
*/
|
2019-10-21 16:29:06 +00:00
|
|
|
protected function doExport( $page, $history, $list_authors, $exportall ) {
|
2012-01-03 21:08:32 +00:00
|
|
|
// If we are grabbing everything, enable full history and ignore the rest
|
2012-01-05 17:10:07 +00:00
|
|
|
if ( $exportall ) {
|
2012-01-03 21:08:32 +00:00
|
|
|
$history = WikiExporter::FULL;
|
|
|
|
|
} else {
|
2016-02-17 09:09:32 +00:00
|
|
|
$pageSet = []; // Inverted index of all pages to look up
|
2012-10-10 18:13:40 +00:00
|
|
|
|
2012-01-03 21:08:32 +00:00
|
|
|
// Split up and normalize input
|
2013-04-14 17:27:14 +00:00
|
|
|
foreach ( explode( "\n", $page ) as $pageName ) {
|
2012-01-03 21:08:32 +00:00
|
|
|
$pageName = trim( $pageName );
|
|
|
|
|
$title = Title::newFromText( $pageName );
|
2014-01-02 10:59:10 +00:00
|
|
|
if ( $title && !$title->isExternal() && $title->getText() !== '' ) {
|
2012-01-03 21:08:32 +00:00
|
|
|
// Only record each page once!
|
|
|
|
|
$pageSet[$title->getPrefixedText()] = true;
|
|
|
|
|
}
|
2009-07-20 02:47:48 +00:00
|
|
|
}
|
2010-05-06 21:07:37 +00:00
|
|
|
|
2012-01-03 21:08:32 +00:00
|
|
|
// Set of original pages to pass on to further manipulation...
|
|
|
|
|
$inputPages = array_keys( $pageSet );
|
2010-05-06 21:07:37 +00:00
|
|
|
|
2012-01-03 21:08:32 +00:00
|
|
|
// Look up any linked pages if asked...
|
2013-04-14 17:27:14 +00:00
|
|
|
if ( $this->templates ) {
|
2012-01-03 21:08:32 +00:00
|
|
|
$pageSet = $this->getTemplates( $inputPages, $pageSet );
|
|
|
|
|
}
|
|
|
|
|
$linkDepth = $this->pageLinkDepth;
|
2013-04-14 17:27:14 +00:00
|
|
|
if ( $linkDepth ) {
|
2012-01-03 21:08:32 +00:00
|
|
|
$pageSet = $this->getPageLinks( $inputPages, $pageSet, $linkDepth );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$pages = array_keys( $pageSet );
|
2010-05-06 21:07:37 +00:00
|
|
|
|
2017-02-20 22:31:04 +00:00
|
|
|
// Normalize titles to the same format and remove dupes, see T19374
|
2013-04-14 17:27:14 +00:00
|
|
|
foreach ( $pages as $k => $v ) {
|
2019-10-21 16:29:06 +00:00
|
|
|
$pages[$k] = str_replace( ' ', '_', $v );
|
2012-01-03 21:08:32 +00:00
|
|
|
}
|
2009-03-27 22:01:12 +00:00
|
|
|
|
2012-01-03 21:08:32 +00:00
|
|
|
$pages = array_unique( $pages );
|
2009-03-27 22:01:12 +00:00
|
|
|
}
|
2011-03-18 20:37:11 +00:00
|
|
|
|
2009-03-16 21:19:01 +00:00
|
|
|
/* Ok, let's get to it... */
|
2020-10-21 17:55:48 +00:00
|
|
|
$db = $this->loadBalancer->getConnectionRef( ILoadBalancer::DB_REPLICA );
|
2011-03-18 20:37:11 +00:00
|
|
|
|
2018-09-11 22:51:01 +00:00
|
|
|
$exporter = new WikiExporter( $db, $history );
|
2009-03-16 21:19:01 +00:00
|
|
|
$exporter->list_authors = $list_authors;
|
|
|
|
|
$exporter->openStream();
|
2011-03-18 20:37:11 +00:00
|
|
|
|
2012-01-03 21:08:32 +00:00
|
|
|
if ( $exportall ) {
|
|
|
|
|
$exporter->allPages();
|
|
|
|
|
} else {
|
2013-04-14 17:27:14 +00:00
|
|
|
foreach ( $pages as $page ) {
|
2017-02-20 22:31:04 +00:00
|
|
|
# T10824: Only export pages the user can read
|
2012-01-03 21:08:32 +00:00
|
|
|
$title = Title::newFromText( $page );
|
2020-01-09 23:48:34 +00:00
|
|
|
if ( $title === null ) {
|
2013-04-14 17:27:14 +00:00
|
|
|
// @todo Perhaps output an <error> tag or something.
|
|
|
|
|
continue;
|
2012-01-03 21:08:32 +00:00
|
|
|
}
|
2013-04-14 17:27:14 +00:00
|
|
|
|
2021-03-02 23:59:56 +00:00
|
|
|
if ( !$this->getAuthority()->authorizeRead( 'read', $title ) ) {
|
2013-04-14 17:27:14 +00:00
|
|
|
// @todo Perhaps output an <error> tag or something.
|
|
|
|
|
continue;
|
2012-01-03 21:08:32 +00:00
|
|
|
}
|
2010-05-06 21:07:37 +00:00
|
|
|
|
2012-01-03 21:08:32 +00:00
|
|
|
$exporter->pageByTitle( $title );
|
|
|
|
|
}
|
2009-03-16 21:19:01 +00:00
|
|
|
}
|
2010-05-06 21:07:37 +00:00
|
|
|
|
2009-03-16 21:19:01 +00:00
|
|
|
$exporter->closeStream();
|
|
|
|
|
}
|
2010-01-05 22:53:00 +00:00
|
|
|
|
2011-12-11 20:57:57 +00:00
|
|
|
/**
|
2014-04-19 08:16:52 +00:00
|
|
|
* @param Title $title
|
2018-08-18 03:10:24 +00:00
|
|
|
* @return string[]
|
2011-12-11 20:57:57 +00:00
|
|
|
*/
|
2019-10-21 16:29:06 +00:00
|
|
|
protected function getPagesFromCategory( $title ) {
|
2016-02-01 14:16:08 +00:00
|
|
|
$maxPages = $this->getConfig()->get( 'ExportPagelistLimit' );
|
|
|
|
|
|
2009-03-16 21:19:01 +00:00
|
|
|
$name = $title->getDBkey();
|
2010-05-06 21:07:37 +00:00
|
|
|
|
2020-10-21 17:55:48 +00:00
|
|
|
$dbr = $this->loadBalancer->getConnectionRef( ILoadBalancer::DB_REPLICA );
|
2010-07-26 17:31:38 +00:00
|
|
|
$res = $dbr->select(
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'page', 'categorylinks' ],
|
|
|
|
|
[ 'page_namespace', 'page_title' ],
|
|
|
|
|
[ 'cl_from=page_id', 'cl_to' => $name ],
|
2010-07-26 17:31:38 +00:00
|
|
|
__METHOD__,
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'LIMIT' => $maxPages ]
|
2010-07-26 17:31:38 +00:00
|
|
|
);
|
2010-05-06 21:07:37 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$pages = [];
|
2011-03-18 20:37:11 +00:00
|
|
|
|
2010-10-13 23:11:40 +00:00
|
|
|
foreach ( $res as $row ) {
|
2018-08-26 17:52:17 +00:00
|
|
|
$pages[] = Title::makeName( $row->page_namespace, $row->page_title );
|
2009-03-16 21:19:01 +00:00
|
|
|
}
|
2013-04-14 17:27:14 +00:00
|
|
|
|
2009-03-16 21:19:01 +00:00
|
|
|
return $pages;
|
|
|
|
|
}
|
2010-05-06 21:07:37 +00:00
|
|
|
|
2011-12-11 20:57:57 +00:00
|
|
|
/**
|
2014-04-19 08:16:52 +00:00
|
|
|
* @param int $nsindex
|
2018-08-18 03:10:24 +00:00
|
|
|
* @return string[]
|
2011-12-11 20:57:57 +00:00
|
|
|
*/
|
2019-10-21 16:29:06 +00:00
|
|
|
protected function getPagesFromNamespace( $nsindex ) {
|
2016-02-01 14:16:08 +00:00
|
|
|
$maxPages = $this->getConfig()->get( 'ExportPagelistLimit' );
|
|
|
|
|
|
2020-10-21 17:55:48 +00:00
|
|
|
$dbr = $this->loadBalancer->getConnectionRef( ILoadBalancer::DB_REPLICA );
|
2010-07-26 17:31:38 +00:00
|
|
|
$res = $dbr->select(
|
|
|
|
|
'page',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'page_namespace', 'page_title' ],
|
|
|
|
|
[ 'page_namespace' => $nsindex ],
|
2010-07-26 17:31:38 +00:00
|
|
|
__METHOD__,
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'LIMIT' => $maxPages ]
|
2010-07-26 17:31:38 +00:00
|
|
|
);
|
2010-05-06 21:07:37 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$pages = [];
|
2011-03-18 20:37:11 +00:00
|
|
|
|
2010-10-13 23:11:40 +00:00
|
|
|
foreach ( $res as $row ) {
|
2018-08-26 17:52:17 +00:00
|
|
|
$pages[] = Title::makeName( $row->page_namespace, $row->page_title );
|
2009-03-16 21:19:01 +00:00
|
|
|
}
|
2013-04-14 17:27:14 +00:00
|
|
|
|
2009-03-16 21:19:01 +00:00
|
|
|
return $pages;
|
|
|
|
|
}
|
2010-05-06 21:07:37 +00:00
|
|
|
|
2009-03-16 21:19:01 +00:00
|
|
|
/**
|
|
|
|
|
* Expand a list of pages to include templates used in those pages.
|
2014-04-19 08:16:52 +00:00
|
|
|
* @param array $inputPages List of titles to look up
|
|
|
|
|
* @param array $pageSet Associative array indexed by titles for output
|
|
|
|
|
* @return array Associative array index by titles
|
2009-03-16 21:19:01 +00:00
|
|
|
*/
|
2019-10-21 16:29:06 +00:00
|
|
|
protected function getTemplates( $inputPages, $pageSet ) {
|
2009-03-16 21:19:01 +00:00
|
|
|
return $this->getLinks( $inputPages, $pageSet,
|
2010-07-26 17:31:38 +00:00
|
|
|
'templatelinks',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'namespace' => 'tl_namespace', 'title' => 'tl_title' ],
|
|
|
|
|
[ 'page_id=tl_from' ]
|
2010-07-26 17:31:38 +00:00
|
|
|
);
|
2009-03-16 21:19:01 +00:00
|
|
|
}
|
2010-05-06 21:07:37 +00:00
|
|
|
|
2009-03-16 21:19:01 +00:00
|
|
|
/**
|
|
|
|
|
* Validate link depth setting, if available.
|
2014-04-19 08:16:52 +00:00
|
|
|
* @param int $depth
|
2011-12-11 20:57:57 +00:00
|
|
|
* @return int
|
2009-03-16 21:19:01 +00:00
|
|
|
*/
|
2019-10-21 16:29:06 +00:00
|
|
|
protected function validateLinkDepth( $depth ) {
|
2013-04-14 17:27:14 +00:00
|
|
|
if ( $depth < 0 ) {
|
2009-03-16 21:19:01 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
2011-03-18 20:37:11 +00:00
|
|
|
|
2009-03-16 20:40:03 +00:00
|
|
|
if ( !$this->userCanOverrideExportDepth() ) {
|
2014-08-03 22:10:25 +00:00
|
|
|
$maxLinkDepth = $this->getConfig()->get( 'ExportMaxLinkDepth' );
|
|
|
|
|
if ( $depth > $maxLinkDepth ) {
|
|
|
|
|
return $maxLinkDepth;
|
2009-03-16 21:19:01 +00:00
|
|
|
}
|
2008-01-20 07:14:12 +00:00
|
|
|
}
|
2011-03-18 20:37:11 +00:00
|
|
|
|
2008-01-20 10:58:45 +00:00
|
|
|
/*
|
2009-03-16 20:40:03 +00:00
|
|
|
* There's a HARD CODED limit of 5 levels of recursion here to prevent a
|
|
|
|
|
* crazy-big export from being done by someone setting the depth
|
|
|
|
|
* number too high. In other words, last resort safety net.
|
|
|
|
|
*/
|
2013-04-14 17:27:14 +00:00
|
|
|
|
2009-03-16 21:19:01 +00:00
|
|
|
return intval( min( $depth, 5 ) );
|
|
|
|
|
}
|
2010-05-06 21:07:37 +00:00
|
|
|
|
2011-12-11 20:57:57 +00:00
|
|
|
/**
|
|
|
|
|
* Expand a list of pages to include pages linked to from that page.
|
2014-04-19 08:16:52 +00:00
|
|
|
* @param array $inputPages
|
|
|
|
|
* @param array $pageSet
|
|
|
|
|
* @param int $depth
|
2011-12-11 20:57:57 +00:00
|
|
|
* @return array
|
|
|
|
|
*/
|
2019-10-21 16:29:06 +00:00
|
|
|
protected function getPageLinks( $inputPages, $pageSet, $depth ) {
|
2013-04-14 17:27:14 +00:00
|
|
|
for ( ; $depth > 0; --$depth ) {
|
2010-07-26 17:31:38 +00:00
|
|
|
$pageSet = $this->getLinks(
|
|
|
|
|
$inputPages, $pageSet, 'pagelinks',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'namespace' => 'pl_namespace', 'title' => 'pl_title' ],
|
|
|
|
|
[ 'page_id=pl_from' ]
|
2010-07-26 17:31:38 +00:00
|
|
|
);
|
2009-04-29 21:31:05 +00:00
|
|
|
$inputPages = array_keys( $pageSet );
|
2009-03-16 21:19:01 +00:00
|
|
|
}
|
2011-03-18 20:37:11 +00:00
|
|
|
|
2009-03-16 21:19:01 +00:00
|
|
|
return $pageSet;
|
|
|
|
|
}
|
2010-05-06 21:07:37 +00:00
|
|
|
|
2009-03-16 21:19:01 +00:00
|
|
|
/**
|
|
|
|
|
* Expand a list of pages to include items used in those pages.
|
2013-04-01 18:24:26 +00:00
|
|
|
* @param array $inputPages Array of page titles
|
|
|
|
|
* @param array $pageSet
|
|
|
|
|
* @param string $table
|
|
|
|
|
* @param array $fields Array of field names
|
|
|
|
|
* @param array $join
|
2012-02-09 21:36:14 +00:00
|
|
|
* @return array
|
2009-03-16 21:19:01 +00:00
|
|
|
*/
|
2019-10-21 16:29:06 +00:00
|
|
|
protected function getLinks( $inputPages, $pageSet, $table, $fields, $join ) {
|
2020-10-21 17:55:48 +00:00
|
|
|
$dbr = $this->loadBalancer->getConnectionRef( ILoadBalancer::DB_REPLICA );
|
2011-03-18 20:37:11 +00:00
|
|
|
|
2013-04-14 17:27:14 +00:00
|
|
|
foreach ( $inputPages as $page ) {
|
2009-03-16 21:19:01 +00:00
|
|
|
$title = Title::newFromText( $page );
|
2011-03-18 20:37:11 +00:00
|
|
|
|
2013-04-14 17:27:14 +00:00
|
|
|
if ( $title ) {
|
2009-03-16 21:19:01 +00:00
|
|
|
$pageSet[$title->getPrefixedText()] = true;
|
2011-05-17 22:03:20 +00:00
|
|
|
/// @todo FIXME: May or may not be more efficient to batch these
|
2009-03-16 21:19:01 +00:00
|
|
|
/// by namespace when given multiple input pages.
|
|
|
|
|
$result = $dbr->select(
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'page', $table ],
|
2010-07-26 17:31:38 +00:00
|
|
|
$fields,
|
|
|
|
|
array_merge(
|
|
|
|
|
$join,
|
2016-02-17 09:09:32 +00:00
|
|
|
[
|
2010-07-26 17:31:38 +00:00
|
|
|
'page_namespace' => $title->getNamespace(),
|
|
|
|
|
'page_title' => $title->getDBkey()
|
2016-02-17 09:09:32 +00:00
|
|
|
]
|
2010-07-26 17:31:38 +00:00
|
|
|
),
|
|
|
|
|
__METHOD__
|
|
|
|
|
);
|
2011-03-18 20:37:11 +00:00
|
|
|
|
2013-04-14 17:27:14 +00:00
|
|
|
foreach ( $result as $row ) {
|
2009-03-16 21:19:01 +00:00
|
|
|
$template = Title::makeTitle( $row->namespace, $row->title );
|
|
|
|
|
$pageSet[$template->getPrefixedText()] = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-03-18 20:37:11 +00:00
|
|
|
|
2009-03-16 21:19:01 +00:00
|
|
|
return $pageSet;
|
|
|
|
|
}
|
2011-03-18 20:37:11 +00:00
|
|
|
|
2013-03-07 20:15:54 +00:00
|
|
|
protected function getGroupName() {
|
|
|
|
|
return 'pagetools';
|
|
|
|
|
}
|
2011-03-05 19:22:43 +00:00
|
|
|
}
|