Avoid usage of deprecated setTags() method, use addTags() instead
authorDerick Alangi <alangiderick@gmail.com>
Sun, 7 Jul 2019 22:07:56 +0000 (23:07 +0100)
committerKrinkle <krinklemail@gmail.com>
Sun, 1 Sep 2019 14:54:03 +0000 (14:54 +0000)
$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

14 files changed:
includes/FileDeleteForm.php
includes/MovePage.php
includes/changetags/ChangeTags.php
includes/filerepo/file/LocalFile.php
includes/logging/ManualLogEntry.php
includes/logging/PatrolLog.php
includes/page/PageArchive.php
includes/page/WikiPage.php
includes/revisiondelete/RevDelList.php
includes/specials/SpecialBlock.php
includes/specials/SpecialPageLanguage.php
includes/specials/SpecialUnblock.php
includes/specials/SpecialUserrights.php
includes/specials/helpers/ImportReporter.php

index 8272ccf..b5333af 100644 (file)
@@ -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 ) {
index e6faace..9f01893 100644 (file)
@@ -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;
index 30c2f7a..9ee000d 100644 (file)
@@ -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 );
index 54fc251..3fe7889 100644 (file)
@@ -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
index 1d0bbfd..5326705 100644 (file)
@@ -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 ];
                }
index d737a4b..9392220 100644 (file)
@@ -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' );
index d69a433..40c63d2 100644 (file)
@@ -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,
index 4607535..a490cfd 100644 (file)
@@ -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(
index 680ae8e..dc43aed 100644 (file)
@@ -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 );
        }
index 59d2806..3a266f2 100644 (file)
@@ -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 );
index c0f004f..1f222f8 100644 (file)
@@ -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 );
index 31c277a..9b8022b 100644 (file)
@@ -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();
index 87534eb..a45ccca 100644 (file)
@@ -464,7 +464,7 @@ class UserrightsPage extends SpecialPage {
                ] );
                $logid = $logEntry->insert();
                if ( count( $tags ) ) {
-                       $logEntry->setTags( $tags );
+                       $logEntry->addTags( $tags );
                }
                $logEntry->publish( $logid );
        }
index 8063804..eac48fa 100644 (file)
@@ -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 );