Merge "Convert Special:DeletedContributions to use OOUI."
[lhc/web/wiklou.git] / includes / specials / SpecialExport.php
index 91fef03..bf535a6 100644 (file)
@@ -109,11 +109,11 @@ class SpecialExport extends SpecialPage {
                        $maxHistory = $config->get( 'ExportMaxHistory' );
                        $limit = $request->getInt( 'limit' );
                        $dir = $request->getVal( 'dir' );
-                       $history = array(
+                       $history = [
                                'dir' => 'asc',
                                'offset' => false,
                                'limit' => $maxHistory,
-                       );
+                       ];
                        $historyCheck = $request->getCheck( 'history' );
 
                        if ( $this->curonly ) {
@@ -168,6 +168,7 @@ class SpecialExport extends SpecialPage {
                        // This should provide safer streaming for pages with history
                        wfResetOutputBuffers();
                        $request->response()->header( "Content-type: application/xml; charset=utf-8" );
+                       $request->response()->header( "X-Robots-Tag: noindex,nofollow" );
 
                        if ( $request->getCheck( 'wpDownload' ) ) {
                                // Provide a sane filename suggestion
@@ -189,8 +190,8 @@ class SpecialExport extends SpecialPage {
                        $categoryName = '';
                }
 
-               $formDescriptor = array(
-                       'catname' => array(
+               $formDescriptor = [
+                       'catname' => [
                                'type' => 'textwithbutton',
                                'name' => 'catname',
                                'horizontal-label' => true,
@@ -200,11 +201,12 @@ class SpecialExport extends SpecialPage {
                                'buttontype' => 'submit',
                                'buttonname' => 'addcat',
                                'buttondefault' => $this->msg( 'export-addcat' )->text(),
-                       ),
-               );
+                               'hide-if' => [ '===', 'exportall', '1' ],
+                       ],
+               ];
                if ( $config->get( 'ExportFromNamespaces' ) ) {
-                       $formDescriptor += array(
-                               'nsindex' => array(
+                       $formDescriptor += [
+                               'nsindex' => [
                                        'type' => 'namespaceselectwithbutton',
                                        'default' => $nsindex,
                                        'label-message' => 'export-addnstext',
@@ -215,93 +217,95 @@ class SpecialExport extends SpecialPage {
                                        'buttontype' => 'submit',
                                        'buttonname' => 'addns',
                                        'buttondefault' => $this->msg( 'export-addns' )->text(),
-                               ),
-                       );
+                                       'hide-if' => [ '===', 'exportall', '1' ],
+                               ],
+                       ];
                }
 
                if ( $config->get( 'ExportAllowAll' ) ) {
-                       $formDescriptor += array(
-                               'exportall' => array(
+                       $formDescriptor += [
+                               'exportall' => [
                                        'type' => 'check',
                                        'label-message' => 'exportall',
                                        'name' => 'exportall',
                                        'id' => 'exportall',
                                        'default' => $request->wasPosted() ? $request->getCheck( 'exportall' ) : false,
-                               ),
-                       );
+                               ],
+                       ];
                }
 
-               $formDescriptor += array(
-                       'textarea' => array(
+               $formDescriptor += [
+                       'textarea' => [
                                'class' => 'HTMLTextAreaField',
                                'name' => 'pages',
+                               'label-message' => 'export-manual',
                                'nodata' => true,
-                               'cols' => 40,
                                'rows' => 10,
                                'default' => $page,
-                       ),
-               );
+                               'hide-if' => [ '===', 'exportall', '1' ],
+                       ],
+               ];
 
                if ( $config->get( 'ExportAllowHistory' ) ) {
-                       $formDescriptor += array(
-                               'curonly' => array(
+                       $formDescriptor += [
+                               'curonly' => [
                                        'type' => 'check',
                                        'label-message' => 'exportcuronly',
                                        'name' => 'curonly',
                                        'id' => 'curonly',
                                        'default' => $request->wasPosted() ? $request->getCheck( 'curonly' ) : true,
-                               ),
-                       );
+                               ],
+                       ];
                } else {
                        $out->addWikiMsg( 'exportnohistory' );
                }
 
-               $formDescriptor += array(
-                       'templates' => array(
+               $formDescriptor += [
+                       'templates' => [
                                'type' => 'check',
                                'label-message' => 'export-templates',
                                'name' => 'templates',
                                'id' => 'wpExportTemplates',
                                'default' => $request->wasPosted() ? $request->getCheck( 'templates' ) : false,
-                       ),
-               );
+                       ],
+               ];
 
                if ( $config->get( 'ExportMaxLinkDepth' ) || $this->userCanOverrideExportDepth() ) {
-                       $formDescriptor += array(
-                               'pagelink-depth' => array(
+                       $formDescriptor += [
+                               'pagelink-depth' => [
                                        'type' => 'text',
                                        'name' => 'pagelink-depth',
                                        'id' => 'pagelink-depth',
                                        'label-message' => 'export-pagelinks',
                                        'default' => '0',
                                        'size' => 20,
-                               ),
-                       );
+                               ],
+                       ];
                }
 
-               $formDescriptor += array(
-                       'wpDownload' => array(
+               $formDescriptor += [
+                       'wpDownload' => [
                                'type' => 'check',
                                'name' =>'wpDownload',
                                'id' => 'wpDownload',
                                'default' => $request->wasPosted() ? $request->getCheck( 'wpDownload' ) : true,
                                'label-message' => 'export-download',
-                       ),
-               );
+                       ],
+               ];
 
                if ( $config->get( 'ExportAllowListContributors' ) ) {
-                       $formDescriptor += array(
-                               'listauthors' => array(
+                       $formDescriptor += [
+                               'listauthors' => [
                                        'type' => 'check',
                                        'label-message' => 'exportlistauthors',
                                        'default' => $request->wasPosted() ? $request->getCheck( 'listauthors' ) : false,
                                        'name' => 'listauthors',
                                        'id' => 'listauthors',
-                               ),
-                       );
+                               ],
+                       ];
                }
 
-               $htmlForm = HTMLForm::factory( 'div', $formDescriptor, $this->getContext() );
+               $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() );
                $htmlForm->setSubmitTextMsg( 'export-submit' );
                $htmlForm->prepareForm()->displayForm( false );
                $this->addHelpLink( 'Help:Export' );
@@ -329,7 +333,7 @@ class SpecialExport extends SpecialPage {
                if ( $exportall ) {
                        $history = WikiExporter::FULL;
                } else {
-                       $pageSet = array(); // Inverted index of all pages to look up
+                       $pageSet = []; // Inverted index of all pages to look up
 
                        // Split up and normalize input
                        foreach ( explode( "\n", $page ) as $pageName ) {
@@ -366,12 +370,12 @@ class SpecialExport extends SpecialPage {
                /* Ok, let's get to it... */
                if ( $history == WikiExporter::CURRENT ) {
                        $lb = false;
-                       $db = wfGetDB( DB_SLAVE );
+                       $db = wfGetDB( DB_REPLICA );
                        $buffer = WikiExporter::BUFFER;
                } else {
                        // Use an unbuffered query; histories may be very long!
                        $lb = wfGetLBFactory()->newMainLB();
-                       $db = $lb->getConnection( DB_SLAVE );
+                       $db = $lb->getConnection( DB_REPLICA );
                        $buffer = WikiExporter::STREAM;
 
                        // This might take a while... :D
@@ -418,18 +422,20 @@ class SpecialExport extends SpecialPage {
        private function getPagesFromCategory( $title ) {
                global $wgContLang;
 
+               $maxPages = $this->getConfig()->get( 'ExportPagelistLimit' );
+
                $name = $title->getDBkey();
 
-               $dbr = wfGetDB( DB_SLAVE );
+               $dbr = wfGetDB( DB_REPLICA );
                $res = $dbr->select(
-                       array( 'page', 'categorylinks' ),
-                       array( 'page_namespace', 'page_title' ),
-                       array( 'cl_from=page_id', 'cl_to' => $name ),
+                       [ 'page', 'categorylinks' ],
+                       [ 'page_namespace', 'page_title' ],
+                       [ 'cl_from=page_id', 'cl_to' => $name ],
                        __METHOD__,
-                       array( 'LIMIT' => '5000' )
+                       [ 'LIMIT' => $maxPages ]
                );
 
-               $pages = array();
+               $pages = [];
 
                foreach ( $res as $row ) {
                        $n = $row->page_title;
@@ -451,16 +457,18 @@ class SpecialExport extends SpecialPage {
        private function getPagesFromNamespace( $nsindex ) {
                global $wgContLang;
 
-               $dbr = wfGetDB( DB_SLAVE );
+               $maxPages = $this->getConfig()->get( 'ExportPagelistLimit' );
+
+               $dbr = wfGetDB( DB_REPLICA );
                $res = $dbr->select(
                        'page',
-                       array( 'page_namespace', 'page_title' ),
-                       array( 'page_namespace' => $nsindex ),
+                       [ 'page_namespace', 'page_title' ],
+                       [ 'page_namespace' => $nsindex ],
                        __METHOD__,
-                       array( 'LIMIT' => '5000' )
+                       [ 'LIMIT' => $maxPages ]
                );
 
-               $pages = array();
+               $pages = [];
 
                foreach ( $res as $row ) {
                        $n = $row->page_title;
@@ -485,8 +493,8 @@ class SpecialExport extends SpecialPage {
        private function getTemplates( $inputPages, $pageSet ) {
                return $this->getLinks( $inputPages, $pageSet,
                        'templatelinks',
-                       array( 'namespace' => 'tl_namespace', 'title' => 'tl_title' ),
-                       array( 'page_id=tl_from' )
+                       [ 'namespace' => 'tl_namespace', 'title' => 'tl_title' ],
+                       [ 'page_id=tl_from' ]
                );
        }
 
@@ -529,8 +537,8 @@ class SpecialExport extends SpecialPage {
                        // @codingStandardsIgnoreEnd
                        $pageSet = $this->getLinks(
                                $inputPages, $pageSet, 'pagelinks',
-                               array( 'namespace' => 'pl_namespace', 'title' => 'pl_title' ),
-                               array( 'page_id=pl_from' )
+                               [ 'namespace' => 'pl_namespace', 'title' => 'pl_title' ],
+                               [ 'page_id=pl_from' ]
                        );
                        $inputPages = array_keys( $pageSet );
                }
@@ -548,7 +556,7 @@ class SpecialExport extends SpecialPage {
         * @return array
         */
        private function getLinks( $inputPages, $pageSet, $table, $fields, $join ) {
-               $dbr = wfGetDB( DB_SLAVE );
+               $dbr = wfGetDB( DB_REPLICA );
 
                foreach ( $inputPages as $page ) {
                        $title = Title::newFromText( $page );
@@ -558,14 +566,14 @@ class SpecialExport extends SpecialPage {
                                /// @todo FIXME: May or may not be more efficient to batch these
                                ///        by namespace when given multiple input pages.
                                $result = $dbr->select(
-                                       array( 'page', $table ),
+                                       [ 'page', $table ],
                                        $fields,
                                        array_merge(
                                                $join,
-                                               array(
+                                               [
                                                        'page_namespace' => $title->getNamespace(),
                                                        'page_title' => $title->getDBkey()
-                                               )
+                                               ]
                                        ),
                                        __METHOD__
                                );