From: jenkins-bot Date: Mon, 30 Sep 2019 19:47:47 +0000 (+0000) Subject: Merge "RevisionStore::newRevisionFromBatch should use Title::newFromRow" X-Git-Tag: 1.34.0-rc.0~38 X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=328f50b982b7da8adf0104fe246cea6aae595ae3;hp=2709495dea3b69740435e3d2cfa9944f04a0c86c Merge "RevisionStore::newRevisionFromBatch should use Title::newFromRow" --- diff --git a/includes/libs/filebackend/FileBackendStore.php b/includes/libs/filebackend/FileBackendStore.php index d7d428ebff..ffb8793ccf 100644 --- a/includes/libs/filebackend/FileBackendStore.php +++ b/includes/libs/filebackend/FileBackendStore.php @@ -1440,7 +1440,10 @@ abstract class FileBackendStore extends FileBackend { $name = strtolower( $name ); $maxHVLen = in_array( $name, $longs ) ? INF : 255; if ( strlen( $name ) > 255 || strlen( $value ) > $maxHVLen ) { - trigger_error( "Header '$name: $value' is too long." ); + $this->logger->error( "Header '{header}' is too long.", [ + 'filebackend' => $this->name, + 'header' => "$name: $value", + ] ); } else { $newHeaders[$name] = strlen( $value ) ? $value : ''; // null/false => "" } @@ -1789,7 +1792,9 @@ abstract class FileBackendStore extends FileBackend { */ final protected function deleteContainerCache( $container ) { if ( !$this->memCache->delete( $this->containerCacheKey( $container ), 300 ) ) { - trigger_error( "Unable to delete stat cache for container $container." ); + $this->logger->warning( "Unable to delete stat cache for container {container}.", + [ 'filebackend' => $this->name, 'container' => $container ] + ); } } @@ -1887,7 +1892,9 @@ abstract class FileBackendStore extends FileBackend { return; // invalid storage path } if ( !$this->memCache->delete( $this->fileCacheKey( $path ), 300 ) ) { - trigger_error( "Unable to delete stat cache for file $path." ); + $this->logger->warning( "Unable to delete stat cache for file {path}.", + [ 'filebackend' => $this->name, 'path' => $path ] + ); } } diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index 9ec58346cc..ccc46bb425 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -759,7 +759,7 @@ class Parser { if ( $this->mGeneratedPPNodeCount > $this->mOptions->getMaxGeneratedPPNodeCount() / 10 ) { wfDebugLog( 'generated-pp-node-count', $this->mGeneratedPPNodeCount . ' ' . - $this->mTitle->getPrefixedDBkey() ); + $this->getTitle()->getPrefixedDBkey() ); } return $text; } @@ -906,9 +906,9 @@ class Parser { /** * Set the context title * - * @param Title $t + * @param Title|null $t */ - public function setTitle( $t ) { + public function setTitle( Title $t = null ) { if ( !$t ) { $t = Title::makeTitle( NS_SPECIAL, 'Badtitle/Parser' ); } @@ -924,9 +924,9 @@ class Parser { /** * Accessor for the Title object * - * @return Title|null + * @return Title */ - public function getTitle() { + public function getTitle() : Title { return $this->mTitle; } @@ -936,7 +936,7 @@ class Parser { * @param Title|null $x Title object or null to just get the current one * @return Title */ - public function Title( $x = null ) { + public function Title( Title $x = null ) : Title { return wfSetVar( $this->mTitle, $x ); } @@ -1022,7 +1022,6 @@ class Parser { * * @since 1.19 * - * @throws MWException * @return Language */ public function getTargetLanguage() { @@ -1032,11 +1031,9 @@ class Parser { return $target; } elseif ( $this->mOptions->getInterfaceMessage() ) { return $this->mOptions->getUserLangObj(); - } elseif ( is_null( $this->mTitle ) ) { - throw new MWException( __METHOD__ . ': $this->mTitle is null' ); } - return $this->mTitle->getPageLanguage(); + return $this->getTitle()->getPageLanguage(); } /** @@ -1676,7 +1673,14 @@ class Parser { } $url = wfMessage( $urlmsg, $id )->inContentLanguage()->text(); $this->addTrackingCategory( $trackingCat ); - return Linker::makeExternalLink( $url, "{$keyword} {$id}", true, $cssClass, [], $this->mTitle ); + return Linker::makeExternalLink( + $url, + "{$keyword} {$id}", + true, + $cssClass, + [], + $this->getTitle() + ); } elseif ( isset( $m[6] ) && $m[6] !== '' && $this->mOptions->getMagicISBNLinks() ) { @@ -1771,7 +1775,7 @@ class Parser { $text = Linker::makeExternalLink( $url, $this->getTargetLanguage()->getConverter()->markNoConversion( $url ), true, 'free', - $this->getExternalLinkAttribs( $url ), $this->mTitle ); + $this->getExternalLinkAttribs( $url ), $this->getTitle() ); # Register it in the output object... $this->mOutput->addExternalLink( $url ); } @@ -2069,7 +2073,7 @@ class Parser { # Funny characters like ö aren't valid in URLs anyway # This was changed in August 2004 $s .= Linker::makeExternalLink( $url, $text, false, $linktype, - $this->getExternalLinkAttribs( $url ), $this->mTitle ) . $dtrail . $trail; + $this->getExternalLinkAttribs( $url ), $this->getTitle() ) . $dtrail . $trail; # Register link in the output object. $this->mOutput->addExternalLink( $url ); @@ -2110,7 +2114,7 @@ class Parser { */ public function getExternalLinkAttribs( $url ) { $attribs = []; - $rel = self::getExternalLinkRel( $url, $this->mTitle ); + $rel = self::getExternalLinkRel( $url, $this->getTitle() ); $target = $this->mOptions->getExternalLinkTarget(); if ( $target ) { @@ -2286,7 +2290,6 @@ class Parser { /** * Process [[ ]] wikilinks (RIL) * @param string &$s - * @throws MWException * @return LinkHolderArray * * @private @@ -2312,10 +2315,7 @@ class Parser { $line = $a->current(); # Workaround for broken ArrayIterator::next() that returns "void" $s = substr( $s, 1 ); - if ( is_null( $this->mTitle ) ) { - throw new MWException( __METHOD__ . ": \$this->mTitle is null\n" ); - } - $nottalk = !$this->mTitle->isTalkPage(); + $nottalk = !$this->getTitle()->isTalkPage(); $useLinkPrefixExtension = $this->getTargetLanguage()->linkPrefixExtension(); $e2 = null; @@ -2509,7 +2509,7 @@ class Parser { } if ( $ns == NS_FILE ) { - if ( !$this->badFileLookup->isBadFile( $nt->getDBkey(), $this->mTitle ) ) { + if ( !$this->badFileLookup->isBadFile( $nt->getDBkey(), $this->getTitle() ) ) { if ( $wasblank ) { # if no parameters were passed, $text # becomes something like "File:Foo.png", @@ -2551,7 +2551,7 @@ class Parser { # Self-link checking. For some languages, variants of the title are checked in # LinkHolderArray::doVariants() to allow batching the existence checks necessary # for linking to a different variant. - if ( $ns != NS_SPECIAL && $nt->equals( $this->mTitle ) && !$nt->hasFragment() ) { + if ( $ns != NS_SPECIAL && $nt->equals( $this->getTitle() ) && !$nt->hasFragment() ) { $s .= $prefix . Linker::makeSelfLinkObj( $nt, $text, '', $trail ); continue; } @@ -2635,7 +2635,7 @@ class Parser { */ public function areSubpagesAllowed() { # Some namespaces don't allow subpages - return $this->nsInfo->hasSubpages( $this->mTitle->getNamespace() ); + return $this->nsInfo->hasSubpages( $this->getTitle()->getNamespace() ); } /** @@ -2647,7 +2647,7 @@ class Parser { * @private */ public function maybeDoSubpageLink( $target, &$text ) { - return Linker::normalizeSubpageLink( $this->mTitle, $target, $text ); + return Linker::normalizeSubpageLink( $this->getTitle(), $target, $text ); } /** @@ -2670,19 +2670,9 @@ class Parser { * @param string $index Magic variable identifier as mapped in MagicWordFactory::$mVariableIDs * @param bool|PPFrame $frame * - * @throws MWException * @return string */ public function getVariableValue( $index, $frame = false ) { - if ( is_null( $this->mTitle ) ) { - // If no title set, bad things are going to happen - // later. Title should always be set since this - // should only be called in the middle of a parse - // operation (but the unit-tests do funky stuff) - throw new MWException( __METHOD__ . ' Should only be ' - . ' called while parsing (no title set)' ); - } - // Avoid PHP 7.1 warning from passing $this by reference $parser = $this; @@ -2749,72 +2739,72 @@ class Parser { $value = $pageLang->formatNum( MWTimestamp::getLocalInstance( $ts )->format( 'd' ), true ); break; case 'pagename': - $value = wfEscapeWikiText( $this->mTitle->getText() ); + $value = wfEscapeWikiText( $this->getTitle()->getText() ); break; case 'pagenamee': - $value = wfEscapeWikiText( $this->mTitle->getPartialURL() ); + $value = wfEscapeWikiText( $this->getTitle()->getPartialURL() ); break; case 'fullpagename': - $value = wfEscapeWikiText( $this->mTitle->getPrefixedText() ); + $value = wfEscapeWikiText( $this->getTitle()->getPrefixedText() ); break; case 'fullpagenamee': - $value = wfEscapeWikiText( $this->mTitle->getPrefixedURL() ); + $value = wfEscapeWikiText( $this->getTitle()->getPrefixedURL() ); break; case 'subpagename': - $value = wfEscapeWikiText( $this->mTitle->getSubpageText() ); + $value = wfEscapeWikiText( $this->getTitle()->getSubpageText() ); break; case 'subpagenamee': - $value = wfEscapeWikiText( $this->mTitle->getSubpageUrlForm() ); + $value = wfEscapeWikiText( $this->getTitle()->getSubpageUrlForm() ); break; case 'rootpagename': - $value = wfEscapeWikiText( $this->mTitle->getRootText() ); + $value = wfEscapeWikiText( $this->getTitle()->getRootText() ); break; case 'rootpagenamee': $value = wfEscapeWikiText( wfUrlencode( str_replace( ' ', '_', - $this->mTitle->getRootText() + $this->getTitle()->getRootText() ) ) ); break; case 'basepagename': - $value = wfEscapeWikiText( $this->mTitle->getBaseText() ); + $value = wfEscapeWikiText( $this->getTitle()->getBaseText() ); break; case 'basepagenamee': $value = wfEscapeWikiText( wfUrlencode( str_replace( ' ', '_', - $this->mTitle->getBaseText() + $this->getTitle()->getBaseText() ) ) ); break; case 'talkpagename': - if ( $this->mTitle->canHaveTalkPage() ) { - $talkPage = $this->mTitle->getTalkPage(); + if ( $this->getTitle()->canHaveTalkPage() ) { + $talkPage = $this->getTitle()->getTalkPage(); $value = wfEscapeWikiText( $talkPage->getPrefixedText() ); } else { $value = ''; } break; case 'talkpagenamee': - if ( $this->mTitle->canHaveTalkPage() ) { - $talkPage = $this->mTitle->getTalkPage(); + if ( $this->getTitle()->canHaveTalkPage() ) { + $talkPage = $this->getTitle()->getTalkPage(); $value = wfEscapeWikiText( $talkPage->getPrefixedURL() ); } else { $value = ''; } break; case 'subjectpagename': - $subjPage = $this->mTitle->getSubjectPage(); + $subjPage = $this->getTitle()->getSubjectPage(); $value = wfEscapeWikiText( $subjPage->getPrefixedText() ); break; case 'subjectpagenamee': - $subjPage = $this->mTitle->getSubjectPage(); + $subjPage = $this->getTitle()->getSubjectPage(); $value = wfEscapeWikiText( $subjPage->getPrefixedURL() ); break; case 'pageid': // requested in T25427 # Inform the edit saving system that getting the canonical output # after page insertion requires a parse that used that exact page ID $this->setOutputFlag( 'vary-page-id', '{{PAGEID}} used' ); - $value = $this->mTitle->getArticleID(); + $value = $this->getTitle()->getArticleID(); if ( !$value ) { $value = $this->mOptions->getSpeculativePageId(); if ( $value ) { @@ -2827,7 +2817,7 @@ class Parser { $this->svcOptions->get( 'MiserMode' ) && !$this->mOptions->getInterfaceMessage() && // @TODO: disallow this word on all namespaces - $this->nsInfo->isContent( $this->mTitle->getNamespace() ) + $this->nsInfo->isContent( $this->getTitle()->getNamespace() ) ) { // Use a stub result instead of the actual revision ID in order to avoid // double parses on page save but still allow preview detection (T137900) @@ -2883,27 +2873,29 @@ class Parser { break; case 'namespace': $value = str_replace( '_', ' ', - $this->contLang->getNsText( $this->mTitle->getNamespace() ) ); + $this->contLang->getNsText( $this->getTitle()->getNamespace() ) ); break; case 'namespacee': - $value = wfUrlencode( $this->contLang->getNsText( $this->mTitle->getNamespace() ) ); + $value = wfUrlencode( $this->contLang->getNsText( $this->getTitle()->getNamespace() ) ); break; case 'namespacenumber': - $value = $this->mTitle->getNamespace(); + $value = $this->getTitle()->getNamespace(); break; case 'talkspace': - $value = $this->mTitle->canHaveTalkPage() - ? str_replace( '_', ' ', $this->mTitle->getTalkNsText() ) + $value = $this->getTitle()->canHaveTalkPage() + ? str_replace( '_', ' ', $this->getTitle()->getTalkNsText() ) : ''; break; case 'talkspacee': - $value = $this->mTitle->canHaveTalkPage() ? wfUrlencode( $this->mTitle->getTalkNsText() ) : ''; + $value = $this->getTitle()->canHaveTalkPage() + ? wfUrlencode( $this->getTitle()->getTalkNsText() ) + : ''; break; case 'subjectspace': - $value = str_replace( '_', ' ', $this->mTitle->getSubjectNsText() ); + $value = str_replace( '_', ' ', $this->getTitle()->getSubjectNsText() ); break; case 'subjectspacee': - $value = ( wfUrlencode( $this->mTitle->getSubjectNsText() ) ); + $value = ( wfUrlencode( $this->getTitle()->getSubjectNsText() ) ); break; case 'currentdayname': $value = $pageLang->getWeekdayName( (int)MWTimestamp::getInstance( $ts )->format( 'w' ) + 1 ); @@ -3377,7 +3369,7 @@ class Parser { $relative = $this->maybeDoSubpageLink( $part1, $subpage ); if ( $part1 !== $relative ) { $part1 = $relative; - $ns = $this->mTitle->getNamespace(); + $ns = $this->getTitle()->getNamespace(); } $title = Title::newFromText( $part1, $ns ); if ( $title ) { @@ -3582,7 +3574,6 @@ class Parser { * @param PPFrame $frame The current frame, contains template arguments * @param string $function Function name * @param array $args Arguments to the function - * @throws MWException * @return array */ public function callParserFunction( $frame, $function, array $args = [] ) { @@ -4221,17 +4212,17 @@ class Parser { $this->mShowToc = false; } if ( isset( $this->mDoubleUnderscores['hiddencat'] ) - && $this->mTitle->getNamespace() == NS_CATEGORY + && $this->getTitle()->getNamespace() == NS_CATEGORY ) { $this->addTrackingCategory( 'hidden-category-category' ); } # (T10068) Allow control over whether robots index a page. # __INDEX__ always overrides __NOINDEX__, see T16899 - if ( isset( $this->mDoubleUnderscores['noindex'] ) && $this->mTitle->canUseNoindex() ) { + if ( isset( $this->mDoubleUnderscores['noindex'] ) && $this->getTitle()->canUseNoindex() ) { $this->mOutput->setIndexPolicy( 'noindex' ); $this->addTrackingCategory( 'noindex-category' ); } - if ( isset( $this->mDoubleUnderscores['index'] ) && $this->mTitle->canUseNoindex() ) { + if ( isset( $this->mDoubleUnderscores['index'] ) && $this->getTitle()->canUseNoindex() ) { $this->mOutput->setIndexPolicy( 'index' ); $this->addTrackingCategory( 'index-category' ); } @@ -4250,7 +4241,7 @@ class Parser { * @return bool Whether the addition was successful */ public function addTrackingCategory( $msg ) { - return $this->mOutput->addTrackingCategory( $msg, $this->mTitle ); + return $this->mOutput->addTrackingCategory( $msg, $this->getTitle() ); } /** @@ -4328,7 +4319,7 @@ class Parser { $toclevel = 0; $prevtoclevel = 0; $markerRegex = self::MARKER_PREFIX . "-h-(\d+)-" . self::MARKER_SUFFIX; - $baseTitleText = $this->mTitle->getPrefixedDBkey(); + $baseTitleText = $this->getTitle()->getPrefixedDBkey(); $oldType = $this->mOutputType; $this->setOutputType( self::OT_WIKI ); $frame = $this->getPreprocessor()->newFrame(); @@ -4561,7 +4552,7 @@ class Parser { $editsectionSection = "T-$sectionIndex"; $editsectionContent = null; } else { - $editsectionPage = $this->mTitle->getPrefixedText(); + $editsectionPage = $this->getTitle()->getPrefixedText(); $editsectionSection = $sectionIndex; $editsectionContent = $headlineHint; } @@ -4752,7 +4743,7 @@ class Parser { $text = preg_replace( $p4, '[[\\1\\2\\3|\\2]]', $text ); $text = preg_replace( $p3, '[[\\1\\2\\3\\4|\\2]]', $text ); - $t = $this->mTitle->getText(); + $t = $this->getTitle()->getText(); $m = []; if ( preg_match( "/^($nc+:|)$tc+?( \\($tc+\\))$/", $t, $m ) ) { $text = preg_replace( $p2, "[[$m[1]\\1$m[2]|\\1]]", $text ); @@ -5179,7 +5170,7 @@ class Parser { $ig = ImageGalleryBase::factory( false ); } - $ig->setContextTitle( $this->mTitle ); + $ig->setContextTitle( $this->getTitle() ); $ig->setShowBytes( false ); $ig->setShowDimensions( false ); $ig->setShowFilename( false ); @@ -6510,7 +6501,7 @@ class Parser { */ protected function setOutputFlag( $flag, $reason ) { $this->mOutput->setFlag( $flag ); - $name = $this->mTitle->getPrefixedText(); + $name = $this->getTitle()->getPrefixedText(); $this->logger->debug( __METHOD__ . ": set $flag flag on '$name'; $reason" ); } } diff --git a/tests/selenium/specs/page.js b/tests/selenium/specs/page.js index 24e1d650c1..e2ca6554c1 100644 --- a/tests/selenium/specs/page.js +++ b/tests/selenium/specs/page.js @@ -10,13 +10,13 @@ const assert = require( 'assert' ), Util = require( 'wdio-mediawiki/Util' ); describe( 'Page', function () { - var content, - name; + var content, name, bot; - before( function () { + before( async function () { // disable VisualEditor welcome dialog BlankPage.open(); browser.setLocalStorage( 've-beta-welcome-dialog', '1' ); + bot = await Api.bot(); } ); beforeEach( function () { @@ -46,17 +46,13 @@ describe( 'Page', function () { it( 'should be re-creatable', function () { const initialContent = Util.getTestString( 'initialContent-' ); - // create - browser.call( function () { - return Api.edit( name, initialContent ); - } ); - - // delete - browser.call( function () { - return Api.delete( name, 'delete prior to recreate' ); + // create and delete + browser.call( async () => { + await bot.edit( name, initialContent, 'create for delete' ); + await bot.delete( name, 'delete prior to recreate' ); } ); - // create + // re-create EditPage.edit( name, content ); // check @@ -66,8 +62,8 @@ describe( 'Page', function () { it( 'should be editable @daily', function () { // create - browser.call( function () { - return Api.edit( name, content ); + browser.call( async () => { + await bot.edit( name, content, 'create for edit' ); } ); // edit @@ -81,26 +77,26 @@ describe( 'Page', function () { it( 'should have history @daily', function () { // create - browser.call( function () { - return Api.edit( name, content ); + browser.call( async () => { + await bot.edit( name, content, `created with "${content}"` ); } ); // check HistoryPage.open( name ); - assert.strictEqual( HistoryPage.comment.getText(), `Created or updated page with "${content}"` ); + assert.strictEqual( HistoryPage.comment.getText(), `created with "${content}"` ); } ); it( 'should be deletable', function () { - // login - UserLoginPage.loginAdmin(); - // create - browser.call( function () { - return Api.edit( name, content ); + browser.call( async () => { + await bot.edit( name, content, 'create for delete' ); } ); + // login + UserLoginPage.loginAdmin(); + // delete - DeletePage.delete( name, content + '-deletereason' ); + DeletePage.delete( name, 'delete reason' ); // check assert.strictEqual( @@ -110,40 +106,32 @@ describe( 'Page', function () { } ); it( 'should be restorable', function () { - // login - UserLoginPage.loginAdmin(); - - // create - browser.call( function () { - return Api.edit( name, content ); + // create and delete + browser.call( async () => { + await bot.edit( name, content, 'create for delete' ); + await bot.delete( name, 'delete for restore' ); } ); - // delete - browser.call( function () { - return Api.delete( name, content + '-deletereason' ); - } ); + // login + UserLoginPage.loginAdmin(); // restore - RestorePage.restore( name, content + '-restorereason' ); + RestorePage.restore( name, 'restore reason' ); // check assert.strictEqual( RestorePage.displayedContent.getText(), name + ' has been restored\nConsult the deletion log for a record of recent deletions and restorations.' ); } ); it( 'should be undoable', function () { - // create - browser.call( function () { - return Api.edit( name, content ); - } ); - - // edit let previousRev, undoRev; - browser.call( function () { - return Api.edit( name, Util.getTestString( 'editContent-' ) ) - .then( ( response ) => { - previousRev = response.edit.oldrevid; - undoRev = response.edit.newrevid; - } ); + browser.call( async () => { + // create + await bot.edit( name, content, 'create to edit and undo' ); + + // edit + const response = await bot.edit( name, Util.getTestString( 'editContent-' ) ); + previousRev = response.edit.oldrevid; + undoRev = response.edit.newrevid; } ); UndoPage.undo( name, previousRev, undoRev ); diff --git a/tests/selenium/wdio-mediawiki/Api.js b/tests/selenium/wdio-mediawiki/Api.js index a1cfa5fe76..cde0752e83 100644 --- a/tests/selenium/wdio-mediawiki/Api.js +++ b/tests/selenium/wdio-mediawiki/Api.js @@ -1,7 +1,5 @@ const MWBot = require( 'mwbot' ); -// TODO: Once we require Node 7 or later, we can use async-await. - module.exports = { /** * Get a logged-in instance of `MWBot` with edit token already set up. @@ -13,20 +11,19 @@ module.exports = { * @param {string} baseUrl - Optional * @return {Promise} */ - bot( + async bot( username = browser.config.mwUser, password = browser.config.mwPwd, baseUrl = browser.config.baseUrl ) { const bot = new MWBot(); - return bot.loginGetEditToken( { + await bot.loginGetEditToken( { apiUrl: `${baseUrl}/api.php`, username: username, password: password - } ).then( function () { - return bot; } ); + return bot; }, /** @@ -42,16 +39,14 @@ module.exports = { * @param {baseUrl} baseUrl - Optional * @return {Object} Promise for API action=edit response data. */ - edit( title, + async edit( title, content, username = browser.config.mwUser, password = browser.config.mwPwd, baseUrl = browser.config.baseUrl ) { - return this.bot( username, password, baseUrl ) - .then( function ( bot ) { - return bot.edit( title, content, `Created or updated page with "${content}"` ); - } ); + const bot = await this.bot( username, password, baseUrl ); + return await bot.edit( title, content, `Created or updated page with "${content}"` ); }, /** @@ -63,11 +58,9 @@ module.exports = { * @param {string} reason * @return {Object} Promise for API action=delete response data. */ - delete( title, reason ) { - return this.bot() - .then( function ( bot ) { - return bot.delete( title, reason ); - } ); + async delete( title, reason ) { + const bot = await this.bot(); + return await bot.delete( title, reason ); }, /** @@ -79,24 +72,23 @@ module.exports = { * @param {string} password * @return {Object} Promise for API action=createaccount response data. */ - createAccount( username, password ) { + async createAccount( username, password ) { const bot = new MWBot(); // Log in as admin - return bot.loginGetCreateaccountToken( { + await bot.loginGetCreateaccountToken( { apiUrl: `${browser.config.baseUrl}/api.php`, username: browser.config.mwUser, password: browser.config.mwPwd - } ).then( function () { - // Create the new account - return bot.request( { - action: 'createaccount', - createreturnurl: browser.config.baseUrl, - createtoken: bot.createaccountToken, - username: username, - password: password, - retype: password - } ); + } ); + // Create the new account + return await bot.request( { + action: 'createaccount', + createreturnurl: browser.config.baseUrl, + createtoken: bot.createaccountToken, + username: username, + password: password, + retype: password } ); }, @@ -109,18 +101,16 @@ module.exports = { * @param {string} [expiry] default is not set. For format see API docs * @return {Object} Promise for API action=block response data. */ - blockUser( username, expiry ) { - return this.bot() - .then( function ( bot ) { - // block user. default = admin - return bot.request( { - action: 'block', - user: username || browser.config.mwUser, - reason: 'browser test', - token: bot.editToken, - expiry - } ); - } ); + async blockUser( username, expiry ) { + const bot = await this.bot(); + // block user. default = admin + return await bot.request( { + action: 'block', + user: username || browser.config.mwUser, + reason: 'browser test', + token: bot.editToken, + expiry + } ); }, /** @@ -131,16 +121,14 @@ module.exports = { * @param {string} [username] defaults to user making the request * @return {Object} Promise for API action=unblock response data. */ - unblockUser( username ) { - return this.bot() - .then( function ( bot ) { - // unblock user. default = admin - return bot.request( { - action: 'unblock', - user: username || browser.config.mwUser, - reason: 'browser test done', - token: bot.editToken - } ); - } ); + async unblockUser( username ) { + const bot = await this.bot(); + // unblock user. default = admin + return await bot.request( { + action: 'unblock', + user: username || browser.config.mwUser, + reason: 'browser test done', + token: bot.editToken + } ); } };