Skip to content

Commit

Permalink
fix support for MediaWiki 1.26 to fix a transaction exception
Browse files Browse the repository at this point in the history
For some reasons in 1.26 (and maybe other versions) the extension
DeleteBatch is not able to call $db->startAtomic() without then
calling $wikipage->doDeleteArticle() and causing an exception
since a transaction is already opened.

In my honest opinion this should not happen since the call
to $wikipage->doDeleteArticle is done with the argoment $commit
parameter set to false, so it should not open another transaction
internally to then try to commit it.

Sadly I do not understand 90% of the workflow so as workaround
I've just disabled the $db->startAtomic() in version <= 1.26.
  • Loading branch information
valerio-bozzolan committed Mar 10, 2022
1 parent 82ab169 commit 8abecc5
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions includes/DeleteBatchForm.php
Expand Up @@ -185,6 +185,7 @@ function deleteBatch( $line = '', $filename = null ) {

/* @todo run tests - run many tests */
$dbw = wfGetDB( DB_PRIMARY );

if ( $filename ) {
/* if from filename, delete from filename */
for ( $linenum = 1; !feof( $file ); $linenum++ ) {
Expand Down Expand Up @@ -246,6 +247,7 @@ function deleteBatch( $line = '', $filename = null ) {
*/
private function deletePage( $line, $user, $db, $reason = '', $multi = false, $linenum = 0 ) {
$page = Title::newFromText( $line );

if ( $page === null ) {
/* invalid title? */
$this->context->getOutput()->addWikiMsg(
Expand Down Expand Up @@ -287,7 +289,16 @@ private function deletePage( $line, $user, $db, $reason = '', $multi = false, $l
}
}

$db->startAtomic( __METHOD__ );
$start_atomic = true;
if( version_compare( MW_VERSION, '1.26', '<=' ) ) {
// it seems MediaWiki 1.26 does not like to create transactions here
$start_atomic = false;
}

if( $start_atomic ) {
$db->startAtomic( __METHOD__ );
}

/* this stuff goes like articleFromTitle in Wiki.php */
// Delete the page; in the case of a file, this would be the File: description page
if ( $pageExists ) {
Expand All @@ -302,6 +313,7 @@ private function deletePage( $line, $user, $db, $reason = '', $multi = false, $l
$wikipage->doDeleteArticleReal( $reason, $user );
}
}

// Delete the actual file, if applicable
if ( $localFileExists ) {
// This deletes all versions of the file. This does not create a
Expand All @@ -316,7 +328,11 @@ private function deletePage( $line, $user, $db, $reason = '', $multi = false, $l
$localFile->delete( $reason );
}
}
$db->endAtomic( __METHOD__ );

if( $start_atomic ) {
$db->endAtomic( __METHOD__ );
}

if ( $localFileExists ) {
// Flush DBs in case of fragile file operations
$lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
Expand Down

0 comments on commit 8abecc5

Please sign in to comment.