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
|
|
|
*/
|
|
|
|
|
|
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 {
|
2010-05-06 21:07:37 +00:00
|
|
|
|
2009-03-16 21:19:01 +00:00
|
|
|
private $curonly, $doExport, $pageLinkDepth, $templates;
|
|
|
|
|
private $images;
|
2010-05-06 21:07:37 +00:00
|
|
|
|
2009-03-16 21:19:01 +00:00
|
|
|
public function __construct() {
|
|
|
|
|
parent::__construct( 'Export' );
|
|
|
|
|
}
|
2010-05-06 21:07:37 +00:00
|
|
|
|
2009-03-16 21:19:01 +00:00
|
|
|
public function execute( $par ) {
|
2011-09-02 16:59:01 +00:00
|
|
|
global $wgSitename, $wgExportAllowListContributors, $wgExportFromNamespaces;
|
2009-03-16 21:19:01 +00:00
|
|
|
global $wgExportAllowHistory, $wgExportMaxHistory, $wgExportMaxLinkDepth;
|
2012-01-03 21:08:32 +00:00
|
|
|
global $wgExportAllowAll;
|
2010-05-06 21:07:37 +00:00
|
|
|
|
2009-03-16 21:19:01 +00:00
|
|
|
$this->setHeaders();
|
|
|
|
|
$this->outputHeader();
|
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' );
|
|
|
|
|
$this->images = $request->getCheck( 'images' ); // Doesn't do anything yet
|
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 ) {
|
|
|
|
|
$page .= "\n" . implode( "\n", $catpages );
|
|
|
|
|
}
|
2009-03-16 21:19:01 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-09-02 16:59:01 +00:00
|
|
|
elseif( $request->getCheck( 'addns' ) && $wgExportFromNamespaces ) {
|
|
|
|
|
$page = $request->getText( 'pages' );
|
|
|
|
|
$nsindex = $request->getText( 'nsindex', '' );
|
2010-05-06 21:07:37 +00:00
|
|
|
|
2009-05-19 14:54:20 +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
|
|
|
}
|
2009-03-16 21:19:01 +00:00
|
|
|
}
|
2012-01-03 21:08:32 +00:00
|
|
|
elseif( $request->getCheck( 'exportall' ) && $wgExportAllowAll ) {
|
|
|
|
|
$this->doExport = true;
|
|
|
|
|
$exportall = true;
|
|
|
|
|
}
|
2011-09-02 16:59:01 +00:00
|
|
|
elseif( $request->wasPosted() && $par == '' ) {
|
|
|
|
|
$page = $request->getText( 'pages' );
|
|
|
|
|
$this->curonly = $request->getCheck( 'curonly' );
|
|
|
|
|
$rawOffset = $request->getVal( 'offset' );
|
2011-03-18 20:37:11 +00:00
|
|
|
|
2009-03-16 21:19:01 +00:00
|
|
|
if( $rawOffset ) {
|
|
|
|
|
$offset = wfTimestamp( TS_MW, $rawOffset );
|
|
|
|
|
} else {
|
|
|
|
|
$offset = null;
|
|
|
|
|
}
|
2011-03-18 20:37:11 +00:00
|
|
|
|
2011-09-02 16:59:01 +00:00
|
|
|
$limit = $request->getInt( 'limit' );
|
|
|
|
|
$dir = $request->getVal( 'dir' );
|
2009-03-16 21:19:01 +00:00
|
|
|
$history = array(
|
2009-08-04 08:54:31 +00:00
|
|
|
'dir' => 'asc',
|
|
|
|
|
'offset' => false,
|
|
|
|
|
'limit' => $wgExportMaxHistory,
|
|
|
|
|
);
|
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 ) {
|
2009-09-29 21:37:07 +00:00
|
|
|
if ( $limit > 0 && ($wgExportMaxHistory == 0 || $limit < $wgExportMaxHistory ) ) {
|
2009-03-16 21:19:01 +00:00
|
|
|
$history['limit'] = $limit;
|
|
|
|
|
}
|
|
|
|
|
if ( !is_null( $offset ) ) {
|
|
|
|
|
$history['offset'] = $offset;
|
|
|
|
|
}
|
|
|
|
|
if ( strtolower( $dir ) == 'desc' ) {
|
|
|
|
|
$history['dir'] = 'desc';
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-05-06 21:07:37 +00:00
|
|
|
|
2010-12-22 18:25:40 +00:00
|
|
|
if( $page != '' ) {
|
|
|
|
|
$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
|
|
|
|
2009-03-16 21:19:01 +00:00
|
|
|
if( $historyCheck ) {
|
|
|
|
|
$history = WikiExporter::FULL;
|
|
|
|
|
} else {
|
|
|
|
|
$history = WikiExporter::CURRENT;
|
|
|
|
|
}
|
2010-05-06 21:07:37 +00:00
|
|
|
|
2010-12-22 18:25:40 +00:00
|
|
|
if( $page != '' ) {
|
|
|
|
|
$this->doExport = true;
|
|
|
|
|
}
|
2009-03-16 21:19:01 +00:00
|
|
|
}
|
2010-05-06 21:07:37 +00:00
|
|
|
|
2009-03-16 21:19:01 +00:00
|
|
|
if( !$wgExportAllowHistory ) {
|
|
|
|
|
// 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' );
|
2010-12-22 18:25:40 +00:00
|
|
|
if ( !$this->curonly || !$wgExportAllowListContributors ) {
|
|
|
|
|
$list_authors = false ;
|
|
|
|
|
}
|
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();
|
2011-09-02 16:59:01 +00:00
|
|
|
$request->response()->header( "Content-type: application/xml; charset=utf-8" );
|
2011-03-18 20:37:11 +00:00
|
|
|
|
2011-09-02 16:59:01 +00:00
|
|
|
if( $request->getCheck( 'wpDownload' ) ) {
|
2009-03-16 21:19:01 +00:00
|
|
|
// Provide a sane filename suggestion
|
|
|
|
|
$filename = urlencode( $wgSitename . '-' . 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
|
|
|
|
2009-03-16 21:19:01 +00:00
|
|
|
$form = Xml::openElement( 'form', array( 'method' => 'post',
|
2009-08-04 08:54:31 +00:00
|
|
|
'action' => $this->getTitle()->getLocalUrl( 'action=submit' ) ) );
|
2010-05-30 17:33:59 +00:00
|
|
|
$form .= Xml::inputLabel( wfMsg( 'export-addcattext' ) , 'catname', 'catname', 40 ) . ' ';
|
2009-03-16 21:19:01 +00:00
|
|
|
$form .= Xml::submitButton( wfMsg( 'export-addcat' ), array( 'name' => 'addcat' ) ) . '<br />';
|
2010-05-06 21:07:37 +00:00
|
|
|
|
2009-03-24 18:48:50 +00:00
|
|
|
if ( $wgExportFromNamespaces ) {
|
2010-05-30 17:33:59 +00:00
|
|
|
$form .= Xml::namespaceSelector( $nsindex, null, 'nsindex', wfMsg( 'export-addnstext' ) ) . ' ';
|
2009-03-24 18:48:50 +00:00
|
|
|
$form .= Xml::submitButton( wfMsg( 'export-addns' ), array( 'name' => 'addns' ) ) . '<br />';
|
|
|
|
|
}
|
2010-05-06 21:07:37 +00:00
|
|
|
|
2012-01-03 21:08:32 +00:00
|
|
|
if ( $wgExportAllowAll ) {
|
|
|
|
|
$form .= Xml::checkLabel(
|
|
|
|
|
wfMsg( 'exportall' ),
|
|
|
|
|
'exportall',
|
|
|
|
|
'exportall',
|
|
|
|
|
$request->wasPosted() ? $request->getCheck( 'exportall' ) : false
|
|
|
|
|
) . '<br />';
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-16 21:19:01 +00:00
|
|
|
$form .= Xml::element( 'textarea', array( 'name' => 'pages', 'cols' => 40, 'rows' => 10 ), $page, false );
|
|
|
|
|
$form .= '<br />';
|
2010-05-06 21:07:37 +00:00
|
|
|
|
2009-03-16 21:19:01 +00:00
|
|
|
if( $wgExportAllowHistory ) {
|
2011-03-05 19:22:43 +00:00
|
|
|
$form .= Xml::checkLabel(
|
|
|
|
|
wfMsg( 'exportcuronly' ),
|
|
|
|
|
'curonly',
|
|
|
|
|
'curonly',
|
2011-09-02 16:59:01 +00:00
|
|
|
$request->wasPosted() ? $request->getCheck( 'curonly' ) : true
|
2011-03-05 19:22:43 +00:00
|
|
|
) . '<br />';
|
2009-03-16 21:19:01 +00:00
|
|
|
} else {
|
2011-09-02 16:59:01 +00:00
|
|
|
$out->addHTML( wfMsgExt( 'exportnohistory', 'parse' ) );
|
2009-03-16 21:19:01 +00:00
|
|
|
}
|
2011-03-18 20:37:11 +00:00
|
|
|
|
2011-03-05 19:22:43 +00:00
|
|
|
$form .= Xml::checkLabel(
|
2011-03-18 20:37:11 +00:00
|
|
|
wfMsg( 'export-templates' ),
|
|
|
|
|
'templates',
|
|
|
|
|
'wpExportTemplates',
|
2011-09-02 16:59:01 +00:00
|
|
|
$request->wasPosted() ? $request->getCheck( 'templates' ) : false
|
2011-03-05 19:22:43 +00:00
|
|
|
) . '<br />';
|
2011-03-18 20:37:11 +00:00
|
|
|
|
2009-03-16 21:19:01 +00:00
|
|
|
if( $wgExportMaxLinkDepth || $this->userCanOverrideExportDepth() ) {
|
|
|
|
|
$form .= Xml::inputLabel( wfMsg( 'export-pagelinks' ), 'pagelink-depth', 'pagelink-depth', 20, 0 ) . '<br />';
|
|
|
|
|
}
|
|
|
|
|
// Enable this when we can do something useful exporting/importing image information. :)
|
|
|
|
|
//$form .= Xml::checkLabel( wfMsg( 'export-images' ), 'images', 'wpExportImages', false ) . '<br />';
|
2011-03-05 19:22:43 +00:00
|
|
|
$form .= Xml::checkLabel(
|
|
|
|
|
wfMsg( 'export-download' ),
|
|
|
|
|
'wpDownload',
|
|
|
|
|
'wpDownload',
|
2011-09-02 16:59:01 +00:00
|
|
|
$request->wasPosted() ? $request->getCheck( 'wpDownload' ) : true
|
2011-03-05 19:22:43 +00:00
|
|
|
) . '<br />';
|
2010-05-06 21:07:37 +00:00
|
|
|
|
2011-11-16 12:01:58 +00:00
|
|
|
if ( $wgExportAllowListContributors ) {
|
|
|
|
|
$form .= Xml::checkLabel(
|
|
|
|
|
wfMsg( 'exportlistauthors' ),
|
|
|
|
|
'listauthors',
|
|
|
|
|
'listauthors',
|
|
|
|
|
$request->wasPosted() ? $request->getCheck( 'listauthors' ) : false
|
|
|
|
|
) . '<br />';
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-04 08:28:27 +00:00
|
|
|
$form .= Xml::submitButton( wfMsg( 'export-submit' ), Linker::tooltipAndAccesskeyAttribs( 'export' ) );
|
2009-03-16 21:19:01 +00:00
|
|
|
$form .= Xml::closeElement( 'form' );
|
2011-03-18 20:37:11 +00:00
|
|
|
|
2011-09-02 16:59:01 +00:00
|
|
|
$out->addHTML( $form );
|
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
|
|
|
|
|
*/
|
2009-03-16 21:19:01 +00:00
|
|
|
private function userCanOverrideExportDepth() {
|
2011-09-02 16:59:01 +00:00
|
|
|
return $this->getUser()->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
|
|
|
*
|
|
|
|
|
* @param $page String: user input on what page(s) to export
|
|
|
|
|
* @param $history Mixed: one of the WikiExporter history export constants
|
|
|
|
|
* @param $list_authors Boolean: Whether to add distinct author list (when
|
|
|
|
|
* not returning full history)
|
2012-01-03 21:08:32 +00:00
|
|
|
* @param $exportall Boolean: Whether to export everything
|
2009-03-16 21:19:01 +00:00
|
|
|
*/
|
2012-01-03 21:08:32 +00:00
|
|
|
private function doExport( $page, $history, $list_authors, $exportall ) {
|
|
|
|
|
|
|
|
|
|
// 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 {
|
|
|
|
|
|
|
|
|
|
$pageSet = array(); // Inverted index of all pages to look up
|
|
|
|
|
|
|
|
|
|
// Split up and normalize input
|
|
|
|
|
foreach( explode( "\n", $page ) as $pageName ) {
|
|
|
|
|
$pageName = trim( $pageName );
|
|
|
|
|
$title = Title::newFromText( $pageName );
|
|
|
|
|
if( $title && $title->getInterwiki() == '' && $title->getText() !== '' ) {
|
|
|
|
|
// 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...
|
|
|
|
|
if( $this->templates ) {
|
|
|
|
|
$pageSet = $this->getTemplates( $inputPages, $pageSet );
|
|
|
|
|
}
|
|
|
|
|
$linkDepth = $this->pageLinkDepth;
|
|
|
|
|
if( $linkDepth ) {
|
|
|
|
|
$pageSet = $this->getPageLinks( $inputPages, $pageSet, $linkDepth );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
// Enable this when we can do something useful exporting/importing image information. :)
|
|
|
|
|
if( $this->images ) ) {
|
|
|
|
|
$pageSet = $this->getImages( $inputPages, $pageSet );
|
|
|
|
|
}
|
|
|
|
|
*/
|
2010-05-06 21:07:37 +00:00
|
|
|
|
2012-01-03 21:08:32 +00:00
|
|
|
$pages = array_keys( $pageSet );
|
2010-05-06 21:07:37 +00:00
|
|
|
|
2012-01-03 21:08:32 +00:00
|
|
|
// Normalize titles to the same format and remove dupes, see bug 17374
|
|
|
|
|
foreach( $pages as $k => $v ) {
|
|
|
|
|
$pages[$k] = str_replace( " ", "_", $v );
|
|
|
|
|
}
|
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... */
|
2012-01-05 17:10:07 +00:00
|
|
|
if( $history == WikiExporter::CURRENT ) {
|
2009-03-16 21:19:01 +00:00
|
|
|
$lb = false;
|
|
|
|
|
$db = wfGetDB( DB_SLAVE );
|
|
|
|
|
$buffer = WikiExporter::BUFFER;
|
|
|
|
|
} else {
|
|
|
|
|
// Use an unbuffered query; histories may be very long!
|
|
|
|
|
$lb = wfGetLBFactory()->newMainLB();
|
|
|
|
|
$db = $lb->getConnection( DB_SLAVE );
|
|
|
|
|
$buffer = WikiExporter::STREAM;
|
2010-05-06 21:07:37 +00:00
|
|
|
|
2009-03-16 21:19:01 +00:00
|
|
|
// This might take a while... :D
|
|
|
|
|
wfSuppressWarnings();
|
|
|
|
|
set_time_limit(0);
|
|
|
|
|
wfRestoreWarnings();
|
|
|
|
|
}
|
2011-03-18 20:37:11 +00:00
|
|
|
|
2009-03-16 21:19:01 +00:00
|
|
|
$exporter = new WikiExporter( $db, $history, $buffer );
|
|
|
|
|
$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 {
|
|
|
|
|
foreach( $pages as $page ) {
|
2009-03-16 21:19:01 +00:00
|
|
|
/*
|
|
|
|
|
if( $wgExportMaxHistory && !$this->curonly ) {
|
|
|
|
|
$title = Title::newFromText( $page );
|
|
|
|
|
if( $title ) {
|
|
|
|
|
$count = Revision::countByTitle( $db, $title );
|
|
|
|
|
if( $count > $wgExportMaxHistory ) {
|
|
|
|
|
wfDebug( __FUNCTION__ .
|
|
|
|
|
": Skipped $page, $count revisions too big\n" );
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}*/
|
|
|
|
|
#Bug 8824: Only export pages the user can read
|
2012-01-03 21:08:32 +00:00
|
|
|
$title = Title::newFromText( $page );
|
|
|
|
|
if( is_null( $title ) ) {
|
|
|
|
|
continue; #TODO: perhaps output an <error> tag or something.
|
|
|
|
|
}
|
|
|
|
|
if( !$title->userCan( 'read', $this->getUser() ) ) {
|
|
|
|
|
continue; #TODO: perhaps output an <error> tag or something.
|
|
|
|
|
}
|
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();
|
2011-03-18 20:37:11 +00:00
|
|
|
|
2009-03-16 21:19:01 +00:00
|
|
|
if( $lb ) {
|
|
|
|
|
$lb->closeAll();
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-01-05 22:53:00 +00:00
|
|
|
|
2011-12-11 20:57:57 +00:00
|
|
|
/**
|
|
|
|
|
* @param $title Title
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
2009-03-16 21:19:01 +00:00
|
|
|
private function getPagesFromCategory( $title ) {
|
|
|
|
|
global $wgContLang;
|
2010-05-06 21:07:37 +00:00
|
|
|
|
2009-03-16 21:19:01 +00:00
|
|
|
$name = $title->getDBkey();
|
2010-05-06 21:07:37 +00:00
|
|
|
|
2009-03-16 21:19:01 +00:00
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
2010-07-26 17:31:38 +00:00
|
|
|
$res = $dbr->select(
|
|
|
|
|
array( 'page', 'categorylinks' ),
|
|
|
|
|
array( 'page_namespace', 'page_title' ),
|
|
|
|
|
array( 'cl_from=page_id', 'cl_to' => $name ),
|
|
|
|
|
__METHOD__,
|
|
|
|
|
array( 'LIMIT' => '5000' )
|
|
|
|
|
);
|
2010-05-06 21:07:37 +00:00
|
|
|
|
2009-03-16 21:19:01 +00:00
|
|
|
$pages = array();
|
2011-03-18 20:37:11 +00:00
|
|
|
|
2010-10-13 23:11:40 +00:00
|
|
|
foreach ( $res as $row ) {
|
2009-03-16 21:19:01 +00:00
|
|
|
$n = $row->page_title;
|
|
|
|
|
if ($row->page_namespace) {
|
|
|
|
|
$ns = $wgContLang->getNsText( $row->page_namespace );
|
|
|
|
|
$n = $ns . ':' . $n;
|
|
|
|
|
}
|
2010-05-06 21:07:37 +00:00
|
|
|
|
2009-03-16 21:19:01 +00:00
|
|
|
$pages[] = $n;
|
|
|
|
|
}
|
|
|
|
|
return $pages;
|
|
|
|
|
}
|
2010-05-06 21:07:37 +00:00
|
|
|
|
2011-12-11 20:57:57 +00:00
|
|
|
/**
|
|
|
|
|
* @param $nsindex int
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
2009-03-16 21:19:01 +00:00
|
|
|
private function getPagesFromNamespace( $nsindex ) {
|
|
|
|
|
global $wgContLang;
|
2010-05-06 21:07:37 +00:00
|
|
|
|
2009-03-16 21:19:01 +00:00
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
2010-07-26 17:31:38 +00:00
|
|
|
$res = $dbr->select(
|
|
|
|
|
'page',
|
|
|
|
|
array( 'page_namespace', 'page_title' ),
|
|
|
|
|
array( 'page_namespace' => $nsindex ),
|
|
|
|
|
__METHOD__,
|
|
|
|
|
array( 'LIMIT' => '5000' )
|
|
|
|
|
);
|
2010-05-06 21:07:37 +00:00
|
|
|
|
2009-03-16 21:19:01 +00:00
|
|
|
$pages = array();
|
2011-03-18 20:37:11 +00:00
|
|
|
|
2010-10-13 23:11:40 +00:00
|
|
|
foreach ( $res as $row ) {
|
2009-03-16 21:19:01 +00:00
|
|
|
$n = $row->page_title;
|
2011-03-18 20:37:11 +00:00
|
|
|
|
2010-07-26 17:31:38 +00:00
|
|
|
if ( $row->page_namespace ) {
|
2009-03-16 21:19:01 +00:00
|
|
|
$ns = $wgContLang->getNsText( $row->page_namespace );
|
|
|
|
|
$n = $ns . ':' . $n;
|
|
|
|
|
}
|
2010-05-06 21:07:37 +00:00
|
|
|
|
2009-03-16 21:19:01 +00:00
|
|
|
$pages[] = $n;
|
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
|
* @param $inputPages array, list of titles to look up
|
|
|
|
|
* @param $pageSet array, associative array indexed by titles for output
|
|
|
|
|
* @return array associative array index by titles
|
|
|
|
|
*/
|
|
|
|
|
private function getTemplates( $inputPages, $pageSet ) {
|
|
|
|
|
return $this->getLinks( $inputPages, $pageSet,
|
2010-07-26 17:31:38 +00:00
|
|
|
'templatelinks',
|
|
|
|
|
array( 'tl_namespace AS namespace', 'tl_title AS title' ),
|
|
|
|
|
array( 'page_id=tl_from' )
|
|
|
|
|
);
|
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.
|
2011-12-11 20:57:57 +00:00
|
|
|
* @param $depth int
|
|
|
|
|
* @return int
|
2009-03-16 21:19:01 +00:00
|
|
|
*/
|
|
|
|
|
private function validateLinkDepth( $depth ) {
|
2010-07-24 19:11:52 +00:00
|
|
|
global $wgExportMaxLinkDepth;
|
2011-03-18 20:37:11 +00:00
|
|
|
|
2009-03-16 21:19:01 +00:00
|
|
|
if( $depth < 0 ) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2011-03-18 20:37:11 +00:00
|
|
|
|
2009-03-16 20:40:03 +00:00
|
|
|
if ( !$this->userCanOverrideExportDepth() ) {
|
2009-03-16 21:19:01 +00:00
|
|
|
if( $depth > $wgExportMaxLinkDepth ) {
|
|
|
|
|
return $wgExportMaxLinkDepth;
|
|
|
|
|
}
|
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.
|
|
|
|
|
*/
|
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.
|
|
|
|
|
* @param $inputPages array
|
|
|
|
|
* @param $pageSet array
|
|
|
|
|
* @param $depth int
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
2009-03-16 21:19:01 +00:00
|
|
|
private function getPageLinks( $inputPages, $pageSet, $depth ) {
|
2010-12-22 18:25:40 +00:00
|
|
|
for( ; $depth > 0; --$depth ) {
|
2010-07-26 17:31:38 +00:00
|
|
|
$pageSet = $this->getLinks(
|
|
|
|
|
$inputPages, $pageSet, 'pagelinks',
|
2011-03-18 20:37:11 +00:00
|
|
|
array( 'pl_namespace AS namespace', 'pl_title AS title' ),
|
2010-07-26 17:31:38 +00:00
|
|
|
array( 'page_id=pl_from' )
|
|
|
|
|
);
|
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 images used in those pages.
|
2011-03-18 20:37:11 +00:00
|
|
|
*
|
2009-03-16 21:19:01 +00:00
|
|
|
* @param $inputPages array, list of titles to look up
|
|
|
|
|
* @param $pageSet array, associative array indexed by titles for output
|
2011-03-18 20:37:11 +00:00
|
|
|
*
|
2009-03-16 21:19:01 +00:00
|
|
|
* @return array associative array index by titles
|
|
|
|
|
*/
|
|
|
|
|
private function getImages( $inputPages, $pageSet ) {
|
2010-07-26 17:31:38 +00:00
|
|
|
return $this->getLinks(
|
|
|
|
|
$inputPages,
|
|
|
|
|
$pageSet,
|
|
|
|
|
'imagelinks',
|
|
|
|
|
array( NS_FILE . ' AS namespace', 'il_to AS title' ),
|
|
|
|
|
array( 'page_id=il_from' )
|
|
|
|
|
);
|
2009-03-16 21:19:01 +00:00
|
|
|
}
|
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.
|
2012-02-09 21:36:14 +00:00
|
|
|
* @return array
|
2009-03-16 21:19:01 +00:00
|
|
|
*/
|
|
|
|
|
private function getLinks( $inputPages, $pageSet, $table, $fields, $join ) {
|
|
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
2011-03-18 20:37:11 +00:00
|
|
|
|
2009-03-16 21:19:01 +00:00
|
|
|
foreach( $inputPages as $page ) {
|
|
|
|
|
$title = Title::newFromText( $page );
|
2011-03-18 20:37:11 +00:00
|
|
|
|
2009-03-16 21:19:01 +00:00
|
|
|
if( $title ) {
|
|
|
|
|
$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(
|
2010-07-26 17:31:38 +00:00
|
|
|
array( 'page', $table ),
|
|
|
|
|
$fields,
|
|
|
|
|
array_merge(
|
|
|
|
|
$join,
|
|
|
|
|
array(
|
|
|
|
|
'page_namespace' => $title->getNamespace(),
|
|
|
|
|
'page_title' => $title->getDBkey()
|
|
|
|
|
)
|
|
|
|
|
),
|
|
|
|
|
__METHOD__
|
|
|
|
|
);
|
2011-03-18 20:37:11 +00:00
|
|
|
|
2009-03-16 21:19:01 +00:00
|
|
|
foreach( $result as $row ) {
|
|
|
|
|
$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
|
|
|
|
2011-03-05 19:22:43 +00:00
|
|
|
}
|