Merge "Make 'subnet' feature of $wgRateLimits work with IPv6"
[lhc/web/wiklou.git] / includes / specials / SpecialExport.php
index 7abfefe..61ed34d 100644 (file)
@@ -29,7 +29,6 @@
  * @ingroup SpecialPage
  */
 class SpecialExport extends SpecialPage {
-
        private $curonly, $doExport, $pageLinkDepth, $templates;
        private $images;
 
@@ -75,8 +74,7 @@ class SpecialExport extends SpecialPage {
                                        }
                                }
                        }
-               }
-               elseif( $request->getCheck( 'addns' ) && $wgExportFromNamespaces ) {
+               } elseif ( $request->getCheck( 'addns' ) && $wgExportFromNamespaces ) {
                        $page = $request->getText( 'pages' );
                        $nsindex = $request->getText( 'nsindex', '' );
 
@@ -89,8 +87,7 @@ class SpecialExport extends SpecialPage {
                                        $page .= "\n" . implode( "\n", $nspages );
                                }
                        }
-               }
-               elseif( $request->getCheck( 'exportall' ) && $wgExportAllowAll ) {
+               } elseif ( $request->getCheck( 'exportall' ) && $wgExportAllowAll ) {
                        $this->doExport = true;
                        $exportall = true;
 
@@ -100,13 +97,12 @@ class SpecialExport extends SpecialPage {
                        doExport(...) further down) */
                        $page = '';
                        $history = '';
-               }
-               elseif( $request->wasPosted() && $par == '' ) {
+               } elseif ( $request->wasPosted() && $par == '' ) {
                        $page = $request->getText( 'pages' );
                        $this->curonly = $request->getCheck( 'curonly' );
                        $rawOffset = $request->getVal( 'offset' );
 
-                       if( $rawOffset ) {
+                       if ( $rawOffset ) {
                                $offset = wfTimestamp( TS_MW, $rawOffset );
                        } else {
                                $offset = null;
@@ -127,15 +123,17 @@ class SpecialExport extends SpecialPage {
                                if ( $limit > 0 && ( $wgExportMaxHistory == 0 || $limit < $wgExportMaxHistory ) ) {
                                        $history['limit'] = $limit;
                                }
+
                                if ( !is_null( $offset ) ) {
                                        $history['offset'] = $offset;
                                }
+
                                if ( strtolower( $dir ) == 'desc' ) {
                                        $history['dir'] = 'desc';
                                }
                        }
 
-                       if( $page != '' ) {
+                       if ( $page != '' ) {
                                $this->doExport = true;
                        }
                } else {
@@ -143,18 +141,18 @@ class SpecialExport extends SpecialPage {
                        $page = $request->getText( 'pages', $par );
                        $historyCheck = $request->getCheck( 'history' );
 
-                       if( $historyCheck ) {
+                       if ( $historyCheck ) {
                                $history = WikiExporter::FULL;
                        } else {
                                $history = WikiExporter::CURRENT;
                        }
 
-                       if( $page != '' ) {
+                       if ( $page != '' ) {
                                $this->doExport = true;
                        }
                }
 
-               if( !$wgExportAllowHistory ) {
+               if ( !$wgExportAllowHistory ) {
                        // Override
                        $history = WikiExporter::CURRENT;
                }
@@ -172,7 +170,7 @@ class SpecialExport extends SpecialPage {
                        wfResetOutputBuffers();
                        $request->response()->header( "Content-type: application/xml; charset=utf-8" );
 
-                       if( $request->getCheck( 'wpDownload' ) ) {
+                       if ( $request->getCheck( 'wpDownload' ) ) {
                                // Provide a sane filename suggestion
                                $filename = urlencode( $wgSitename . '-' . wfTimestampNow() . '.xml' );
                                $request->response()->header( "Content-disposition: attachment;filename={$filename}" );
@@ -187,9 +185,17 @@ class SpecialExport extends SpecialPage {
                $out->addWikiMsg( 'exporttext' );
 
                $form = Xml::openElement( 'form', array( 'method' => 'post',
-                       'action' => $this->getTitle()->getLocalUrl( 'action=submit' ) ) );
-               $form .= Xml::inputLabel( $this->msg( 'export-addcattext' )->text(), 'catname', 'catname', 40 ) . '&#160;';
-               $form .= Xml::submitButton( $this->msg( 'export-addcat' )->text(), array( 'name' => 'addcat' ) ) . '<br />';
+                       'action' => $this->getTitle()->getLocalURL( 'action=submit' ) ) );
+               $form .= Xml::inputLabel(
+                       $this->msg( 'export-addcattext' )->text(),
+                       'catname',
+                       'catname',
+                       40
+               ) . '&#160;';
+               $form .= Xml::submitButton(
+                       $this->msg( 'export-addcat' )->text(),
+                       array( 'name' => 'addcat' )
+               ) . '<br />';
 
                if ( $wgExportFromNamespaces ) {
                        $form .= Html::namespaceSelector(
@@ -197,12 +203,15 @@ class SpecialExport extends SpecialPage {
                                        'selected' => $nsindex,
                                        'label' => $this->msg( 'export-addnstext' )->text()
                                ), array(
-                                       'name'  => 'nsindex',
-                                       'id'    => 'namespace',
+                                       'name' => 'nsindex',
+                                       'id' => 'namespace',
                                        'class' => 'namespaceselector',
                                )
                        ) . '&#160;';
-                       $form .= Xml::submitButton( $this->msg( 'export-addns' )->text(), array( 'name' => 'addns' ) ) . '<br />';
+                       $form .= Xml::submitButton(
+                               $this->msg( 'export-addns' )->text(),
+                               array( 'name' => 'addns' )
+                       ) . '<br />';
                }
 
                if ( $wgExportAllowAll ) {
@@ -214,10 +223,15 @@ class SpecialExport extends SpecialPage {
                        ) . '<br />';
                }
 
-               $form .= Xml::element( 'textarea', array( 'name' => 'pages', 'cols' => 40, 'rows' => 10 ), $page, false );
+               $form .= Xml::element(
+                       'textarea',
+                       array( 'name' => 'pages', 'cols' => 40, 'rows' => 10 ),
+                       $page,
+                       false
+               );
                $form .= '<br />';
 
-               if( $wgExportAllowHistory ) {
+               if ( $wgExportAllowHistory ) {
                        $form .= Xml::checkLabel(
                                $this->msg( 'exportcuronly' )->text(),
                                'curonly',
@@ -235,9 +249,16 @@ class SpecialExport extends SpecialPage {
                        $request->wasPosted() ? $request->getCheck( 'templates' ) : false
                ) . '<br />';
 
-               if( $wgExportMaxLinkDepth || $this->userCanOverrideExportDepth() ) {
-                       $form .= Xml::inputLabel( $this->msg( 'export-pagelinks' )->text(), 'pagelink-depth', 'pagelink-depth', 20, 0 ) . '<br />';
+               if ( $wgExportMaxLinkDepth || $this->userCanOverrideExportDepth() ) {
+                       $form .= Xml::inputLabel(
+                               $this->msg( 'export-pagelinks' )->text(),
+                               'pagelink-depth',
+                               'pagelink-depth',
+                               20,
+                               0
+                       ) . '<br />';
                }
+
                // Enable this when we can do something useful exporting/importing image information. :)
                //$form .= Xml::checkLabel( $this->msg( 'export-images' )->text(), 'images', 'wpExportImages', false ) . '<br />';
                $form .= Xml::checkLabel(
@@ -256,7 +277,10 @@ class SpecialExport extends SpecialPage {
                        ) . '<br />';
                }
 
-               $form .= Xml::submitButton( $this->msg( 'export-submit' )->text(), Linker::tooltipAndAccesskeyAttribs( 'export' ) );
+               $form .= Xml::submitButton(
+                       $this->msg( 'export-submit' )->text(),
+                       Linker::tooltipAndAccesskeyAttribs( 'export' )
+               );
                $form .= Xml::closeElement( 'form' );
 
                $out->addHTML( $form );
@@ -288,10 +312,10 @@ class SpecialExport extends SpecialPage {
                        $pageSet = array(); // Inverted index of all pages to look up
 
                        // Split up and normalize input
-                       foreach( explode( "\n", $page ) as $pageName ) {
+                       foreach ( explode( "\n", $page ) as $pageName ) {
                                $pageName = trim( $pageName );
                                $title = Title::newFromText( $pageName );
-                               if( $title && $title->getInterwiki() == '' && $title->getText() !== '' ) {
+                               if ( $title && $title->getInterwiki() == '' && $title->getText() !== '' ) {
                                        // Only record each page once!
                                        $pageSet[$title->getPrefixedText()] = true;
                                }
@@ -301,25 +325,23 @@ class SpecialExport extends SpecialPage {
                        $inputPages = array_keys( $pageSet );
 
                        // Look up any linked pages if asked...
-                       if( $this->templates ) {
+                       if ( $this->templates ) {
                                $pageSet = $this->getTemplates( $inputPages, $pageSet );
                        }
                        $linkDepth = $this->pageLinkDepth;
-                       if( $linkDepth ) {
+                       if ( $linkDepth ) {
                                $pageSet = $this->getPageLinks( $inputPages, $pageSet, $linkDepth );
                        }
 
-                       /*
-                        // Enable this when we can do something useful exporting/importing image information. :)
-                        if( $this->images ) ) {
-                        $pageSet = $this->getImages( $inputPages, $pageSet );
-                        }
-                       */
+                       // Enable this when we can do something useful exporting/importing image information.
+                       // if( $this->images ) ) {
+                       // $pageSet = $this->getImages( $inputPages, $pageSet );
+                       // }
 
                        $pages = array_keys( $pageSet );
 
                        // Normalize titles to the same format and remove dupes, see bug 17374
-                       foreach( $pages as $k => $v ) {
+                       foreach ( $pages as $k => $v ) {
                                $pages[$k] = str_replace( " ", "_", $v );
                        }
 
@@ -327,7 +349,7 @@ class SpecialExport extends SpecialPage {
                }
 
                /* Ok, let's get to it... */
-               if( $history == WikiExporter::CURRENT ) {
+               if ( $history == WikiExporter::CURRENT ) {
                        $lb = false;
                        $db = wfGetDB( DB_SLAVE );
                        $buffer = WikiExporter::BUFFER;
@@ -350,26 +372,17 @@ class SpecialExport extends SpecialPage {
                if ( $exportall ) {
                        $exporter->allPages();
                } else {
-                       foreach( $pages as $page ) {
-                       /*
-                        if( $wgExportMaxHistory && !$this->curonly ) {
-                        $title = Title::newFromText( $page );
-                        if( $title ) {
-                        $count = Revision::countByTitle( $db, $title );
-                        if( $count > $wgExportMaxHistory ) {
-                        wfDebug( __FUNCTION__ .
-                        ": Skipped $page, $count revisions too big\n" );
-                        continue;
-                        }
-                        }
-                        }*/
-                       #Bug 8824: Only export pages the user can read
+                       foreach ( $pages as $page ) {
+                               #Bug 8824: Only export pages the user can read
                                $title = Title::newFromText( $page );
-                               if( is_null( $title ) ) {
-                                       continue; #TODO: perhaps output an <error> tag or something.
+                               if ( is_null( $title ) ) {
+                                       // @todo Perhaps output an <error> tag or something.
+                                       continue;
                                }
-                               if( !$title->userCan( 'read', $this->getUser() ) ) {
-                                       continue; #TODO: perhaps output an <error> tag or something.
+
+                               if ( !$title->userCan( 'read', $this->getUser() ) ) {
+                                       // @todo Perhaps output an <error> tag or something.
+                                       continue;
                                }
 
                                $exporter->pageByTitle( $title );
@@ -378,7 +391,7 @@ class SpecialExport extends SpecialPage {
 
                $exporter->closeStream();
 
-               if( $lb ) {
+               if ( $lb ) {
                        $lb->closeAll();
                }
        }
@@ -412,6 +425,7 @@ class SpecialExport extends SpecialPage {
 
                        $pages[] = $n;
                }
+
                return $pages;
        }
 
@@ -443,6 +457,7 @@ class SpecialExport extends SpecialPage {
 
                        $pages[] = $n;
                }
+
                return $pages;
        }
 
@@ -468,12 +483,12 @@ class SpecialExport extends SpecialPage {
        private function validateLinkDepth( $depth ) {
                global $wgExportMaxLinkDepth;
 
-               if( $depth < 0 ) {
+               if ( $depth < 0 ) {
                        return 0;
                }
 
                if ( !$this->userCanOverrideExportDepth() ) {
-                       if( $depth > $wgExportMaxLinkDepth ) {
+                       if ( $depth > $wgExportMaxLinkDepth ) {
                                return $wgExportMaxLinkDepth;
                        }
                }
@@ -483,6 +498,7 @@ class SpecialExport extends SpecialPage {
                 * crazy-big export from being done by someone setting the depth
                 * number too high. In other words, last resort safety net.
                 */
+
                return intval( min( $depth, 5 ) );
        }
 
@@ -494,7 +510,7 @@ class SpecialExport extends SpecialPage {
         * @return array
         */
        private function getPageLinks( $inputPages, $pageSet, $depth ) {
-               for( ; $depth > 0; --$depth ) {
+               for ( ; $depth > 0; --$depth ) {
                        $pageSet = $this->getLinks(
                                $inputPages, $pageSet, 'pagelinks',
                                array( 'namespace' => 'pl_namespace', 'title' => 'pl_title' ),
@@ -526,15 +542,20 @@ class SpecialExport extends SpecialPage {
 
        /**
         * Expand a list of pages to include items used in those pages.
+        * @param array $inputPages Array of page titles
+        * @param array $pageSet
+        * @param string $table
+        * @param array $fields Array of field names
+        * @param array $join
         * @return array
         */
        private function getLinks( $inputPages, $pageSet, $table, $fields, $join ) {
                $dbr = wfGetDB( DB_SLAVE );
 
-               foreach( $inputPages as $page ) {
+               foreach ( $inputPages as $page ) {
                        $title = Title::newFromText( $page );
 
-                       if( $title ) {
+                       if ( $title ) {
                                $pageSet[$title->getPrefixedText()] = true;
                                /// @todo FIXME: May or may not be more efficient to batch these
                                ///        by namespace when given multiple input pages.
@@ -551,7 +572,7 @@ class SpecialExport extends SpecialPage {
                                        __METHOD__
                                );
 
-                               foreach( $result as $row ) {
+                               foreach ( $result as $row ) {
                                        $template = Title::makeTitle( $row->namespace, $row->title );
                                        $pageSet[$template->getPrefixedText()] = true;
                                }