Page MenuHomePhabricator

Argument 1 passed to DOMXPath::__construct() must be an instance of DOMDocument.
Closed, ResolvedPublic

Description

The loadHTML() returns a boolean. It should just take the input and then be passed into DOMXPath.

diff --git a/extensions/RandomImage/RandomImage.class.php b/extensions/RandomImage/RandomImage.class.php
index ec8111308..d99c8b495 100755
--- a/extensions/RandomImage/RandomImage.class.php
+++ b/extensions/RandomImage/RandomImage.class.php
@@ -118,12 +118,12 @@ class RandomImage {
      */
     protected function removeMagnifier( $html ) {
         $dom = new DOMDocument();
-        $doc = $dom->loadHTML( $html );
-        $xpath = new DOMXPath( $doc );
+        $dom->loadHTML( $html );
+        $xpath = new DOMXPath( $dom );
         foreach ( $xpath->query( '//div[@class="magnify"]' ) as $mag ) {
             $mag->parentNode->removeChild( $mag );
         }
-        return preg_replace( '!<\?xml[^?]*\?>!', '', $doc->saveXml() );
+        return preg_replace( '!<\?xml[^?]*\?>!', '', $dom->saveXml() );
     }
 
     /**
[c74e4ffff5fa6e19e06e1a9e] /RandomImage_Example TypeError from line 122 of extensions/RandomImage/RandomImage.class.php: Argument 1 passed to DOMXPath::__construct() must be an instance of DOMDocument, boolean given

Backtrace:

#0 extensions/RandomImage/RandomImage.class.php(122): DOMXPath->__construct(boolean)
#1 extensions/RandomImage/RandomImage.class.php(72): RandomImage->removeMagnifier(string)
#2 extensions/RandomImage/RandomImage.class.php(287): RandomImage->render()
#3 includes/parser/Parser.php(3882): RandomImage::renderHook(NULL, array, Parser, PPFrame_DOM)
#4 includes/parser/Preprocessor_DOM.php(1284): Parser->extensionSubstitution(array, PPFrame_DOM)
#5 includes/parser/Parser.php(2942): PPFrame_DOM->expand(DOMElement, integer)
#6 includes/parser/Parser.php(1297): Parser->replaceVariables(string)
#7 includes/parser/Parser.php(451): Parser->internalParse(string)
#8 includes/content/WikitextContent.php(330): Parser->parse(string, Title, ParserOptions, boolean, boolean, integer)
#9 includes/content/AbstractContent.php(497): WikitextContent->fillParserOutput(Title, integer, ParserOptions, boolean, ParserOutput)
#10 includes/poolcounter/PoolWorkArticleView.php(139): AbstractContent->getParserOutput(Title, integer, ParserOptions)
#11 includes/poolcounter/PoolCounterWork.php(123): PoolWorkArticleView->doWork()
#12 includes/page/Article.php(586): PoolCounterWork->execute()
#13 includes/actions/ViewAction.php(68): Article->view()
#14 includes/MediaWiki.php(499): ViewAction->show()
#15 includes/MediaWiki.php(293): MediaWiki->performAction(Article, Title)
#16 includes/MediaWiki.php(862): MediaWiki->performRequest()
#17 includes/MediaWiki.php(523): MediaWiki->main()
#18 index.php(43): MediaWiki->run()
#19 {main}

Event Timeline

Alexia created this task.Jul 26 2017, 2:58 PM
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptJul 26 2017, 2:58 PM

@Alexia: Thanks for taking a look at the code. You are very welcome to use developer access to submit the proposed code changes as a Git branch directly into Gerrit. If you don't want to set up Git/Gerrit, you can also use the Gerrit Patch Uploader. Thanks again!

Change 379197 had a related patch set uploaded (by Samwilson; owner: Samwilson):
[mediawiki/extensions/RandomImage@master] Fix up DOMDOcument::loadHTML() usage

https://gerrit.wikimedia.org/r/379197

Change 379197 merged by jenkins-bot:
[mediawiki/extensions/RandomImage@master] Fix up DOMDOcument::loadHTML() usage

https://gerrit.wikimedia.org/r/379197

SamanthaNguyen closed this task as Resolved.Oct 1 2017, 3:20 PM
SamanthaNguyen assigned this task to Samwilson.
SamanthaNguyen removed a project: Patch-For-Review.
SamanthaNguyen removed a subscriber: gerritbot.