28use Wikimedia\Timestamp\TimestampFormat as TS;
48 parent::__construct(
'Export' );
57 $this->curonly =
true;
60 $this->templates = $request->getCheck(
'templates' );
62 $request->getIntOrNull(
'pagelink-depth' )
67 if ( $request->getCheck(
'addcat' ) ) {
68 $page = $request->getText(
'pages' );
69 $catname = $request->getText(
'catname' );
71 if ( $catname !==
'' && $catname !==
null && $catname !==
false ) {
72 $t = Title::makeTitleSafe(
NS_MAIN, $catname );
84 $page .= implode(
"\n", $catpages );
89 $page = $request->getText(
'pages' );
90 $nsindex = $request->getText(
'nsindex',
'' );
92 if ( strval( $nsindex ) !==
'' ) {
98 $page .=
"\n" . implode(
"\n", $nspages );
111 } elseif ( $request->wasPosted() && $par ==
'' ) {
114 LoggerFactory::getInstance(
'export' )->debug(
115 'Special:Export POST, dir: [{dir}], offset: [{offset}], limit: [{limit}]', [
116 'dir' => $request->getRawVal(
'dir' ),
117 'offset' => $request->getRawVal(
'offset' ),
118 'limit' => $request->getRawVal(
'limit' ),
121 $page = $request->getText(
'pages' );
122 $this->curonly = $request->getCheck(
'curonly' );
123 $rawOffset = $request->getVal(
'offset' );
132 $limit = $request->getInt(
'limit' );
133 $dir = $request->getVal(
'dir' );
137 'limit' => $maxHistory,
139 $historyCheck = $request->getCheck(
'history' );
141 if ( $this->curonly ) {
142 $history = WikiExporter::CURRENT;
143 } elseif ( !$historyCheck ) {
144 if ( $limit > 0 && ( $maxHistory == 0 || $limit < $maxHistory ) ) {
145 $history[
'limit'] = $limit;
148 if ( $offset !==
null ) {
149 $history[
'offset'] = $offset;
152 if ( strtolower( $dir ??
'' ) ==
'desc' ) {
153 $history[
'dir'] =
'desc';
162 $page = $request->getText(
'pages', $par ??
'' );
163 $historyCheck = $request->getCheck(
'history' );
165 if ( $historyCheck ) {
166 $history = WikiExporter::FULL;
168 $history = WikiExporter::CURRENT;
178 $history = WikiExporter::CURRENT;
181 $list_authors = $request->getCheck(
'listauthors' );
183 $list_authors =
false;
192 $request->response()->header(
'Content-type: application/xml; charset=utf-8' );
193 $request->response()->header(
'X-Robots-Tag: noindex,nofollow' );
194 ContentSecurityPolicy::sendRestrictiveHeader();
196 if ( $request->getCheck(
'wpDownload' ) ) {
200 $request->response()->header(
"Content-disposition: attachment;filename={$filename}" );
204 $this->
doExport( $page, $history, $list_authors, $exportall );
210 $out->addWikiMsg(
'exporttext' );
213 $categoryName = $request->getText(
'catname' );
218 $hideIf = $canExportAll ? [
'hide-if' => [
'===',
'exportall',
'1' ] ] : [];
222 'type' =>
'textwithbutton',
224 'horizontal-label' =>
true,
225 'label-message' =>
'export-addcattext',
226 'default' => $categoryName,
228 'buttontype' =>
'submit',
229 'buttonname' =>
'addcat',
230 'buttondefault' => $this->
msg(
'export-addcat' )->text(),
236 'type' =>
'namespaceselectwithbutton',
237 'default' => $nsindex,
238 'label-message' =>
'export-addnstext',
239 'horizontal-label' =>
true,
242 'cssclass' =>
'namespaceselector',
243 'buttontype' =>
'submit',
244 'buttonname' =>
'addns',
245 'buttondefault' => $this->
msg(
'export-addns' )->text(),
250 if ( $canExportAll ) {
254 'label-message' =>
'exportall',
255 'name' =>
'exportall',
257 'default' => $request->wasPosted() && $request->getCheck(
'exportall' ),
264 'class' => HTMLTextAreaField::class,
266 'label-message' =>
'export-manual',
277 'label-message' =>
'exportcuronly',
280 'default' => !$request->wasPosted() || $request->getCheck(
'curonly' ),
284 $out->addWikiMsg(
'exportnohistory' );
290 'label-message' =>
'export-templates',
291 'name' =>
'templates',
292 'id' =>
'wpExportTemplates',
293 'default' => $request->wasPosted() && $request->getCheck(
'templates' ),
299 'pagelink-depth' => [
301 'name' =>
'pagelink-depth',
302 'id' =>
'pagelink-depth',
303 'label-message' =>
'export-pagelinks',
313 'name' =>
'wpDownload',
314 'id' =>
'wpDownload',
315 'default' => !$request->wasPosted() || $request->getCheck(
'wpDownload' ),
316 'label-message' =>
'export-download',
324 'label-message' =>
'exportlistauthors',
325 'default' => $request->wasPosted() && $request->getCheck(
'listauthors' ),
326 'name' =>
'listauthors',
327 'id' =>
'listauthors',
332 $htmlForm = HTMLForm::factory(
'ooui', $formDescriptor, $this->
getContext() );
333 $htmlForm->setSubmitTextMsg(
'export-submit' );
334 $htmlForm->prepareForm()->displayForm(
false );
342 return $this->
getAuthority()->isAllowed(
'override-export-depth' );
354 protected function doExport( $page, $history, $list_authors, $exportall ) {
357 $history = WikiExporter::FULL;
362 foreach ( explode(
"\n", $page ) as $pageName ) {
363 $pageName = trim( $pageName );
364 $title = Title::newFromText( $pageName );
365 if ( $title && !$title->isExternal() && $title->getText() !==
'' ) {
367 $pageSet[$title->getPrefixedText()] =
true;
372 $inputPages = array_keys( $pageSet );
375 if ( $this->templates ) {
376 $pageSet = $this->
getTemplates( $inputPages, $pageSet );
378 $pageSet = $this->getExtraPages( $inputPages, $pageSet );
381 $pageSet = $this->
getPageLinks( $inputPages, $pageSet, $linkDepth );
384 $pages = array_keys( $pageSet );
387 foreach ( $pages as $k => $v ) {
388 $pages[$k] = str_replace(
' ',
'_', $v );
391 $pages = array_unique( $pages );
395 $db = $this->dbProvider->getReplicaDatabase();
397 $exporter = $this->wikiExporterFactory->getWikiExporter( $db, $history );
398 $exporter->list_authors = $list_authors;
399 $exporter->openStream();
402 $exporter->allPages();
405 foreach ( $pages as $page ) {
406 # T10824: Only export pages the user can read
407 $title = Title::newFromText( $page );
408 if ( $title ===
null ) {
413 if ( !$this->
getAuthority()->authorizeRead(
'read', $title ) ) {
418 $exporter->pageByTitle( $title );
422 $exporter->closeStream();
434 $dbr = $this->dbProvider->getReplicaDatabase( CategoryLinksTable::VIRTUAL_DOMAIN );
435 $res = $dbr->newSelectQueryBuilder()
436 ->select( [
'page_namespace',
'page_title' ] )
438 ->join(
'categorylinks',
null,
'cl_from=page_id' )
439 ->join(
'linktarget',
null,
'cl_target_id = lt_id' )
440 ->where( [
'lt_title' => $name,
'lt_namespace' =>
NS_CATEGORY ] )
442 ->caller( __METHOD__ )
447 foreach ( $res as $row ) {
448 $pages[] = Title::makeName( $row->page_namespace, $row->page_title );
461 $dbr = $this->dbProvider->getReplicaDatabase();
462 $res = $dbr->newSelectQueryBuilder()
463 ->select( [
'page_namespace',
'page_title' ] )
465 ->where( [
'page_namespace' => $nsindex ] )
467 ->caller( __METHOD__ )->fetchResultSet();
471 foreach ( $res as $row ) {
472 $pages[] = Title::makeName( $row->page_namespace, $row->page_title );
485 [ $nsField, $titleField ] = $this->linksMigration->getTitleFields(
'templatelinks' );
486 $queryInfo = $this->linksMigration->getQueryInfo(
'templatelinks' );
487 $dbr = $this->dbProvider->getReplicaDatabase( TemplateLinksTable::VIRTUAL_DOMAIN );
488 $queryBuilder = $dbr->newSelectQueryBuilder()
489 ->caller( __METHOD__ )
490 ->select( [
'namespace' => $nsField,
'title' => $titleField ] )
492 ->join(
'templatelinks',
null,
'page_id=tl_from' )
493 ->tables( array_diff( $queryInfo[
'tables'], [
'templatelinks' ] ) )
494 ->joinConds( $queryInfo[
'joins'] );
495 return $this->
getLinks( $inputPages, $pageSet, $queryBuilder );
504 private function getExtraPages( $inputPages, $pageSet ) {
506 $this->
getHookRunner()->onSpecialExportGetExtraPages( $inputPages, $extraPages );
507 foreach ( $extraPages as $extraPage ) {
508 $pageSet[$this->titleFormatter->getPrefixedText( $extraPage )] =
true;
519 if ( $depth ===
null || $depth < 0 ) {
525 if ( $depth > $maxLinkDepth ) {
526 return $maxLinkDepth;
536 return intval( min( $depth, 5 ) );
547 for ( ; $depth > 0; --$depth ) {
548 [ $nsField, $titleField ] = $this->linksMigration->getTitleFields(
'pagelinks' );
549 $queryInfo = $this->linksMigration->getQueryInfo(
'pagelinks' );
550 $dbr = $this->dbProvider->getReplicaDatabase( PageLinksTable::VIRTUAL_DOMAIN );
551 $queryBuilder = $dbr->newSelectQueryBuilder()
552 ->caller( __METHOD__ )
553 ->select( [
'namespace' => $nsField,
'title' => $titleField ] )
555 ->join(
'pagelinks',
null,
'page_id=pl_from' )
556 ->tables( array_diff( $queryInfo[
'tables'], [
'pagelinks' ] ) )
557 ->joinConds( $queryInfo[
'joins'] );
558 $pageSet = $this->
getLinks( $inputPages, $pageSet, $queryBuilder );
559 $inputPages = array_keys( $pageSet );
573 foreach ( $inputPages as $page ) {
574 $title = Title::newFromText( $page );
576 $pageSet[$title->getPrefixedText()] =
true;
579 $result = ( clone $queryBuilder )
581 'page_namespace' => $title->getNamespace(),
582 'page_title' => $title->getDBkey()
586 foreach ( $result as $row ) {
588 $pageSet[$template->getPrefixedText()] =
true;
603class_alias( SpecialExport::class,
'SpecialExport' );
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 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()
Handle sending Content-Security-Policy headers.
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.