Jump to content

Wikia code/includes/Linker.php

From mediawiki.org
--- D:\Programming\SVN\mediawiki\branches\REL1_16\phase3\includes\Linker.php	2011-07-18 22:31:28.068359400 +0100
+++ D:\Programming\SVN\wikia\trunk\includes\Linker.php	2011-08-17 15:28:46.430664100 +0100

@@ -237,9 +238,12 @@
 		# (i.e., for a nonexistent special page).
 		if( in_array( 'broken', $options ) and empty( $query['action'] )
 		and $target->getNamespace() != NS_SPECIAL ) {
+			global $wgWikiaEnableAutoPageCreateExt;
+			if( empty( $wgWikiaEnableAutoPageCreateExt ) ) {
 			$query['action'] = 'edit';
 			$query['redlink'] = '1';
 		}
+		}
 		$ret = $target->getLinkUrl( $query );
 		wfProfileOut( __METHOD__ );
 		return $ret;
@@ -528,6 +532,13 @@
 				'title' => $fp['title'],
 				'valign' => isset( $fp['valign'] ) ? $fp['valign'] : false ,
 				'img-class' => isset( $fp['border'] ) ? 'thumbborder' : false );
+			/* Wikia change begin - @author: Marooned */
+			/* Images SEO project */
+			if (Wikia::isOasis()) {
+				$wrapperId = preg_replace('/[^a-z0-9_]/i', '-', Sanitizer::escapeId($title->getText()));
+				$params['id'] = $wrapperId;
+			}
+			/* Wikia change end */
 			if ( !empty( $fp['link-url'] ) ) {
 				$params['custom-url-link'] = $fp['link-url'];
 			} elseif ( !empty( $fp['link-title'] ) ) {
@@ -565,6 +576,11 @@
 
 	function makeThumbLink2( Title $title, $file, $frameParams = array(), $handlerParams = array(), $time = false, $query = "" ) {
 		global $wgStylePath, $wgContLang;
+
+		/*Wiki change start, author: Federico "Lox" Lucignano*/
+		global $wgUser;
+		/*Wikia change end*/
+
 		$exists = $file && $file->exists();
 
 		# Shortcuts
@@ -627,7 +643,16 @@
 
 		$more = htmlspecialchars( wfMsg( 'thumbnail-more' ) );
 
+		/* Wikia change begin - @author: Marooned */
+		/* Images SEO project */
+		if (Wikia::isOasis()) {
+			$wrapperId = preg_replace('/[^a-z0-9_]/i', '-', Sanitizer::escapeId($title->getText()));
+			$s = "<figure class=\"thumb t{$fp['align']} thumbinner\" style=\"width:{$outerWidth}px;\">";
+		} else {
+			$wrapperId = '';
 		$s = "<div class=\"thumb t{$fp['align']}\"><div class=\"thumbinner\" style=\"width:{$outerWidth}px;\">";
+		}
+		/* Wikia change end */
 		if( !$exists ) {
 			$s .= $this->makeBrokenImageLinkObj( $title, $fp['title'], '', '', '', $time==true );
 			$zoomicon = '';
@@ -638,19 +663,43 @@
 			$s .= $thumb->toHtml( array(
 				'alt' => $fp['alt'],
 				'title' => $fp['title'],
+				/* Wikia change begin - @author: Marooned */
+				/* Images SEO project */
+				'id' => $wrapperId,
+				/* Wikia change end */
 				'img-class' => 'thumbimage',
 				'desc-link' => true,
 				'desc-query' => $query ) );
 			if ( isset( $fp['framed'] ) ) {
 				$zoomicon="";
 			} else {
-				$zoomicon =  '<div class="magnify">'.
-					'<a href="'.$url.'" class="internal" title="'.$more.'">'.
-					'<img src="'.$wgStylePath.'/common/images/magnify-clip.png" ' .
-					'width="15" height="11" alt="" /></a></div>';
-			}
-		}
+				/* Wikia change begin - @author: christian, Marooned */
+				/* Change img src from magnify-clip.png to blank.gif. Image is set via CSS Background */
+				global $wgBlankImgUrl;
+				$zoomicon =  '<a href="'.$url.'" class="internal sprite details magnify" title="'.$more.'"></a>';
+				/* Wikia change end */
+			}
+		}
+		/* Wikia change begin - @author: Marooned, Federico "Lox" Lucignano */
+		/* Images SEO project */
+		if (Wikia::isOasis()) {
+			$s .= $zoomicon;
+
+			if( !empty( $fp[ 'caption' ] ) ) $s .= '<figcaption class="thumbcaption">' . $fp['caption'] . '</figcaption>';
+			$s .= '<!-- picture-attribution -->';
+
+			$s .= '</figure>';
+		} else {
 		$s .= '  <div class="thumbcaption">'.$zoomicon.$fp['caption']."</div></div></div>";
+		}
+		/* Wikia change end */
+
+		/* Wikia change begin - @author: macbre */
+		/* Give extensions ability to add HTML to thumbed / framed images */
+		/* @author: wladek - added outerWidth parameter for BugId: 3734 */
+		wfRunHooks('MakeThumbLink2', array($this, $title, $file, $frameParams, $handlerParams, &$s, $outerWidth));
+		/* Wikia change end */
+
 		return str_replace("\n", ' ', $s);
 	}
 
@@ -685,12 +734,20 @@
 
 				list( $inside, $trail ) = self::splitTrail( $trail );
 
+				// wikia changes start
+				$nofollow = array();
+				global $wgWikiaUseNoFollow;
+				if( !empty( $wgWikiaUseNoFollow ) ) {
+					$nofollow = array('rel' => "nofollow" );
+				}
+				// wikia changes end
+
 				wfProfileOut( __METHOD__ );
 				return Html::element( 'a', array(
 					'href' => $href,
 					'class' => 'new',
 					'title' => $title->getPrefixedText()
-				), $prefix . $text . $inside ) . $trail;
+				) + $nofollow, $prefix . $text . $inside ) . $trail;
 			} else {
 				wfProfileOut( __METHOD__ );
 				return $this->makeKnownLinkObj( $title, $text, $query, $trail, $prefix );
@@ -739,18 +796,24 @@
 		} else {
 			$img  = wfFindFile( $title, array( 'time' => $time ) );
 			if( $img ) {
-				$url  = $img->getURL();
+				$url  = wfReplaceImageServer( $img->getURL(), $img->getTimestamp() );
 				$class = 'internal';
+				$nofollow = '';
 			} else {
 				$url = $this->getUploadUrl( $title );
 				$class = 'new';
+				global $wgWikiaUseNoFollow;
+				$nofollow = '';
+				if( !empty( $wgWikiaUseNoFollow ) ) {
+					$nofollow = ' rel="nofollow"';
+				}
 			}
 			$alt = htmlspecialchars( $title->getText() );
 			if( $text == '' ) {
 				$text = $alt;
 			}
 			$u = htmlspecialchars( $url );
-			return "<a href=\"{$u}\" class=\"$class\" title=\"{$alt}\">{$text}</a>";
+			return "<a href=\"{$u}\" class=\"$class\" title=\"{$alt}\"{$nofollow}>{$text}</a>";
 		}
 	}
 
@@ -794,7 +857,7 @@
 			$text = htmlspecialchars( $text );
 		}
 		$link = '';
-		$success = wfRunHooks('LinkerMakeExternalLink', array( &$url, &$text, &$link, &$attribs, $linktype ) );
+		$success = wfRunHooks('LinkerMakeExternalLink', array( &$url, &$text, &$link, &$attribs, &$linktype, $this ) );
 		if(!$success) {
 			wfDebug("Hook LinkerMakeExternalLink changed the output of link with url {$url} and text {$text} to {$link}\n", true);
 			return $link;
@@ -1280,10 +1345,15 @@
 	 * parameter level defines if we are on an indentation level
 	 */
 	function tocLine( $anchor, $tocline, $tocnumber, $level, $sectionIndex = false ) {
+		$nofollow = '';
+		global $wgWikiaUseNoFollow;
+		if( !empty( $wgWikiaUseNoFollow ) ) {
+			$nofollow = ' rel="nofollow"';
+		}
 		$classes = "toclevel-$level";
 		if ( $sectionIndex !== false )
 			$classes .= " tocsection-$sectionIndex";
-		return "\n<li class=\"$classes\"><a href=\"#" .
+		return "\n<li class=\"$classes\"><a{$nofollow} href=\"#" .
 			$anchor . '"><span class="tocnumber">' .
 			$tocnumber . '</span> <span class="toctext">' .
 			$tocline . '</span></a>';
@@ -1312,12 +1382,16 @@
 		 # no trailing newline, script should not be wrapped in a
 		 # paragraph
 		 . "</ul>\n</td></tr></table>"
+			/* Wikia change begin - @author: macbre, Marooned */
+			/* Fixes for #2643 and #3730 - macbre */
+			/* Fixes for rt#18733 (do not wait for ads to run this script) - Marooned */
 		 . Html::inlineScript(
-			'if (window.showTocToggle) {'
-			. ' var tocShowText = "' . Xml::escapeJsString( wfMsg('showtoc') ) . '";'
-			. ' var tocHideText = "' . Xml::escapeJsString( wfMsg('hidetoc') ) . '";'
+				'wgAfterContentAndJS.push(function() {'
+				. 'if (window.showTocToggle) {'
+				. ' window.tocShowText = "' . Xml::escapeJsString( wfMsg('showtoc') ) . '";'
+				. ' window.tocHideText = "' . Xml::escapeJsString( wfMsg('hidetoc') ) . '";'
 			. ' showTocToggle();'
-			. ' } ' )
+				. ' } });' )
 		. "\n";
 	}
 
@@ -1364,6 +1438,13 @@
 		// HTML generated here should probably have userlangattributes
 		// added to it for LTR text on RTL pages
 		$attribs = array();
+		global $wgWikiaUseNoFollow;
+		if( !empty( $wgWikiaUseNoFollow ) ) {
+			/* Wikia change begin - @author: uknkown */
+			/* Ad rel="nofollow" attribute to edit section links */
+			$attribs['rel'] = 'nofollow';
+			/* Wikia change end */
+		}
 		if( !is_null( $tooltip ) ) {
 			$attribs['title'] = wfMsg( 'editsectionhint', $tooltip );
 		}
@@ -1415,12 +1496,17 @@
 	 * @return string HTML headline
 	 */
 	public function makeHeadline( $level, $attribs, $anchor, $text, $link, $legacyAnchor = false ) {
+		$nofollow = '';
+		global $wgWikiaUseNoFollow;
+		if( !empty( $wgWikiaUseNoFollow ) ) {
+			$nofollow = ' rel="nofollow"';
+		}
 		$ret = "<h$level$attribs"
 			. $link
 			. " <span class=\"mw-headline\" id=\"$anchor\">$text</span>"
 			. "</h$level>";
 		if ( $legacyAnchor !== false ) {
-			$ret = "<a id=\"$legacyAnchor\"></a>$ret";
+			$ret = "<a{$nofollow} id=\"$legacyAnchor\"></a>$ret";
 		}
 		return $ret;
 	}
@@ -1552,6 +1638,12 @@
 			}
 			$outText .= '</ul>';
 		}
+
+		/* Wikia change begin - @author: Macnre */
+		/* #22760: Shorten edit page 'transcluded pages' list using JS */
+		wfRunHooks('LinkerFormatTemplates', array(&$this, &$templates, &$outText));
+		/* Wikia change end */
+
 		wfProfileOut( __METHOD__  );
 		return $outText;
 	}
@@ -1825,7 +1917,26 @@
 			$text = $this->linkText( $nt );
 		}
 
-		$ret = $this->link( $nt, "$prefix$text$inside", array(), $query ) . $trail;
+		/* Wikia change begin - @author: unknown, Inez */
+		$attribs = array();
+		if( $nt && $nt->isExternal()) {
+			$iwclass = strtolower($nt->getInterwiki());
+			if(in_array($iwclass, array('w', 'wikia', 'wikicities'))) {
+				$iwclass = 'w';
+				$iw_temp = explode(':', strtolower($nt->getText()));
+				if(!empty($iw_temp[0])) {
+					if ('c' == $iw_temp[0]) {
+						if (!empty($iw_temp[1])) {
+							$iwclass .= " wikia-{$iw_temp[1]}";
+						}
+					}
+				}
+			}
+			$attribs['class'] = "interwiki-{$iwclass}";
+		}
+		/* Wikia change end */
+
+		$ret = $this->link( $nt, "$prefix$text$inside", $attribs, $query ) . $trail;
 
 		wfProfileOut( __METHOD__ );
 		return $ret;
@@ -1882,13 +1993,34 @@
 	function makeBrokenLinkObj( $title, $text = '', $query = '', $trail = '', $prefix = '' ) {
 		wfProfileIn( __METHOD__ );
 
+		// wikia change begin
+		global $wgWikiaEnableSharedHelpExt;
+		if ( $wgWikiaEnableSharedHelpExt
+			&& ( NS_HELP == $title->getNamespace() )
+			&& SharedHelpArticleExists($title) )
+		{
+			return $this->makeKnownLinkObj( $title, $text, $query, $trail, $prefix );
+		}
+		// wikia change end
+
 		list( $inside, $trail ) = Linker::splitTrail( $trail );
 		if( $text === '' ) {
 			$text = $this->linkText( $title );
 		}
 		$nt = $this->normaliseSpecialPage( $title );
 
-		$ret = $this->link( $title, "$prefix$text$inside", array(),
+		// wikia change begin
+		$attribs = array();
+		global $wgWikiaUseNoFollow, $wgWikiaEnableAutoPageCreateExt;
+		if( !empty( $wgWikiaUseNoFollow )
+			&& ( ( empty( $wgWikiaEnableAutoPageCreateExt ) && !empty( $wgWikiaUseNoFollowForContent ) )
+			|| ( !$title->isContentPage() ) ) )
+		{
+			$attribs['rel'] = 'nofollow';
+		}
+		// wikia change end
+
+		$ret = $this->link( $title, "$prefix$text$inside", $attribs,
 			wfCgiToArray( $query ), 'broken' ) . $trail;
 
 		wfProfileOut( __METHOD__ );