Paladox has uploaded a new change for review.
https://gerrit.wikimedia.org/r/264960
Change subject: Fix some js and php code style
......................................................................
Fix some js and php code style
Change-Id: I256183aded6f2c7e787c18b7f0020b646673b6a2
---
M SocialLogin.body.php
M SocialLogin.php
2 files changed, 58 insertions(+), 33 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/SocialLogin
refs/changes/60/264960/1
diff --git a/SocialLogin.body.php b/SocialLogin.body.php
index dbe9077..64fde57 100644
--- a/SocialLogin.body.php
+++ b/SocialLogin.body.php
@@ -2,31 +2,18 @@
interface SocialLoginPlugin {
public static function login( $code );
public static function check( $id, $access_token );
- public static function loginUrl( );
-}
-
-function SLgetContents( $url, $data = false ) {
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_POST, $data?1:0);
- if ($data) curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_TIMEOUT, 10);
- $output = curl_exec($ch);
- curl_close($ch);
- return $output;
+ public static function loginUrl();
}
class SocialLogin extends SpecialPage {
- function __construct( ) {
+ function __construct() {
global $wgHooks;
- parent::__construct('SocialLogin');
+ parent::__construct( 'SocialLogin' );
$wgHooks['UserLoadAfterLoadFromSession'][] = $this;
}
- static function getContents( $url, $data = false ) {
- $ch = curl_init();
+ public function SLgetContents( $url, $data = false ) {
+ $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, $data?1:0);
@@ -38,8 +25,20 @@
return $output;
}
- static function translit( $str )
- {
+ static function getContents( $url, $data = false ) {
+ $ch = curl_init();
+ curl_setopt($ch, CURLOPT_URL, $url);
+ curl_setopt($ch, CURLOPT_HEADER, 0);
+ curl_setopt($ch, CURLOPT_POST, $data?1:0);
+ if ($data) curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+ curl_setopt($ch, CURLOPT_TIMEOUT, 10);
+ $output = curl_exec($ch);
+ curl_close($ch);
+ return $output;
+ }
+
+ static function translit( $str ) {
$tr = array(
"А"=>"A","Б"=>"B","В"=>"V","Г"=>"G",
"Д"=>"D","Е"=>"E","Ж"=>"J","З"=>"Z","И"=>"I",
@@ -84,13 +83,19 @@
$possibles = array();
foreach ($names as $name) {
$name = SocialLogin::processName($name);
- if (!$name) continue;
+ if (!$name) {
+ continue;
+ }
$possibles[] = $name;
- if (!SocialLogin::userExist($name)) return $name;
+ if (!SocialLogin::userExist($name)) {
+ return $name;
+ }
}
foreach ($possibles as $possible) {
$i = 1;
- while(SocialLogin::userExist($possible . "_$i")) $i++;
+ while(SocialLogin::userExist($possible . "_$i")) {
+ $i++;
+ }
return $possible . "_$i";
}
@@ -135,33 +140,44 @@
} else {
$wgOut->addHTML("</table>");
}
- $wgOut->addHeadItem('Authorization', "<script
type='text/javascript' src='/extensions/SocialLogin/auth.js'></script>");
- $scripts = "$(function() {";
+ $wgOut->addModules( array( 'sociallogin.js' ) );
+ $scripts = "jQuery(function() {";
foreach ($wgSocialLoginServices as $key =>
$name) {
$s = explode('.', $key);
$s = $s[0];
$scripts .= "
- $('.$s').click(function() {
+ jQuery('.$s').click(function() {
login('" .
call_user_func(array(str_replace(".", "_", $key), "loginUrl")) . "',
function(code) {
tryLogin({service: '$key', code: code}, function(response) {
- if
(response == 'yes') document.location.href = '/';
- else
hacking();
+ if
(response == 'yes') {
+
document.location.href = '/';
+ } else {
+
hacking();
+ }
});
});
});";
}
$scripts .= "});";
- $wgOut->addHeadItem('Login scripts', "<script
type='text/javascript'>$scripts</script>");
- if ($wgSocialLoginAddForms &&
!$user->isLoggedIn())
$wgOut->addHTML($this->msg('sl-login-register')->escaped());
+ $wgOut->addHeadItem( 'Login scripts',
Html::inlineScript( ResourceLoader::makeInlineScript( $scripts ) ) ) );
+ if ($wgSocialLoginAddForms &&
!$user->isLoggedIn()) {
+
$wgOut->addHTML($this->msg('sl-login-register')->escaped());
+ }
break;
case "signin":
$name =
$wgContLang->ucfirst($wgRequest->getText('name'));
$pass = $wgRequest->getText('pass');
$error = "";
- if (!User::isValidUserName($name)) $error .=
"<li>" . $this->msg('sl-invalid-name', $name)->escaped() . "</li>";
- if (!SocialLogin::userExist($name)) $error .=
"<li>" . $this->msg('sl-user-not-exist', $name)->escaped() . "</li>";
+ if (!User::isValidUserName($name)) {
+ $error .= "<li>" .
$this->msg('sl-invalid-name', $name)->escaped() . "</li>";
+ }
+ if (!SocialLogin::userExist($name)) {
+ $error .= "<li>" .
$this->msg('sl-user-not-exist', $name)->escaped() . "</li>";
+ }
$newUser = User::newFromName($name);
- if (!$newUser->isValidPassword($pass)) $error
.= "<li>" . $this->msg('sl-invalid-password')->escaped() . "</li>";
+ if (!$newUser->isValidPassword($pass)) {
+ $error .= "<li>" .
$this->msg('sl-invalid-password')->escaped() . "</li>";
+ }
if ($error) {
$wgOut->addHTML("<ul
class='error'>$error</ul>");
} else {
diff --git a/SocialLogin.php b/SocialLogin.php
index b819d84..b32e6f8 100644
--- a/SocialLogin.php
+++ b/SocialLogin.php
@@ -22,3 +22,12 @@
$wgExtensionMessagesFiles['SocialLogin'] = $dir . 'SocialLogin.i18n.php';
$wgExtensionMessagesFiles['SocialLoginAlias'] = $dir . 'SocialLogin.alias.php';
$wgSpecialPages['sociallogin'] = 'SocialLogin'; # Сообщите MediaWiki о Вашей
новой спецстранице.
+
+$wgResourceModules['sociallogin.js'] = array(
+ 'position' => 'top',
+ 'scripts' => array(
+ 'SocialLogin/auth.js',
+ ),
+ 'remoteBasePath' => &$GLOBALS['wgStylePath'],
+ 'localBasePath' => &$GLOBALS['wgStyleDirectory']
+);
--
To view, visit https://gerrit.wikimedia.org/r/264960
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I256183aded6f2c7e787c18b7f0020b646673b6a2
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/SocialLogin
Gerrit-Branch: master
Gerrit-Owner: Paladox <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits