mirror of
https://github.com/Universal-Omega/PortableInfobox.git
synced 2024-11-24 00:06:25 +00:00
Bring back and fix PortableInfoboxDataBag
This commit is contained in:
parent
52197e5c22
commit
8ccae693d5
|
@ -19,6 +19,16 @@ class PortableInfoboxHooks {
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
public static function onBeforeParserrenderImageGallery ( $parser, $gallery ) {
|
||||||
|
if ( $gallery instanceof ImageGalleryBase ) {
|
||||||
|
\Wikia\PortableInfobox\Helpers\PortableInfoboxDataBag::getInstance()->setGallery(
|
||||||
|
Parser::MARKER_PREFIX . "-gallery-" . sprintf( '%08X', $parser->mMarkerIndex-1 ) . Parser::MARKER_SUFFIX,
|
||||||
|
$gallery
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public static function onAllInfoboxesQueryRecached() {
|
public static function onAllInfoboxesQueryRecached() {
|
||||||
$cache = ObjectCache::getMainWANInstance();
|
$cache = ObjectCache::getMainWANInstance();
|
||||||
|
|
|
@ -68,6 +68,7 @@
|
||||||
"Wikia\\PortableInfobox\\Parser\\Nodes\\NodeTitle": "services/Parser/Nodes/NodeTitle.php",
|
"Wikia\\PortableInfobox\\Parser\\Nodes\\NodeTitle": "services/Parser/Nodes/NodeTitle.php",
|
||||||
"Wikia\\PortableInfobox\\Parser\\Nodes\\NodeUnimplemented": "services/Parser/Nodes/NodeUnimplemented.php",
|
"Wikia\\PortableInfobox\\Parser\\Nodes\\NodeUnimplemented": "services/Parser/Nodes/NodeUnimplemented.php",
|
||||||
"Wikia\\PortableInfobox\\Helpers\\InfoboxParamsValidator": "services/Helpers/InfoboxParamsValidator.php",
|
"Wikia\\PortableInfobox\\Helpers\\InfoboxParamsValidator": "services/Helpers/InfoboxParamsValidator.php",
|
||||||
|
"Wikia\\PortableInfobox\\Helpers\\PortableInfoboxDataBag": "services/Helpers/PortableInfoboxDataBag.php",
|
||||||
"Wikia\\PortableInfobox\\Helpers\\PortableInfoboxMustacheEngine": "services/Helpers/PortableInfoboxMustacheEngine.php",
|
"Wikia\\PortableInfobox\\Helpers\\PortableInfoboxMustacheEngine": "services/Helpers/PortableInfoboxMustacheEngine.php",
|
||||||
"Wikia\\PortableInfobox\\Helpers\\PortableInfoboxImagesHelper": "services/Helpers/PortableInfoboxImagesHelper.php",
|
"Wikia\\PortableInfobox\\Helpers\\PortableInfoboxImagesHelper": "services/Helpers/PortableInfoboxImagesHelper.php",
|
||||||
"Wikia\\PortableInfobox\\Helpers\\PortableInfoboxParsingHelper": "services/Helpers/PortableInfoboxParsingHelper.php",
|
"Wikia\\PortableInfobox\\Helpers\\PortableInfoboxParsingHelper": "services/Helpers/PortableInfoboxParsingHelper.php",
|
||||||
|
@ -92,6 +93,7 @@
|
||||||
"ParserAfterTidy": "PortableInfoboxParserTagController::replaceInfoboxMarkers",
|
"ParserAfterTidy": "PortableInfoboxParserTagController::replaceInfoboxMarkers",
|
||||||
"BeforePageDisplay": "PortableInfoboxHooks::onBeforePageDisplay",
|
"BeforePageDisplay": "PortableInfoboxHooks::onBeforePageDisplay",
|
||||||
"BeforePageDisplayMobile": "PortableInfoboxHooks::onBeforePageDisplayMobile",
|
"BeforePageDisplayMobile": "PortableInfoboxHooks::onBeforePageDisplayMobile",
|
||||||
|
"BeforeParserrenderImageGallery": "PortableInfoboxHooks::onBeforeParserrenderImageGallery",
|
||||||
"wgQueryPages": "PortableInfoboxHooks::onWgQueryPages",
|
"wgQueryPages": "PortableInfoboxHooks::onWgQueryPages",
|
||||||
"AllInfoboxesQueryRecached": "PortableInfoboxHooks::onAllInfoboxesQueryRecached",
|
"AllInfoboxesQueryRecached": "PortableInfoboxHooks::onAllInfoboxesQueryRecached",
|
||||||
"ArticlePurge": "PortableInfoboxHooks::onArticlePurge",
|
"ArticlePurge": "PortableInfoboxHooks::onArticlePurge",
|
||||||
|
|
40
services/Helpers/PortableInfoboxDataBag.php
Normal file
40
services/Helpers/PortableInfoboxDataBag.php
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Wikia\PortableInfobox\Helpers;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class PortableInfoboxDataBag
|
||||||
|
* @package Wikia\PortableInfobox\Helpers
|
||||||
|
*/
|
||||||
|
class PortableInfoboxDataBag {
|
||||||
|
private static $instance = null;
|
||||||
|
private $galleries = [];
|
||||||
|
|
||||||
|
private function __construct() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return null|PortableInfoboxDataBag
|
||||||
|
*/
|
||||||
|
public static function getInstance() {
|
||||||
|
if ( is_null( self::$instance ) ) {
|
||||||
|
self::$instance = new self;
|
||||||
|
}
|
||||||
|
return self::$instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setGallery( $marker, $content ) {
|
||||||
|
$this->galleries[$marker] = $content;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve source content of a gallery identified by Parser marker id
|
||||||
|
*/
|
||||||
|
public function getGallery( $marker ) {
|
||||||
|
if ( isset( $this->galleries[$marker] ) ) {
|
||||||
|
return $this->galleries[$marker];
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,6 +3,7 @@ namespace Wikia\PortableInfobox\Parser\Nodes;
|
||||||
|
|
||||||
use HtmlHelper;
|
use HtmlHelper;
|
||||||
use WikiaFileHelper;
|
use WikiaFileHelper;
|
||||||
|
use Wikia\PortableInfobox\Helpers\PortableInfoboxDataBag;
|
||||||
|
|
||||||
class NodeImage extends Node {
|
class NodeImage extends Node {
|
||||||
const GALLERY = 'GALLERY';
|
const GALLERY = 'GALLERY';
|
||||||
|
@ -20,21 +21,14 @@ class NodeImage extends Node {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getGalleryData( $html ) {
|
public static function getGalleryData( $marker ) {
|
||||||
$data = [];
|
$gallery = PortableInfoboxDataBag::getInstance()->getGallery( $marker );
|
||||||
$doc = HtmlHelper::createDOMDocumentFromText( $html );
|
return isset( $gallery ) ? array_map( function ( $image ) {
|
||||||
$sxml = simplexml_import_dom( $doc );
|
return [
|
||||||
$imgs = $sxml->xpath( '//li[@class=\'gallerybox\']' );
|
'label' => $image[1] ?: $image[0]->getText(),
|
||||||
foreach ( $imgs as $img ) {
|
'title' => $image[0]
|
||||||
if ( preg_match( '/ src="(?:[^"]*\/)?([^"]*?)"/', $img->asXML(), $out ) ) {
|
];
|
||||||
$caption = trim( $img->xpath( 'descendant::div[@class=\'gallerytext\']' )[0] );
|
}, $gallery->getimages() ) : [];
|
||||||
$data[] = [
|
|
||||||
'label' => $caption ?: $out[1],
|
|
||||||
'title' => $out[1]
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getTabberData( $html ) {
|
public static function getTabberData( $html ) {
|
||||||
|
@ -95,8 +89,7 @@ class NodeImage extends Node {
|
||||||
$galleryItems = [];
|
$galleryItems = [];
|
||||||
$galleryMarkers = self::getMarkers( $value, self::GALLERY );
|
$galleryMarkers = self::getMarkers( $value, self::GALLERY );
|
||||||
foreach ( $galleryMarkers as $marker ) {
|
foreach ( $galleryMarkers as $marker ) {
|
||||||
$galleryHtml = $this->getExternalParser()->parseRecursive( $marker );
|
$galleryItems = array_merge( $galleryItems, self::getGalleryData( $marker ) );
|
||||||
$galleryItems = array_merge( $galleryItems, self::getGalleryData( $galleryHtml ) );
|
|
||||||
}
|
}
|
||||||
return $galleryItems;
|
return $galleryItems;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue