Legoktm has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/361585 )

Change subject: [DONOTMERGE] Don't always assume dsr is set
......................................................................

[DONOTMERGE] Don't always assume dsr is set

Change-Id: I9f92cd5ab8b249e34f8140fd18f807ccfebd3bb7
---
M includes/ApiRecordLint.php
M includes/Database.php
M includes/LintError.php
3 files changed, 21 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Linter 
refs/changes/85/361585/1

diff --git a/includes/ApiRecordLint.php b/includes/ApiRecordLint.php
index ae3fbe8..77a09d7 100644
--- a/includes/ApiRecordLint.php
+++ b/includes/ApiRecordLint.php
@@ -62,7 +62,11 @@
                        if ( !$categoryMgr->isKnownCategory( $info['type'] ) ) {
                                continue;
                        }
-                       $info['location'] = array_slice( $info['dsr'], 0, 2 );
+                       if ( isset( $info['dsr'] ) ) {
+                               $info['location'] = array_slice( $info['dsr'], 
0, 2 );
+                       } else {
+                               $info['location'] = false;
+                       }
                        if ( isset( $info['templateInfo'] ) && 
$info['templateInfo'] ) {
                                $info['params']['templateInfo'] = 
$info['templateInfo'];
                        }
diff --git a/includes/Database.php b/includes/Database.php
index d6f93b1..ba1e439 100644
--- a/includes/Database.php
+++ b/includes/Database.php
@@ -120,12 +120,18 @@
         * @return array
         */
        private function serializeError( LintError $error ) {
+               if ( $error->location ) {
+                       list( $locStart, $locEnd ) = $error->location;
+               } else {
+                       // Bogus value
+                       $locStart = $locEnd = 0;
+               }
                return [
                        'linter_page' => $this->pageId,
                        'linter_cat' => $this->categoryManager->getCategoryId( 
$error->category ),
                        'linter_params' => FormatJson::encode( $error->params, 
false, FormatJson::ALL_OK ),
-                       'linter_start' => $error->location[0],
-                       'linter_end' => $error->location[1],
+                       'linter_start' => $locStart,
+                       'linter_end' => $locEnd,
                ];
        }
 
diff --git a/includes/LintError.php b/includes/LintError.php
index 3620e33..8025a67 100644
--- a/includes/LintError.php
+++ b/includes/LintError.php
@@ -32,7 +32,7 @@
        public $category;
 
        /**
-        * @var int[] [ start, end ]
+        * @var int[]|bool [ start, end ] or false
         */
        public $location;
 
@@ -53,7 +53,7 @@
 
        /**
         * @param string $category
-        * @param int[] $location [ start, end ]
+        * @param int[]|bool $location [ start, end ], false if no location
         * @param string|array $params JSON string or already decoded array
         * @param int $lintId linter_id
         */
@@ -77,7 +77,12 @@
         * @return string
         */
        public function id() {
-               return $this->category . 
",{$this->location[0]},{$this->location[1]},"
+               if ( $this->location ) {
+                       $loc = "{$this->location[0]},{$this->location[1]},";
+               } else {
+                       $loc = "false,";
+               }
+               return "{$this->category},$loc"
                        . FormatJson::encode( $this->params );
        }
 

-- 
To view, visit https://gerrit.wikimedia.org/r/361585
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9f92cd5ab8b249e34f8140fd18f807ccfebd3bb7
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Linter
Gerrit-Branch: master
Gerrit-Owner: Legoktm <lego...@member.fsf.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to