From 89cd937798b52e75834a12a66d9a728fcce4f06f Mon Sep 17 00:00:00 2001 From: Derick Alangi Date: Sun, 7 Jul 2019 23:07:56 +0100 Subject: [PATCH] Avoid usage of deprecated setTags() method, use addTags() instead $tags can be `null` as seen in most cases and this causes failures, so, the safer path is to make sure if $tags is a null, do nothing. Change-Id: I5b7e39adba5d08fdcd42c437a72a391be98c8695 --- includes/FileDeleteForm.php | 4 ++-- includes/MovePage.php | 4 ++-- includes/changetags/ChangeTags.php | 2 +- includes/filerepo/file/LocalFile.php | 2 +- includes/logging/ManualLogEntry.php | 10 ++++++---- includes/logging/PatrolLog.php | 2 +- includes/page/PageArchive.php | 2 +- includes/page/WikiPage.php | 4 ++-- includes/revisiondelete/RevDelList.php | 2 +- includes/specials/SpecialBlock.php | 2 +- includes/specials/SpecialPageLanguage.php | 2 +- includes/specials/SpecialUnblock.php | 2 +- includes/specials/SpecialUserrights.php | 2 +- includes/specials/helpers/ImportReporter.php | 2 +- 14 files changed, 22 insertions(+), 20 deletions(-) diff --git a/includes/FileDeleteForm.php b/includes/FileDeleteForm.php index 8272ccf767..b5333afe4e 100644 --- a/includes/FileDeleteForm.php +++ b/includes/FileDeleteForm.php @@ -181,7 +181,7 @@ class FileDeleteForm { $logEntry->setPerformer( $user ); $logEntry->setTarget( $title ); $logEntry->setComment( $logComment ); - $logEntry->setTags( $tags ); + $logEntry->addTags( $tags ); $logid = $logEntry->insert(); $logEntry->publish( $logid ); @@ -212,7 +212,7 @@ class FileDeleteForm { $logEntry->setPerformer( $user ); $logEntry->setTarget( clone $title ); $logEntry->setComment( $reason ); - $logEntry->setTags( $tags ); + $logEntry->addTags( $tags ); $logid = $logEntry->insert(); $dbw->onTransactionPreCommitOrIdle( function () use ( $logEntry, $logid ) { diff --git a/includes/MovePage.php b/includes/MovePage.php index e6faacef47..9f018930d3 100644 --- a/includes/MovePage.php +++ b/includes/MovePage.php @@ -598,7 +598,7 @@ class MovePage { '4::oldtitle' => $this->oldTitle->getPrefixedText(), ] ); $logEntry->setRelations( [ 'pr_id' => $logRelationsValues ] ); - $logEntry->setTags( $changeTags ); + $logEntry->addTags( $changeTags ); $logId = $logEntry->insert(); $logEntry->publish( $logId ); } @@ -895,7 +895,7 @@ class MovePage { # Log the move $logid = $logEntry->insert(); - $logEntry->setTags( $changeTags ); + $logEntry->addTags( $changeTags ); $logEntry->publish( $logid ); return $nullRevision; diff --git a/includes/changetags/ChangeTags.php b/includes/changetags/ChangeTags.php index 30c2f7a428..9ee000d590 100644 --- a/includes/changetags/ChangeTags.php +++ b/includes/changetags/ChangeTags.php @@ -1001,7 +1001,7 @@ class ChangeTags { } $logEntry->setParameters( $params ); $logEntry->setRelations( [ 'Tag' => $tag ] ); - $logEntry->setTags( $logEntryTags ); + $logEntry->addTags( $logEntryTags ); $logId = $logEntry->insert( $dbw ); $logEntry->publish( $logId ); diff --git a/includes/filerepo/file/LocalFile.php b/includes/filerepo/file/LocalFile.php index 54fc251f4b..3fe788914c 100644 --- a/includes/filerepo/file/LocalFile.php +++ b/includes/filerepo/file/LocalFile.php @@ -1758,7 +1758,7 @@ class LocalFile extends File { # Add change tags, if any if ( $tags ) { - $logEntry->setTags( $tags ); + $logEntry->addTags( $tags ); } # Uploads can be patrolled diff --git a/includes/logging/ManualLogEntry.php b/includes/logging/ManualLogEntry.php index 1d0bbfd6fa..5326705ff1 100644 --- a/includes/logging/ManualLogEntry.php +++ b/includes/logging/ManualLogEntry.php @@ -191,18 +191,20 @@ class ManualLogEntry extends LogEntryBase implements Taggable { wfDebug( 'Overwriting existing ManualLogEntry tags' ); } $this->tags = []; - if ( $tags !== null ) { - $this->addTags( $tags ); - } + $this->addTags( $tags ); } /** * Add change tags for the log entry * * @since 1.33 - * @param string|string[] $tags Tags to apply + * @param string|string[]|null $tags Tags to apply */ public function addTags( $tags ) { + if ( $tags === null ) { + return; + } + if ( is_string( $tags ) ) { $tags = [ $tags ]; } diff --git a/includes/logging/PatrolLog.php b/includes/logging/PatrolLog.php index d737a4b1e1..9392220eb8 100644 --- a/includes/logging/PatrolLog.php +++ b/includes/logging/PatrolLog.php @@ -63,7 +63,7 @@ class PatrolLog { $entry->setTarget( $rc->getTitle() ); $entry->setParameters( self::buildParams( $rc, $auto ) ); $entry->setPerformer( $user ); - $entry->setTags( $tags ); + $entry->addTags( $tags ); $logid = $entry->insert(); if ( !$auto ) { $entry->publish( $logid, 'udp' ); diff --git a/includes/page/PageArchive.php b/includes/page/PageArchive.php index d69a433d9c..40c63d22e4 100644 --- a/includes/page/PageArchive.php +++ b/includes/page/PageArchive.php @@ -461,7 +461,7 @@ class PageArchive { $logEntry->setPerformer( $user ); $logEntry->setTarget( $this->title ); $logEntry->setComment( $comment ); - $logEntry->setTags( $tags ); + $logEntry->addTags( $tags ); $logEntry->setParameters( [ ':assoc:count' => [ 'revisions' => $textRestored, diff --git a/includes/page/WikiPage.php b/includes/page/WikiPage.php index 460753514c..a490cfd953 100644 --- a/includes/page/WikiPage.php +++ b/includes/page/WikiPage.php @@ -2390,7 +2390,7 @@ class WikiPage implements Page, IDBAccessObject { if ( !is_null( $nullRevision ) ) { $logEntry->setAssociatedRevId( $nullRevision->getId() ); } - $logEntry->setTags( $tags ); + $logEntry->addTags( $tags ); if ( $logRelationsField !== null && count( $logRelationsValues ) ) { $logEntry->setRelations( [ $logRelationsField => $logRelationsValues ] ); } @@ -2791,7 +2791,7 @@ class WikiPage implements Page, IDBAccessObject { $logEntry->setPerformer( $deleter ); $logEntry->setTarget( $logTitle ); $logEntry->setComment( $reason ); - $logEntry->setTags( $tags ); + $logEntry->addTags( $tags ); $logid = $logEntry->insert(); $dbw->onTransactionPreCommitOrIdle( diff --git a/includes/revisiondelete/RevDelList.php b/includes/revisiondelete/RevDelList.php index 680ae8e52f..dc43aedb40 100644 --- a/includes/revisiondelete/RevDelList.php +++ b/includes/revisiondelete/RevDelList.php @@ -394,7 +394,7 @@ abstract class RevDelList extends RevisionListBase { } $logEntry->setRelations( $relations ); // Apply change tags to the log entry - $logEntry->setTags( $params['tags'] ); + $logEntry->addTags( $params['tags'] ); $logId = $logEntry->insert(); $logEntry->publish( $logId ); } diff --git a/includes/specials/SpecialBlock.php b/includes/specials/SpecialBlock.php index 59d2806b0a..3a266f23d7 100644 --- a/includes/specials/SpecialBlock.php +++ b/includes/specials/SpecialBlock.php @@ -1031,7 +1031,7 @@ class SpecialBlock extends FormSpecialPage { $logId = $logEntry->insert(); if ( !empty( $data['Tags'] ) ) { - $logEntry->setTags( $data['Tags'] ); + $logEntry->addTags( $data['Tags'] ); } $logEntry->publish( $logId ); diff --git a/includes/specials/SpecialPageLanguage.php b/includes/specials/SpecialPageLanguage.php index c0f004ffa6..1f222f8a79 100644 --- a/includes/specials/SpecialPageLanguage.php +++ b/includes/specials/SpecialPageLanguage.php @@ -253,7 +253,7 @@ class SpecialPageLanguage extends FormSpecialPage { $entry->setTarget( $title ); $entry->setParameters( $logParams ); $entry->setComment( $reason ); - $entry->setTags( $tags ); + $entry->addTags( $tags ); $logid = $entry->insert(); $entry->publish( $logid ); diff --git a/includes/specials/SpecialUnblock.php b/includes/specials/SpecialUnblock.php index 31c277a27d..9b8022b7c2 100644 --- a/includes/specials/SpecialUnblock.php +++ b/includes/specials/SpecialUnblock.php @@ -249,7 +249,7 @@ class SpecialUnblock extends SpecialPage { $logEntry->setComment( $data['Reason'] ); $logEntry->setPerformer( $performer ); if ( isset( $data['Tags'] ) ) { - $logEntry->setTags( $data['Tags'] ); + $logEntry->addTags( $data['Tags'] ); } $logEntry->setRelations( [ 'ipb_id' => $block->getId() ] ); $logId = $logEntry->insert(); diff --git a/includes/specials/SpecialUserrights.php b/includes/specials/SpecialUserrights.php index 87534eb885..a45ccca8a7 100644 --- a/includes/specials/SpecialUserrights.php +++ b/includes/specials/SpecialUserrights.php @@ -464,7 +464,7 @@ class UserrightsPage extends SpecialPage { ] ); $logid = $logEntry->insert(); if ( count( $tags ) ) { - $logEntry->setTags( $tags ); + $logEntry->addTags( $tags ); } $logEntry->publish( $logid ); } diff --git a/includes/specials/helpers/ImportReporter.php b/includes/specials/helpers/ImportReporter.php index 80638042b0..eac48faed6 100644 --- a/includes/specials/helpers/ImportReporter.php +++ b/includes/specials/helpers/ImportReporter.php @@ -160,7 +160,7 @@ class ImportReporter extends ContextSource { // Make sure the null revision will be tagged as well $logEntry->setAssociatedRevId( $nullRevId ); if ( count( $this->logTags ) ) { - $logEntry->setTags( $this->logTags ); + $logEntry->addTags( $this->logTags ); } $logid = $logEntry->insert(); $logEntry->publish( $logid ); -- 2.20.1