77 $this->curonly =
true;
80 $this->templates = $request->getCheck(
'templates' );
82 $request->getIntOrNull(
'pagelink-depth' )
87 if ( $request->getCheck(
'addcat' ) ) {
88 $page = $request->getText(
'pages' );
89 $catname = $request->getText(
'catname' );
91 if ( $catname !==
'' && $catname !==
null && $catname !==
false ) {
92 $t = Title::makeTitleSafe(
NS_MAIN, $catname );
101 if ( $page !==
'' ) {
104 $page .= implode(
"\n", $catpages );
108 } elseif ( $request->getCheck(
'addns' ) &&
109 $config->get( MainConfigNames::ExportFromNamespaces ) ) {
110 $page = $request->getText(
'pages' );
111 $nsindex = $request->getText(
'nsindex',
'' );
113 if ( strval( $nsindex ) !==
'' ) {
119 $page .=
"\n" . implode(
"\n", $nspages );
122 } elseif ( $request->getCheck(
'exportall' ) &&
123 $config->get( MainConfigNames::ExportAllowAll ) ) {
133 } elseif ( $request->wasPosted() && $par ==
'' ) {
136 LoggerFactory::getInstance(
'export' )->debug(
137 'Special:Export POST, dir: [{dir}], offset: [{offset}], limit: [{limit}]', [
138 'dir' => $request->getRawVal(
'dir' ),
139 'offset' => $request->getRawVal(
'offset' ),
140 'limit' => $request->getRawVal(
'limit' ),
143 $page = $request->getText(
'pages' );
144 $this->curonly = $request->getCheck(
'curonly' );
145 $rawOffset = $request->getVal(
'offset' );
153 $maxHistory = $config->get( MainConfigNames::ExportMaxHistory );
154 $limit = $request->getInt(
'limit' );
155 $dir = $request->getVal(
'dir' );
159 'limit' => $maxHistory,
161 $historyCheck = $request->getCheck(
'history' );
163 if ( $this->curonly ) {
164 $history = WikiExporter::CURRENT;
165 } elseif ( !$historyCheck ) {
166 if ( $limit > 0 && ( $maxHistory == 0 || $limit < $maxHistory ) ) {
167 $history[
'limit'] = $limit;
170 if ( $offset !==
null ) {
171 $history[
'offset'] = $offset;
174 if ( strtolower( $dir ??
'' ) ==
'desc' ) {
175 $history[
'dir'] =
'desc';
184 $page = $request->getText(
'pages', $par ??
'' );
185 $historyCheck = $request->getCheck(
'history' );
187 if ( $historyCheck ) {
188 $history = WikiExporter::FULL;
190 $history = WikiExporter::CURRENT;
198 if ( !$config->get( MainConfigNames::ExportAllowHistory ) ) {
200 $history = WikiExporter::CURRENT;
203 $list_authors = $request->getCheck(
'listauthors' );
204 if ( !$this->curonly || !$config->get( MainConfigNames::ExportAllowListContributors ) ) {
205 $list_authors =
false;
214 $request->response()->header(
'Content-type: application/xml; charset=utf-8' );
215 $request->response()->header(
'X-Robots-Tag: noindex,nofollow' );
217 if ( $request->getCheck(
'wpDownload' ) ) {
219 $filename = urlencode( $config->get( MainConfigNames::Sitename ) .
'-' .
221 $request->response()->header(
"Content-disposition: attachment;filename={$filename}" );
226 $this->
doExport( $page, $history, $list_authors, $exportall );
232 $out->addWikiMsg(
'exporttext' );
235 $categoryName = $request->getText(
'catname' );
239 $canExportAll = $config->get( MainConfigNames::ExportAllowAll );
240 $hideIf = $canExportAll ? [
'hide-if' => [
'===',
'exportall',
'1' ] ] : [];
244 'type' =>
'textwithbutton',
246 'horizontal-label' =>
true,
247 'label-message' =>
'export-addcattext',
248 'default' => $categoryName,
250 'buttontype' =>
'submit',
251 'buttonname' =>
'addcat',
252 'buttondefault' => $this->
msg(
'export-addcat' )->text(),
255 if ( $config->get( MainConfigNames::ExportFromNamespaces ) ) {
258 'type' =>
'namespaceselectwithbutton',
259 'default' => $nsindex,
260 'label-message' =>
'export-addnstext',
261 'horizontal-label' =>
true,
264 'cssclass' =>
'namespaceselector',
265 'buttontype' =>
'submit',
266 'buttonname' =>
'addns',
267 'buttondefault' => $this->
msg(
'export-addns' )->text(),
272 if ( $canExportAll ) {
276 'label-message' =>
'exportall',
277 'name' =>
'exportall',
279 'default' => $request->wasPosted() ? $request->getCheck(
'exportall' ) :
false,
286 'class' => HTMLTextAreaField::class,
288 'label-message' =>
'export-manual',
295 if ( $config->get( MainConfigNames::ExportAllowHistory ) ) {
299 'label-message' =>
'exportcuronly',
302 'default' => $request->wasPosted() ? $request->getCheck(
'curonly' ) :
true,
306 $out->addWikiMsg(
'exportnohistory' );
312 'label-message' =>
'export-templates',
313 'name' =>
'templates',
314 'id' =>
'wpExportTemplates',
315 'default' => $request->wasPosted() ? $request->getCheck(
'templates' ) :
false,
319 if ( $config->get( MainConfigNames::ExportMaxLinkDepth ) ||
320 $this->userCanOverrideExportDepth() ) {
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' ) :
true,
339 'label-message' =>
'export-download',
343 if ( $config->get( MainConfigNames::ExportAllowListContributors ) ) {
347 'label-message' =>
'exportlistauthors',
348 'default' => $request->wasPosted() ? $request->getCheck(
'listauthors' ) :
false,
349 'name' =>
'listauthors',
350 'id' =>
'listauthors',
355 $htmlForm = HTMLForm::factory(
'ooui', $formDescriptor, $this->
getContext() );
356 $htmlForm->setSubmitTextMsg(
'export-submit' );
357 $htmlForm->prepareForm()->displayForm(
false );
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 );
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->loadBalancer->getConnectionRef( ILoadBalancer::DB_REPLICA );
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 );
441 $exporter->pageByTitle(
$title );
445 $exporter->closeStream();
589 protected function getLinks( $inputPages, $pageSet, $table, $fields, $join ) {
590 $dbr = $this->loadBalancer->getConnectionRef( ILoadBalancer::DB_REPLICA );
593 foreach ( $inputPages as $page ) {
594 $title = Title::newFromText( $page );
596 $pageSet[
$title->getPrefixedText()] =
true;
599 $result =
$dbr->select(
603 'page_namespace' =>
$title->getNamespace(),
604 'page_title' =>
$title->getDBkey()
611 foreach ( $result as $row ) {
612 $template = Title::makeTitle( $row->namespace, $row->title );
613 $pageSet[$template->getPrefixedText()] =
true;