Greetings from Chile
Just wanted to ask if anyone thinks it's possible to return just a string (and not an array) from an API extension? I've been looking at ApiBase.php and ApiResult.php and it seems it's not, is it?
Thanks in advance. Numerico
What do you mean by return from an api extension? Are you saying you want to custom-format the resulting API output? non-json, etc?
On Fri, Dec 28, 2012 at 3:07 PM, webmaster@numerica.cl wrote:
Greetings from Chile
Just wanted to ask if anyone thinks it's possible to return just a string (and not an array) from an API extension? I've been looking at ApiBase.php and ApiResult.php and it seems it's not, is it?
Thanks in advance. Numerico
______________________________**_________________ Mediawiki-api mailing list Mediawiki-api@lists.wikimedia.**org Mediawiki-api@lists.wikimedia.org https://lists.wikimedia.org/**mailman/listinfo/mediawiki-apihttps://lists.wikimedia.org/mailman/listinfo/mediawiki-api
On 28.12.2012 17:13, Yuri Astrakhan wrote:
What do you mean by return from an api extension? Are you saying you want to custom-format the resulting API output? non-json, etc?
hi Yuri, thanks for the quick reply. Exactly, I would need it to return just plain text/html for an other program to interpret it, so having it inside an array is problematic. Sounds too difficult?
what i think you need is to create a custom printer for your action. I remember some api modules do that for various reasons. See getCustomPrinter
On Fri, Dec 28, 2012 at 3:26 PM, webmaster@numerica.cl wrote:
On 28.12.2012 17:13, Yuri Astrakhan wrote:
What do you mean by return from an api extension? Are you saying you want to custom-format the resulting API output? non-json, etc?
hi Yuri, thanks for the quick reply.
Exactly, I would need it to return just plain text/html for an other program to interpret it, so having it inside an array is problematic. Sounds too difficult?
______________________________**_________________ Mediawiki-api mailing list Mediawiki-api@lists.wikimedia.**org Mediawiki-api@lists.wikimedia.org https://lists.wikimedia.org/**mailman/listinfo/mediawiki-apihttps://lists.wikimedia.org/mailman/listinfo/mediawiki-api
Great, that method had called my attention indeed. Let's see what it can do... Thanks for the pointer.
¡Felices fiestas!
On 28.12.2012 17:29, Yuri Astrakhan wrote:
what i think you need is to create a custom printer for your action. I remember some api modules do that for various reasons. See getCustomPrinter
On Fri, Dec 28, 2012 at 3:26 PM, wrote:
On 28.12.2012 17 [1]:13, Yuri Astrakhan wrote:
What do you mean by return from an api extension? Are you saying you want to custom-format the resulting API output? non-json, etc?
hi Yuri, thanks for the quick reply. Exactly, I would need it to return just plain text/html for an other program to interpret it, so having it inside an array is problematic. Sounds too difficult?
Mediawiki-api mailing list Mediawiki-api@lists.wikimedia.org [2] https://lists.wikimedia.org/mailman/listinfo/mediawiki-api [3]
Links:
[1] http://mail.numerica.cl/tel:28.12.2012%2017 [2] mailto:Mediawiki-api@lists.wikimedia.org [3] https://lists.wikimedia.org/mailman/listinfo/mediawiki-api [4] mailto:webmaster@numerica.cl
By the way, Yuri's suggestion did work. I don't know if you use to post code in this list for the archive, so i will be succint: let's say I subclassed ApiFormatBase and overwrote execute like this
public function execute() { $data = $this->getResultData(); $this->printText($data[0]); }
so it strips the array from the response just gettings it's first value.
Then, in the extension code, getCustomePrinter is also overriden like this
public function getCustomPrinter() { return new MyApiFormat($this->getMain(),'plain'); }
& that's all folks.
Not too pretty, since the return array can be set only once, but it's enough for my needs and I think it can be easily worked on.
So this is my give back.
On 28.12.2012 17:34, webmaster@numerica.cl wrote:
Great, that method had called my attention indeed. Let's see what it can do... Thanks for the pointer.
¡Felices fiestas!
On 28.12.2012 17:29, Yuri Astrakhan wrote:
what i think you need is to create a custom printer for your action. I remember some api modules do that for various reasons. See getCustomPrinter
On Fri, Dec 28, 2012 at 3:26 PM, wrote:
On 28.12.2012 17 [1]:13, Yuri Astrakhan wrote:
What do you mean by return from an api extension? Are you saying you want to custom-format the resulting API output? non-json, etc?
hi Yuri, thanks for the quick reply. Exactly, I would need it to return just plain text/html for an other program to interpret it, so having it inside an array is problematic. Sounds too difficult?
Mediawiki-api mailing list Mediawiki-api@lists.wikimedia.org [2] https://lists.wikimedia.org/mailman/listinfo/mediawiki-api [3]
Links:
[1] http://mail.numerica.cl/tel:28.12.2012%2017 [2] mailto:Mediawiki-api@lists.wikimedia.org [3] https://lists.wikimedia.org/mailman/listinfo/mediawiki-api [4] mailto:webmaster@numerica.cl
Mediawiki-api mailing list Mediawiki-api@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-api
On Fri, Dec 28, 2012 at 3:26 PM, webmaster@numerica.cl wrote:
Exactly, I would need it to return just plain text/html for an other program to interpret it, so having it inside an array is problematic. Sounds too difficult?
Be careful you don't introduce security holes when doing this. https://www.mediawiki.org/wiki/Cross-site_scripting might be a good read.
On Mon, Dec 31, 2012 at 7:49 AM, Brad Jorsch bjorsch@wikimedia.org wrote:
On Fri, Dec 28, 2012 at 3:26 PM, webmaster@numerica.cl wrote:
Exactly, I would need it to return just plain text/html for an other program to interpret it, so having it inside an array is problematic. Sounds too difficult?
Be careful you don't introduce security holes when doing this. https://www.mediawiki.org/wiki/Cross-site_scripting might be a good read.
Yes please. Whatever the output, you want to make sure it's not interpreted as html, otherwise a <script> tag in the text will execute javascript if it's loaded in an iframe, or one of your users is redirected to the api's output somehow. Obviously, if this is just for your own wiki, you can decide if that's a threat or not. If you want to merge it into core, then you will need to do a lot of filtering on the output.
Chris & Brad, thanks for your feedback. However, correct me if I'm wrong, but I think there is no risk in my extension as i'm spitting a bittorrent response, which is mime-type 'text/html' but is actually just plain 'text'. So it isn't to be interpreted as html, neither could user input be returned at all...
On 02.01.2013 14:45, Chris Steipp wrote:
On Mon, Dec 31, 2012 at 7:49 AM, Brad Jorsch bjorsch@wikimedia.org wrote:
On Fri, Dec 28, 2012 at 3:26 PM, webmaster@numerica.cl wrote:
Exactly, I would need it to return just plain text/html for an other program to interpret it, so having it inside an array is problematic. Sounds too difficult?
Be careful you don't introduce security holes when doing this. https://www.mediawiki.org/wiki/Cross-site_scripting might be a good read.
Yes please. Whatever the output, you want to make sure it's not interpreted as html, otherwise a <script> tag in the text will execute javascript if it's loaded in an iframe, or one of your users is redirected to the api's output somehow. Obviously, if this is just for your own wiki, you can decide if that's a threat or not. If you want to merge it into core, then you will need to do a lot of filtering on the output.
Mediawiki-api mailing list Mediawiki-api@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-api
mediawiki-api@lists.wikimedia.org