Albert221 has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/400128 )
Change subject: Add minus-x and phpcs&phpcbf to composer test and fix
......................................................................
Add minus-x and phpcs&phpcbf to composer test and fix
Bug: T175794
Change-Id: I1a646b3b73d6cc46f60113a64595bd819226d9ad
---
A .phpcs.xml
M TweetANew.body.php
M TweetANew.php
M composer.json
M lib/GoogleURL.php
M lib/tmhOAuth.php
6 files changed, 67 insertions(+), 33 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/TweetANew
refs/changes/28/400128/1
diff --git a/.phpcs.xml b/.phpcs.xml
new file mode 100644
index 0000000..981820a
--- /dev/null
+++ b/.phpcs.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0"?>
+<ruleset>
+ <rule ref="./vendor/mediawiki/mediawiki-codesniffer/MediaWiki">
+ <exclude name="Generic.Files.LineLength.TooLong" />
+ <exclude
name="MediaWiki.WhiteSpace.SpaceBeforeSingleLineComment.NewLineComment" />
+ <exclude name="Generic.Files.LineLength.TooLong" />
+ <exclude name="MediaWiki.Commenting.FunctionComment.MissingParamTag" />
+ <exclude name="MediaWiki.Commenting.FunctionComment.MissingParamName"
/>
+ <exclude name="Generic.Files.LineLength.TooLong" />
+ <exclude
name="MediaWiki.WhiteSpace.SpaceBeforeSingleLineComment.NewLineComment" />
+ <exclude name="Generic.WhiteSpace.DisallowSpaceIndent.SpacesUsed" />
+ <exclude
name="MediaWiki.WhiteSpace.SpaceyParenthesis.SingleSpaceAfterOpenParenthesis" />
+ <exclude
name="Generic.ControlStructures.InlineControlStructure.NotAllowed" />
+ <exclude
name="MediaWiki.WhiteSpace.SpaceyParenthesis.SingleSpaceBeforeCloseParenthesis"
/>
+ <exclude name="MediaWiki.Files.ClassMatchesFilename.NotMatch" />
+ <exclude
name="MediaWiki.NamingConventions.LowerCamelFunctionsName.FunctionName" />
+ <exclude
name="MediaWiki.AlternativeSyntax.AlternativeSyntax.AlternativeSyntax" />
+ <exclude
name="MediaWiki.ControlStructures.IfElseStructure.SpaceAfterElse" />
+ <exclude name="MediaWiki.Commenting.FunctionComment.NotShortBoolParam"
/>
+ <exclude name="MediaWiki.Commenting.FunctionComment.ParamNameNoMatch"
/>
+ <exclude
name="MediaWiki.Commenting.FunctionComment.SpacingBeforeParamType" />
+ <exclude
name="Generic.Functions.FunctionCallArgumentSpacing.NoSpaceAfterComma" />
+ <exclude name="Generic.Arrays.DisallowLongArraySyntax.Found" />
+ <exclude name="MediaWiki.Commenting.FunctionComment.MissingReturn" />
+ <exclude
name="MediaWiki.ControlStructures.IfElseStructure.SpaceBeforeElse" />
+ <exclude
name="MediaWiki.WhiteSpace.DisallowEmptyLineFunctions.NoEmptyLine" />
+ <exclude
name="MediaWiki.Commenting.FunctionComment.MissingParamComment" />
+ <exclude
name="MediaWiki.Commenting.FunctionComment.MissingDocumentationPublic" />
+ <exclude name="Squiz.Operators.ValidLogicalOperators.NotAllowed" />
+ <exclude name="Generic.PHP.NoSilencedErrors.Discouraged" />
+ <exclude name="Squiz.Classes.ValidClassName.NotCamelCaps" />
+ <exclude name="PSR2.Classes.PropertyDeclaration.Underscore" />
+ </rule>
+ <file>.</file>
+ <arg name="extensions" value="php,php5,inc" />
+ <arg name="encoding" value="UTF-8" />
+</ruleset>
diff --git a/TweetANew.body.php b/TweetANew.body.php
old mode 100755
new mode 100644
index 5f1f4d0..3e00b2f
--- a/TweetANew.body.php
+++ b/TweetANew.body.php
@@ -25,7 +25,6 @@
# Check if $wgTweetANewTweet['New'] is enabled or the Tweet
checkbox was selected on the edit page
if ( $wgRequest->getCheck( 'wpTweetANew' ) ||
$wgTweetANewTweet['New'] ) {
-
# Check if page is in content namespace or if the Tweet
checkbox was selected on the edit page
if ( !MWNamespace::isContent(
$wikiPage->getTitle()->getNamespace() )
&& !$wgRequest->getCheck( 'wpTweetANew' )
@@ -107,7 +106,6 @@
# Check if $wgTweetANewTweet['Edit'] is enabled or the Tweet
checkbox was selected on the edit page
if ( $wgRequest->getCheck( 'wpTweetANewEdit' ) ||
$wgTweetANewTweet['Edit'] ) {
-
# Unless the tweet checkbox is selected, only proceeds
if page is outside content namespace
# and if a minor edit, checks
$wgTweetANewTweet['SkipMinor']
# Also prevents new articles from processing as
TweetANewNewArticle function is used instead
@@ -121,7 +119,7 @@
# Determine the time and date of last modification -
exit if newer than $wgTweetANewTweet['LessMinutesOld']
# ToDo - there must be a cleaner way of doing this
- $dbr = wfGetDB( DB_SLAVE );
+ $dbr = wfGetDB( DB_REPLICA );
$res = $dbr->select(
'revision',
array( 'rev_timestamp' ),
@@ -227,7 +225,6 @@
# Check setting to enable/disable use of bitly
if ( $wgTweetANewBitly['Enable'] ) {
-
# Generate url for bitly
$shortened =
"https://api-ssl.bitly.com/v3/shorten?longUrl="
. urlencode( $longurl ) . "&login=" .
$wgTweetANewBitly['Login']
@@ -237,7 +234,6 @@
$response = Http::get( $shortened );
} # Check setting to enable/disable use of goo.gl
elseif ( $wgTweetANewGoogl['Enable'] ) {
-
# Setup goo.gl
$url = new GoogleURL( $wgTweetANewGoogl['API'] );
diff --git a/TweetANew.php b/TweetANew.php
index 8f5eeed..3cacdd3 100644
--- a/TweetANew.php
+++ b/TweetANew.php
@@ -220,7 +220,6 @@
function efTweetANewEditCheckBox( $editpage, &$checkboxes, &$tabindex = null )
{
global $wgTweetANewEditpage, $wgTweetANewTweet;
-
$options = array(
'label-message' => null,
'id' => null,
diff --git a/composer.json b/composer.json
index aebd773..3e99105 100644
--- a/composer.json
+++ b/composer.json
@@ -1,11 +1,18 @@
{
"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/minus-x": "0.2.1"
},
"scripts": {
"test": [
- "parallel-lint . --exclude vendor --exclude
node_modules"
+ "parallel-lint . --exclude vendor --exclude
node_modules",
+ "phpcs",
+ "minus-x check ."
+ ],
+ "fix": [
+ "phpcbf",
+ "minus-x fix ."
]
}
}
diff --git a/lib/GoogleURL.php b/lib/GoogleURL.php
old mode 100755
new mode 100644
index 6160fab..04138a2
--- a/lib/GoogleURL.php
+++ b/lib/GoogleURL.php
@@ -14,15 +14,14 @@
/**
* Define google url shortener api
*/
-define("API_URL", "https://www.googleapis.com/urlshortener/v1/url?key=");
+define("API_URL", "https://www.googleapis.com/urlshortener/v1/url?key=");
/**
* GoogleURL to generate shorten and expend url
*
*
*/
-class GoogleURL
-{
+class GoogleURL {
/**
*
@@ -42,7 +41,7 @@
* @param string $apiKey
*/
public function __construct($apiKey) {
- //Google URL Shortener
+ // Google URL Shortener
$this->_apiUrl = API_URL.$apiKey;
}
@@ -53,8 +52,7 @@
* @param string $longUrl long url
* @return string shorten url
*/
- public function shorten($longUrl)
- {
+ public function shorten($longUrl) {
$data = $this->getContent($longUrl);
$this->_shortUrl = $data->id;
return $data->id;
@@ -67,8 +65,7 @@
* @param string $shortUrl
* @return string
*/
- public function expand($shortUrl)
- {
+ public function expand($shortUrl) {
$data = $this->getContent($shortUrl, "expand");
$this->_shortUrl = $data->id;
return $data->longUrl;
@@ -80,17 +77,17 @@
* @access public
* @return int
*/
- public function getLongUrlCliks(){
+ public function getLongUrlCliks() {
$data = $this->getContent($this->_shortUrl, 'info');
return $data->analytics->allTime->longUrlClicks;
}
/**
* Get number of short url click
- *
+ *
* @access public
* @return int
*/
- public function getShortUrlClicks(){
+ public function getShortUrlClicks() {
$data = $this->getContent($this->_shortUrl, 'info');
return $data->analytics->allTime->shortUrlClicks;
}
@@ -102,29 +99,27 @@
* @param string $requestType
* @return string json format
*/
- private function getContent( $url, $requestType = "shorten" ){
+ private function getContent( $url, $requestType = "shorten" ) {
$curl = curl_init();
-
- if( $requestType === "expand" ){
+
+ if ( $requestType === "expand" ) {
curl_setopt($curl, CURLOPT_URL, $this->_apiUrl.'&shortUrl='.$url);
- }else if( $requestType === "info" ){
+ }elseif ( $requestType === "info" ) {
curl_setopt($curl, CURLOPT_URL,
$this->_apiUrl.'&shortUrl='.$url.'&projection=FULL');
}else{
curl_setopt($curl, CURLOPT_URL, $this->_apiUrl);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode(array('longUrl'
=> $url)));
}
-
+
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_HTTPHEADER,
array('Content-type:application/json'));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($curl);
curl_close($curl);
- //change the response json string to object
+ // change the response json string to object
return json_decode($response);
}
}
-
-?>
\ No newline at end of file
diff --git a/lib/tmhOAuth.php b/lib/tmhOAuth.php
index c8fe2ce..2d57f70 100644
--- a/lib/tmhOAuth.php
+++ b/lib/tmhOAuth.php
@@ -17,7 +17,7 @@
/**
* Creates a new tmhOAuth object
*
- * @param string $config, the configuration to use for this request
+ * @param string $config the configuration to use for this request
*/
function __construct($config) {
$this->params = array();
@@ -58,8 +58,8 @@
'curl_ssl_verifypeer' => true,
// you can get the latest cacert.pem from here
http://curl.haxx.se/ca/cacert.pem
- 'curl_cainfo' => dirname(__FILE__) . '/cacert.pem',
- 'curl_capath' => dirname(__FILE__),
+ 'curl_cainfo' => __DIR__ . '/cacert.pem',
+ 'curl_capath' => __DIR__,
'curl_followlocation' => false, // whether to follow redirects
or not
@@ -136,7 +136,7 @@
private function safe_encode($data) {
if (is_array($data)) {
return array_map(array($this, 'safe_encode'), $data);
- } else if (is_scalar($data)) {
+ } elseif (is_scalar($data)) {
return str_ireplace(
array('+', '%7E'),
array(' ', '~'),
@@ -157,7 +157,7 @@
private function safe_decode($data) {
if (is_array($data)) {
return array_map(array($this, 'safe_decode'), $data);
- } else if (is_scalar($data)) {
+ } elseif (is_scalar($data)) {
return rawurldecode($data);
} else {
return '';
@@ -653,4 +653,4 @@
$this->response['errno'] = $errno;
return $code;
}
-}
\ No newline at end of file
+}
--
To view, visit https://gerrit.wikimedia.org/r/400128
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I1a646b3b73d6cc46f60113a64595bd819226d9ad
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/TweetANew
Gerrit-Branch: master
Gerrit-Owner: Albert221 <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits