Phuedx has uploaded a new change for review.

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

Change subject: Set the wiki page on the derivative request
......................................................................

Set the wiki page on the derivative request

ApiMobileView#getFilePage is a hack to get the mobile-formatted HTML of
a page in the File namespace. It does this by dispatching an view action
on the associated file page with a request context derived from the API
request context.

ExtMobileFormatter::DOMParse retrieves the HTML to format from the wiki
page associated with the request context. However, #getFilePage wasn't
associating a wiki page with the request context.
DerivativeContext#getWikiPage will fall back to
RequestContext#getWikiPage, which is initialised with a known bad title,
which causes an exception to be thrown.

Set the wiki page on the derivative request context to that associated
with the file page to stop the exception being thrown.

Bug: T123821
Change-Id: I55cf5d5d1d04f4ed6514c4cd1448cce75da8ccb5
---
M includes/api/ApiMobileView.php
1 file changed, 12 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend 
refs/changes/47/264947/1

diff --git a/includes/api/ApiMobileView.php b/includes/api/ApiMobileView.php
index e73ade3..5bd31bf 100644
--- a/includes/api/ApiMobileView.php
+++ b/includes/api/ApiMobileView.php
@@ -615,9 +615,21 @@
                $context = new DerivativeContext( $this->getContext() );
                $context->setTitle( $title );
                $context->setOutput( new OutputPage( $context ) );
+
                $page = new ImagePage( $title );
                $page->setContext( $context );
+
+
+               // T123821: Without setting the wiki page on the derivative 
context,
+               // DerivativeContext#getWikiPage will (eventually) fall back to
+               // RequestContext#getWikiPage. Here, the request context is 
distinct from the
+               // derivative context and deliberately constructed with a bad 
title [0].
+               //
+               // [0] 
https://github.com/wikimedia/mediawiki/blob/0acebab76c99fda07ea8944de9d3f406de99201f/api.php#L55-L61
+               $context->setWikiPage( $page->getPage() );
+
                $page->view();
+
                $html = $context->getOutput()->getHTML();
 
                return $html;

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I55cf5d5d1d04f4ed6514c4cd1448cce75da8ccb5
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Phuedx <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to