Merge "Add hook to allow lazy loading of import sources"
This commit is contained in:
commit
70e760ee4e
4 changed files with 48 additions and 12 deletions
|
|
@ -1633,6 +1633,11 @@ Return false to stop further processing of the tag
|
|||
$reader: XMLReader object
|
||||
$revisionInfo: Array of information
|
||||
|
||||
'ImportSources': Called when reading from the $wgImportSources configuration
|
||||
variable. Can be used to lazy-load the import sources list.
|
||||
&$importSources: The value of $wgImportSources. Modify as necessary. See the
|
||||
comment in DefaultSettings.php for the detail of how to structure this array.
|
||||
|
||||
'InfoAction': When building information to display on the action=info page.
|
||||
$context: IContextSource object
|
||||
&$pageInfo: Array of information
|
||||
|
|
|
|||
|
|
@ -6363,8 +6363,8 @@ $wgShowCreditsIfMax = true;
|
|||
|
||||
/**
|
||||
* List of interwiki prefixes for wikis we'll accept as sources for
|
||||
* Special:Import (for sysops). Since complete page history can be imported,
|
||||
* these should be 'trusted'.
|
||||
* Special:Import and API action=import. Since complete page history can be
|
||||
* imported, these should be 'trusted'.
|
||||
*
|
||||
* This can either be a regular array, or an associative map specifying
|
||||
* subprojects on the interwiki map of the target wiki, or a mix of the two,
|
||||
|
|
@ -6377,6 +6377,9 @@ $wgShowCreditsIfMax = true;
|
|||
* );
|
||||
* @endcode
|
||||
*
|
||||
* If you have a very complex import sources setup, you can lazy-load it using
|
||||
* the ImportSources hook.
|
||||
*
|
||||
* If a user has the 'import' permission but not the 'importupload' permission,
|
||||
* they will only be able to run imports through this transwiki interface.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -92,6 +92,30 @@ class ApiImport extends ApiBase {
|
|||
$result->addValue( null, $this->getModuleName(), $resultData );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of interwiki prefixes corresponding to each defined import
|
||||
* source.
|
||||
*
|
||||
* @return array
|
||||
* @since 1.26
|
||||
*/
|
||||
public function getAllowedImportSources() {
|
||||
$importSources = $this->getConfig()->get( 'ImportSources' );
|
||||
Hooks::run( 'ImportSources', array( &$importSources ) );
|
||||
|
||||
$result = array();
|
||||
foreach ( $importSources as $key => $value ) {
|
||||
if ( is_int( $key ) ) {
|
||||
$result[] = $value;
|
||||
} else {
|
||||
foreach ( $value as $subproject ) {
|
||||
$result[] = "$key:$subproject";
|
||||
}
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function mustBePosted() {
|
||||
return true;
|
||||
}
|
||||
|
|
@ -107,7 +131,7 @@ class ApiImport extends ApiBase {
|
|||
ApiBase::PARAM_TYPE => 'upload',
|
||||
),
|
||||
'interwikisource' => array(
|
||||
ApiBase::PARAM_TYPE => $this->getConfig()->get( 'ImportSources' ),
|
||||
ApiBase::PARAM_TYPE => $this->getAllowedImportSources(),
|
||||
),
|
||||
'interwikipage' => null,
|
||||
'fullhistory' => false,
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ class SpecialImport extends SpecialPage {
|
|||
private $history = true;
|
||||
private $includeTemplates = false;
|
||||
private $pageLinkDepth;
|
||||
private $importSources;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
|
|
@ -66,6 +67,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 +140,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 +311,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 +360,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 +407,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 +439,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 );
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue