56 $this->curonly =
true;
59 $this->templates = $request->getCheck(
'templates' );
61 $request->getIntOrNull(
'pagelink-depth' )
66 if ( $request->getCheck(
'addcat' ) ) {
67 $page = $request->getText(
'pages' );
68 $catname = $request->getText(
'catname' );
70 if ( $catname !==
'' && $catname !==
null && $catname !==
false ) {
71 $t = Title::makeTitleSafe(
NS_MAIN, $catname );
83 $page .= implode(
"\n", $catpages );
87 } elseif ( $request->getCheck(
'addns' ) && $config->get(
'ExportFromNamespaces' ) ) {
88 $page = $request->getText(
'pages' );
89 $nsindex = $request->getText(
'nsindex',
'' );
91 if ( strval( $nsindex ) !==
'' ) {
97 $page .=
"\n" . implode(
"\n", $nspages );
100 } elseif ( $request->getCheck(
'exportall' ) && $config->get(
'ExportAllowAll' ) ) {
110 } elseif ( $request->wasPosted() && $par ==
'' ) {
113 LoggerFactory::getInstance(
'export' )->debug(
114 'Special:Export POST, dir: [{dir}], offset: [{offset}], limit: [{limit}]', [
115 'dir' => $request->getRawVal(
'dir' ),
116 'offset' => $request->getRawVal(
'offset' ),
117 'limit' => $request->getRawVal(
'limit' ),
120 $page = $request->getText(
'pages' );
121 $this->curonly = $request->getCheck(
'curonly' );
122 $rawOffset = $request->getVal(
'offset' );
130 $maxHistory = $config->get(
'ExportMaxHistory' );
131 $limit = $request->getInt(
'limit' );
132 $dir = $request->getVal(
'dir' );
136 'limit' => $maxHistory,
138 $historyCheck = $request->getCheck(
'history' );
140 if ( $this->curonly ) {
142 } elseif ( !$historyCheck ) {
143 if ( $limit > 0 && ( $maxHistory == 0 || $limit < $maxHistory ) ) {
144 $history[
'limit'] = $limit;
147 if ( $offset !==
null ) {
148 $history[
'offset'] = $offset;
151 if ( strtolower( $dir ) ==
'desc' ) {
152 $history[
'dir'] =
'desc';
161 $page = $request->getText(
'pages', $par );
162 $historyCheck = $request->getCheck(
'history' );
164 if ( $historyCheck ) {
175 if ( !$config->get(
'ExportAllowHistory' ) ) {
180 $list_authors = $request->getCheck(
'listauthors' );
181 if ( !$this->curonly || !$config->get(
'ExportAllowListContributors' ) ) {
182 $list_authors =
false;
191 $request->response()->header(
'Content-type: application/xml; charset=utf-8' );
192 $request->response()->header(
'X-Robots-Tag: noindex,nofollow' );
194 if ( $request->getCheck(
'wpDownload' ) ) {
196 $filename = urlencode( $config->get(
'Sitename' ) .
'-' .
wfTimestampNow() .
'.xml' );
197 $request->response()->header(
"Content-disposition: attachment;filename={$filename}" );
200 $this->
doExport( $page, $history, $list_authors, $exportall );
206 $out->addWikiMsg(
'exporttext' );
209 $categoryName = $request->getText(
'catname' );
216 'type' =>
'textwithbutton',
218 'horizontal-label' =>
true,
219 'label-message' =>
'export-addcattext',
220 'default' => $categoryName,
222 'buttontype' =>
'submit',
223 'buttonname' =>
'addcat',
224 'buttondefault' => $this->
msg(
'export-addcat' )->text(),
225 'hide-if' => [
'===',
'exportall',
'1' ],
228 if ( $config->get(
'ExportFromNamespaces' ) ) {
231 'type' =>
'namespaceselectwithbutton',
232 'default' => $nsindex,
233 'label-message' =>
'export-addnstext',
234 'horizontal-label' =>
true,
237 'cssclass' =>
'namespaceselector',
238 'buttontype' =>
'submit',
239 'buttonname' =>
'addns',
240 'buttondefault' => $this->
msg(
'export-addns' )->text(),
241 'hide-if' => [
'===',
'exportall',
'1' ],
246 if ( $config->get(
'ExportAllowAll' ) ) {
250 'label-message' =>
'exportall',
251 'name' =>
'exportall',
253 'default' => $request->wasPosted() ? $request->getCheck(
'exportall' ) :
false,
260 'class' => HTMLTextAreaField::class,
262 'label-message' =>
'export-manual',
266 'hide-if' => [
'===',
'exportall',
'1' ],
270 if ( $config->get(
'ExportAllowHistory' ) ) {
274 'label-message' =>
'exportcuronly',
277 'default' => $request->wasPosted() ? $request->getCheck(
'curonly' ) :
true,
281 $out->addWikiMsg(
'exportnohistory' );
287 'label-message' =>
'export-templates',
288 'name' =>
'templates',
289 'id' =>
'wpExportTemplates',
290 'default' => $request->wasPosted() ? $request->getCheck(
'templates' ) :
false,
294 if ( $config->get(
'ExportMaxLinkDepth' ) || $this->userCanOverrideExportDepth() ) {
296 'pagelink-depth' => [
298 'name' =>
'pagelink-depth',
299 'id' =>
'pagelink-depth',
300 'label-message' =>
'export-pagelinks',
310 'name' =>
'wpDownload',
311 'id' =>
'wpDownload',
312 'default' => $request->wasPosted() ? $request->getCheck(
'wpDownload' ) :
true,
313 'label-message' =>
'export-download',
317 if ( $config->get(
'ExportAllowListContributors' ) ) {
321 'label-message' =>
'exportlistauthors',
322 'default' => $request->wasPosted() ? $request->getCheck(
'listauthors' ) :
false,
323 'name' =>
'listauthors',
324 'id' =>
'listauthors',
329 $htmlForm = HTMLForm::factory(
'ooui', $formDescriptor, $this->
getContext() );
330 $htmlForm->setSubmitTextMsg(
'export-submit' );
331 $htmlForm->prepareForm()->displayForm(
false );
351 protected function doExport( $page, $history, $list_authors, $exportall ) {
359 foreach ( explode(
"\n", $page ) as $pageName ) {
360 $pageName = trim( $pageName );
361 $title = Title::newFromText( $pageName );
364 $pageSet[
$title->getPrefixedText()] =
true;
369 $inputPages = array_keys( $pageSet );
372 if ( $this->templates ) {
373 $pageSet = $this->
getTemplates( $inputPages, $pageSet );
377 $pageSet = $this->
getPageLinks( $inputPages, $pageSet, $linkDepth );
380 $pages = array_keys( $pageSet );
383 foreach ( $pages as $k => $v ) {
384 $pages[$k] = str_replace(
' ',
'_', $v );
387 $pages = array_unique( $pages );
391 $db = $this->loadBalancer->getConnectionRef( ILoadBalancer::DB_REPLICA );
394 $exporter->list_authors = $list_authors;
395 $exporter->openStream();
398 $exporter->allPages();
400 foreach ( $pages as $page ) {
401 # T10824: Only export pages the user can read
402 $title = Title::newFromText( $page );
413 $exporter->pageByTitle(
$title );
417 $exporter->closeStream();
541 protected function getLinks( $inputPages, $pageSet, $table, $fields, $join ) {
542 $dbr = $this->loadBalancer->getConnectionRef( ILoadBalancer::DB_REPLICA );
544 foreach ( $inputPages as $page ) {
545 $title = Title::newFromText( $page );
548 $pageSet[
$title->getPrefixedText()] =
true;
551 $result =
$dbr->select(
557 'page_namespace' =>
$title->getNamespace(),
558 'page_title' =>
$title->getDBkey()
564 foreach ( $result as $row ) {
565 $template = Title::makeTitle( $row->namespace, $row->title );
566 $pageSet[$template->getPrefixedText()] =
true;