From c30089517caa70b6d239fc920b5c0e419163d81e Mon Sep 17 00:00:00 2001 From: Adnane Lamghari Date: Wed, 17 Jul 2019 10:55:29 +0200 Subject: [PATCH] add export images info --- includes/ExportController.php | 32 ++++++++++++++++++++++++++++++++ includes/SpecialExport.php | 4 ++++ 2 files changed, 36 insertions(+) diff --git a/includes/ExportController.php b/includes/ExportController.php index 1678ce9..e98db56 100644 --- a/includes/ExportController.php +++ b/includes/ExportController.php @@ -6,6 +6,7 @@ use Revision; use WikiPage; use Hooks; +use WikifabExploreResultFormatter; /** * File holding the ExportController class that provides basic functions for @@ -58,6 +59,8 @@ class ExportController { protected $fieldsToParse = []; + protected $addImageInfo = false; + /** * @var DeepRedirectTargetResolver */ @@ -78,6 +81,11 @@ public function setFieldsToParse($fields) { $this->fieldsToParse = $fields; } + public function setAddImagesInfo($value) + { + $this->addImageInfo = $value; + } + /** * Initialize all internal structures to begin with some serialization. * Returns true if initialization was successful (this means that the @@ -178,10 +186,34 @@ protected function serializePage( Title $title, $recursiondepth = 1 ) { //for fields : parse any wikitext : $this->parseWikitextFieldToHtml($data); + // this will add full url of all images + if ($this->addImageInfo) { + $this->addImagesURL($data); + } + $this->serializer->addPage($title, $pageInfo, $data); } + protected function addImagesURL(& $data) + { + if (array_key_exists('Main_Picture', $data['Tuto Details']) && !array_key_exists('Main_Picture_annotation', $data['Tuto Details'])) { + $data['Tuto Details']['Main_Picture_url'] = WikifabExploreResultFormatter::getImageUrl($data['Tuto Details']['Main_Picture']); + } + foreach ($data['Tuto Step'] as $key => $val) { + $iteration = 0; + while (true) { + $pictureNumber = sprintf( 'Step_Picture_%02d', $iteration ) ; + if (array_key_exists($pictureNumber,$val) && !array_key_exists($pictureNumber.'_annotation',$val)) { + $data['Tuto Step'][$key][$pictureNumber.'_url'] = WikifabExploreResultFormatter::getImageUrl($data['Tuto Step'][$key][$pictureNumber]); + } else { + break; + } + $iteration++; + } + } + } + protected function parseWikitextFieldToHtml(& $data) { if (! $this->fieldsToParse) { diff --git a/includes/SpecialExport.php b/includes/SpecialExport.php index f2d2697..586e47c 100644 --- a/includes/SpecialExport.php +++ b/includes/SpecialExport.php @@ -135,6 +135,10 @@ protected function startExport() { $fieldsToParse = explode(',', $fieldsToParse); $this->export_controller->setFieldsToParse($fieldsToParse); + + if ($wgRequest->getCheck( 'imagesInfo' ) ) { + $this->export_controller->setAddImagesInfo(true); + } } /**