FS-Mod/FSMod/FSModHooks.php

154 lines
5.2 KiB
PHP

<?php
/**
* @file
* @ingroup Extensions
* @author Björn Kinscher
* @copyright © 2009 Björn Kinscher
* @modified 2014 Christian Zirkelbach
* @modified 2018,2019 Einhard Leichtfuß
* @modified 2019 Bennet Bleßmann
* @license GNU General Public Licence 2.0 or later
*/
if( !defined( 'MEDIAWIKI' ) ) {
echo( "This file is an extension to the MediaWiki software and cannot be used standalone.\n" );
die( 1 );
}
use MediaWiki\Revision\{RevisionRecord, SlotRecord};
class FSModHooks {
/**
* Hook: ParserFirstCallInit
*/
static function hooksSetup(Parser $parser){
$parser->setHook( 'fsgallery' , FSMod::deprecatedTagCallback('fsgallery') );
$parser->setHook( 'proceeding' , [TagProceeding::class , 'proceedingsRender' ]);
// TODO eventually deprecate the jobexchange tag, see the fsgallery tag
$parser->setHook( 'jobexchange' , [TagJobboerse::class , 'jobexchangeRender' ]);
$parser->setHook( 'jobs-preview' , [TagJobboerse::class , 'jobexchangePreviewRender']);
$parser->setHook( 'userlist' , [TagUserlist::class , 'userlistRender' ]);
$parser->setHook( 'intern' , [TagIntern::class , 'internRender' ]);
$parser->setHook( 'cau-intern' , [TagIntern::class , 'internCAU' ]);
$parser->setHook( 'nocau-intern' , [TagIntern::class , 'noInternCAU' ]);
$parser->setHook( 'examinationlogs', [TagExaminations::class , 'exLogsRender' ]);
$parser->setHook( 'fsevents' , [TagEvents::class , 'eventsRenderer' ]);
return true;
}
/**
* Hook: SkinBuildSidebar
*/
static function hideSidebar($skin,&$bar){
// TODO try to find a better way than to create a new user object
// previously used global $wgUser but that has been deprecated
$user = User::newFromSession();
// Hide sidebar for anonymous users
if (!$user->isRegistered()) {
$lines = explode( "\n", wfMessage( 'Anon_Sidebar' ) );
$heading = '';
$messageTitle = $skin->getConfig()->get( 'EnableSidebarCache' )
? Title::newMainPage() : $skin->getTitle();
foreach ( $lines as $line ) {
if ( strpos( $line, '*' ) !== 0 ) {
continue;
}
$line = rtrim( $line, "\r" ); // for Windows compat
if ( strpos( $line, '**' ) !== 0 ) {
$heading = trim( $line, '* ' );
if ( !array_key_exists( $heading, $bar ) ) {
$bar[$heading] = [];
}
} else {
$line = trim( $line, '* ' );
if ( strpos( $line, '|' ) !== false ) { // sanity check
$line = MessageCache::singleton()->transform( $line, false, null, $messageTitle );
$line = array_map( 'trim', explode( '|', $line, 2 ) );
if ( count( $line ) !== 2 ) {
// Second sanity check, could be hit by people doing
// funky stuff with parserfuncs... (T35321)
continue;
}
$extraAttribs = [];
$msgLink = $skin->msg( $line[0] )->title( $messageTitle )->inContentLanguage();
if ( $msgLink->exists() ) {
$link = $msgLink->text();
if ( $link == '-' ) {
continue;
}
} else {
$link = $line[0];
}
$msgText = $skin->msg( $line[1] )->title( $messageTitle );
if ( $msgText->exists() ) {
$text = $msgText->text();
} else {
$text = $line[1];
}
if ( preg_match( '/^(?i:' . wfUrlProtocols() . ')/', $link ) ) {
$href = $link;
// Parser::getExternalLinkAttribs won't work here because of the Namespace things
global $wgNoFollowLinks, $wgNoFollowDomainExceptions;
if ( $wgNoFollowLinks && !wfMatchesDomainList( $href, $wgNoFollowDomainExceptions ) ) {
$extraAttribs['rel'] = 'nofollow';
}
global $wgExternalLinkTarget;
if ( $wgExternalLinkTarget ) {
$extraAttribs['target'] = $wgExternalLinkTarget;
}
} else {
$title = Title::newFromText( $link );
if ( $title ) {
$title = $title->fixSpecialName();
$href = $title->getLinkURL();
} else {
$href = 'INVALID-TITLE';
}
}
$bar[$heading][] = array_merge( [
'text' => $text,
'href' => $href,
'id' => Sanitizer::escapeIdForAttribute( 'n-' . strtr( $line[1], ' ', '-' ) ),
'active' => false,
], $extraAttribs );
} else {
continue;
}
}
}
}
return true;
}
/**
* Hook: PageRenderingHash
*/
static function onPageRenderingHash(&$confstr, $user, $optionsUsed){
if ($user->isRegistered()){
$confstr .= "!visibility=full";
}else if (self::isCAUIP()) {
$confstr .= "!visibility=cau";
}else{
$confstr .= "!visibility=default";
}
return true;
}
static function onUserEffectiveGroups(&$user, &$aUserGroups) {
if ($user->isRegistered() && (FSMod::fsStatus($user->getName()) == 2)) {
$aUserGroups[] = "fach-schaf";
}
return true;
}
}