Umherirrender has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/354872 )
Change subject: Add phpcs and make pass
......................................................................
Add phpcs and make pass
Change-Id: I8d7db66655d983eb295f302f38ab27fd711f23e5
---
M RSSData.php
M RSSHooks.php
M RSSParser.php
M composer.json
A phpcs.xml
5 files changed, 73 insertions(+), 52 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/RSS
refs/changes/72/354872/1
diff --git a/RSSData.php b/RSSData.php
index 9ac81c5..4489532 100644
--- a/RSSData.php
+++ b/RSSData.php
@@ -29,7 +29,7 @@
}
foreach ( $items as $item ) {
- $bit = array();
+ $bit = [];
foreach ( $item->childNodes as $n ) {
$name = $this->rssTokenToName( $n->nodeName );
if ( $name != null ) {
@@ -60,7 +60,7 @@
*/
protected function rssTokenToName( $name ) {
- $tokenNames = array(
+ $tokenNames = [
'dc:date' => 'date',
'pubDate' => 'date',
'updated' => 'date',
@@ -75,7 +75,7 @@
'slash:hit_parade' => null,
'slash:section' => null,
'wfw:commentRss' => null,
- );
+ ];
if ( array_key_exists( $name, $tokenNames ) ) {
return $tokenNames[ $name ];
diff --git a/RSSHooks.php b/RSSHooks.php
index 24acfd2..2af1f89 100644
--- a/RSSHooks.php
+++ b/RSSHooks.php
@@ -8,8 +8,8 @@
* @return bool
*/
static function onParserFirstCallInit( $parser ) {
- # Install parser hook for <rss> tags
- $parser->setHook( 'rss', array( __CLASS__, 'renderRss' ) );
+ // Install parser hook for <rss> tags
+ $parser->setHook( 'rss', [ __CLASS__, 'renderRss' ] );
return true;
}
@@ -31,7 +31,7 @@
$ns = $parser->getTitle()->getNamespace();
$checkNS = array_flip( $wgRSSNamespaces );
- if( !isset( $checkNS[$ns] ) ) {
+ if ( !isset( $checkNS[$ns] ) ) {
return RSSUtils::RSSError( 'rss-ns-permission'
);
}
}
@@ -63,7 +63,7 @@
$numberAllowed = $parser->getFunctionLang()->formatNum(
count( $wgRSSUrlWhitelist ) );
return RSSUtils::RSSError( 'rss-url-is-not-whitelisted',
- array( $input, $listOfAllowed, $numberAllowed )
+ [ $input, $listOfAllowed, $numberAllowed ]
);
}
diff --git a/RSSParser.php b/RSSParser.php
index 5d5759d..a59f2f1 100644
--- a/RSSParser.php
+++ b/RSSParser.php
@@ -5,19 +5,18 @@
protected $date = "Y-m-d H:i:s";
protected $ItemMaxLength = 200;
protected $reversed = false;
- protected $highlight = array();
- protected $filter = array();
- protected $filterOut = array();
+ protected $highlight = [];
+ protected $filter = [];
+ protected $filterOut = [];
protected $itemTemplate;
protected $url;
protected $etag;
protected $lastModified;
protected $xml;
protected $error;
- protected $displayFields = array( 'author', 'title', 'encodedContent',
'description' );
+ protected $displayFields = [ 'author', 'title', 'encodedContent',
'description' ];
protected $stripItems;
protected $markerString;
-
/**
* @var RSSData
@@ -36,7 +35,7 @@
*/
private static function explodeOnSpaces( $str ) {
$found = preg_split( '# +#', $str );
- return is_array( $found ) ? $found : array();
+ return is_array( $found ) ? $found : [];
}
/**
@@ -50,7 +49,7 @@
$this->url = $url;
$this->markerString = wfRandomString( 32 );
- $this->stripItems = array();
+ $this->stripItems = [];
# Get max number of headlines from argument-array
if ( isset( $args['max'] ) ) {
@@ -131,14 +130,14 @@
// if the attribute parameter templatename= is not
present
// then it defaults to
- // {{ Template:RSSPost | title = {{{title}}} | ... }} -
if Template:RSSPost exists from pre-1.9 versions
- // {{ MediaWiki:Rss-feed | title = {{{title}}} | ... }}
- otherwise
+ // {{ Template:RSSPost | title = {{{title}}} | ... }}
+ // - if Template:RSSPost exists from pre-1.9
versions
+ // {{ MediaWiki:Rss-feed | title = {{{title}}} | ... }}
+ // - otherwise
$this->itemTemplate = wfMessage( 'rss-item',
$feedTemplatePagename )->plain();
-
}
}
-
function insertStripItem( $item ) {
$this->stripItems[] = $item;
@@ -228,10 +227,10 @@
return false;
}
$r = $wgMemc->set( $key,
- array( $this->etag, $this->lastModified, $this->rss ),
+ [ $this->etag, $this->lastModified, $this->rss ],
$wgRSSCacheAge );
- wfDebugLog( 'RSS', "Stored '$key' as in cache? $r");
+ wfDebugLog( 'RSS', "Stored '$key' as in cache? $r" );
return true;
}
@@ -241,7 +240,7 @@
* @param $headers Array: headers to send along with the request
* @return Status object
*/
- protected function fetchRemote( $key, array $headers = array()) {
+ protected function fetchRemote( $key, array $headers = [] ) {
global $wgRSSFetchTimeout, $wgRSSUserAgent, $wgRSSProxy,
$wgRSSUrlNumberOfAllowedRedirects;
@@ -268,7 +267,7 @@
* forthcoming version.
*/
- $url = $this->url;
+ $url = $this->url;
$noProxy = !isset( $wgRSSProxy );
// Example for disabling proxy use for certain urls
@@ -284,14 +283,14 @@
// we set followRedirects intentionally to true to see error
messages
// in cases where the maximum number of redirects is reached
$client = MWHttpRequest::factory( $url,
- array(
+ [
'timeout' => $wgRSSFetchTimeout,
'followRedirects' => true,
'maxRedirects' => $maxRedirects,
'proxy' => $wgRSSProxy,
'noProxy' => $noProxy,
'userAgent' => $wgRSSUserAgent,
- )
+ ]
);
foreach ( $headers as $header => $value ) {
@@ -407,7 +406,8 @@
case 'date':
$tempTimezone =
date_default_timezone_get();
date_default_timezone_set( 'UTC' );
- $txt = date( $this->date, strtotime(
$this->escapeTemplateParameter( $item['date'] ) ) );
+ $txt = date( $this->date,
+ strtotime(
$this->escapeTemplateParameter( $item['date'] ) ) );
date_default_timezone_set(
$tempTimezone );
$renderedItem = str_replace(
'{{{date}}}', $txt, $renderedItem );
break;
@@ -415,7 +415,8 @@
$str = $this->escapeTemplateParameter(
$item[$info] );
$str =
$parser->getFunctionLang()->truncate( $str, $this->ItemMaxLength );
$str = $this->highlightTerms( $str );
- $renderedItem = str_replace( '{{{' .
$info . '}}}', $this->insertStripItem( $str ), $renderedItem );
+ $renderedItem = str_replace( '{{{' .
$info . '}}}',
+ $this->insertStripItem( $str ),
$renderedItem );
}
}
}
@@ -439,13 +440,13 @@
$url = preg_replace( '/[\000-\037\177]/', '', trim( $url ) );
# Escape other problematic characters
$out = '';
- for ( $i = 0; $i < strlen( $url ); $i++ ) {
+ for ( $i = 0, $len = strlen( $url ); $i < $len; $i++ ) {
$boringLength = strcspn( $url, '<>"[|]\ {', $i );
if ( $boringLength ) {
$out .= substr( $url, $i, $boringLength );
$i += $boringLength;
}
- if ( $i < strlen( $url ) ) {
+ if ( $i < $len ) {
$out .= rawurlencode( $url[$i] );
}
}
@@ -469,8 +470,8 @@
protected function escapeTemplateParameter( $text ) {
global $wgRSSAllowLinkTag, $wgRSSAllowImageTag;
- $extraInclude = array();
- $extraExclude = array( "iframe" );
+ $extraInclude = [];
+ $extraExclude = [ "iframe" ];
if ( isset( $wgRSSAllowLinkTag ) && $wgRSSAllowLinkTag ) {
$extraInclude[] = "a";
@@ -487,36 +488,40 @@
if ( ( isset( $wgRSSAllowLinkTag ) && $wgRSSAllowLinkTag )
|| ( isset( $wgRSSAllowImageTag ) &&
$wgRSSAllowImageTag ) ) {
- $ret = Sanitizer::removeHTMLtags( $text, null, array(),
$extraInclude, $extraExclude );
+ $ret = Sanitizer::removeHTMLtags( $text, null, [],
$extraInclude, $extraExclude );
} else { // use the old escape method for a while
$text = str_replace(
- array( '[', '|', ']', '\'',
'ISBN ',
+ [
+ '[', '|', ']', '\'',
'ISBN ',
'RFC ', '://', "\n=", '{{',
'}}',
- ),
- array( '[', '|', ']', ''',
'ISBN ',
+ ],
+ [
+ '[', '|', ']', ''',
'ISBN ',
'RFC ', '://', "\n=",
'{{', '}}',
- ),
+ ],
htmlspecialchars( str_replace( "\n", "", $text
) )
);
// keep some basic layout tags
$ret = str_replace(
- array( '<p>', '</p>',
+ [
+ '<p>', '</p>',
'<br/>', '<br>',
'</br>',
'<b>', '</b>',
'<i>', '</i>',
'<u>', '</u>',
'<s>', '</s>',
- ),
- array( "", "<br/>",
+ ],
+ [
+ "", "<br/>",
"<br/>", "<br/>", "<br/>",
"'''", "'''",
"''", "''",
"<u>", "</u>",
"<s>", "</s>",
- ),
+ ],
$text
);
}
@@ -540,7 +545,7 @@
$this->xml = new DOMDocument;
$raw_xml = $this->client->getContent();
- if( $raw_xml == '' ) {
+ if ( $raw_xml == '' ) {
return Status::newFatal( 'rss-parse-error', 'No
XML content' );
}
@@ -615,7 +620,8 @@
}
/* Using : for delimiter here since it'll be quoted
automatically. */
- $match = preg_match( ':(' . implode( '|', array_map(
'preg_quote', $filter ) ) . '):i', $text ) ;
+ $match = preg_match( ':(' . implode( '|',
+ array_map( 'preg_quote', $filter ) ) . '):i', $text );
if ( $match ) {
return true;
}
@@ -634,18 +640,20 @@
}
$terms = array_flip( array_map( 'strtolower', $this->highlight
) );
- $highlight = ':'. implode( '|', array_map( 'preg_quote',
array_values( $this->highlight ) ) ) . ':i';
+ $highlight = ':' . implode( '|',
+ array_map( 'preg_quote', array_values( $this->highlight
) ) ) . ':i';
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>';
+ $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',
+ $bgcolor = [ '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' );
+ '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' );
+ $color = [ 'black', 'black', 'black', 'black', 'black',
+ 'white', 'white', 'white', 'white', 'white' ];
$index = $terms[strtolower( $match[0] )] % count(
$bgcolor );
@@ -668,8 +676,9 @@
// since the cache doesn't vary by user language: use
->inContentLanguage()
// The ->parse() part makes everything safe from an escaping
standpoint.
- return Html::rawElement( 'span', array( 'class' => 'error' ),
- "Extension:RSS -- Error: " . wfMessage(
$errorMessageName )->inContentLanguage()->params( $param )->parse()
+ return Html::rawElement( 'span', [ 'class' => 'error' ],
+ "Extension:RSS -- Error: " . wfMessage(
$errorMessageName )
+ ->inContentLanguage()->params( $param )->parse()
);
}
diff --git a/composer.json b/composer.json
index 686b65b..b8f68fb 100644
--- a/composer.json
+++ b/composer.json
@@ -1,11 +1,14 @@
{
"require-dev": {
"jakub-onderka/php-parallel-lint": "0.9.2",
- "jakub-onderka/php-console-highlighter": "0.3.2"
+ "jakub-onderka/php-console-highlighter": "0.3.2",
+ "mediawiki/mediawiki-codesniffer": "0.7.2"
},
"scripts": {
+ "fix": "phpcbf",
"test": [
- "parallel-lint . --exclude vendor"
+ "parallel-lint . --exclude vendor",
+ "phpcs -p -s"
]
}
}
diff --git a/phpcs.xml b/phpcs.xml
new file mode 100644
index 0000000..ede6c5d
--- /dev/null
+++ b/phpcs.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ruleset>
+ <rule ref="vendor/mediawiki/mediawiki-codesniffer/MediaWiki"/>
+ <file>.</file>
+ <arg name="extensions" value="php,php5,inc"/>
+ <arg name="encoding" value="utf8"/>
+ <exclude-pattern>vendor</exclude-pattern>
+ <exclude-pattern>node_modules</exclude-pattern>
+</ruleset>
--
To view, visit https://gerrit.wikimedia.org/r/354872
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I8d7db66655d983eb295f302f38ab27fd711f23e5
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/RSS
Gerrit-Branch: master
Gerrit-Owner: Umherirrender <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits