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-08-27 11:41:33 +00:00
|
|
|
public static function onBeforePageDisplay( OutputPage $out, Skin $skin ) {
|
2016-03-16 10:52:12 +00:00
|
|
|
global $wgEnablePortableInfoboxEuropaTheme;
|
|
|
|
|
2015-12-04 23:56:29 +00:00
|
|
|
Wikia::addAssetsToOutput( 'portable_infobox_js' );
|
2015-05-18 13:56:45 +00:00
|
|
|
if ( F::app()->checkSkin( 'monobook', $skin ) ) {
|
|
|
|
Wikia::addAssetsToOutput( 'portable_infobox_monobook_scss' );
|
2016-11-03 13:44:29 +00:00
|
|
|
Wikia::addAssetsToOutput( 'portable_infobox_monobook_js' );
|
2015-05-18 13:56:45 +00:00
|
|
|
} else {
|
|
|
|
Wikia::addAssetsToOutput( 'portable_infobox_scss' );
|
2016-03-16 10:52:12 +00:00
|
|
|
if ( !empty( $wgEnablePortableInfoboxEuropaTheme ) ) {
|
|
|
|
Wikia::addAssetsToOutput( 'portable_infobox_europa_theme_scss' );
|
|
|
|
}
|
2015-05-18 13:56:45 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
/**
|
2017-01-12 12:54:32 +00:00
|
|
|
* Store data of all galleries in article to handle images in infoboxes
|
2015-08-20 13:14:23 +00:00
|
|
|
*
|
2017-01-12 12:54:32 +00:00
|
|
|
* @param $marker
|
|
|
|
* @param WikiaPhotoGallery $gallery
|
2015-08-20 13:14:23 +00:00
|
|
|
* @return bool
|
2015-06-19 10:31:22 +00:00
|
|
|
*/
|
2017-01-12 12:54:32 +00:00
|
|
|
public static function onAfterParserParseImageGallery( $marker, WikiaPhotoGallery $gallery ) {
|
|
|
|
\Wikia\PortableInfobox\Helpers\PortableInfoboxDataBag::getInstance()->setGallery( $marker, $gallery->getData() );
|
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-09-08 17:42:49 +00:00
|
|
|
|
2015-09-22 15:48:38 +00:00
|
|
|
public static function onAllInfoboxesQueryRecached() {
|
2015-09-08 17:42:49 +00:00
|
|
|
F::app()->wg->Memc->delete( wfMemcKey( ApiQueryAllinfoboxes::MCACHE_KEY ) );
|
2015-09-22 15:48:38 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Purge memcache before edit
|
|
|
|
*
|
2015-09-25 07:23:25 +00:00
|
|
|
* @param $article Page|WikiPage
|
2015-09-22 15:48:38 +00:00
|
|
|
* @param $user
|
|
|
|
* @param $text
|
|
|
|
* @param $summary
|
|
|
|
* @param $minor
|
|
|
|
* @param $watchthis
|
|
|
|
* @param $sectionanchor
|
|
|
|
* @param $flags
|
|
|
|
* @param $status
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
2015-09-25 07:23:25 +00:00
|
|
|
public static function onArticleSave( Page &$article, &$user, &$text, &$summary, $minor, $watchthis, $sectionanchor,
|
2015-09-22 15:48:38 +00:00
|
|
|
&$flags, &$status ) {
|
2015-09-25 14:53:39 +00:00
|
|
|
PortableInfoboxDataService::newFromTitle( $article->getTitle() )->delete();
|
2015-09-22 15:48:38 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-09-25 14:53:39 +00:00
|
|
|
* Purge memcache, this will not rebuild infobox data
|
2015-09-22 15:48:38 +00:00
|
|
|
*
|
2015-09-25 07:23:25 +00:00
|
|
|
* @param Page|WikiPage $article
|
2015-09-22 15:48:38 +00:00
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
2015-09-25 07:23:25 +00:00
|
|
|
public static function onArticlePurge( Page &$article ) {
|
2015-09-22 15:48:38 +00:00
|
|
|
PortableInfoboxDataService::newFromTitle( $article->getTitle() )->purge();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-09-23 13:56:08 +00:00
|
|
|
/**
|
|
|
|
* Purge articles memcache when template is edited
|
|
|
|
*
|
2015-09-25 07:23:25 +00:00
|
|
|
* @param $articles Array of Titles
|
2015-09-23 13:56:08 +00:00
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
2015-09-24 15:17:47 +00:00
|
|
|
public static function onBacklinksPurge( Array $articles ) {
|
2015-09-22 15:48:38 +00:00
|
|
|
foreach ( $articles as $title ) {
|
2016-12-21 08:09:25 +00:00
|
|
|
PortableInfoboxDataService::newFromTitle( $title )->delete();
|
2015-09-22 15:48:38 +00:00
|
|
|
}
|
|
|
|
|
2015-09-08 17:42:49 +00:00
|
|
|
return true;
|
|
|
|
}
|
2016-03-31 07:31:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Insert a newly created infobox into querycache, and purge the list of
|
|
|
|
* infoboxes.
|
|
|
|
*
|
|
|
|
* @param Page $page The created page object
|
|
|
|
* @param User $user The user who created the page
|
|
|
|
* @param string $text Text of the new article
|
|
|
|
* @param string $summary Edit summary
|
|
|
|
* @param int $minoredit Minor edit flag
|
|
|
|
* @param boolean $watchThis Whether or not the user should watch the page
|
|
|
|
* @param null $sectionAnchor Not used, set to null
|
|
|
|
* @param int $flags Flags for this page
|
|
|
|
* @param Revision $revision The newly inserted revision object
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public static function onArticleInsertComplete( Page $page, User $user, $text, $summary, $minoredit,
|
|
|
|
$watchThis, $sectionAnchor, &$flags, Revision $revision ) {
|
|
|
|
$title = $page->getTitle();
|
2016-04-06 08:50:01 +00:00
|
|
|
if ( $title->inNamespace( NS_TEMPLATE ) ) {
|
2016-04-06 09:54:04 +00:00
|
|
|
( new AllinfoboxesQueryPage() )->addTitleToCache( $title );
|
2016-03-31 07:31:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2016-06-17 10:07:38 +00:00
|
|
|
|
2016-05-09 11:56:28 +00:00
|
|
|
public static function onArticleAsJsonBeforeEncode( &$text ) {
|
2016-06-17 10:07:38 +00:00
|
|
|
$tagController = PortableInfoboxParserTagController::getInstance();
|
|
|
|
$tagController->moveFirstMarkerToTop( $text );
|
|
|
|
|
|
|
|
$text = $tagController->replaceMarkers( $text );
|
2016-05-09 11:56:28 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2015-04-27 14:05:31 +00:00
|
|
|
}
|