Daniel Kinzler has uploaded a new change for review.

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


Change subject: Remove redundant bloat from API modules.
......................................................................

Remove redundant bloat from API modules.

This generalizes the implementation of the following methods:

 * getVersion()
 * getHelpUrls()
 * needsToken()
 * mustBePosted()

These methods have been puleld up into the Api base class.

Change-Id: Ic62cfac9819b64ecd987c44d75a54a68db77e33f
---
M repo/includes/api/Api.php
M repo/includes/api/ApiEditEntity.php
M repo/includes/api/ApiGetClaims.php
M repo/includes/api/ApiGetEntities.php
M repo/includes/api/ApiLinkTitles.php
M repo/includes/api/ApiModifyClaim.php
M repo/includes/api/ApiModifyEntity.php
M repo/includes/api/ApiSearchEntities.php
M repo/includes/api/ApiSetAliases.php
M repo/includes/api/ApiSetDescription.php
M repo/includes/api/ApiSetLabel.php
M repo/includes/api/ApiSetReference.php
M repo/includes/api/ApiSetSiteLink.php
M repo/includes/api/RemoveQualifiers.php
M repo/includes/api/RemoveReferences.php
M repo/includes/api/SetClaim.php
M repo/includes/api/SetQualifier.php
M repo/includes/api/SetStatementRank.php
18 files changed, 34 insertions(+), 424 deletions(-)


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

diff --git a/repo/includes/api/Api.php b/repo/includes/api/Api.php
index 007ab12..92642a7 100644
--- a/repo/includes/api/Api.php
+++ b/repo/includes/api/Api.php
@@ -14,6 +14,7 @@
  *
  * @licence GNU GPL v2+
  * @author John Erling Blad < [email protected] >
+ * @author Daniel Kinzler
  */
 abstract class Api extends \ApiBase {
 
@@ -70,6 +71,38 @@
        }
 
        /**
+        * @see \ApiBase::needsToken()
+        */
+       public function needsToken() {
+               return $this->isWriteMode() && ( !Settings::get( 'apiInDebug' ) 
|| Settings::get( 'apiDebugWithTokens' ) );
+       }
+
+       /**
+        * @see \ApiBase::mustBePosted()
+        */
+       public function mustBePosted() {
+               return $this->isWriteMode() && ( !Settings::get( 'apiInDebug' ) 
|| Settings::get( 'apiDebugWithPost' ) );
+       }
+
+       /**
+        * @see ApiBase::getVersion
+        *
+        * @since 0.4
+        *
+        * @return string
+        */
+       public function getVersion() {
+               return get_class( $this ) . '-' . WB_VERSION;
+       }
+
+       /**
+        * @see ApiBase::getHelpUrls()
+        */
+       public function getHelpUrls() {
+               return 'https://www.mediawiki.org/wiki/Extension:Wikibase/API#' 
. $this->getModuleName();
+       }
+
+       /**
         * Add aliases to result
         *
         * @deprecated
diff --git a/repo/includes/api/ApiEditEntity.php 
b/repo/includes/api/ApiEditEntity.php
index 1a419d0..ab9e0a1 100644
--- a/repo/includes/api/ApiEditEntity.php
+++ b/repo/includes/api/ApiEditEntity.php
@@ -452,24 +452,6 @@
        }
 
        /**
-        * @see ApiBase::getHelpUrls()
-        */
-       public function getHelpUrls() {
-               return 
'https://www.mediawiki.org/wiki/Extension:Wikibase/API#wbeditentity';
-       }
-
-       /**
-        * @see ApiBase::getVersion
-        *
-        * @since 0.1
-        *
-        * @return string
-        */
-       public function getVersion() {
-               return __CLASS__ . '-' . WB_VERSION;
-       }
-
-       /**
         * Check some of the supplied data for multilang arg
         *
         * @param $arg Array: The argument array to verify
diff --git a/repo/includes/api/ApiGetClaims.php 
b/repo/includes/api/ApiGetClaims.php
index 5f31e5b..6caf1c3 100644
--- a/repo/includes/api/ApiGetClaims.php
+++ b/repo/includes/api/ApiGetClaims.php
@@ -255,26 +255,4 @@
                );
        }
 
-       /**
-        * @see ApiBase::getHelpUrls
-        *
-        * @since 0.3
-        *
-        * @return string
-        */
-       public function getHelpUrls() {
-               return 
'https://www.mediawiki.org/wiki/Extension:Wikibase/API#wbgetclaims';
-       }
-
-       /**
-        * @see ApiBase::getVersion
-        *
-        * @since 0.3
-        *
-        * @return string
-        */
-       public function getVersion() {
-               return __CLASS__ . '-' . WB_VERSION;
-       }
-
 }
diff --git a/repo/includes/api/ApiGetEntities.php 
b/repo/includes/api/ApiGetEntities.php
index 5ab6acc..390df9d 100644
--- a/repo/includes/api/ApiGetEntities.php
+++ b/repo/includes/api/ApiGetEntities.php
@@ -328,23 +328,4 @@
                        => 'Get the item for page "Berlin" on the site 
"enwiki", with language attributes in English language',
                );
        }
-
-       /**
-        * @see ApiBase::getHelpUrls()
-        */
-       public function getHelpUrls() {
-               return 
'https://www.mediawiki.org/wiki/Extension:Wikibase/API#wbgetentities';
-       }
-
-       /**
-        * @see ApiBase::getVersion
-        *
-        * @since 0.1
-        *
-        * @return string
-        */
-       public function getVersion() {
-               return __CLASS__ . '-' . WB_VERSION;
-       }
-
 }
diff --git a/repo/includes/api/ApiLinkTitles.php 
b/repo/includes/api/ApiLinkTitles.php
index 9e3c40e..04198df 100644
--- a/repo/includes/api/ApiLinkTitles.php
+++ b/repo/includes/api/ApiLinkTitles.php
@@ -196,20 +196,6 @@
        }
 
        /**
-        * @see \ApiBase::needsToken()
-        */
-       public function needsToken() {
-               return Settings::get( 'apiInDebug' ) ? Settings::get( 
'apiDebugWithTokens' ) : true;
-       }
-
-       /**
-        * @see \ApiBase::mustBePosted()
-        */
-       public function mustBePosted() {
-               return Settings::get( 'apiInDebug' ) ? Settings::get( 
'apiDebugWithPost' ) : true;
-       }
-
-       /**
         * @see \ApiBase::isWriteMode()
         */
        public function isWriteMode() {
@@ -290,24 +276,6 @@
                        
'api.php?action=wblinktitles&fromsite=enwiki&fromtitle=Hydrogen&tosite=dewiki&totitle=Wasserstoff'
                        => 'Add a link "Hydrogen" from the English page to 
"Wasserstoff" at the German page',
                );
-       }
-
-       /**
-        * @return bool|string|array Returns a false if the module has no help 
url, else returns a (array of) string
-        */
-       public function getHelpUrls() {
-               return 
'https://www.mediawiki.org/wiki/Extension:Wikibase/API#wblinktitles';
-       }
-
-       /**
-        * @see ApiBase::getVersion
-        *
-        * @since 0.1
-        *
-        * @return string
-        */
-       public function getVersion() {
-               return __CLASS__ . '-' . WB_VERSION;
        }
 
 }
diff --git a/repo/includes/api/ApiModifyClaim.php 
b/repo/includes/api/ApiModifyClaim.php
index 54bad46..c1b337c 100644
--- a/repo/includes/api/ApiModifyClaim.php
+++ b/repo/includes/api/ApiModifyClaim.php
@@ -161,42 +161,6 @@
        }
 
        /**
-        * @see ApiBase::getHelpUrls
-        *
-        * @since 0.2
-        *
-        * @return string
-        */
-       public function getHelpUrls() {
-               return 'https://www.mediawiki.org/wiki/Extension:Wikibase/API#' 
. $this->getModuleName();
-       }
-
-       /**
-        * @see ApiBase::getVersion
-        *
-        * @since 0.2
-        *
-        * @return string
-        */
-       public function getVersion() {
-               return get_class( $this ) . '-' . WB_VERSION;
-       }
-
-       /**
-        * @see \ApiBase::needsToken()
-        */
-       public function needsToken() {
-               return Settings::get( 'apiInDebug' ) ? Settings::get( 
'apiDebugWithTokens' ) : true;
-       }
-
-       /**
-        * @see \ApiBase::mustBePosted()
-        */
-       public function mustBePosted() {
-               return Settings::get( 'apiInDebug' ) ? Settings::get( 
'apiDebugWithPost' ) : true;
-       }
-
-       /**
         * @see \ApiBase::isWriteMode()
         */
        public function isWriteMode() {
diff --git a/repo/includes/api/ApiModifyEntity.php 
b/repo/includes/api/ApiModifyEntity.php
index f773217..f540bd6 100644
--- a/repo/includes/api/ApiModifyEntity.php
+++ b/repo/includes/api/ApiModifyEntity.php
@@ -251,20 +251,6 @@
        }
 
        /**
-        * @see \ApiBase::needsToken()
-        */
-       public function needsToken() {
-               return Settings::get( 'apiInDebug' ) ? Settings::get( 
'apiDebugWithTokens' ) : true;
-       }
-
-       /**
-        * @see \ApiBase::mustBePosted()
-        */
-       public function mustBePosted() {
-               return Settings::get( 'apiInDebug' ) ? Settings::get( 
'apiDebugWithPost' ) : true;
-       }
-
-       /**
         * @see \ApiBase::isWriteMode()
         */
        public function isWriteMode() {
diff --git a/repo/includes/api/ApiSearchEntities.php 
b/repo/includes/api/ApiSearchEntities.php
index 28d4b8c..bdd8a7a 100644
--- a/repo/includes/api/ApiSearchEntities.php
+++ b/repo/includes/api/ApiSearchEntities.php
@@ -25,6 +25,7 @@
  * @author Tobias Gritschacher < [email protected] >
  */
 class ApiSearchEntities extends ApiBase {
+       //XXX: why not derive from Wikibase\Api?
 
        /**
         * Get the entities corresponding to the provided language and term 
pair.
@@ -290,13 +291,6 @@
                        'api.php?action=wbsearchentities&search=abc&language=en'
                        => 'Search for "abc" in English language, with defaults 
for type and limit.',
                );
-       }
-
-       /**
-        * @see ApiBase::getHelpUrls
-        */
-       public function getHelpUrls() {
-               return 
'https://www.mediawiki.org/wiki/Extension:Wikibase/API#wbsearchentities';
        }
 
        /**
diff --git a/repo/includes/api/ApiSetAliases.php 
b/repo/includes/api/ApiSetAliases.php
index 92a0161..ebf08a1 100644
--- a/repo/includes/api/ApiSetAliases.php
+++ b/repo/includes/api/ApiSetAliases.php
@@ -200,23 +200,4 @@
                                => 'Remove Foo and Bar from the list of English 
labels for the entity with id 1',
                );
        }
-
-       /**
-        * @see ApiBase::getHelpUrls()
-        */
-       public function getHelpUrls() {
-               return 
'https://www.mediawiki.org/wiki/Extension:Wikibase/API#wbsetaliases';
-       }
-
-       /**
-        * @see ApiBase::getVersion
-        *
-        * @since 0.1
-        *
-        * @return string
-        */
-       public function getVersion() {
-               return __CLASS__ . '-' . WB_VERSION;
-       }
-
 }
diff --git a/repo/includes/api/ApiSetDescription.php 
b/repo/includes/api/ApiSetDescription.php
index 128523c..14ca8a6 100644
--- a/repo/includes/api/ApiSetDescription.php
+++ b/repo/includes/api/ApiSetDescription.php
@@ -73,23 +73,4 @@
                                => 'Set the string "An encyclopedia that 
everyone can edit" for page with id "42" as a decription in English language',
                );
        }
-
-       /**
-        * @see ApiBase::getHelpUrls()
-        */
-       public function getHelpUrls() {
-               return 
'https://www.mediawiki.org/wiki/Extension:Wikibase/API#wbsetdescription';
-       }
-
-       /**
-        * @see ApiBase::getVersion
-        *
-        * @since 0.1
-        *
-        * @return string
-        */
-       public function getVersion() {
-               return __CLASS__ . '-' . WB_VERSION;
-       }
-
 }
diff --git a/repo/includes/api/ApiSetLabel.php 
b/repo/includes/api/ApiSetLabel.php
index 497aa75..21526f5 100644
--- a/repo/includes/api/ApiSetLabel.php
+++ b/repo/includes/api/ApiSetLabel.php
@@ -74,22 +74,4 @@
                );
        }
 
-       /**
-        * @see ApiBase::getHelpUrls()
-        */
-       public function getHelpUrls() {
-               return 
'https://www.mediawiki.org/wiki/Extension:Wikibase/API#wbsetlabel';
-       }
-
-       /**
-        * @see ApiBase::getVersion
-        *
-        * @since 0.1
-        *
-        * @return string
-        */
-       public function getVersion() {
-               return __CLASS__ . '-' . WB_VERSION;
-       }
-
 }
diff --git a/repo/includes/api/ApiSetReference.php 
b/repo/includes/api/ApiSetReference.php
index deede8c..ae2c5c4 100644
--- a/repo/includes/api/ApiSetReference.php
+++ b/repo/includes/api/ApiSetReference.php
@@ -280,42 +280,6 @@
        }
 
        /**
-        * @see ApiBase::getHelpUrls
-        *
-        * @since 0.3
-        *
-        * @return string
-        */
-       public function getHelpUrls() {
-               return 
'https://www.mediawiki.org/wiki/Extension:Wikibase/API#wbsetreference';
-       }
-
-       /**
-        * @see ApiBase::getVersion
-        *
-        * @since 0.3
-        *
-        * @return string
-        */
-       public function getVersion() {
-               return __CLASS__ . '-' . WB_VERSION;
-       }
-
-       /**
-        * @see \ApiBase::needsToken()
-        */
-       public function needsToken() {
-               return Settings::get( 'apiInDebug' ) ? Settings::get( 
'apiDebugWithTokens' ) : true;
-       }
-
-       /**
-        * @see \ApiBase::mustBePosted()
-        */
-       public function mustBePosted() {
-               return Settings::get( 'apiInDebug' ) ? Settings::get( 
'apiDebugWithPost' ) : true;
-       }
-
-       /**
         * @see \ApiBase::isWriteMode()
         */
        public function isWriteMode() {
diff --git a/repo/includes/api/ApiSetSiteLink.php 
b/repo/includes/api/ApiSetSiteLink.php
index 7796e28..f763369 100644
--- a/repo/includes/api/ApiSetSiteLink.php
+++ b/repo/includes/api/ApiSetSiteLink.php
@@ -211,22 +211,4 @@
                );
        }
 
-       /**
-        * @return bool|string|array Returns a false if the module has no help 
url, else returns a (array of) string
-        */
-       public function getHelpUrls() {
-               return 
'https://www.mediawiki.org/wiki/Extension:Wikibase/API#wbsetsitelink';
-       }
-
-       /**
-        * @see ApiBase::getVersion
-        *
-        * @since 0.1
-        *
-        * @return string
-        */
-       public function getVersion() {
-               return __CLASS__ . '-' . WB_VERSION;
-       }
-
 }
diff --git a/repo/includes/api/RemoveQualifiers.php 
b/repo/includes/api/RemoveQualifiers.php
index 42b8f71..b869204 100644
--- a/repo/includes/api/RemoveQualifiers.php
+++ b/repo/includes/api/RemoveQualifiers.php
@@ -226,42 +226,6 @@
        }
 
        /**
-        * @see ApiBase::getHelpUrls
-        *
-        * @since 0.3
-        *
-        * @return string
-        */
-       public function getHelpUrls() {
-               return 
'https://www.mediawiki.org/wiki/Extension:Wikibase/API#wbremovequalifiers';
-       }
-
-       /**
-        * @see ApiBase::getVersion
-        *
-        * @since 0.3
-        *
-        * @return string
-        */
-       public function getVersion() {
-               return __CLASS__ . '-' . WB_VERSION;
-       }
-
-       /**
-        * @see \ApiBase::needsToken()
-        */
-       public function needsToken() {
-               return Settings::get( 'apiInDebug' ) ? Settings::get( 
'apiDebugWithTokens' ) : true;
-       }
-
-       /**
-        * @see \ApiBase::mustBePosted()
-        */
-       public function mustBePosted() {
-               return Settings::get( 'apiInDebug' ) ? Settings::get( 
'apiDebugWithPost' ) : true;
-       }
-
-       /**
         * @see \ApiBase::isWriteMode()
         */
        public function isWriteMode() {
diff --git a/repo/includes/api/RemoveReferences.php 
b/repo/includes/api/RemoveReferences.php
index 547d820..1f286f4 100644
--- a/repo/includes/api/RemoveReferences.php
+++ b/repo/includes/api/RemoveReferences.php
@@ -237,42 +237,6 @@
        }
 
        /**
-        * @see ApiBase::getHelpUrls
-        *
-        * @since 0.3
-        *
-        * @return string
-        */
-       public function getHelpUrls() {
-               return 
'https://www.mediawiki.org/wiki/Extension:Wikibase/API#wbremovereferences';
-       }
-
-       /**
-        * @see ApiBase::getVersion
-        *
-        * @since 0.3
-        *
-        * @return string
-        */
-       public function getVersion() {
-               return __CLASS__ . '-' . WB_VERSION;
-       }
-
-       /**
-        * @see \ApiBase::needsToken()
-        */
-       public function needsToken() {
-               return Settings::get( 'apiInDebug' ) ? Settings::get( 
'apiDebugWithTokens' ) : true;
-       }
-
-       /**
-        * @see \ApiBase::mustBePosted()
-        */
-       public function mustBePosted() {
-               return Settings::get( 'apiInDebug' ) ? Settings::get( 
'apiDebugWithPost' ) : true;
-       }
-
-       /**
         * @see \ApiBase::isWriteMode()
         */
        public function isWriteMode() {
diff --git a/repo/includes/api/SetClaim.php b/repo/includes/api/SetClaim.php
index f220d02..54f7265 100644
--- a/repo/includes/api/SetClaim.php
+++ b/repo/includes/api/SetClaim.php
@@ -249,26 +249,4 @@
                );
        }
 
-       /**
-        * @see ApiBase::getHelpUrls
-        *
-        * @since 0.4
-        *
-        * @return string
-        */
-       public function getHelpUrls() {
-               return 
'https://www.mediawiki.org/wiki/Extension:Wikibase/API#wbsetclaimvalue';
-       }
-
-       /**
-        * @see ApiBase::getVersion
-        *
-        * @since 0.4
-        *
-        * @return string
-        */
-       public function getVersion() {
-               return __CLASS__ . '-' . WB_VERSION;
-       }
-
 }
diff --git a/repo/includes/api/SetQualifier.php 
b/repo/includes/api/SetQualifier.php
index d8e735d..cffcc7b 100644
--- a/repo/includes/api/SetQualifier.php
+++ b/repo/includes/api/SetQualifier.php
@@ -390,42 +390,6 @@
        }
 
        /**
-        * @see ApiBase::getHelpUrls
-        *
-        * @since 0.3
-        *
-        * @return string
-        */
-       public function getHelpUrls() {
-               return 
'https://www.mediawiki.org/wiki/Extension:Wikibase/API#wbsetqualifier';
-       }
-
-       /**
-        * @see ApiBase::getVersion
-        *
-        * @since 0.3
-        *
-        * @return string
-        */
-       public function getVersion() {
-               return __CLASS__ . '-' . WB_VERSION;
-       }
-
-       /**
-        * @see \ApiBase::needsToken()
-        */
-       public function needsToken() {
-               return Settings::get( 'apiInDebug' ) ? Settings::get( 
'apiDebugWithTokens' ) : true;
-       }
-
-       /**
-        * @see \ApiBase::mustBePosted()
-        */
-       public function mustBePosted() {
-               return Settings::get( 'apiInDebug' ) ? Settings::get( 
'apiDebugWithPost' ) : true;
-       }
-
-       /**
         * @see \ApiBase::isWriteMode()
         */
        public function isWriteMode() {
diff --git a/repo/includes/api/SetStatementRank.php 
b/repo/includes/api/SetStatementRank.php
index be9cf9c..49309e8 100644
--- a/repo/includes/api/SetStatementRank.php
+++ b/repo/includes/api/SetStatementRank.php
@@ -244,42 +244,6 @@
        }
 
        /**
-        * @see ApiBase::getHelpUrls
-        *
-        * @since 0.3
-        *
-        * @return string
-        */
-       public function getHelpUrls() {
-               return 
'https://www.mediawiki.org/wiki/Extension:Wikibase/API#wbsetstatementrank';
-       }
-
-       /**
-        * @see ApiBase::getVersion
-        *
-        * @since 0.3
-        *
-        * @return string
-        */
-       public function getVersion() {
-               return __CLASS__ . '-' . WB_VERSION;
-       }
-
-       /**
-        * @see \ApiBase::needsToken()
-        */
-       public function needsToken() {
-               return Settings::get( 'apiInDebug' ) ? Settings::get( 
'apiDebugWithTokens' ) : true;
-       }
-
-       /**
-        * @see \ApiBase::mustBePosted()
-        */
-       public function mustBePosted() {
-               return Settings::get( 'apiInDebug' ) ? Settings::get( 
'apiDebugWithPost' ) : true;
-       }
-
-       /**
         * @see \ApiBase::isWriteMode()
         */
        public function isWriteMode() {

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

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

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

Reply via email to