69 parent::__construct(
'Export' );
70 $this->dbProvider = $dbProvider;
71 $this->wikiExporterFactory = $wikiExporterFactory;
72 $this->titleFormatter = $titleFormatter;
73 $this->linksMigration = $linksMigration;
81 $this->curonly =
true;
84 $this->templates = $request->getCheck(
'templates' );
86 $request->getIntOrNull(
'pagelink-depth' )
91 if ( $request->getCheck(
'addcat' ) ) {
92 $page = $request->getText(
'pages' );
93 $catname = $request->getText(
'catname' );
95 if ( $catname !==
'' && $catname !==
null && $catname !==
false ) {
96 $t = Title::makeTitleSafe(
NS_MAIN, $catname );
105 if ( $page !==
'' ) {
108 $page .= implode(
"\n", $catpages );
113 $page = $request->getText(
'pages' );
114 $nsindex = $request->getText(
'nsindex',
'' );
116 if ( strval( $nsindex ) !==
'' ) {
122 $page .=
"\n" . implode(
"\n", $nspages );
135 } elseif ( $request->wasPosted() && $par ==
'' ) {
138 LoggerFactory::getInstance(
'export' )->debug(
139 'Special:Export POST, dir: [{dir}], offset: [{offset}], limit: [{limit}]', [
140 'dir' => $request->getRawVal(
'dir' ),
141 'offset' => $request->getRawVal(
'offset' ),
142 'limit' => $request->getRawVal(
'limit' ),
145 $page = $request->getText(
'pages' );
146 $this->curonly = $request->getCheck(
'curonly' );
147 $rawOffset = $request->getVal(
'offset' );
156 $limit = $request->getInt(
'limit' );
157 $dir = $request->getVal(
'dir' );
161 'limit' => $maxHistory,
163 $historyCheck = $request->getCheck(
'history' );
165 if ( $this->curonly ) {
166 $history = WikiExporter::CURRENT;
167 } elseif ( !$historyCheck ) {
168 if ( $limit > 0 && ( $maxHistory == 0 || $limit < $maxHistory ) ) {
169 $history[
'limit'] = $limit;
172 if ( $offset !==
null ) {
173 $history[
'offset'] = $offset;
176 if ( strtolower( $dir ) ==
'desc' ) {
177 $history[
'dir'] =
'desc';
186 $page = $request->getText(
'pages', $par ??
'' );
187 $historyCheck = $request->getCheck(
'history' );
189 if ( $historyCheck ) {
190 $history = WikiExporter::FULL;
192 $history = WikiExporter::CURRENT;
202 $history = WikiExporter::CURRENT;
205 $list_authors = $request->getCheck(
'listauthors' );
207 $list_authors =
false;
216 $request->response()->header(
'Content-type: application/xml; charset=utf-8' );
217 $request->response()->header(
'X-Robots-Tag: noindex,nofollow' );
219 if ( $request->getCheck(
'wpDownload' ) ) {
223 $request->response()->header(
"Content-disposition: attachment;filename={$filename}" );
228 $this->
doExport( $page, $history, $list_authors, $exportall );
234 $out->addWikiMsg(
'exporttext' );
237 $categoryName = $request->getText(
'catname' );
242 $hideIf = $canExportAll ? [
'hide-if' => [
'===',
'exportall',
'1' ] ] : [];
246 'type' =>
'textwithbutton',
248 'horizontal-label' =>
true,
249 'label-message' =>
'export-addcattext',
250 'default' => $categoryName,
252 'buttontype' =>
'submit',
253 'buttonname' =>
'addcat',
254 'buttondefault' => $this->
msg(
'export-addcat' )->text(),
260 'type' =>
'namespaceselectwithbutton',
261 'default' => $nsindex,
262 'label-message' =>
'export-addnstext',
263 'horizontal-label' =>
true,
266 'cssclass' =>
'namespaceselector',
267 'buttontype' =>
'submit',
268 'buttonname' =>
'addns',
269 'buttondefault' => $this->
msg(
'export-addns' )->text(),
274 if ( $canExportAll ) {
278 'label-message' =>
'exportall',
279 'name' =>
'exportall',
281 'default' => $request->wasPosted() && $request->getCheck(
'exportall' ),
288 'class' => HTMLTextAreaField::class,
290 'label-message' =>
'export-manual',
301 'label-message' =>
'exportcuronly',
304 'default' => !$request->wasPosted() || $request->getCheck(
'curonly' ),
308 $out->addWikiMsg(
'exportnohistory' );
314 'label-message' =>
'export-templates',
315 'name' =>
'templates',
316 'id' =>
'wpExportTemplates',
317 'default' => $request->wasPosted() && $request->getCheck(
'templates' ),
323 'pagelink-depth' => [
325 'name' =>
'pagelink-depth',
326 'id' =>
'pagelink-depth',
327 'label-message' =>
'export-pagelinks',
337 'name' =>
'wpDownload',
338 'id' =>
'wpDownload',
339 'default' => !$request->wasPosted() || $request->getCheck(
'wpDownload' ),
340 'label-message' =>
'export-download',
348 'label-message' =>
'exportlistauthors',
349 'default' => $request->wasPosted() && $request->getCheck(
'listauthors' ),
350 'name' =>
'listauthors',
351 'id' =>
'listauthors',
356 $htmlForm = HTMLForm::factory(
'ooui', $formDescriptor, $this->
getContext() );
357 $htmlForm->setSubmitTextMsg(
'export-submit' );
358 $htmlForm->prepareForm()->displayForm(
false );
366 return $this->
getAuthority()->isAllowed(
'override-export-depth' );
378 protected function doExport( $page, $history, $list_authors, $exportall ) {
381 $history = WikiExporter::FULL;
386 foreach ( explode(
"\n", $page ) as $pageName ) {
387 $pageName = trim( $pageName );
388 $title = Title::newFromText( $pageName );
389 if ( $title && !$title->isExternal() && $title->getText() !==
'' ) {
391 $pageSet[$title->getPrefixedText()] =
true;
396 $inputPages = array_keys( $pageSet );
399 if ( $this->templates ) {
400 $pageSet = $this->
getTemplates( $inputPages, $pageSet );
402 $pageSet = $this->getExtraPages( $inputPages, $pageSet );
405 $pageSet = $this->
getPageLinks( $inputPages, $pageSet, $linkDepth );
408 $pages = array_keys( $pageSet );
411 foreach ( $pages as $k => $v ) {
412 $pages[$k] = str_replace(
' ',
'_', $v );
415 $pages = array_unique( $pages );
419 $db = $this->dbProvider->getReplicaDatabase();
421 $exporter = $this->wikiExporterFactory->getWikiExporter( $db, $history );
422 $exporter->list_authors = $list_authors;
423 $exporter->openStream();
426 $exporter->allPages();
429 foreach ( $pages as $page ) {
430 # T10824: Only export pages the user can read
431 $title = Title::newFromText( $page );
432 if ( $title ===
null ) {
437 if ( !$this->
getAuthority()->authorizeRead(
'read', $title ) ) {
442 $exporter->pageByTitle( $title );
446 $exporter->closeStream();
456 $name = $title->getDBkey();
458 $dbr = $this->dbProvider->getReplicaDatabase();
459 $res = $dbr->newSelectQueryBuilder()
460 ->select( [
'page_namespace',
'page_title' ] )
462 ->join(
'categorylinks',
null,
'cl_from=page_id' )
463 ->where( [
'cl_to' => $name ] )
465 ->caller( __METHOD__ )->fetchResultSet();
469 foreach ( $res as $row ) {
470 $pages[] = Title::makeName( $row->page_namespace, $row->page_title );
483 $dbr = $this->dbProvider->getReplicaDatabase();
484 $res = $dbr->newSelectQueryBuilder()
485 ->select( [
'page_namespace',
'page_title' ] )
487 ->where( [
'page_namespace' => $nsindex ] )
489 ->caller( __METHOD__ )->fetchResultSet();
493 foreach ( $res as $row ) {
494 $pages[] = Title::makeName( $row->page_namespace, $row->page_title );
507 [ $nsField, $titleField ] = $this->linksMigration->getTitleFields(
'templatelinks' );
508 $queryInfo = $this->linksMigration->getQueryInfo(
'templatelinks' );
509 $dbr = $this->dbProvider->getReplicaDatabase();
510 $queryBuilder = $dbr->newSelectQueryBuilder()
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 ->select( [
'namespace' => $nsField,
'title' => $titleField ] )
575 ->join(
'pagelinks',
null,
'page_id=pl_from' )
576 ->tables( array_diff( $queryInfo[
'tables'], [
'pagelinks' ] ) )
577 ->joinConds( $queryInfo[
'joins'] );
578 $pageSet = $this->
getLinks( $inputPages, $pageSet, $queryBuilder );
579 $inputPages = array_keys( $pageSet );
593 foreach ( $inputPages as $page ) {
594 $title = Title::newFromText( $page );
596 $pageSet[$title->getPrefixedText()] =
true;
599 $result = ( clone $queryBuilder )
601 'page_namespace' => $title->getNamespace(),
602 'page_title' => $title->getDBkey()
606 foreach ( $result as $row ) {
607 $template = Title::makeTitle( $row->namespace, $row->title );
608 $pageSet[$template->getPrefixedText()] =
true;
622class_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()
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.