Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…merge_requests/16/diffs (#44)

* Backport https://gitlab.wikimedia.org/repos/phabricator/extensions/-/merge_requests/16/diffs

* Update PhutilMediaWikiAuthAdapter.php

* Update PhabricatorMediaWikiAuthProvider.php

* CI: lint code to MediaWiki standards

Check commit and GitHub actions for more details

---------

Co-authored-by: github-actions <[email protected]>
  • Loading branch information
paladox and github-actions authored Jan 26, 2024
1 parent aac51b3 commit 63c7961
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/oauth/PhabricatorMediaWikiAuthProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function getWikiURI() {
$normalized .= ':' . $uri->getPort();
}

if ( strlen( ( $uri->getPath() ) ) > 0 && $uri->getPath() !== '/' ) {
if ( $uri->getPath() !== null && $uri->getPath() !== '' && $uri->getPath() !== '/' ) {
$normalized .= $uri->getPath();
}

Expand Down Expand Up @@ -143,7 +143,7 @@ public function processEditForm(
$key_secret = self::PROPERTY_CONSUMER_SECRET;
$key_consumer = self::PROPERTY_CONSUMER_KEY;

if ( !strlen( $values[$key_uri] ) ) {
if ( $values[$key_uri] === null || $values[$key_uri] === '' ) {
$errors[] = pht( 'MediaWiki base URI is required.' );
$issues[$key_uri] = pht( 'Required' );
} else {
Expand All @@ -157,12 +157,12 @@ public function processEditForm(
}
}

if ( !$is_setup && !strlen( $values[$key_secret] ) ) {
if ( !$is_setup && ( $values[$key_secret] === null || $values[$key_secret] === '' ) ) {
$errors[] = pht( 'Consumer Secret is required' );
$issues[$key_secret] = pht( 'Required' );
}

if ( !$is_setup && !strlen( $values[$key_consumer] ) ) {
if ( !$is_setup && ( $values[$key_consumer] === null || $values[$key_consumer] === '' ) ) {
$errors[] = pht( 'Consumer Key is required' );
$issues[$key_consumer] = pht( 'Required' );
}
Expand Down Expand Up @@ -251,7 +251,7 @@ public function extendEditForm(
);

if ( !$is_setup ) {
if ( !strlen( $config->getProperty( self::PROPERTY_CONSUMER_KEY ) ) ) {
if ( $config->getProperty( self::PROPERTY_CONSUMER_KEY ) === null || $config->getProperty( self::PROPERTY_CONSUMER_KEY ) === '' ) {
$form->appendRemarkupInstructions(
pht(
'NOTE: Copy the keys generated by the MediaWiki OAuth' .
Expand Down
6 changes: 3 additions & 3 deletions src/oauth/PhutilMediaWikiAuthAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function getAccountName() {
public function getAccountURI() {
$name = $this->getAccountName();

if ( strlen( $name ) ) {
if ( $name !== null && $name !== '' ) {
return $this->getWikiPageURI( 'User:' . $name );
}

Expand Down Expand Up @@ -132,7 +132,7 @@ private function getUserInfo() {
// We gen this so we can check for replay below:
$nonce = Filesystem::readRandomCharacters( 32 );

list( $body ) = $this->newOAuth1Future( $uri )
[ $body ] = $this->newOAuth1Future( $uri )
->setMethod( 'GET' )
->setNonce( $nonce )
->addHeader( 'User-Agent', __CLASS__ )
Expand Down Expand Up @@ -205,7 +205,7 @@ private function decodeAndVerifyJWT( $jwt, $nonce ) {

/** decode a JWT and verify the signature is valid */
private function decodeJWT( $jwt ) {
list( $headb64, $bodyb64, $sigb64 ) = explode( '.', $jwt );
[ $headb64, $bodyb64, $sigb64 ] = explode( '.', $jwt );

$header = json_decode( $this->urlsafeB64Decode( $headb64 ) );
$body = json_decode( $this->urlsafeB64Decode( $bodyb64 ) );
Expand Down

0 comments on commit 63c7961

Please sign in to comment.