]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blobdiff - includes/specials/SpecialImport.php
MediaWiki 1.16.3
[autoinstallsdev/mediawiki.git] / includes / specials / SpecialImport.php
index 5e1a653329f0b7f4957df936fddc952e56f0b275..248709a87c582b355f2e9e99d93bf5ca5ac30905 100644 (file)
@@ -30,6 +30,7 @@ class SpecialImport extends SpecialPage {
        private $frompage = '';
        private $logcomment= false;
        private $history = true;
+       private $includeTemplates = false;
        
        /**
         * Constructor
@@ -44,7 +45,7 @@ class SpecialImport extends SpecialPage {
         * Execute
         */
        function execute( $par ) {
-               global $wgRequest;
+               global $wgRequest, $wgUser, $wgOut;
                
                $this->setHeaders();
                $this->outputHeader();
@@ -55,6 +56,28 @@ class SpecialImport extends SpecialPage {
                        return;
                }
                
+               if( !$wgUser->isAllowed( 'import' ) && !$wgUser->isAllowed( 'importupload' ) )
+                       return $wgOut->permissionRequired( 'import' );
+
+               # TODO: allow Title::getUserPermissionsErrors() to take an array
+               # FIXME: Title::checkSpecialsAndNSPermissions() has a very wierd expectation of what
+               # getUserPermissionsErrors() might actually be used for, hence the 'ns-specialprotected'
+               $errors = wfMergeErrorArrays(
+                       $this->getTitle()->getUserPermissionsErrors(
+                               'import', $wgUser, true,
+                               array( 'ns-specialprotected', 'badaccess-group0', 'badaccess-groups' )
+                       ),
+                       $this->getTitle()->getUserPermissionsErrors(
+                               'importupload', $wgUser, true,
+                               array( 'ns-specialprotected', 'badaccess-group0', 'badaccess-groups' )
+                       )
+               );
+
+               if( $errors ){
+                       $wgOut->showPermissionsErrorPage( $errors );
+                       return;
+               }
+
                if ( $wgRequest->wasPosted() && $wgRequest->getVal( 'action' ) == 'submit' ) {
                        $this->doImport();
                }
@@ -65,12 +88,13 @@ class SpecialImport extends SpecialPage {
         * Do the actual import
         */
        private function doImport() {
-               global $wgOut, $wgRequest, $wgUser, $wgImportSources;
+               global $wgOut, $wgRequest, $wgUser, $wgImportSources, $wgExportMaxLinkDepth;
                $isUpload = false;
                $this->namespace = $wgRequest->getIntOrNull( 'namespace' );
                $sourceName = $wgRequest->getVal( "source" );
 
                $this->logcomment = $wgRequest->getText( 'log-comment' );
+               $this->pageLinkDepth = $wgExportMaxLinkDepth == 0 ? 0 : $wgRequest->getIntOrNull( 'pagelink-depth' );
 
                if ( !$wgUser->matchEditToken( $wgRequest->getVal( 'editToken' ) ) ) {
                        $source = new WikiErrorMsg( 'import-token-mismatch' );
@@ -82,16 +106,22 @@ class SpecialImport extends SpecialPage {
                                return $wgOut->permissionRequired( 'importupload' );
                        }
                } elseif ( $sourceName == "interwiki" ) {
+                       if( !$wgUser->isAllowed( 'import' ) ){
+                               return $wgOut->permissionRequired( 'import' );
+                       }
                        $this->interwiki = $wgRequest->getVal( 'interwiki' );
                        if ( !in_array( $this->interwiki, $wgImportSources ) ) {
                                $source = new WikiErrorMsg( "import-invalid-interwiki" );
                        } else {
                                $this->history = $wgRequest->getCheck( 'interwikiHistory' );
                                $this->frompage = $wgRequest->getText( "frompage" );
+                               $this->includeTemplates = $wgRequest->getCheck( 'interwikiTemplates' );
                                $source = ImportStreamSource::newFromInterwiki(
                                        $this->interwiki,
                                        $this->frompage,
-                                       $this->history );
+                                       $this->history,
+                                       $this->includeTemplates,
+                                       $this->pageLinkDepth );
                        }
                } else {
                        $source = new WikiErrorMsg( "importunknownsource" );
@@ -127,20 +157,16 @@ class SpecialImport extends SpecialPage {
        }
 
        private function showForm() {
-               global $wgUser, $wgOut, $wgRequest, $wgTitle, $wgImportSources;
-               # FIXME: Quick hack to disable import for non privileged users /Raymond 
-               # Regression from 43963 
-               if( !$wgUser->isAllowed( 'import' ) && !$wgUser->isAllowed( 'importupload' ) )
-                       return $wgOut->permissionRequired( 'import' );
+               global $wgUser, $wgOut, $wgRequest, $wgImportSources, $wgExportMaxLinkDepth;
 
-               $action = $wgTitle->getLocalUrl( 'action=submit' );
+               $action = $this->getTitle()->getLocalUrl( array( 'action' => 'submit' ) );
 
                if( $wgUser->isAllowed( 'importupload' ) ) {
                        $wgOut->addWikiMsg( "importtext" );
                        $wgOut->addHTML(
-                               Xml::openElement( 'fieldset' ).
-                               Xml::element( 'legend', null, wfMsg( 'import-upload' ) ) .
-                               Xml::openElement( 'form', array( 'enctype' => 'multipart/form-data', 'method' => 'post', 'action' => $action ) ) .
+                               Xml::fieldset( wfMsg( 'import-upload' ) ).
+                               Xml::openElement( 'form', array( 'enctype' => 'multipart/form-data', 'method' => 'post',
+                                       'action' => $action, 'id' => 'mw-import-upload-form' ) ) .
                                Xml::hidden( 'action', 'submit' ) .
                                Xml::hidden( 'source', 'upload' ) .
                                Xml::openElement( 'table', array( 'id' => 'mw-import-table' ) ) .
@@ -164,7 +190,7 @@ class SpecialImport extends SpecialPage {
                                </tr>
                                <tr>
                                        <td></td>
-                                       <td class='mw-input'>" .
+                                       <td class='mw-submit'>" .
                                                Xml::submitButton( wfMsg( 'uploadbtn' ) ) .
                                        "</td>
                                </tr>" .
@@ -180,10 +206,22 @@ class SpecialImport extends SpecialPage {
                }
 
                if( $wgUser->isAllowed( 'import' ) && !empty( $wgImportSources ) ) {
+                       # Show input field for import depth only if $wgExportMaxLinkDepth > 0
+                       $importDepth = '';
+                       if( $wgExportMaxLinkDepth > 0 ) {
+                               $importDepth = "<tr>
+                                                       <td class='mw-label'>" .
+                                                               wfMsgExt( 'export-pagelinks', 'parseinline' ) .
+                                                       "</td>
+                                                       <td class='mw-input'>" .
+                                                               Xml::input( 'pagelink-depth', 3, 0 ) .
+                                                       "</td>
+                                               </tr>";
+                       }
+
                        $wgOut->addHTML(
-                               Xml::openElement( 'fieldset' ) .
-                               Xml::element( 'legend', null, wfMsg( 'importinterwiki' ) ) .
-                               Xml::openElement( 'form', array( 'method' => 'post', 'action' => $action ) ) .
+                               Xml::fieldset(  wfMsg( 'importinterwiki' ) ) .
+                               Xml::openElement( 'form', array( 'method' => 'post', 'action' => $action, 'id' => 'mw-import-interwiki-form' ) ) .
                                wfMsgExt( 'import-interwiki-text', array( 'parse' ) ) .
                                Xml::hidden( 'action', 'submit' ) .
                                Xml::hidden( 'source', 'interwiki' ) .
@@ -200,6 +238,7 @@ class SpecialImport extends SpecialPage {
                                $selected = ( $this->interwiki === $prefix ) ? ' selected="selected"' : '';
                                $wgOut->addHTML( Xml::option( $prefix, $prefix, $selected ) );
                        }
+
                        $wgOut->addHTML(
                                                Xml::closeElement( 'select' ) .
                                                Xml::input( 'frompage', 50, $this->frompage ) .
@@ -213,7 +252,15 @@ class SpecialImport extends SpecialPage {
                                        "</td>
                                </tr>
                                <tr>
-                                       <td>" .
+                                       <td>
+                                       </td>
+                                       <td class='mw-input'>" .
+                                               Xml::checkLabel( wfMsg( 'import-interwiki-templates' ), 'interwikiTemplates', 'interwikiTemplates', $this->includeTemplates ) .
+                                       "</td>
+                               </tr>
+                               $importDepth
+                               <tr>
+                                       <td class='mw-label'>" .
                                                Xml::label( wfMsg( 'import-interwiki-namespace' ), 'namespace' ) .
                                        "</td>
                                        <td class='mw-input'>" .
@@ -232,7 +279,7 @@ class SpecialImport extends SpecialPage {
                                <tr>
                                        <td>
                                        </td>
-                                       <td class='mw-input'>" .
+                                       <td class='mw-submit'>" .
                                                Xml::submitButton( wfMsg( 'import-interwiki-submit' ), array( 'accesskey' => 's' ) ) .
                                        "</td>
                                </tr>" .
@@ -249,7 +296,7 @@ class SpecialImport extends SpecialPage {
  * @ingroup SpecialPage
  */
 class ImportReporter {
-      private $reason=false;
+       private $reason=false;
 
        function __construct( $importer, $upload, $interwiki , $reason=false ) {
                $importer->setPageOutCallback( array( $this, 'reportPage' ) );
@@ -275,7 +322,7 @@ class ImportReporter {
                $contentCount = $wgContLang->formatNum( $successCount );
 
                if( $successCount > 0 ) {
-                       $wgOut->addHTML( "<li>" . $skin->makeKnownLinkObj( $title ) . " " .
+                       $wgOut->addHTML( "<li>" . $skin->linkKnown( $title ) . " " .
                                wfMsgExt( 'import-revision-count', array( 'parsemag', 'escape' ), $localCount ) .
                                "</li>\n"
                        );
@@ -285,7 +332,7 @@ class ImportReporter {
                                $detail = wfMsgExt( 'import-logentry-upload-detail', array( 'content', 'parsemag' ),
                                        $contentCount );
                                if ( $this->reason ) {
-                                       $detail .=  wfMsgForContent( 'colon-separator' ) . $this->reason;
+                                       $detail .=  wfMsgForContent( 'colon-separator' ) . $this->reason;
                                }
                                $log->addEntry( 'upload', $title, $detail );
                        } else {
@@ -294,7 +341,7 @@ class ImportReporter {
                                $detail = wfMsgExt( 'import-logentry-interwiki-detail', array( 'content', 'parsemag' ),
                                        $contentCount, $interwiki );
                                if ( $this->reason ) {
-                                       $detail .=  wfMsgForContent( 'colon-separator' ) . $this->reason;
+                                       $detail .=  wfMsgForContent( 'colon-separator' ) . $this->reason;
                                }
                                $log->addEntry( 'interwiki', $title, $detail );
                        }
@@ -309,7 +356,8 @@ class ImportReporter {
                        $article->updateRevisionOn( $dbw, $nullRevision );
                        wfRunHooks( 'NewRevisionFromEditComplete', array($article, $nullRevision, $latest, $wgUser) );
                } else {
-                       $wgOut->addHTML( '<li>' . wfMsgHtml( 'import-nonewrevisions' ) . '</li>' );
+                       $wgOut->addHTML( "<li>" . $skin->linkKnown( $title ) . " " .
+                               wfMsgHtml( 'import-nonewrevisions' ) . "</li>\n" );
                }
        }