Hooks: Added ImportLogInterwikiLink hook
[lhc/web/wiklou.git] / includes / specials / SpecialImport.php
index 4cdf6dd..0574dbc 100644 (file)
@@ -42,6 +42,7 @@ class SpecialImport extends SpecialPage {
        private $history = true;
        private $includeTemplates = false;
        private $pageLinkDepth;
+       private $importSources;
 
        /**
         * Constructor
@@ -50,6 +51,10 @@ class SpecialImport extends SpecialPage {
                parent::__construct( 'Import', 'import' );
        }
 
+       public function doesWrites() {
+               return true;
+       }
+
        /**
         * Execute
         * @param string|null $par
@@ -66,6 +71,9 @@ class SpecialImport extends SpecialPage {
 
                $this->getOutput()->addModules( 'mediawiki.special.import' );
 
+               $this->importSources = $this->getConfig()->get( 'ImportSources' );
+               Hooks::run( 'ImportSources', array( &$this->importSources ) );
+
                $user = $this->getUser();
                if ( !$user->isAllowedAny( 'import', 'importupload' ) ) {
                        throw new PermissionsError( 'import' );
@@ -136,16 +144,17 @@ class SpecialImport extends SpecialPage {
                        }
                        $this->interwiki = $this->fullInterwikiPrefix = $request->getVal( 'interwiki' );
                        // does this interwiki have subprojects?
-                       $importSources = $this->getConfig()->get( 'ImportSources' );
-                       $hasSubprojects = array_key_exists( $this->interwiki, $importSources );
-                       if ( !$hasSubprojects && !in_array( $this->interwiki, $importSources ) ) {
+                       $hasSubprojects = array_key_exists( $this->interwiki, $this->importSources );
+                       if ( !$hasSubprojects && !in_array( $this->interwiki, $this->importSources ) ) {
                                $source = Status::newFatal( "import-invalid-interwiki" );
                        } else {
                                if ( $hasSubprojects ) {
                                        $this->subproject = $request->getVal( 'subproject' );
                                        $this->fullInterwikiPrefix .= ':' . $request->getVal( 'subproject' );
                                }
-                               if ( $hasSubprojects && !in_array( $this->subproject, $importSources[$this->interwiki] ) ) {
+                               if ( $hasSubprojects &&
+                                       !in_array( $this->subproject, $this->importSources[$this->interwiki] )
+                               ) {
                                        $source = Status::newFatal( "import-invalid-interwiki" );
                                } else {
                                        $this->history = $request->getCheck( 'interwikiHistory' );
@@ -306,7 +315,6 @@ class SpecialImport extends SpecialPage {
                $user = $this->getUser();
                $out = $this->getOutput();
                $this->addHelpLink( '//meta.wikimedia.org/wiki/Special:MyLanguage/Help:Import', true );
-               $importSources = $this->getConfig()->get( 'ImportSources' );
 
                if ( $user->isAllowed( 'importupload' ) ) {
                        $mappingSelection = $this->getMappingFormPart( 'upload' );
@@ -356,12 +364,12 @@ class SpecialImport extends SpecialPage {
                                        Xml::closeElement( 'fieldset' )
                        );
                } else {
-                       if ( empty( $importSources ) ) {
+                       if ( empty( $this->importSources ) ) {
                                $out->addWikiMsg( 'importnosources' );
                        }
                }
 
-               if ( $user->isAllowed( 'import' ) && !empty( $importSources ) ) {
+               if ( $user->isAllowed( 'import' ) && !empty( $this->importSources ) ) {
                        # Show input field for import depth only if $wgExportMaxLinkDepth > 0
                        $importDepth = '';
                        if ( $this->getConfig()->get( 'ExportMaxLinkDepth' ) > 0 ) {
@@ -403,7 +411,7 @@ class SpecialImport extends SpecialPage {
                        );
 
                        $needSubprojectField = false;
-                       foreach ( $importSources as $key => $value ) {
+                       foreach ( $this->importSources as $key => $value ) {
                                if ( is_int( $key ) ) {
                                        $key = $value;
                                } elseif ( $value !== $key ) {
@@ -435,7 +443,7 @@ class SpecialImport extends SpecialPage {
                                );
 
                                $subprojectsToAdd = array();
-                               foreach ( $importSources as $key => $value ) {
+                               foreach ( $this->importSources as $key => $value ) {
                                        if ( is_array( $value ) ) {
                                                $subprojectsToAdd = array_merge( $subprojectsToAdd, $value );
                                        }
@@ -592,30 +600,33 @@ class ImportReporter extends ContextSource {
                                        "</li>\n"
                        );
 
+                       $logParams = array( '4:number:count' => $successCount );
                        if ( $this->mIsUpload ) {
                                $detail = $this->msg( 'import-logentry-upload-detail' )->numParams(
                                        $successCount )->inContentLanguage()->text();
-                               if ( $this->reason ) {
-                                       $detail .= $this->msg( 'colon-separator' )->inContentLanguage()->text()
-                                               . $this->reason;
-                               }
                                $action = 'upload';
                        } else {
-                               $interwiki = '[[:' . $this->mInterwiki . ':' .
-                                       $foreignTitle->getFullText() . ']]';
+                               $pageTitle = $foreignTitle->getFullText();
+                               $fullInterwikiPrefix = $this->mInterwiki;
+                               Hooks::run( 'ImportLogInterwikiLink', array( &$fullInterwikiPrefix, &$pageTitle ) );
+
+                               $interwikiTitleStr = $fullInterwikiPrefix . ':' . $pageTitle;
+                               $interwiki = '[[:' . $interwikiTitleStr . ']]';
                                $detail = $this->msg( 'import-logentry-interwiki-detail' )->numParams(
                                        $successCount )->params( $interwiki )->inContentLanguage()->text();
-                               if ( $this->reason ) {
-                                       $detail .= $this->msg( 'colon-separator' )->inContentLanguage()->text()
-                                               . $this->reason;
-                               }
                                $action = 'interwiki';
+                               $logParams['5:title-link:interwiki'] = $interwikiTitleStr;
+                       }
+                       if ( $this->reason ) {
+                               $detail .= $this->msg( 'colon-separator' )->inContentLanguage()->text()
+                                       . $this->reason;
                        }
 
                        $logEntry = new ManualLogEntry( 'import', $action );
                        $logEntry->setTarget( $title );
-                       $logEntry->setComment( $detail );
+                       $logEntry->setComment( $this->reason );
                        $logEntry->setPerformer( $this->getUser() );
+                       $logEntry->setParameters( $logParams );
                        $logid = $logEntry->insert();
                        $logEntry->publish( $logid );