jenkins-bot has submitted this change and it was merged.

Change subject: Don't access undefined properties from LinksUpdate
......................................................................


Don't access undefined properties from LinksUpdate

Neither mDb, nor mOptions is defined in LinksUpdate (anymore). Accessing them
will emit an Undefined Property error and accessing $this->mDb while assuming
a Database object from LinksUpdate will throw a fatal error, as the value is
null.

mDb is now filled with wfGetDB( DB_MASTER ) and mOptions is removed completely,
as it's not clear, what it should contain (so assuming an empty array).

This fixes failing tests for the extension.

Change-Id: I81ca9f61cf3e875aa0d98b20e91f9029f5203fa9
---
M Wikilog.php
M WikilogLinksUpdate.php
A tests/phpunit/WikilogLinksUpdateTest.php
3 files changed, 27 insertions(+), 5 deletions(-)

Approvals:
  Aaron Schulz: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/Wikilog.php b/Wikilog.php
index 7826a66..d0af4b7 100644
--- a/Wikilog.php
+++ b/Wikilog.php
@@ -135,6 +135,7 @@
 $wgHooks['SkinTemplateTabAction'][] = 'Wikilog::SkinTemplateTabAction';
 $wgHooks['SkinTemplateTabs'][] = 'Wikilog::SkinTemplateTabs';
 $wgHooks['SkinTemplateNavigation'][] = 'Wikilog::SkinTemplateNavigation';
+$wgHooks['UnitTestsList'][] = 'Wikilog::UnitTestsList';
 
 // General Wikilog hooks
 $wgHooks['ArticleEditUpdates'][] = 'WikilogHooks::ArticleEditUpdates';
@@ -423,6 +424,11 @@
                        return null;
                }
        }
+
+       static function UnitTestsList( array &$paths ) {
+               $paths[] = __DIR__ . '/tests/phpunit';
+               return true;
+       }
 }
 
 /**
diff --git a/WikilogLinksUpdate.php b/WikilogLinksUpdate.php
index 20cfc85..9a91b35 100644
--- a/WikilogLinksUpdate.php
+++ b/WikilogLinksUpdate.php
@@ -41,9 +41,7 @@
                $this->mId = $lupd->mId;
                $this->mTitle = $lupd->mTitle;
                // Accessible via SqlDataUpdate ancestor (T112409)
-               $this->mDb = $lupd->mDb;
-               $this->mOptions = $lupd->mOptions;
-
+               $this->mDb = wfGetDB( DB_MASTER );
                $this->mAuthors = $parserOutput->getAuthors();
                $this->mTags = $parserOutput->getTags();
        }
@@ -114,7 +112,7 @@
 
        private function getExistingAuthors() {
                $res = $this->mDb->select( 'wikilog_authors', array( 
'wla_page', 'wla_author' ),
-                       array( 'wla_page' => $this->mId ), __METHOD__, 
$this->mOptions );
+                       array( 'wla_page' => $this->mId ), __METHOD__ );
                $arr = array();
                while ( $row = $this->mDb->fetchObject( $res ) ) {
                        $arr[$row->wla_author] = 1;
@@ -125,7 +123,7 @@
 
        private function getExistingTags() {
                $res = $this->mDb->select( 'wikilog_tags', array( 'wlt_page', 
'wlt_tag' ),
-                       array( 'wlt_page' => $this->mId ), __METHOD__, 
$this->mOptions );
+                       array( 'wlt_page' => $this->mId ), __METHOD__ );
                $arr = array();
                while ( $row = $this->mDb->fetchObject( $res ) ) {
                        $arr[$row->wlt_tag] = 1;
diff --git a/tests/phpunit/WikilogLinksUpdateTest.php 
b/tests/phpunit/WikilogLinksUpdateTest.php
new file mode 100644
index 0000000..b9e3c3b
--- /dev/null
+++ b/tests/phpunit/WikilogLinksUpdateTest.php
@@ -0,0 +1,18 @@
+<?php
+
+/**
+ * @group Database
+ */
+class WikilogLinksUpdateTest extends MediaWikiTestCase {
+       /**
+        * The test goal is to make sure, that WikilogLinksUpdate::LinkUpdate 
works without throw a
+        * fatal exception or undefined property erros when accessing undefined 
properties from
+        * LinksUpdate.
+        */
+       public function testNoLinksUpdateUndefinedProperty() {
+               $po = new ParserOutput();
+               $po->mExtWikilog = new WikilogParserOutput();
+               $lupd = new LinksUpdate( Title::newFromText( 'UTPage' ), $po );
+               $this->assertTrue( WikilogLinksUpdate::LinksUpdate( $lupd ) );
+       }
+}
\ No newline at end of file

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I81ca9f61cf3e875aa0d98b20e91f9029f5203fa9
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Wikilog
Gerrit-Branch: master
Gerrit-Owner: Florianschmidtwelzow <florian.schmidt.stargatewis...@gmail.com>
Gerrit-Reviewer: Aaron Schulz <asch...@wikimedia.org>
Gerrit-Reviewer: Daniel Kinzler <daniel.kinz...@wikimedia.de>
Gerrit-Reviewer: Nikerabbit <niklas.laxst...@gmail.com>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to