addDescription( "Approve the current revision of all pages " . "that do not yet have an approved revision." ); $this->addOption( "force", "Approve the latest version, even if an earlier " . "revision of the page has already been approved." ); $this->addOption( 'namespaces', 'Limit to this comma-separated list of namespace numbers.', false, true ); $this->addOption( "username", "The username to use for all the approval actions." ); if ( method_exists( $this, 'requireExtension' ) ) { $this->requireExtension( 'Approved Revs' ); } } public function execute() { global $wgTitle; global $wgEnotifWatchlist; if ( $this->hasOption( 'namespaces' ) ) { $allowedNamespaces = explode( ',', $this->getOption( 'namespaces' ) ); } else { $allowedNamespaces = null; } // Don't send out any notifications about people's watch lists. $wgEnotifWatchlist = false; $dbr = ApprovedRevs::getReadDB(); $pages = $dbr->select( 'page', [ 'page_id', 'page_latest' ], [], __METHOD__ ); foreach ( $pages as $page ) { $title = Title::newFromID( $page->page_id ); // Some extensions, like Page Forms, need $wgTitle // set as well for these checks. $wgTitle = $title; if ( $allowedNamespaces !== null ) { if ( !in_array( $title->getNamespace(), $allowedNamespaces ) ) { continue; } } if ( !ApprovedRevs::pageIsApprovable( $title ) ) { continue; } $approvedRevID = ApprovedRevs::getApprovedRevID( $title ); $latestRevID = $page->page_latest; if ( $this->getOption( "force" ) ) { if ( $latestRevID == $approvedRevID ) { continue; } } else { if ( $approvedRevID != null ) { continue; } } if ( $this->hasOption( 'username' ) ) { $username = $this->getOption( 'username' ); $user = MediaWikiServices::getInstance()->getUserFactory()->newFromName( $username ); if ( $user == null || !$user->isRegistered() ) { print "Error: \"$username\" is not a valid username.\n"; return; } } else { $user = new User(); } // Let's approve the latest revision... ApprovedRevs::setApprovedRevID( $title, $latestRevID, $user, true ); $this->output( wfTimestamp( TS_DB ) . ' Approved the last revision of page "' . $title->getFullText() . "\".\n" ); } if ( $allowedNamespaces == null ) { $this->output( "\n Finished setting all current " . "revisions to approved. \n" ); } else { $this->output( "\n Finished setting specified " . "revisions to approved. \n" ); } } } $maintClass = ApproveAllPages::class; require_once RUN_MAINTENANCE_IF_MAIN;