PortableInfobox/PortableInfoboxHooks.class.php

103 lines
2.9 KiB
PHP
Raw Normal View History

<?php
class PortableInfoboxHooks {
2015-06-19 12:16:07 +00:00
const PARSER_TAG_GALLERY = 'gallery';
const INFOBOX_BUILDER_MERCURY_ROUTE = 'infoboxBuilder';
2015-06-19 12:16:07 +00:00
public static function onBeforePageDisplay( OutputPage $out, Skin $skin ) {
if ( F::app()->checkSkin( 'monobook', $skin ) ) {
Wikia::addAssetsToOutput( 'portable_infobox_monobook_scss' );
} else {
Wikia::addAssetsToOutput( 'portable_infobox_scss' );
}
return true;
}
public static function onImageServingCollectImages( &$imageNamesArray, $articleTitle ) {
if ( $articleTitle ) {
$infoboxImages = PortableInfoboxDataService::newFromTitle( $articleTitle )->getImages();
if ( !empty( $infoboxImages ) ) {
$imageNamesArray = array_merge( $infoboxImages, (array)$imageNamesArray );
}
}
return true;
}
/**
* Store information about raw content of all galleries in article to handle images in infoboxes
*
* @param $name Parser tag name
* @param $marker substitution marker
* @param $content raw tag contents
* @param $attributes
* @param $parser
* @param $frame
*
* @return bool
*/
public static function onParserTagHooksBeforeInvoke( $name, $marker, $content, $attributes, $parser, $frame ) {
2015-06-19 12:16:07 +00:00
if ( $name === self::PARSER_TAG_GALLERY ) {
\Wikia\PortableInfobox\Helpers\PortableInfoboxDataBag::getInstance()->setGallery( $marker, $content );
}
return true;
}
public static function onWgQueryPages( &$queryPages = [ ] ) {
$queryPages[] = [ 'AllinfoboxesQueryPage', 'AllInfoboxes' ];
return true;
}
/**
* @param EditPageLayoutController $editPage
*
* @return bool
*/
public static function onEditPageLayoutExecute( $editPage ) {
// run only on template
$requestContext = $editPage->getContext();
$title = $requestContext->getTitle();
if ( $title->getNamespace() == NS_TEMPLATE &&
2015-09-01 13:00:34 +00:00
!$title->exists() &&
$requestContext->getRequest()->getBool( PortableInfoboxBuilderController::INFOBOX_BUILDER_PARAM )
) {
$host = $requestContext->getRequest()->getAllHeaders()['HOST'];
$url = 'http://' . $host . '/' . self::INFOBOX_BUILDER_MERCURY_ROUTE . '/' . $title->getBaseText();
$editPage->getResponse()->setVal( 'isPortableInfoboxBuilder', true );
$editPage->getResponse()->setVal( 'portableInfoboxBuilderUrl', $url );
}
return true;
}
/**
* @param Skin $skin
* @param string $text
*
* @return bool
*/
public static function onSkinAfterBottomScripts( $skin, &$text ) {
$title = $skin->getTitle();
2015-09-01 13:00:34 +00:00
$request = $skin->getRequest();
if ( $title->getNamespace() == NS_TEMPLATE &&
2015-09-01 13:00:34 +00:00
!$title->exists() &&
$request->getVal( 'action' ) == 'edit' &&
$request->getBool( PortableInfoboxBuilderController::INFOBOX_BUILDER_PARAM )
) {
2015-09-01 13:00:34 +00:00
//$text .= JSMessages::printPackages( [ 'PortableInfoboxBuilder' ] );
$scripts = AssetsManager::getInstance()->getURL( 'portable_infobox_builder_js' );
foreach ( $scripts as $script ) {
$text .= Html::linkedScript( $script );
}
}
return true;
}
}