Page MenuHomePhabricator

Editing an Interwiki entry without making any changes results in an error with no language string, but does in fact update successfully.
Open, LowPublic

Description

Ideally the boolean return of $dbw->update() should be checked and used as part of the second if check. Updating a database row with no changes result in success, but with no affected rows. This currently produces the error message <interwiki_editfailed> which does not exist.

			if ( $do === 'add' ) {
				$dbw->insert( 'interwiki', $data, __METHOD__, 'IGNORE' );
			} else { // $do === 'edit'
				$dbw->update( 'interwiki', $data, array( 'iw_prefix' => $prefix ), __METHOD__, 'IGNORE' );
			}

			// used here: interwiki_addfailed, interwiki_added, interwiki_edited
			if ( $dbw->affectedRows() === 0 ) {
				$this->error( "interwiki_{$do}failed", $prefix );
				$this->showForm( $do );
			} else {
				$this->getOutput()->addWikiMsg( "interwiki_{$do}ed", $prefix );
				$log = new LogPage( 'interwiki' );
				$log->addEntry( 'iw_' . $do, $selfTitle, $reason, array( $prefix, $theurl, $trans, $local ) );
				$wgMemc->delete( wfMemcKey( 'interwiki', $prefix ) );
			}

Suggested changes:

			$success = true;
			if ( $do === 'add' ) {
				$success = $dbw->insert( 'interwiki', $data, __METHOD__, 'IGNORE' );
			} else { // $do === 'edit'
				$success = $dbw->update( 'interwiki', $data, array( 'iw_prefix' => $prefix ), __METHOD__, 'IGNORE' );
			}

			// used here: interwiki_addfailed, interwiki_added, interwiki_edited
			if ( $dbw->affectedRows() === 0 || !$success ) {
				$this->error( "interwiki_{$do}failed", $prefix );
				$this->showForm( $do );
			} else {
				$this->getOutput()->addWikiMsg( "interwiki_{$do}ed", $prefix );
				$log = new LogPage( 'interwiki' );
				$log->addEntry( 'iw_' . $do, $selfTitle, $reason, array( $prefix, $theurl, $trans, $local ) );
				$wgMemc->delete( wfMemcKey( 'interwiki', $prefix ) );
			}

Event Timeline

Alexia raised the priority of this task from to Needs Triage.
Alexia updated the task description. (Show Details)
Alexia moved this task to Backlog on the MediaWiki-extensions-Interwiki board.
Alexia subscribed.

Thanks for taking a look at the code!

You are very welcome to use developer access to submit the proposed code changes as a Git branch directly into Gerrit.
Putting your branch in Git makes it easier to review it quickly. If you don't want to set up Git/Gerrit, you can also use the Gerrit Patch Uploader.

I forgot about the patch uploader. I just sent one through with corrected logic.

https://gerrit.wikimedia.org/r/#/c/198235/