*/
class SpecialExport extends SpecialPage {
-
+
private $curonly, $doExport, $pageLinkDepth, $templates;
private $images;
-
+
public function __construct() {
parent::__construct( 'Export' );
}
public function execute( $par ) {
global $wgOut, $wgRequest, $wgSitename, $wgExportAllowListContributors;
global $wgExportAllowHistory, $wgExportMaxHistory;
-
+
+ $this->setHeaders();
+ $this->outputHeader();
+
// Set some variables
$this->curonly = true;
$this->doExport = false;
if ( $wgRequest->getCheck( 'addcat' ) ) {
$page = $wgRequest->getText( 'pages' );
$catname = $wgRequest->getText( 'catname' );
-
+
if ( $catname !== '' && $catname !== NULL && $catname !== false ) {
$t = Title::makeTitleSafe( NS_MAIN, $catname );
if ( $t ) {
$history['dir'] = 'desc';
}
}
-
+
if( $page != '' ) $this->doExport = true;
} else {
// Default to current-only for GET requests
- $page = $wgRequest->getText( 'pages', $page );
+ $page = $wgRequest->getText( 'pages' );
$historyCheck = $wgRequest->getCheck( 'history' );
if( $historyCheck ) {
$history = WikiExporter::FULL;
} else {
$history = WikiExporter::CURRENT;
}
-
+
if( $page != '' ) $this->doExport = true;
}
-
+
if( !$wgExportAllowHistory ) {
// Override
$history = WikiExporter::CURRENT;
}
-
+
$list_authors = $wgRequest->getCheck( 'listauthors' );
if ( !$this->curonly || !$wgExportAllowListContributors ) $list_authors = false ;
-
+
if ( $this->doExport ) {
$wgOut->disable();
// Cancel output buffering and gzipping if set
$this->doExport( $page, $history );
return;
}
-
+
$wgOut->addHTML( wfMsgExt( 'exporttext', 'parse' ) );
-
+
$form = Xml::openElement( 'form', array( 'method' => 'post',
'action' => $this->getTitle()->getLocalUrl( 'action=submit' ) ) );
$form .= Xml::inputLabel( wfMsg( 'export-addcattext' ) , 'catname', 'catname', 40 ) . ' ';
$form .= Xml::submitButton( wfMsg( 'export-addcat' ), array( 'name' => 'addcat' ) ) . '<br />';
$form .= Xml::element( 'textarea', array( 'name' => 'pages', 'cols' => 40, 'rows' => 10 ), $page, false );
$form .= '<br />';
-
+
if( $wgExportAllowHistory ) {
$form .= Xml::checkLabel( wfMsg( 'exportcuronly' ), 'curonly', 'curonly', true ) . '<br />';
} else {
// Enable this when we can do something useful exporting/importing image information. :)
//$form .= Xml::checkLabel( wfMsg( 'export-images' ), 'images', 'wpExportImages', false ) . '<br />';
$form .= Xml::checkLabel( wfMsg( 'export-download' ), 'wpDownload', 'wpDownload', true ) . '<br />';
-
+
$form .= Xml::submitButton( wfMsg( 'export-submit' ), array( 'accesskey' => 's' ) );
$form .= Xml::closeElement( 'form' );
$wgOut->addHTML( $form );
}
-
+
/**
* Do the actual page exporting
* @param string $page User input on what page(s) to export
*/
private function doExport( $page, $history ) {
global $wgExportMaxHistory;
-
+
/* Split up the input and look up linked pages */
$inputPages = array_filter( explode( "\n", $page ), array( $this, 'filterPage' ) );
$pageSet = array_flip( $inputPages );
-
+
if( $this->templates ) {
$pageSet = $this->getTemplates( $inputPages, $pageSet );
}
-
+
if( $linkDepth = $this->pageLinkDepth ) {
$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 );
}
*/
-
+
$pages = array_keys( $pageSet );
-
+
/* Ok, let's get to it... */
if( $history == WikiExporter::CURRENT ) {
$lb = false;
$lb = wfGetLBFactory()->newMainLB();
$db = $lb->getConnection( DB_SLAVE );
$buffer = WikiExporter::STREAM;
-
+
// This might take a while... :D
wfSuppressWarnings();
set_time_limit(0);
$title = Title::newFromText( $page );
if( is_null( $title ) ) continue; #TODO: perhaps output an <error> tag or something.
if( !$title->userCanRead() ) continue; #TODO: perhaps output an <error> tag or something.
-
+
$exporter->pageByTitle( $title );
}
-
+
$exporter->closeStream();
if( $lb ) {
$lb->closeAll();
}
}
-
+
private function getPagesFromCategory( $title ) {
global $wgContLang;
$name = $title->getDBkey();
-
+
$dbr = wfGetDB( DB_SLAVE );
-
+
list( $page, $categorylinks ) = $dbr->tableNamesN( 'page', 'categorylinks' );
$sql = "SELECT page_namespace, page_title FROM $page " .
"JOIN $categorylinks ON cl_from = page_id " .
"WHERE cl_to = " . $dbr->addQuotes( $name );
-
+
$pages = array();
$res = $dbr->query( $sql, __METHOD__ );
while ( $row = $dbr->fetchObject( $res ) ) {
$ns = $wgContLang->getNsText( $row->page_namespace );
$n = $ns . ':' . $n;
}
-
+
$pages[] = $n;
}
$dbr->freeResult($res);
-
- return $pages;
+
+ return $pages;
}
/**
}
return $pageSet;
}
-
+
/**
* Expand a list of pages to include images used in those pages.
* @param $inputPages array, list of titles to look up
array( NS_FILE . ' AS namespace', 'il_to AS title' ),
array( 'page_id=il_from' ) );
}
-
+
/**
* Expand a list of pages to include items used in those pages.
* @private