Revision: 47964 Author: werdna Date: 2009-03-03 02:56:30 +0000 (Tue, 03 Mar 2009)
Log Message: ----------- (bug 11857) Add 'protect' option to importImages.php maintenance script. Includes related Article changes -- fixing an E_NOTICE and reporting errors in the debug log. Modified Paths: -------------- trunk/phase3/includes/Article.php trunk/phase3/maintenance/importImages.php Modified: trunk/phase3/includes/Article.php =================================================================== --- trunk/phase3/includes/Article.php 2009-03-03 00:23:39 UTC (rev 47963) +++ trunk/phase3/includes/Article.php 2009-03-03 02:56:30 UTC (rev 47964) @@ -1943,9 +1943,20 @@ global $wgUser, $wgRestrictionTypes, $wgContLang; $id = $this->mTitle->getArticleID(); - if( $id <= 0 || wfReadOnly() || !$this->mTitle->userCan('protect') ) { + if ( $id <= 0 ) { + wfDebug( "updateRestrictions failed: $id <= 0\n" ); return false; } + + if ( wfReadOnly() ) { + wfDebug( "updateRestrictions failed: read-only\n" ); + return false; + } + + if ( wfReadOnly() ) { + wfDebug( "updateRestrictions failed: insufficient permissions\n" ); + return false; + } if( !$cascade ) { $cascade = false; @@ -2014,6 +2025,9 @@ $encodedExpiry = array(); $protect_description = ''; foreach( $limit as $action => $restrictions ) { + if ( !isset($expiry[$action]) ) + $expiry[$action] = 'infinite'; + $encodedExpiry[$action] = Block::encodeExpiry($expiry[$action], $dbw ); if( $restrictions != '' ) { $protect_description .= "[$action=$restrictions] ("; Modified: trunk/phase3/maintenance/importImages.php =================================================================== --- trunk/phase3/maintenance/importImages.php 2009-03-03 00:23:39 UTC (rev 47963) +++ trunk/phase3/maintenance/importImages.php 2009-03-03 02:56:30 UTC (rev 47964) @@ -21,6 +21,13 @@ $dir = $args[0]; + # Check Protection + if (isset($options['protect']) && isset($options['unprotect'])) + die("Cannot specify both protect and unprotect. Only 1 is allowed.\n"); + + if ($options['protect'] == 1) + die("You must specify a protection option.\n"); + # Prepare the list of allowed extensions global $wgFileExtensions; $extensions = isset( $options['extensions'] ) @@ -114,13 +121,47 @@ continue; } } + + $doProtect = false; + $restrictions = array(); + + global $wgRestrictionLevels; + + $protectLevel = isset($options['protect']) ? $options['protect'] : null; + + if ( $protectLevel && in_array( $protectLevel, $wgRestrictionLevels ) ) { + $restrictions['move'] = $protectLevel; + $restrictions['edit'] = $protectLevel; + $doProtect = true; + } + if (isset($options['unprotect'])) { + $restrictions['move'] = ''; + $restrictions['edit'] = ''; + $doProtect = true; + } + $$svar++; if ( isset( $options['dry'] ) ) { echo( "done.\n" ); } else if ( $image->recordUpload( $archive->value, $commentText, $license ) ) { # We're done! echo( "done.\n" ); + if ($doProtect) { + # Protect the file + $article = new Article( $title ); + echo "\nWaiting for slaves...\n"; + // Wait for slaves. + sleep(2.0); + wfWaitForSlaves( 1.0 ); + + echo( "\nSetting image restrictions ... " ); + if ( $article->updateRestrictions($restrictions) ) + echo( "done.\n" ); + else + echo( "failed.\n" ); + } + } else { echo( "failed.\n" ); } @@ -166,6 +207,8 @@ but the extension <ext>. --license=<code> Use an optional license template --dry Dry run, don't import anything +--protect=<protect> Specify the protect value (autoconfirmed,sysop) +--unprotect Unprotects all uploaded images END; exit(); _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs