Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't fail on libxml errors if the RSD URL can still be found #35

Merged
merged 1 commit into from
May 3, 2017

Conversation

samwilson
Copy link
Member

Various things, such as duplicate element IDs or repeated
attributes, break DOMDocument::loadHTML() and so this turns off
the direct reporting (E_ERROR) of these and istead adds them
to the RsdException if the RSD URL really can't be determined
from the HTML. In most cases, the URL can be found correctly
and the errors can be disregarded.

A test is added for this as well, although it does not test
for the case when the RSD URL can't be found and there are
libxml errors (because we need to serve up a broken HTML file,
and the mediawiki-api-base test system can only interact with
MediaWiki via the API, which makes it hard to produce broken
HTML that doesn't also have the correct LINK element for the
RSD URL).

A new TestEnvironment::savePage method is added, for easier
creation of test wiki pages.

Bug: https://phabricator.wikimedia.org/T163527

@@ -79,15 +79,30 @@ public static function newFromApiEndpoint( $apiEndpoint ) {
* @throws RsdException If the RSD URL could not be found in the page's HTML.
*/
public static function newFromPage( $url ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is starting to get a little bit big.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RSD could conceivably be done in its own package, then here we'd just have to do something like

$rsd = new Rsd($url);
if (!$rsd->hasApi('MediaWiki')) {
	throw new RsdException( "Unable to find RSD URL in page: $url" );
}
return self::newFromApiEndpoint( $rsd->getApi('MediaWiki')->getApiLink() );

But I reckon methods that can be seen whole on one screen are okay. Although I know some people say 20 lines is about the max.

Up to you; I'm happy to rework. (I don't think splitting bits into other methods in this class is much better than this though.)

@addshore
Copy link
Member

addshore commented May 2, 2017

@samwilson I'm guessing this could go in a bugfix release?

@samwilson
Copy link
Member Author

I'm guessing this could go in a bugfix release?

Are we following semver? If so, I'd say this is a backwards-compatible bug fix that doesn't introduce any new features, so yeah, a patch release is fine. :-)

@addshore
Copy link
Member

addshore commented May 3, 2017

@samwilson Looks like this is good to go once rebased! IMO

Various things, such as duplicate element IDs or repeated
attributes, break DOMDocument::loadHTML() and so this turns off
the direct reporting (E_ERROR) of these and istead adds them
to the RsdException if the RSD URL really can't be determined
from the HTML. In most cases, the URL can be found correctly
and the errors can be disregarded.

A test is added for this as well, although it does *not* test
for the case when the RSD URL can't be found and there are
libxml errors (because we need to serve up a broken HTML file,
and the mediawiki-api-base test system can only interact with
MediaWiki via the API, which makes it hard to produce broken
HTML that doesn't also have the correct LINK element for the
RSD URL).

A new TestEnvironment::savePage method is added, for easier
creation of test wiki pages.

Bug: https://phabricator.wikimedia.org/T163527
@samwilson
Copy link
Member Author

Done

@addshore addshore merged commit 0e35e20 into addwiki:master May 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants