Aude has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/119730

Change subject: Add methods for evaluating token and base revision api params
......................................................................

Add methods for evaluating token and base revision api params

slightly simplifies the attemptSaveEntity method

Change-Id: Ib7968940a4263d879cef97fd6e6288fbedd82154
---
M repo/includes/api/ApiWikibase.php
1 file changed, 31 insertions(+), 9 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/30/119730/1

diff --git a/repo/includes/api/ApiWikibase.php 
b/repo/includes/api/ApiWikibase.php
index bc76c4b..236a9db 100644
--- a/repo/includes/api/ApiWikibase.php
+++ b/repo/includes/api/ApiWikibase.php
@@ -481,8 +481,7 @@
                        $flags |= EDIT_FORCE_BOT;
                }
 
-               $baseRevisionId = isset( $params['baserevid'] ) ? intval( 
$params['baserevid'] ) : null;
-               $baseRevisionId = $baseRevisionId > 0 ? $baseRevisionId : false;
+               $baseRevisionId = $this->evaluateBaseRevisionParam( $params );
 
                //TODO: allow injection/override!
                $entityTitleLookup = 
WikibaseRepo::getDefaultInstance()->getEntityTitleLookup();
@@ -498,13 +497,7 @@
                        $baseRevisionId,
                        $this->getContext() );
 
-               if ( !$this->needsToken() ) {
-                       // false disabled the token check
-                       $token = false;
-               } else {
-                       // null fails the token check
-                       $token = isset( $params['token'] ) ? $params['token'] : 
null;
-               }
+               $token = $this->evaluateTokenParam( $params );
 
                $status = $editEntity->attemptSave(
                        $summary,
@@ -516,6 +509,35 @@
                return $status;
        }
 
+       /**
+        * @param array $params
+        *
+        * @return false|null|string
+        */
+       protected function evaluateTokenParam( array $params ) {
+               if ( !$this->needsToken() ) {
+                       // false disabled the token check
+                       $token = false;
+               } else {
+                       // null fails the token check
+                       $token = isset( $params['token'] ) ? $params['token'] : 
null;
+               }
+
+               return $token;
+       }
+
+       /**
+        * @param array $params
+        *
+        * @return null|false|int
+        */
+       protected function evaluateBaseRevisionParam( array $params ) {
+               $baseRevisionId = isset( $params['baserevid'] ) ? intval( 
$params['baserevid'] ) : null;
+               $baseRevisionId = $baseRevisionId > 0 ? $baseRevisionId : false;
+
+               return $baseRevisionId;
+       }
+
        protected function formatSummary( Summary $summary ) {
                $formatter = 
WikibaseRepo::getDefaultInstance()->getSummaryFormatter();
                return $formatter->formatSummary( $summary );

-- 
To view, visit https://gerrit.wikimedia.org/r/119730
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib7968940a4263d879cef97fd6e6288fbedd82154
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Aude <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to