jenkins-bot has submitted this change and it was merged.
Change subject: Split out internal parseAndStash from the edit stashing API
......................................................................
Split out internal parseAndStash from the edit stashing API
Bug: T90040
Change-Id: Ifa49fb9955dafff0c82ae635a5e1b3fb16d5e783
---
M includes/api/ApiStashEdit.php
1 file changed, 29 insertions(+), 9 deletions(-)
Approvals:
Ori.livneh: Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/api/ApiStashEdit.php b/includes/api/ApiStashEdit.php
index 3457670..c4b717c 100644
--- a/includes/api/ApiStashEdit.php
+++ b/includes/api/ApiStashEdit.php
@@ -33,6 +33,11 @@
* @since 1.25
*/
class ApiStashEdit extends ApiBase {
+ const ERROR_NONE = 'stashed';
+ const ERROR_PARSE = 'error_parse';
+ const ERROR_CACHE = 'error_cache';
+ const ERROR_UNCACHEABLE = 'uncacheable';
+
public function execute() {
global $wgMemc;
@@ -105,41 +110,56 @@
$key = self::getStashKey( $title, $content, $user );
// De-duplicate requests on the same key
if ( $user->pingLimiter( 'stashedit' ) ) {
- $editInfo = false;
$status = 'ratelimited';
} elseif ( $wgMemc->lock( $key, 0, 30 ) ) {
- $format = $content->getDefaultFormat();
- $editInfo = $page->prepareContentForEdit( $content,
null, $user, $format, false );
- $status = 'error'; // default
$unlocker = new ScopedCallback( function() use ( $key )
{
global $wgMemc;
$wgMemc->unlock( $key );
} );
+ $status = self::parseAndStash( $page, $content, $user );
} else {
- $editInfo = false;
$status = 'busy';
}
+ $this->getResult()->addValue( null, $this->getModuleName(),
array( 'status' => $status ) );
+ }
+
+ /**
+ * @param WikiPage $page
+ * @param Content $content
+ * @param User $user
+ * @return integer ApiStashEdit::ERROR_* constant
+ * @since 1.25
+ */
+ public static function parseAndStash( WikiPage $page, Content $content,
User $user ) {
+ global $wgMemc;
+
+ $format = $content->getDefaultFormat();
+ $editInfo = $page->prepareContentForEdit( $content, null,
$user, $format, false );
+
if ( $editInfo && $editInfo->output ) {
+ $key = self::getStashKey( $page->getTitle(), $content,
$user );
+
list( $stashInfo, $ttl ) = self::buildStashValue(
$editInfo->pstContent, $editInfo->output,
$editInfo->timestamp
);
+
if ( $stashInfo ) {
$ok = $wgMemc->set( $key, $stashInfo, $ttl );
if ( $ok ) {
- $status = 'stashed';
wfDebugLog( 'StashEdit', "Cached parser
output for key '$key'." );
+ return self::ERROR_NONE;
} else {
- $status = 'error';
wfDebugLog( 'StashEdit', "Failed to
cache parser output for key '$key'." );
+ return self::ERROR_CACHE;
}
} else {
- $status = 'uncacheable';
wfDebugLog( 'StashEdit', "Uncacheable parser
output for key '$key'." );
+ return self::ERROR_UNCACHEABLE;
}
}
- $this->getResult()->addValue( null, $this->getModuleName(),
array( 'status' => $status ) );
+ return self::ERROR_PARSE;
}
/**
--
To view, visit https://gerrit.wikimedia.org/r/200027
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ifa49fb9955dafff0c82ae635a5e1b3fb16d5e783
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Anomie <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: Ori.livneh <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits