2015-04-27 14:05:31 +00:00
|
|
|
<?php
|
2015-05-06 12:49:15 +00:00
|
|
|
|
2015-04-27 14:05:31 +00:00
|
|
|
class PortableInfoboxHooks {
|
2015-06-19 12:16:07 +00:00
|
|
|
const PARSER_TAG_GALLERY = 'gallery';
|
2015-09-02 11:02:33 +00:00
|
|
|
const INFOBOX_BUILDER_SPECIAL_PAGE = 'Special:PortableInfoboxBuilder';
|
2015-06-19 12:16:07 +00:00
|
|
|
|
2015-08-27 11:41:33 +00:00
|
|
|
public static function onBeforePageDisplay( OutputPage $out, Skin $skin ) {
|
2015-05-18 13:56:45 +00:00
|
|
|
if ( F::app()->checkSkin( 'monobook', $skin ) ) {
|
|
|
|
Wikia::addAssetsToOutput( 'portable_infobox_monobook_scss' );
|
|
|
|
} else {
|
|
|
|
Wikia::addAssetsToOutput( 'portable_infobox_scss' );
|
|
|
|
}
|
|
|
|
|
2015-04-27 14:05:31 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-06-09 10:14:49 +00:00
|
|
|
|
2015-08-27 11:41:33 +00:00
|
|
|
public static function onImageServingCollectImages( &$imageNamesArray, $articleTitle ) {
|
2015-06-09 10:14:49 +00:00
|
|
|
if ( $articleTitle ) {
|
2015-06-23 08:41:15 +00:00
|
|
|
$infoboxImages = PortableInfoboxDataService::newFromTitle( $articleTitle )->getImages();
|
2015-06-09 10:14:49 +00:00
|
|
|
if ( !empty( $infoboxImages ) ) {
|
2015-06-22 15:15:26 +00:00
|
|
|
$imageNamesArray = array_merge( $infoboxImages, (array)$imageNamesArray );
|
2015-06-09 10:14:49 +00:00
|
|
|
}
|
|
|
|
}
|
2015-06-22 15:15:26 +00:00
|
|
|
|
2015-06-09 10:14:49 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-06-19 10:31:22 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
2015-08-20 13:14:23 +00:00
|
|
|
*
|
|
|
|
* @return bool
|
2015-06-19 10:31:22 +00:00
|
|
|
*/
|
2015-08-27 11:41:33 +00:00
|
|
|
public static function onParserTagHooksBeforeInvoke( $name, $marker, $content, $attributes, $parser, $frame ) {
|
2015-06-19 12:16:07 +00:00
|
|
|
if ( $name === self::PARSER_TAG_GALLERY ) {
|
2015-06-19 10:31:22 +00:00
|
|
|
\Wikia\PortableInfobox\Helpers\PortableInfoboxDataBag::getInstance()->setGallery( $marker, $content );
|
|
|
|
}
|
|
|
|
|
2015-06-09 10:14:49 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-08-20 13:14:23 +00:00
|
|
|
|
2015-08-27 11:41:33 +00:00
|
|
|
public static function onWgQueryPages( &$queryPages = [ ] ) {
|
2015-08-20 13:14:23 +00:00
|
|
|
$queryPages[] = [ 'AllinfoboxesQueryPage', 'AllInfoboxes' ];
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2015-08-27 11:41:33 +00:00
|
|
|
|
2015-09-02 11:02:33 +00:00
|
|
|
/**
|
|
|
|
* @param $article
|
|
|
|
* @param $text
|
|
|
|
* @param $wgOut
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public static function onAddPortableInfoboxBuilderText( &$article, &$text, &$wgOut, &$errors ) {
|
|
|
|
if ( !count( $errors ) ) {
|
|
|
|
$text = '';
|
|
|
|
$templateTitle = $article->getTitle()->getText();
|
|
|
|
|
|
|
|
$HTML = F::app()->renderView(
|
|
|
|
'PortableInfoboxBuilderSpecialController',
|
|
|
|
'renderCreateTemplateEntryPoint',
|
|
|
|
[ 'title' => $templateTitle ]
|
|
|
|
);
|
2015-09-02 08:52:57 +00:00
|
|
|
|
2015-09-02 11:02:33 +00:00
|
|
|
$wgOut->addHTML($HTML);
|
|
|
|
}
|
2015-09-01 14:43:26 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-08-27 12:50:02 +00:00
|
|
|
/**
|
|
|
|
* @param Skin $skin
|
|
|
|
* @param string $text
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public static function onSkinAfterBottomScripts( $skin, &$text ) {
|
|
|
|
$title = $skin->getTitle();
|
|
|
|
|
2015-09-01 15:10:38 +00:00
|
|
|
if ( $title->isSpecial( PortableInfoboxBuilderSpecialController::PAGE_NAME ) ) {
|
2015-08-27 12:50:02 +00:00
|
|
|
$scripts = AssetsManager::getInstance()->getURL( 'portable_infobox_builder_js' );
|
2015-09-01 15:10:38 +00:00
|
|
|
|
2015-08-27 12:50:02 +00:00
|
|
|
foreach ( $scripts as $script ) {
|
|
|
|
$text .= Html::linkedScript( $script );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2015-04-27 14:05:31 +00:00
|
|
|
}
|