Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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