68 parent::__construct(
'Export' );
69 $this->dbProvider = $dbProvider;
70 $this->wikiExporterFactory = $wikiExporterFactory;
71 $this->titleFormatter = $titleFormatter;
72 $this->linksMigration = $linksMigration;
80 $this->curonly =
true;
83 $this->templates = $request->getCheck(
'templates' );
85 $request->getIntOrNull(
'pagelink-depth' )
90 if ( $request->getCheck(
'addcat' ) ) {
91 $page = $request->getText(
'pages' );
92 $catname = $request->getText(
'catname' );
94 if ( $catname !==
'' && $catname !==
null && $catname !==
false ) {
95 $t = Title::makeTitleSafe(
NS_MAIN, $catname );
104 if ( $page !==
'' ) {
107 $page .= implode(
"\n", $catpages );
112 $page = $request->getText(
'pages' );
113 $nsindex = $request->getText(
'nsindex',
'' );
115 if ( strval( $nsindex ) !==
'' ) {
121 $page .=
"\n" . implode(
"\n", $nspages );
134 } elseif ( $request->wasPosted() && $par ==
'' ) {
137 LoggerFactory::getInstance(
'export' )->debug(
138 'Special:Export POST, dir: [{dir}], offset: [{offset}], limit: [{limit}]', [
139 'dir' => $request->getRawVal(
'dir' ),
140 'offset' => $request->getRawVal(
'offset' ),
141 'limit' => $request->getRawVal(
'limit' ),
144 $page = $request->getText(
'pages' );
145 $this->curonly = $request->getCheck(
'curonly' );
146 $rawOffset = $request->getVal(
'offset' );
155 $limit = $request->getInt(
'limit' );
156 $dir = $request->getVal(
'dir' );
160 'limit' => $maxHistory,
162 $historyCheck = $request->getCheck(
'history' );
164 if ( $this->curonly ) {
165 $history = WikiExporter::CURRENT;
166 } elseif ( !$historyCheck ) {
167 if ( $limit > 0 && ( $maxHistory == 0 || $limit < $maxHistory ) ) {
168 $history[
'limit'] = $limit;
171 if ( $offset !==
null ) {
172 $history[
'offset'] = $offset;
175 if ( strtolower( $dir ??
'' ) ==
'desc' ) {
176 $history[
'dir'] =
'desc';
185 $page = $request->getText(
'pages', $par ??
'' );
186 $historyCheck = $request->getCheck(
'history' );
188 if ( $historyCheck ) {
189 $history = WikiExporter::FULL;
191 $history = WikiExporter::CURRENT;
201 $history = WikiExporter::CURRENT;
204 $list_authors = $request->getCheck(
'listauthors' );
206 $list_authors =
false;
215 $request->response()->header(
'Content-type: application/xml; charset=utf-8' );
216 $request->response()->header(
'X-Robots-Tag: noindex,nofollow' );
218 if ( $request->getCheck(
'wpDownload' ) ) {
222 $request->response()->header(
"Content-disposition: attachment;filename={$filename}" );
227 $this->
doExport( $page, $history, $list_authors, $exportall );
233 $out->addWikiMsg(
'exporttext' );
236 $categoryName = $request->getText(
'catname' );
241 $hideIf = $canExportAll ? [
'hide-if' => [
'===',
'exportall',
'1' ] ] : [];
245 'type' =>
'textwithbutton',
247 'horizontal-label' =>
true,
248 'label-message' =>
'export-addcattext',
249 'default' => $categoryName,
251 'buttontype' =>
'submit',
252 'buttonname' =>
'addcat',
253 'buttondefault' => $this->
msg(
'export-addcat' )->text(),
259 'type' =>
'namespaceselectwithbutton',
260 'default' => $nsindex,
261 'label-message' =>
'export-addnstext',
262 'horizontal-label' =>
true,
265 'cssclass' =>
'namespaceselector',
266 'buttontype' =>
'submit',
267 'buttonname' =>
'addns',
268 'buttondefault' => $this->
msg(
'export-addns' )->text(),
273 if ( $canExportAll ) {
277 'label-message' =>
'exportall',
278 'name' =>
'exportall',
280 'default' => $request->wasPosted() && $request->getCheck(
'exportall' ),
287 'class' => HTMLTextAreaField::class,
289 'label-message' =>
'export-manual',
300 'label-message' =>
'exportcuronly',
303 'default' => !$request->wasPosted() || $request->getCheck(
'curonly' ),
307 $out->addWikiMsg(
'exportnohistory' );
313 'label-message' =>
'export-templates',
314 'name' =>
'templates',
315 'id' =>
'wpExportTemplates',
316 'default' => $request->wasPosted() && $request->getCheck(
'templates' ),
322 'pagelink-depth' => [
324 'name' =>
'pagelink-depth',
325 'id' =>
'pagelink-depth',
326 'label-message' =>
'export-pagelinks',
336 'name' =>
'wpDownload',
337 'id' =>
'wpDownload',
338 'default' => !$request->wasPosted() || $request->getCheck(
'wpDownload' ),
339 'label-message' =>
'export-download',
347 'label-message' =>
'exportlistauthors',
348 'default' => $request->wasPosted() && $request->getCheck(
'listauthors' ),
349 'name' =>
'listauthors',
350 'id' =>
'listauthors',
355 $htmlForm = HTMLForm::factory(
'ooui', $formDescriptor, $this->
getContext() );
356 $htmlForm->setSubmitTextMsg(
'export-submit' );
357 $htmlForm->prepareForm()->displayForm(
false );
365 return $this->
getAuthority()->isAllowed(
'override-export-depth' );
377 protected function doExport( $page, $history, $list_authors, $exportall ) {
380 $history = WikiExporter::FULL;
385 foreach ( explode(
"\n", $page ) as $pageName ) {
386 $pageName = trim( $pageName );
387 $title = Title::newFromText( $pageName );
388 if ( $title && !$title->isExternal() && $title->getText() !==
'' ) {
390 $pageSet[$title->getPrefixedText()] =
true;
395 $inputPages = array_keys( $pageSet );
398 if ( $this->templates ) {
399 $pageSet = $this->
getTemplates( $inputPages, $pageSet );
401 $pageSet = $this->getExtraPages( $inputPages, $pageSet );
404 $pageSet = $this->
getPageLinks( $inputPages, $pageSet, $linkDepth );
407 $pages = array_keys( $pageSet );
410 foreach ( $pages as $k => $v ) {
411 $pages[$k] = str_replace(
' ',
'_', $v );
414 $pages = array_unique( $pages );
418 $db = $this->dbProvider->getReplicaDatabase();
420 $exporter = $this->wikiExporterFactory->getWikiExporter( $db, $history );
421 $exporter->list_authors = $list_authors;
422 $exporter->openStream();
425 $exporter->allPages();
428 foreach ( $pages as $page ) {
429 # T10824: Only export pages the user can read
430 $title = Title::newFromText( $page );
431 if ( $title ===
null ) {
436 if ( !$this->
getAuthority()->authorizeRead(
'read', $title ) ) {
441 $exporter->pageByTitle( $title );
445 $exporter->closeStream();
457 $dbr = $this->dbProvider->getReplicaDatabase();
458 $res = $dbr->newSelectQueryBuilder()
459 ->select( [
'page_namespace',
'page_title' ] )
461 ->join(
'categorylinks',
null,
'cl_from=page_id' )
462 ->where( [
'cl_to' => $name ] )
464 ->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' );
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.
Interface for objects (potentially) representing an editable wiki page.