getSkin()->getSkinName() === 'nextbestnetwork'; } /** * Expose NextBestNetworkSkinUseTooltips configuration variable * * @param array $vars */ public static function onResourceLoaderGetConfigVars( array &$vars ) { $vars['wgNextBestNetworkSkinUseTooltips'] = $GLOBALS['wgNextBestNetworkSkinUseTooltips']; } /** * Setting up parser functions * * @param Parser $parser Parser object being initialized */ public static function onParserFirstCallInit( Parser $parser ) { $parser->setHook( 'TOC', 'NextBestNetworkHooks::TOC' ); $parser->setHook( 'legend', 'NextBestNetworkHooks::legend' ); $parser->setHook( 'footer', 'NextBestNetworkHooks::footer' ); $parser->setHook( 'accordion', 'NextBestNetworkHooks::buildAccordion' ); $parser->setHook( 'label', 'NextBestNetworkHooks::buildLabel' ); if ( $GLOBALS['wgNextBestNetworkSkinUseBtnParser'] === true ) { $parser->setHook( 'btn', 'NextBestNetworkHooks::buildButtons' ); } $parser->setFunctionHook( 'nextbestnetworkhide', 'NextBestNetworkHooks::setHiddenElements' ); $parser->setFunctionHook( 'nextbestnetworknav', 'NextBestNetworkHooks::setCustomNavElement' ); $parser->setFunctionHook( 'nextbestnetworkhideexcept', 'NextBestNetworkHooks::setHiddenElementsGroups' ); $parser->setFunctionHook( 'nextbestnetworkbodyclass', 'NextBestNetworkHooks::addBodyclass' ); $parser->setFunctionHook( 'nextbestnetworkrealname', 'NextBestNetworkHooks::renderRealname' ); } /** * Adding modules * * @param OutputPage $out The OutputPage object. * @param Skin $skin Skin object that will be used to generate the page */ public static function onBeforePageDisplay( OutputPage $out, Skin $skin ) { if( $skin->getSkinName() == 'nextbestnetwork' ) { $config = \MediaWiki\MediaWikiServices::getInstance()->getConfigFactory()->makeConfig( 'nextbestnetwork' ); $styles = []; // load mediawiki styles $styles[] = 'skins.nextbestnetwork.mediawiki.styles'; // load font awesome $styles[] = 'skins.nextbestnetwork.awesome.styles'; // load externally defined style module if( $config->get( 'NextBestNetworkSkinCustomStyleModule' ) ) { $styles[] = $config->get( 'NextBestNetworkSkinCustomStyleModule' ); // or: load modules defined by nextbestnetwork } else { if( !$config->get( 'NextBestNetworkSkinUseCustomFiles' ) ) { $styles[] = 'skins.nextbestnetwork.styles'; } else { $styles[] = 'skins.nextbestnetwork.custom.styles'; } } // load external link styles if( $config->get( 'NextBestNetworkSkinUseExternallinkStyles' ) ) { $styles[] = 'skins.nextbestnetwork.externallinks.styles'; } // load additional modules foreach( $GLOBALS['wgNextBestNetworkSkinCustomCSS'] as $customstyle ) { $styles[] = $customstyle; } $hookContainer = MediaWikiServices::getInstance()->getHookContainer(); $hookContainer->run( 'SkinNextBestNetworkStyleModules', [ $skin, &$styles ] ); $out->addModuleStyles( $styles ); } } /** * GetPreferences hook * * Adds NextBestNetwork-releated items to the preferences * * @param User $user User whose preferences are being modified * @param array $preferences Preferences description array, to be fed to an HTMLForm object */ public static function onGetPreferences( User $user, array &$preferences ) { $preferences['nextbestnetwork-advanced'] = [ 'type' => 'toggle', 'label-message' => 'prefs-nextbestnetwork-advanced-desc', 'section' => 'rendering/nextbestnetwork-advanced', 'help-message' => 'prefs-nextbestnetwork-advanced-help' ]; } /** * Pages could be hidden for anonymous users or only be shown for specific groups * so we put a user's group memberships into the page rendering hash * * @param string $confstr Reference to a hash key string which can be modified * @param User $user User object that is requesting the page * @param array $options Array of options used to generate the $confstr hash key */ static function onPageRenderingHash( &$confstr, User $user, array &$options ) { $userGroupManager = MediaWikiServices::getInstance()->getUserGroupManager(); $groups = $userGroupManager->getUserEffectiveGroups($user); sort( $groups ); $confstr .= "!groups=" . join(',', $groups ); } /** * Add body classes * * @param OutputPage $out The OutputPage which called the hook, can be used to get the real title * @param Skin $sk The Skin that called OutputPage::headElement * @param array $bodyAttrs An array of attributes for the body tag passed to Html::openElement */ static function onOutputPageBodyAttributes( OutputPage $out, Skin $sk, array &$bodyAttrs ) { if( $sk->getSkinName() == 'nextbestnetwork' ) { $additionalBodyClasses = [ 'nextbestnetwork-animateLayout' ]; $user = $out->getUser(); $userAdvanced = MediaWikiServices::getInstance()->getUserOptionsLookup()->getOption( $user, 'nextbestnetwork-advanced' ); $additionalBodyClasses[] = $userAdvanced ? 'nextbestnetwork-advanced' : 'nextbestnetwork-non-advanced'; $additionalBodyClasses[] = $user->isRegistered() ? 'nextbestnetwork-user-logged-in' : 'nextbestnetwork-user-anon'; $additionalBodyClasses = array_merge( $additionalBodyClasses, $GLOBALS['wgNextBestNetworkSkinAdditionalBodyClasses'] ); $hookContainer = MediaWikiServices::getInstance()->getHookContainer(); $hookContainer->run( 'SkinNextBestNetworkAdditionalBodyClasses', [ $sk, &$additionalBodyClasses ] ); if( count( $additionalBodyClasses ) > 0 ) { $bodyAttrs['class'] = $bodyAttrs['class'] . ' ' . preg_replace( "/[^a-zA-Z0-9_\s-]/", "", implode( " ", $additionalBodyClasses ) ); } } } /** * Use real names instead of user names * * @param LinkRenderer $linkRenderer the LinkRenderer object * @param LinkTarget $target the LinkTarget that the link is pointing to * @param boolean $isKnown boolean indicating whether the page is known or not * @param string|HtmlArmor $text the contents that the tag should have; either a plain, unescaped string or a HtmlArmor object. * @param array $attribs the final HTML attributes of the tag, after processing, in associative array form. * @param string $ret the value to return if your hook returns false. */ public static function onHtmlPageLinkRendererEnd( LinkRenderer $linkRenderer, LinkTarget $target, $isKnown, &$text, array &$attribs, &$ret ) { if( $GLOBALS['wgNextBestNetworkSkinUseRealnames'] == true && $target->getNamespace() === 2 ) { $userkey = $target->getDBKey(); // use real name if link text hadn't been set explicitly to be different from the page name $title = Title::newFromText( HtmlArmor::getHtml( $text ) ); if( $title && ( $title->getPrefixedText() == $target->getPrefixedText() || $title->getText() == $target->getText() ) ) { $text = self::getRealname( $userkey ); } } } /** * Use real names instead of user names in selflinks * * @param Title $nt the title object of the page * @param string $html Link text * @param string $trail Text after link * @param string $prefix Text before link * @param string $ret Self link text to be used if the hook returns false */ public static function onSelfLinkBegin( Title $nt, &$html, &$trail, &$prefix, &$ret ) { if( $GLOBALS['wgNextBestNetworkSkinUseRealnames'] == true && $nt->getNamespace() === 2 ) { $userkey = $nt->getDBKey(); // use real name if link text hadn't been set explicitly to be different from the page name $title = Title::newFromText( HtmlArmor::getHtml( $html ) ); if( $title && ( $title->getPrefixedText() == $nt->getPrefixedText() || $title->getText() == $nt->getText() ) ) { $html = self::getRealname( $userkey ); } } } /** * Customize edit section links * * @param Skin $skin Skin object rendering the UI * @param Title $title Title object for the title being linked to * @param string $section The designation of the section being pointed to, to be included in the link * @param string $tooltip The default tooltip. * @param array $links Array containing all link detail arrays. * @param string $lang The language code to use for the link in the wfMessage function * * @todo: make this work with VisualEditor */ static function onSkinEditSectionLinks( Skin $skin, Title $title, $section, $tooltip, array &$links, $lang = false ) { if( $skin->getSkinName() == 'nextbestnetwork' && $GLOBALS['wgNextBestNetworkSkinCustomEditSectionLink'] == true ) { if ( version_compare( MW_VERSION, '1.40', '<' ) ) { $icon = wfMessage( 'nextbestnetwork-editsection-icon' )->inLanguage( $lang )->parse(); $text = wfMessage( 'nextbestnetwork-editsection-text' )->inLanguage( $lang )->parse(); $class = wfMessage( 'nextbestnetwork-editsection-class' )->inLanguage( $lang )->parse(); $text = new HtmlArmor( $icon . ( ( $icon != '' ) ? ' ' : '' ) . $text ); $links['editsection']['text'] = $text; $links['editsection']['attribs']['class'] = $class; } else { $links['editsection']['link-html'] = wfMessage( 'nextbestnetwork-editsection-icon' )->inLanguage( $lang )->parse(); $links['editsection']['text'] = wfMessage( 'nextbestnetwork-editsection-text' )->inLanguage( $lang )->parse(); $links['editsection']['attribs']['class'] = wfMessage( 'nextbestnetwork-editsection-class' )->inLanguage( $lang )->parse(); } } return false; } /** * Change TOC and page content of file pages to togglable tabs * * @param OutputPage $outputPage */ public static function onAfterFinalPageOutput( OutputPage $outputPage ) { if( $outputPage->getSkin()->getSkinName() == 'nextbestnetwork' && $outputPage->getTitle()->getNamespace() == 6 && $GLOBALS['wgNextBestNetworkSkinImagePageTOCTabs'] == true ) { $out = ob_get_clean(); $out = str_replace( '