62 parent::__construct(
'Export' );
63 $this->dbProvider = $dbProvider;
64 $this->wikiExporterFactory = $wikiExporterFactory;
65 $this->titleFormatter = $titleFormatter;
66 $this->linksMigration = $linksMigration;
74 $this->curonly =
true;
77 $this->templates = $request->getCheck(
'templates' );
79 $request->getIntOrNull(
'pagelink-depth' )
84 if ( $request->getCheck(
'addcat' ) ) {
85 $page = $request->getText(
'pages' );
86 $catname = $request->getText(
'catname' );
88 if ( $catname !==
'' && $catname !==
null && $catname !==
false ) {
89 $t = Title::makeTitleSafe(
NS_MAIN, $catname );
101 $page .= implode(
"\n", $catpages );
106 $page = $request->getText(
'pages' );
107 $nsindex = $request->getText(
'nsindex',
'' );
109 if ( strval( $nsindex ) !==
'' ) {
115 $page .=
"\n" . implode(
"\n", $nspages );
128 } elseif ( $request->wasPosted() && $par ==
'' ) {
131 LoggerFactory::getInstance(
'export' )->debug(
132 'Special:Export POST, dir: [{dir}], offset: [{offset}], limit: [{limit}]', [
133 'dir' => $request->getRawVal(
'dir' ),
134 'offset' => $request->getRawVal(
'offset' ),
135 'limit' => $request->getRawVal(
'limit' ),
138 $page = $request->getText(
'pages' );
139 $this->curonly = $request->getCheck(
'curonly' );
140 $rawOffset = $request->getVal(
'offset' );
149 $limit = $request->getInt(
'limit' );
150 $dir = $request->getVal(
'dir' );
154 'limit' => $maxHistory,
156 $historyCheck = $request->getCheck(
'history' );
158 if ( $this->curonly ) {
159 $history = WikiExporter::CURRENT;
160 } elseif ( !$historyCheck ) {
161 if ( $limit > 0 && ( $maxHistory == 0 || $limit < $maxHistory ) ) {
162 $history[
'limit'] = $limit;
165 if ( $offset !==
null ) {
166 $history[
'offset'] = $offset;
169 if ( strtolower( $dir ??
'' ) ==
'desc' ) {
170 $history[
'dir'] =
'desc';
179 $page = $request->getText(
'pages', $par ??
'' );
180 $historyCheck = $request->getCheck(
'history' );
182 if ( $historyCheck ) {
183 $history = WikiExporter::FULL;
185 $history = WikiExporter::CURRENT;
195 $history = WikiExporter::CURRENT;
198 $list_authors = $request->getCheck(
'listauthors' );
200 $list_authors =
false;
209 $request->response()->header(
'Content-type: application/xml; charset=utf-8' );
210 $request->response()->header(
'X-Robots-Tag: noindex,nofollow' );
212 if ( $request->getCheck(
'wpDownload' ) ) {
216 $request->response()->header(
"Content-disposition: attachment;filename={$filename}" );
221 $this->
doExport( $page, $history, $list_authors, $exportall );
227 $out->addWikiMsg(
'exporttext' );
230 $categoryName = $request->getText(
'catname' );
235 $hideIf = $canExportAll ? [
'hide-if' => [
'===',
'exportall',
'1' ] ] : [];
239 'type' =>
'textwithbutton',
241 'horizontal-label' =>
true,
242 'label-message' =>
'export-addcattext',
243 'default' => $categoryName,
245 'buttontype' =>
'submit',
246 'buttonname' =>
'addcat',
247 'buttondefault' => $this->
msg(
'export-addcat' )->text(),
253 'type' =>
'namespaceselectwithbutton',
254 'default' => $nsindex,
255 'label-message' =>
'export-addnstext',
256 'horizontal-label' =>
true,
259 'cssclass' =>
'namespaceselector',
260 'buttontype' =>
'submit',
261 'buttonname' =>
'addns',
262 'buttondefault' => $this->
msg(
'export-addns' )->text(),
267 if ( $canExportAll ) {
271 'label-message' =>
'exportall',
272 'name' =>
'exportall',
274 'default' => $request->wasPosted() && $request->getCheck(
'exportall' ),
281 'class' => HTMLTextAreaField::class,
283 'label-message' =>
'export-manual',
294 'label-message' =>
'exportcuronly',
297 'default' => !$request->wasPosted() || $request->getCheck(
'curonly' ),
301 $out->addWikiMsg(
'exportnohistory' );
307 'label-message' =>
'export-templates',
308 'name' =>
'templates',
309 'id' =>
'wpExportTemplates',
310 'default' => $request->wasPosted() && $request->getCheck(
'templates' ),
316 'pagelink-depth' => [
318 'name' =>
'pagelink-depth',
319 'id' =>
'pagelink-depth',
320 'label-message' =>
'export-pagelinks',
330 'name' =>
'wpDownload',
331 'id' =>
'wpDownload',
332 'default' => !$request->wasPosted() || $request->getCheck(
'wpDownload' ),
333 'label-message' =>
'export-download',
341 'label-message' =>
'exportlistauthors',
342 'default' => $request->wasPosted() && $request->getCheck(
'listauthors' ),
343 'name' =>
'listauthors',
344 'id' =>
'listauthors',
349 $htmlForm = HTMLForm::factory(
'ooui', $formDescriptor, $this->
getContext() );
350 $htmlForm->setSubmitTextMsg(
'export-submit' );
351 $htmlForm->prepareForm()->displayForm(
false );
359 return $this->
getAuthority()->isAllowed(
'override-export-depth' );
371 protected function doExport( $page, $history, $list_authors, $exportall ) {
374 $history = WikiExporter::FULL;
379 foreach ( explode(
"\n", $page ) as $pageName ) {
380 $pageName = trim( $pageName );
381 $title = Title::newFromText( $pageName );
382 if ( $title && !$title->isExternal() && $title->getText() !==
'' ) {
384 $pageSet[$title->getPrefixedText()] =
true;
389 $inputPages = array_keys( $pageSet );
392 if ( $this->templates ) {
393 $pageSet = $this->
getTemplates( $inputPages, $pageSet );
395 $pageSet = $this->getExtraPages( $inputPages, $pageSet );
398 $pageSet = $this->
getPageLinks( $inputPages, $pageSet, $linkDepth );
401 $pages = array_keys( $pageSet );
404 foreach ( $pages as $k => $v ) {
405 $pages[$k] = str_replace(
' ',
'_', $v );
408 $pages = array_unique( $pages );
412 $db = $this->dbProvider->getReplicaDatabase();
414 $exporter = $this->wikiExporterFactory->getWikiExporter( $db, $history );
415 $exporter->list_authors = $list_authors;
416 $exporter->openStream();
419 $exporter->allPages();
422 foreach ( $pages as $page ) {
423 # T10824: Only export pages the user can read
424 $title = Title::newFromText( $page );
425 if ( $title ===
null ) {
430 if ( !$this->
getAuthority()->authorizeRead(
'read', $title ) ) {
435 $exporter->pageByTitle( $title );
439 $exporter->closeStream();
452 $dbr = $this->dbProvider->getReplicaDatabase();
453 $queryBuilder = $dbr->newSelectQueryBuilder()
454 ->select( [
'page_namespace',
'page_title' ] )
456 ->join(
'categorylinks',
null,
'cl_from=page_id' )
457 ->limit( $maxPages );
459 $queryBuilder->where( [
'cl_to' => $name ] );
461 $queryBuilder->join(
'linktarget',
null,
'cl_target_id = lt_id' )
462 ->where( [
'lt_title' => $name,
'lt_namespace' =>
NS_CATEGORY ] );
464 $res = $queryBuilder->caller( __METHOD__ )->fetchResultSet();
468 foreach ( $res as $row ) {
469 $pages[] = Title::makeName( $row->page_namespace, $row->page_title );
482 $dbr = $this->dbProvider->getReplicaDatabase();
483 $res = $dbr->newSelectQueryBuilder()
484 ->select( [
'page_namespace',
'page_title' ] )
486 ->where( [
'page_namespace' => $nsindex ] )
488 ->caller( __METHOD__ )->fetchResultSet();
492 foreach ( $res as $row ) {
493 $pages[] = Title::makeName( $row->page_namespace, $row->page_title );
506 [ $nsField, $titleField ] = $this->linksMigration->getTitleFields(
'templatelinks' );
507 $queryInfo = $this->linksMigration->getQueryInfo(
'templatelinks' );
508 $dbr = $this->dbProvider->getReplicaDatabase();
509 $queryBuilder = $dbr->newSelectQueryBuilder()
510 ->caller( __METHOD__ )
511 ->select( [
'namespace' => $nsField,
'title' => $titleField ] )
513 ->join(
'templatelinks',
null,
'page_id=tl_from' )
514 ->tables( array_diff( $queryInfo[
'tables'], [
'templatelinks' ] ) )
515 ->joinConds( $queryInfo[
'joins'] );
516 return $this->
getLinks( $inputPages, $pageSet, $queryBuilder );
525 private function getExtraPages( $inputPages, $pageSet ) {
527 $this->
getHookRunner()->onSpecialExportGetExtraPages( $inputPages, $extraPages );
528 foreach ( $extraPages as $extraPage ) {
529 $pageSet[$this->titleFormatter->getPrefixedText( $extraPage )] =
true;
540 if ( $depth ===
null || $depth < 0 ) {
546 if ( $depth > $maxLinkDepth ) {
547 return $maxLinkDepth;
557 return intval( min( $depth, 5 ) );
568 for ( ; $depth > 0; --$depth ) {
569 [ $nsField, $titleField ] = $this->linksMigration->getTitleFields(
'pagelinks' );
570 $queryInfo = $this->linksMigration->getQueryInfo(
'pagelinks' );
571 $dbr = $this->dbProvider->getReplicaDatabase();
572 $queryBuilder = $dbr->newSelectQueryBuilder()
573 ->caller( __METHOD__ )
574 ->select( [
'namespace' => $nsField,
'title' => $titleField ] )
576 ->join(
'pagelinks',
null,
'page_id=pl_from' )
577 ->tables( array_diff( $queryInfo[
'tables'], [
'pagelinks' ] ) )
578 ->joinConds( $queryInfo[
'joins'] );
579 $pageSet = $this->
getLinks( $inputPages, $pageSet, $queryBuilder );
580 $inputPages = array_keys( $pageSet );
594 foreach ( $inputPages as $page ) {
595 $title = Title::newFromText( $page );
597 $pageSet[$title->getPrefixedText()] =
true;
600 $result = ( clone $queryBuilder )
602 'page_namespace' => $title->getNamespace(),
603 'page_title' => $title->getDBkey()
607 foreach ( $result as $row ) {
608 $template = Title::makeTitle( $row->namespace, $row->title );
609 $pageSet[$template->getPrefixedText()] =
true;
623class_alias( SpecialExport::class,
'SpecialExport' );
const SCHEMA_COMPAT_READ_OLD
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
wfResetOutputBuffers( $resetGzipEncoding=true)
Clear away any user-level output buffers, discarding contents.
A class containing constants representing the names of configuration variables.
const ExportMaxLinkDepth
Name constant for the ExportMaxLinkDepth setting, for use with Config::get()
const CategoryLinksSchemaMigrationStage
Name constant for the CategoryLinksSchemaMigrationStage setting, for use with Config::get()
const Sitename
Name constant for the Sitename setting, for use with Config::get()
const ExportAllowAll
Name constant for the ExportAllowAll setting, for use with Config::get()
const ExportMaxHistory
Name constant for the ExportMaxHistory setting, for use with Config::get()
const ExportAllowListContributors
Name constant for the ExportAllowListContributors setting, for use with Config::get()
const ExportPagelistLimit
Name constant for the ExportPagelistLimit setting, for use with Config::get()
const ExportFromNamespaces
Name constant for the ExportFromNamespaces setting, for use with Config::get()
const ExportAllowHistory
Name constant for the ExportAllowHistory setting, for use with Config::get()
Parent class for all special pages.
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getConfig()
Shortcut to get main config object.
getContext()
Gets the context this SpecialPage is executed in.
getRequest()
Get the WebRequest being used for this instance.
msg( $key,... $params)
Wrapper around wfMessage that sets the current context.
getOutput()
Get the OutputPage being used for this instance.
getAuthority()
Shortcut to get the Authority executing this instance.
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages By default the message key is the canonical name of...
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
Interface for objects (potentially) representing an editable wiki page.