addDescription( "Approve the current revision of all files " . "that do not yet have an approved revision." ); $this->addOption( "force", "Approve the latest version, even if an earlier " . "revision of the file has already been approved." ); if ( method_exists( $this, 'requireExtension' ) ) { $this->requireExtension( 'Approved Revs' ); } } public function execute() { global $wgEnotifWatchlist; global $egApprovedRevsEnabledNamespaces; // Exit quickly if NS_FILE is not approvable. if ( $egApprovedRevsEnabledNamespaces[NS_FILE] !== true ) { print "Approved Revs is not enabled for files on this wiki; exiting.\n"; return; } // Don't send out any notifications about people's watch lists. $wgEnotifWatchlist = false; $dbr = ApprovedRevs::getReadDB(); $pages = $dbr->select( 'page', [ 'page_id', 'page_latest' ], [ 'page_namespace = ' . NS_FILE ], __METHOD__ ); foreach ( $pages as $page ) { $title = Title::newFromID( $page->page_id ); if ( !ApprovedRevs::fileIsApprovable( $title ) ) { continue; } $file = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo()->newFile( $title ); if ( !$file->exists() ) { continue; } [ $approvedTimestamp, $approvedSha1 ] = ApprovedRevs::getApprovedFileInfo( $title ); $fileTimestamp = $file->getTimestamp(); $fileSha1 = $file->getSha1(); if ( $this->getOption( "force" ) ) { if ( $fileTimestamp == $approvedTimestamp ) { continue; } } else { if ( $approvedTimestamp != null ) { continue; } } // Let's approve the latest revision... // fixme: the user here is empty - use a system user? ApprovedRevs::setApprovedFileInDB( $title, $fileTimestamp, $fileSha1, new User() ); $this->output( wfTimestamp( TS_DB ) . ' Approved the last revision of the file "' . $title->getFullText() . "\".\n" ); } $this->output( "\n Finished setting all current " . "revisions to approved. \n" ); } } $maintClass = ApproveAllFiles::class; require_once RUN_MAINTENANCE_IF_MAIN;