From 1f1c72bb2cbaa4b80660f48175e27d5f0c8e8f9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thiemo=20M=C3=A4ttig?= Date: Mon, 26 Oct 2015 12:05:47 +0100 Subject: [PATCH] Use mExtensionData instead of undeclared class property Change-Id: I155e37fda412cd467da7b34c52b34661c7c20224 --- PageImages.body.php | 14 +++++++------- tests/phpunit/PageImagesTest.php | 8 ++++---- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/PageImages.body.php b/PageImages.body.php index 3ec8264..cfe7f19 100644 --- a/PageImages.body.php +++ b/PageImages.body.php @@ -89,10 +89,6 @@ class PageImages { } } - $out = $parser->getOutput(); - if ( !isset( $out->pageImages ) ) { - $out->pageImages = array(); - } if ( is_array( $handlerParams ) ) { $myParams = $handlerParams; self::calcWidth( $myParams, $file ); @@ -103,7 +99,11 @@ class PageImages { $myParams['filename'] = $file->getTitle()->getDBkey(); $myParams['fullwidth'] = $file->getWidth(); $myParams['fullheight'] = $file->getHeight(); - $out->pageImages[] = $myParams; + + $out = $parser->getOutput(); + $pageImages = $out->getExtensionData( 'pageImages' ) ?: array(); + $pageImages[] = $myParams; + $out->setExtensionData( 'pageImages', $pageImages ); } /** @@ -144,11 +144,11 @@ class PageImages { * @return bool */ public static function onLinksUpdate( LinksUpdate $linksUpdate ) { - if ( !isset( $linksUpdate->getParserOutput()->pageImages ) ) { + $images = $linksUpdate->getParserOutput()->getExtensionData( 'pageImages' ); + if ( $images === null ) { return true; } - $images = $linksUpdate->getParserOutput()->pageImages; $scores = array(); $counter = 0; foreach ( $images as $image ) { diff --git a/tests/phpunit/PageImagesTest.php b/tests/phpunit/PageImagesTest.php index 46e074b..e2b8df6 100644 --- a/tests/phpunit/PageImagesTest.php +++ b/tests/phpunit/PageImagesTest.php @@ -4,7 +4,7 @@ namespace PageImages\Tests; use MediaWikiTestCase; use PageImages; -use stdClass; +use ParserOutput; use Title; /** @@ -35,10 +35,10 @@ class PageImagesTest extends MediaWikiTestCase { } public function testOnLinksUpdate() { - $parserOutput = new stdClass(); - $parserOutput->pageImages = array( + $parserOutput = new ParserOutput(); + $parserOutput->setExtensionData( 'pageImages', array( array( 'filename' => 'A.jpg', 'fullwidth' => 100, 'fullheight' => 50 ), - ); + ) ); $linksUpdate = $this->getMockBuilder( 'LinksUpdate' ) ->disableOriginalConstructor()