Opening file-link in new tab

Jump to: navigation, search

File links should open in a new tab in the browser. Do you have suggestions how to change the settings?


MediaWiki 1.19.1 PHP 5.4.9 (cgi-fcgi) MySQL 5.5.21-log

194.29.4.16614:45, 5 June 2013

I've done this by using a hook. If you want a pointer to the code, feel free to ask.

MarkAHershberger(talk)15:58, 10 June 2013

Hey Mark, it would be great to see your solution. I was looking for one in the search but couldnt find it.

https://www.mediawiki.org/wiki/Manual:Hooks

Thank you in advance, Aron

194.29.4.16608:53, 11 June 2013

I used the following code to open PDFs in a new window. This should give you an idea.

class Hooks {
 
	static private function doPDFTarget ( $target, &$text, &$attribs ) {
		global $wgExternalLinkTarget;
		wfProfileIn( __METHOD__ );
		if ( strtolower( substr( $target, -4 ) ) === ".pdf" ) {
			if( $wgExternalLinkTarget !== false ) {
				$attribs["target"] = $wgExternalLinkTarget;
			} else {
				$attribs["target"] = "_blank";
			}
		}
		wfProfileOut( __METHOD__ );
 
		return true;
	}
 
	static public function ImageParams ( $title, $file, &$params ) {
		self::doPDFTarget( $title, $params['frame']['title'], $params['frame'] );
		# Make all image links go no where.
		if( empty( $params['frame']['link'] ) && empty( $params['frame']['target'] ) ) {
			$params['frame']['no-link'] = 'xxx';
		}
		return true;
	}
 
	/* may not be necessary? */
	static public function FetchFile ( $parser, $title, &$options, &$desQuery ) {
		$options['target'] = '_blank';
		return true;
	}
 
	static public function ExternalLink ( &$url, &$text, &$link, &$attribs ) {
		self::doPDFTarget ( $url, $text, $attribs );
 
		return true;
	}
 
	static public function InternalLink ( $dummy, $target, $options, $html, &$attribs, &$ret ) {
		self::doPDFTarget ( $target, $text, $attribs );
 
		return true;
 
	}
}
$wgHooks['LinkerMakeExternalLink'][] = 'Hooks::ExternalLink';
$wgHooks['ParserMakeImageParams'][] = 'Hooks::ImageParams';
$wgHooks['BeforeParserFetchFileAndTitle'][] = 'Hooks::FetchFile';
$wgHooks['LinkEnd'][] = 'Hooks::InternalLink';
MarkAHershberger(talk)15:07, 11 June 2013

Thank you, I ll try this! Have a great day

194.29.4.16607:42, 12 June 2013