<commit_before><?php
# Extension: Highlight Links in Category
# Copyright 2013, <NAME>
# Released under a MIT-style license, as well as under the same terms
#    as Mediawiki.  See LICENSE for details


$wgExtensionCredits['other'][] = array( 
        'name' => 'Highlight Link in Category', 
        'author' => '<NAME>' '<NAME> (GethN7)',
        'version' => '0.5',
        'url' => 'https://github.com/labster/mediawiki-highlight-links-in-category',
        'descriptionmsg' => 'Highlights links in categories via customizable CSS classes',
); 

$wgHooks['LinkEnd'][] = 'HighlightCategoryLinks::HCLExtensionLinkEnd';


class HighlightCategoryLinks {

	private static $CategoryTrope;
	private static $CategoryYMMV;

	public static function HCLExtensionLinkEnd( $dummy, Title $target, array $options, &$html, array &$attribs, &$ret ) {
		if (isset($attribs['class'])) {
			return true; # don't mess with it if we have interwiki/broken/redirect
		} elseif ( self::pageInCategory("YMMV",  self::$CategoryYMMV,  $target) ) {
			$attribs['class'] = "ymmvlink";
		} elseif ( self::pageInCategory("Trope", self::$CategoryTrope, $target) ) {
			$attribs['class'] = "tropelink";
		}
		return true;
	}

	private static function pageInCategory ($category, &$categoryArray, $target) {
		if (! $categoryArray) {
			self::getCatHash($category, $categoryArray);
		}
		return isset($categoryArray[$target->getArticleID()]);
	}

	private static function getCatHash ($category, &$categoryArray) {
		# Check memcached first (can be commented out if you have memcached enabled)
		$categoryArray = $wgMemc->get("HLCategoryList:$category");
		if ($categoryArray) { return; }

		# We need to look this up in the DB
		$underscored_category = $category;
		preg_replace( '/ /', '_', $underscored_category);
		$dbr = wfGetDB( DB_SLAVE );
		$res = $dbr->select( 'categorylinks', 'cl_from', array( 'cl_to' => $underscored_category ) );
		foreach ( $res as $row ) {
			$categoryArray[$row->cl_from] = True;  # map page ids to true for O(1) lookups
		}

		# Cache result for a day, and return (this can be disabled if you don't have memcahced enabled)
		$wgMemc->set("HLCategoryList:$category", $categoryArray, 86400 );
		return;
	}

}

<commit_msg>unbreak the build, lol<commit_after><?php
# Extension: Highlight Links in Category
# Copyright 2013, <NAME> and GethN7
# Released under a MIT-style license, as well as under the same terms
#    as Mediawiki.  See LICENSE for details


$wgExtensionCredits['other'][] = array( 
        'name' => 'Highlight Link in Category', 
        'author' => '<NAME>, Arcane 21 (GethN7)',
        'version' => '0.5',
        'url' => 'https://github.com/labster/mediawiki-highlight-links-in-category',
        'descriptionmsg' => 'Highlights links in categories via customizable CSS classes',
); 

$wgHooks['LinkEnd'][] = 'HighlightCategoryLinks::HCLExtensionLinkEnd';


class HighlightCategoryLinks {

	private static $CategoryTrope;
	private static $CategoryYMMV;

	public static function HCLExtensionLinkEnd( $dummy, Title $target, array $options, &$html, array &$attribs, &$ret ) {
		if (isset($attribs['class'])) {
			return true; # don't mess with it if we have interwiki/broken/redirect
		} elseif ( self::pageInCategory("YMMV",  self::$CategoryYMMV,  $target) ) {
			$attribs['class'] = "ymmvlink";
		} elseif ( self::pageInCategory("Trope", self::$CategoryTrope, $target) ) {
			$attribs['class'] = "tropelink";
		}
		return true;
	}

	private static function pageInCategory ($category, &$categoryArray, $target) {
		if (! $categoryArray) {
			self::getCatHash($category, $categoryArray);
		}
		return isset($categoryArray[$target->getArticleID()]);
	}

	private static function getCatHash ($category, &$categoryArray) {
		# Check memcached first (can be commented out if the absence of memcached)
		$categoryArray = $wgMemc->get("HLCategoryList:$category");
		if ($categoryArray) { return; }

		# We need to look this up in the DB
		$underscored_category = $category;
		preg_replace( '/ /', '_', $underscored_category);
		$dbr = wfGetDB( DB_SLAVE );
		$res = $dbr->select( 'categorylinks', 'cl_from', array( 'cl_to' => $underscored_category ) );
		foreach ( $res as $row ) {
			$categoryArray[$row->cl_from] = True;  # map page ids to true for O(1) lookups
		}

		# Cache result for a day, and return (can be commented out if the absence of memcached)
		$wgMemc->set("HLCategoryList:$category", $categoryArray, 86400 );
		return;
	}

}


{'fraction_non_alphanumeric': 0.14660978895374943, 'fraction_numerical': 0.006511001347103727, 'mean_word_length': 4.486453201970443, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 30, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2105969', 'n_tokens_mistral': 1568, 'n_tokens_neox': 1435, 'n_words': 393}