Skip to content

Commit

Permalink
add export images info
Browse files Browse the repository at this point in the history
  • Loading branch information
adnanelamghari committed Jul 24, 2019
1 parent 13d6bbd commit bb6f17f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
32 changes: 32 additions & 0 deletions includes/ExportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Revision;
use WikiPage;
use Hooks;
use WikifabExploreResultFormatter;

/**
* File holding the ExportController class that provides basic functions for
Expand Down Expand Up @@ -58,6 +59,8 @@ class ExportController {

protected $fieldsToParse = [];

protected $addImageInfo = false;

/**
* @var DeepRedirectTargetResolver
*/
Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions includes/SpecialExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ protected function startExport() {
$fieldsToParse = explode(',', $fieldsToParse);

$this->export_controller->setFieldsToParse($fieldsToParse);

if ($wgRequest->getCheck( 'imagesInfo' ) ) {
$this->export_controller->setAddImagesInfo(true);
}
}

/**
Expand Down

0 comments on commit bb6f17f

Please sign in to comment.