Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 45 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| PurgeMapPages | |
0.00% |
0 / 39 |
|
0.00% |
0 / 2 |
56 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| execute | |
0.00% |
0 / 34 |
|
0.00% |
0 / 1 |
42 | |||
| 1 | <?php |
| 2 | $IP = getenv( 'MW_INSTALL_PATH' ); |
| 3 | if ( $IP === false ) { |
| 4 | $IP = __DIR__ . '/../../..'; |
| 5 | } |
| 6 | require_once "$IP/maintenance/Maintenance.php"; |
| 7 | |
| 8 | use MediaWiki\Deferred\LinksUpdate\CategoryLinksTable; |
| 9 | use MediaWiki\Maintenance\Maintenance; |
| 10 | use MediaWiki\Title\Title; |
| 11 | use MediaWiki\Utils\BatchRowIterator; |
| 12 | |
| 13 | /** |
| 14 | * Purges all pages that use <maplink> or <mapframe>, using the tracking category. |
| 15 | * |
| 16 | * @license MIT |
| 17 | */ |
| 18 | class PurgeMapPages extends Maintenance { |
| 19 | |
| 20 | public function __construct() { |
| 21 | parent::__construct(); |
| 22 | $this->addDescription( 'Purge all pages that use <maplink> or <mapframe>.' ); |
| 23 | $this->addOption( 'dry-run', 'Only print page names, do not purge them' ); |
| 24 | $this->setBatchSize( 100 ); |
| 25 | $this->requireExtension( 'Kartographer' ); |
| 26 | } |
| 27 | |
| 28 | /** @inheritDoc */ |
| 29 | public function execute() { |
| 30 | $categoryMessage = wfMessage( 'kartographer-tracking-category' ); |
| 31 | if ( $categoryMessage->isDisabled() ) { |
| 32 | $this->error( "Tracking category for maps pages is disabled\n" ); |
| 33 | return; |
| 34 | } |
| 35 | $categoryTitle = Title::makeTitle( NS_CATEGORY, $categoryMessage->inContentLanguage()->text() ); |
| 36 | $dryRun = $this->hasOption( 'dry-run' ); |
| 37 | $linksMigration = $this->getServiceContainer()->getLinksMigration(); |
| 38 | $queryInfo = $linksMigration->getQueryInfo( 'categorylinks' ); |
| 39 | $iterator = new BatchRowIterator( |
| 40 | $this->getReplicaDB( CategoryLinksTable::VIRTUAL_DOMAIN ), |
| 41 | array_merge( $queryInfo['tables'], [ 'page' ] ), |
| 42 | [ 'cl_type', 'cl_sortkey', 'cl_from' ], |
| 43 | $this->getBatchSize() |
| 44 | ); |
| 45 | $iterator->addConditions( $linksMigration->getLinksConditions( 'categorylinks', $categoryTitle ) ); |
| 46 | $iterator->addJoinConditions( [ 'page' => [ 'INNER JOIN', [ 'page_id=cl_from' ] ] ] ); |
| 47 | $iterator->addJoinConditions( $queryInfo['joins'] ); |
| 48 | $iterator->setFetchColumns( [ 'page_id', 'page_namespace', 'page_title' ] ); |
| 49 | $iterator->setCaller( __METHOD__ ); |
| 50 | |
| 51 | $pages = 0; |
| 52 | $failures = 0; |
| 53 | $wikiPageFactory = $this->getServiceContainer()->getWikiPageFactory(); |
| 54 | foreach ( $iterator as $batch ) { |
| 55 | foreach ( $batch as $row ) { |
| 56 | $title = Title::newFromRow( $row ); |
| 57 | if ( $dryRun ) { |
| 58 | $this->output( $title->getPrefixedText() . "\n" ); |
| 59 | } else { |
| 60 | $page = $wikiPageFactory->newFromTitle( $title ); |
| 61 | if ( $page->doPurge() ) { |
| 62 | $this->output( "Purged {$title->getPrefixedText()}\n" ); |
| 63 | } else { |
| 64 | $this->error( "FAILED TO PURGE {$title->getPrefixedText()}\n" ); |
| 65 | $failures++; |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | $pages += count( $batch ); |
| 70 | } |
| 71 | $this->output( "\nFinished. Total: $pages pages. Failed: $failures.\n" ); |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | $maintClass = PurgeMapPages::class; |
| 76 | require_once RUN_MAINTENANCE_IF_MAIN; |