2021-07-15 00:02:23 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
$IP = getenv( 'MW_INSTALL_PATH' );
|
|
|
|
if ( $IP === false ) {
|
|
|
|
$IP = __DIR__ . '/../../..';
|
|
|
|
}
|
|
|
|
require_once "$IP/maintenance/Maintenance.php";
|
|
|
|
|
2021-11-25 21:35:46 +00:00
|
|
|
use MediaWiki\Extension\TemplateData\TemplateDataBlob;
|
2024-10-20 11:20:47 +00:00
|
|
|
use MediaWiki\Maintenance\Maintenance;
|
2023-08-19 04:19:39 +00:00
|
|
|
use MediaWiki\Title\Title;
|
2021-11-25 21:35:46 +00:00
|
|
|
|
2023-08-23 07:29:25 +00:00
|
|
|
/**
|
|
|
|
* @license GPL-2.0-or-later
|
|
|
|
*/
|
2021-07-15 00:02:23 +00:00
|
|
|
class ValidateTemplateData extends Maintenance {
|
|
|
|
|
|
|
|
public function __construct() {
|
|
|
|
parent::__construct();
|
|
|
|
$this->addDescription( 'Checks all TemplateData JSON pages are valid and outputs the name of invalid rows' );
|
|
|
|
|
|
|
|
$this->setBatchSize( 500 );
|
|
|
|
$this->requireExtension( 'TemplateData' );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function execute() {
|
2024-06-07 09:05:08 +00:00
|
|
|
$db = $this->getReplicaDB();
|
2021-07-15 00:02:23 +00:00
|
|
|
|
|
|
|
$lastId = 0;
|
|
|
|
$rowsChecked = 0;
|
|
|
|
$badRows = 0;
|
|
|
|
$this->output( "Pages with invalid Template Data:\n" );
|
|
|
|
do {
|
2022-08-12 21:54:22 +00:00
|
|
|
$res = $db->newSelectQueryBuilder()
|
|
|
|
->from( 'page_props' )
|
|
|
|
->join( 'page', null, 'pp_page=page_id' )
|
|
|
|
->fields( [ 'pp_page', 'pp_value', 'page_namespace', 'page_title' ] )
|
|
|
|
->where( [
|
2023-11-10 23:30:41 +00:00
|
|
|
$db->expr( 'pp_page', '>', $lastId ),
|
2021-07-15 00:02:23 +00:00
|
|
|
'pp_propname' => 'templatedata'
|
2022-08-12 21:54:22 +00:00
|
|
|
] )
|
|
|
|
->orderBy( 'pp_page' )
|
|
|
|
->limit( $this->getBatchSize() )
|
|
|
|
->caller( __METHOD__ )
|
|
|
|
->fetchResultSet();
|
2021-07-15 00:02:23 +00:00
|
|
|
|
|
|
|
$count = $res->numRows();
|
|
|
|
|
|
|
|
foreach ( $res as $row ) {
|
|
|
|
$tdb = TemplateDataBlob::newFromDatabase( $db, $row->pp_value );
|
|
|
|
$status = $tdb->getStatus();
|
|
|
|
if ( !$status->isOK() ) {
|
|
|
|
$this->output(
|
|
|
|
Title::newFromRow( $row )->getPrefixedText() . "\n"
|
|
|
|
);
|
|
|
|
$badRows++;
|
|
|
|
}
|
|
|
|
$lastId = $row->pp_page;
|
|
|
|
$rowsChecked++;
|
|
|
|
}
|
|
|
|
} while ( $count !== 0 );
|
|
|
|
|
|
|
|
$this->output( "\nDone!\n" );
|
|
|
|
$this->output( "Rows checked: {$rowsChecked}\n" );
|
|
|
|
$this->output( "Bad rows: {$badRows}\n" );
|
|
|
|
}
|
2023-08-23 07:29:25 +00:00
|
|
|
|
2021-07-15 00:02:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$maintClass = ValidateTemplateData::class;
|
|
|
|
require_once RUN_MAINTENANCE_IF_MAIN;
|