jenkins-bot has submitted this change and it was merged.
Change subject: Merge RSSHighlighter class into RSSParser::highlightTerms()
......................................................................
Merge RSSHighlighter class into RSSParser::highlightTerms()
There is no other caller.
Change-Id: Ia3b62e45b8bbcc7c3cee60f1e3cd962fba7efe8a
---
M RSS.php
M RSSParser.php
2 files changed, 14 insertions(+), 36 deletions(-)
Approvals:
Reedy: Looks good to me, approved
jenkins-bot: Verified
diff --git a/RSS.php b/RSS.php
index 9b1317b..dc01f91 100644
--- a/RSS.php
+++ b/RSS.php
@@ -40,7 +40,6 @@
$wgAutoloadClasses['RSSHooks'] = $dir . 'RSSHooks.php';
$wgAutoloadClasses['RSSParser'] = $dir . 'RSSParser.php';
$wgAutoloadClasses['RSSUtils'] = $dir . 'RSSParser.php';
-$wgAutoloadClasses['RSSHighlighter'] = $dir . 'RSSParser.php';
$wgAutoloadClasses['RSSData'] = $dir . 'RSSData.php';
// List tracking category on Special:TrackingCategories
diff --git a/RSSParser.php b/RSSParser.php
index b1702c1..628623d 100644
--- a/RSSParser.php
+++ b/RSSParser.php
@@ -626,45 +626,24 @@
return $text;
}
- RSSHighlighter::setTerms( $this->highlight );
+ $terms = array_flip( array_map( 'strtolower', $this->highlight
) );
$highlight = ':'. implode( '|', array_map( 'preg_quote',
array_values( $this->highlight ) ) ) . ':i';
- return preg_replace_callback( $highlight,
'RSSHighlighter::highlightThis', $text );
- }
-}
+ return preg_replace_callback( $highlight, function ( $match )
use ( $terms ) {
+ $styleStart = "<span style='font-weight: bold;
background: none repeat scroll 0%% 0%% rgb(%s); color: %s;'>";
+ $styleEnd = '</span>';
-class RSSHighlighter {
- static $terms = array();
+ # bg colors cribbed from Google's highlighting of
search terms
+ $bgcolor = array( '255, 255, 102', '160, 255, 255',
'153, 255, 153',
+ '255, 153, 153', '255, 102, 255', '136, 0, 0',
'0, 170, 0', '136, 104, 0',
+ '0, 70, 153', '153, 0, 153' );
+ # Spelling out the fg colors instead of using
processing time to create this list
+ $color = array( 'black', 'black', 'black', 'black',
'black',
+ 'white', 'white', 'white', 'white', 'white' );
- /**
- * Set the list of terms to match for the next highlighting session
- * @param $terms Array: list of words to match.
- */
- static function setTerms( array $terms ) {
- self::$terms = array_flip( array_map( 'strtolower', $terms ) );
- }
+ $index = $terms[strtolower( $match[0] )] % count(
$bgcolor );
- /**
- * Actually replace the supplied list of words with HTML code to
highlight the words.
- * @param $match Array: list of matched words to highlight.
- * The words are assigned colors based upon the order
- * they were supplied in setTerms()
- * @return String word wrapped in HTML code.
- */
- static function highlightThis( $match ) {
- $styleStart = "<span style='font-weight: bold; background: none
repeat scroll 0%% 0%% rgb(%s); color: %s;'>";
- $styleEnd = '</span>';
-
- # bg colors cribbed from Google's highlighting of search terms
- $bgcolor = array( '255, 255, 102', '160, 255, 255', '153, 255,
153',
- '255, 153, 153', '255, 102, 255', '136, 0, 0', '0, 170,
0', '136, 104, 0',
- '0, 70, 153', '153, 0, 153' );
- # Spelling out the fg colors instead of using processing time
to create this list
- $color = array( 'black', 'black', 'black', 'black', 'black',
- 'white', 'white', 'white', 'white', 'white' );
-
- $index = self::$terms[strtolower( $match[0] )] % count(
$bgcolor );
-
- return sprintf( $styleStart, $bgcolor[$index], $color[$index] )
. $match[0] . $styleEnd;
+ return sprintf( $styleStart, $bgcolor[$index],
$color[$index] ) . $match[0] . $styleEnd;
+ }, $text );
}
}
--
To view, visit https://gerrit.wikimedia.org/r/187930
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ia3b62e45b8bbcc7c3cee60f1e3cd962fba7efe8a
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/RSS
Gerrit-Branch: master
Gerrit-Owner: PleaseStand <[email protected]>
Gerrit-Reviewer: MarkAHershberger <[email protected]>
Gerrit-Reviewer: Reedy <[email protected]>
Gerrit-Reviewer: Wikinaut <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits