ApiQueryBase: wfDeprecated() takes a string as second parameter, not number
[lhc/web/wiklou.git] / includes / api / ApiQueryBase.php
index fb88201..6b08fc5 100644 (file)
@@ -47,6 +47,11 @@ abstract class ApiQueryBase extends ApiBase {
                $this->resetQueryParams();
        }
 
+       /************************************************************************//**
+        * @name   Methods to implement
+        * @{
+        */
+
        /**
         * Get the cache mode for the data generated by this module. Override
         * this in the module subclass. For possible return values and other
@@ -62,6 +67,68 @@ abstract class ApiQueryBase extends ApiBase {
                return 'private';
        }
 
+       /**
+        * Override this method to request extra fields from the pageSet
+        * using $pageSet->requestField('fieldName')
+        * @param ApiPageSet $pageSet
+        */
+       public function requestExtraData( $pageSet ) {
+       }
+
+       /**@}*/
+
+       /************************************************************************//**
+        * @name   Data access
+        * @{
+        */
+
+       /**
+        * Get the main Query module
+        * @return ApiQuery
+        */
+       public function getQuery() {
+               return $this->mQueryModule;
+       }
+
+       /**
+        * Get the Query database connection (read-only)
+        * @return DatabaseBase
+        */
+       protected function getDB() {
+               if ( is_null( $this->mDb ) ) {
+                       $this->mDb = $this->getQuery()->getDB();
+               }
+
+               return $this->mDb;
+       }
+
+       /**
+        * Selects the query database connection with the given name.
+        * See ApiQuery::getNamedDB() for more information
+        * @param string $name Name to assign to the database connection
+        * @param int $db One of the DB_* constants
+        * @param array $groups Query groups
+        * @return DatabaseBase
+        */
+       public function selectNamedDB( $name, $db, $groups ) {
+               $this->mDb = $this->getQuery()->getNamedDB( $name, $db, $groups );
+       }
+
+       /**
+        * Get the PageSet object to work on
+        * @return ApiPageSet
+        */
+       protected function getPageSet() {
+               return $this->getQuery()->getPageSet();
+       }
+
+       /**@}*/
+
+       /************************************************************************//**
+        * @name   Querying
+        * @{
+        */
+
        /**
         * Blank the internal arrays with query parameters
         */
@@ -305,29 +372,64 @@ abstract class ApiQueryBase extends ApiBase {
        }
 
        /**
-        * Estimate the row count for the SELECT query that would be run if we
-        * called select() right now, and check if it's acceptable.
-        * @return bool True if acceptable, false otherwise
+        * @param string $query
+        * @param string $protocol
+        * @return null|string
         */
-       protected function checkRowCount() {
-               $db = $this->getDB();
-               $this->profileDBIn();
-               $rowcount = $db->estimateRowCount(
-                       $this->tables,
-                       $this->fields,
-                       $this->where,
-                       __METHOD__,
-                       $this->options
-               );
-               $this->profileDBOut();
+       public function prepareUrlQuerySearchString( $query = null, $protocol = null ) {
+               $db = $this->getDb();
+               if ( !is_null( $query ) || $query != '' ) {
+                       if ( is_null( $protocol ) ) {
+                               $protocol = 'http://';
+                       }
 
-               if ( $rowcount > $this->getConfig()->get( 'APIMaxDBRows' ) ) {
-                       return false;
+                       $likeQuery = LinkFilter::makeLikeArray( $query, $protocol );
+                       if ( !$likeQuery ) {
+                               $this->dieUsage( 'Invalid query', 'bad_query' );
+                       }
+
+                       $likeQuery = LinkFilter::keepOneWildcard( $likeQuery );
+
+                       return 'el_index ' . $db->buildLike( $likeQuery );
+               } elseif ( !is_null( $protocol ) ) {
+                       return 'el_index ' . $db->buildLike( "$protocol", $db->anyString() );
                }
 
-               return true;
+               return null;
        }
 
+       /**
+        * Filters hidden users (where the user doesn't have the right to view them)
+        * Also adds relevant block information
+        *
+        * @param bool $showBlockInfo
+        * @return void
+        */
+       public function showHiddenUsersAddBlockInfo( $showBlockInfo ) {
+               $this->addTables( 'ipblocks' );
+               $this->addJoinConds( array(
+                       'ipblocks' => array( 'LEFT JOIN', 'ipb_user=user_id' ),
+               ) );
+
+               $this->addFields( 'ipb_deleted' );
+
+               if ( $showBlockInfo ) {
+                       $this->addFields( array( 'ipb_id', 'ipb_by', 'ipb_by_text', 'ipb_reason', 'ipb_expiry' ) );
+               }
+
+               // Don't show hidden names
+               if ( !$this->getUser()->isAllowed( 'hideuser' ) ) {
+                       $this->addWhere( 'ipb_deleted = 0 OR ipb_deleted IS NULL' );
+               }
+       }
+
+       /**@}*/
+
+       /************************************************************************//**
+        * @name   Utility methods
+        * @{
+        */
+
        /**
         * Add information (title and namespace) about a Title object to a
         * result array
@@ -340,22 +442,6 @@ abstract class ApiQueryBase extends ApiBase {
                $arr[$prefix . 'title'] = $title->getPrefixedText();
        }
 
-       /**
-        * Override this method to request extra fields from the pageSet
-        * using $pageSet->requestField('fieldName')
-        * @param ApiPageSet $pageSet
-        */
-       public function requestExtraData( $pageSet ) {
-       }
-
-       /**
-        * Get the main Query module
-        * @return ApiQuery
-        */
-       public function getQuery() {
-               return $this->mQueryModule;
-       }
-
        /**
         * Add a sub-element under the page element with the given page ID
         * @param int $pageId Page ID
@@ -405,89 +491,21 @@ abstract class ApiQueryBase extends ApiBase {
        }
 
        /**
-        * Get the Query database connection (read-only)
-        * @return DatabaseBase
-        */
-       protected function getDB() {
-               if ( is_null( $this->mDb ) ) {
-                       $this->mDb = $this->getQuery()->getDB();
-               }
-
-               return $this->mDb;
-       }
-
-       /**
-        * Selects the query database connection with the given name.
-        * See ApiQuery::getNamedDB() for more information
-        * @param string $name Name to assign to the database connection
-        * @param int $db One of the DB_* constants
-        * @param array $groups Query groups
-        * @return DatabaseBase
-        */
-       public function selectNamedDB( $name, $db, $groups ) {
-               $this->mDb = $this->getQuery()->getNamedDB( $name, $db, $groups );
-       }
-
-       /**
-        * Get the PageSet object to work on
-        * @return ApiPageSet
-        */
-       protected function getPageSet() {
-               return $this->getQuery()->getPageSet();
-       }
-
-       /**
-        * Convert a title to a DB key
-        * @param string $title Page title with spaces
-        * @return string Page title with underscores
-        */
-       public function titleToKey( $title ) {
-               // Don't throw an error if we got an empty string
-               if ( trim( $title ) == '' ) {
-                       return '';
-               }
-               $t = Title::newFromText( $title );
-               if ( !$t ) {
-                       $this->dieUsageMsg( array( 'invalidtitle', $title ) );
-               }
-
-               return $t->getPrefixedDBkey();
-       }
-
-       /**
-        * The inverse of titleToKey()
-        * @param string $key Page title with underscores
-        * @return string Page title with spaces
-        */
-       public function keyToTitle( $key ) {
-               // Don't throw an error if we got an empty string
-               if ( trim( $key ) == '' ) {
-                       return '';
-               }
-               $t = Title::newFromDBkey( $key );
-               // This really shouldn't happen but we gotta check anyway
-               if ( !$t ) {
-                       $this->dieUsageMsg( array( 'invalidtitle', $key ) );
-               }
-
-               return $t->getPrefixedText();
-       }
-
-       /**
-        * An alternative to titleToKey() that doesn't trim trailing spaces, and
-        * does not mangle the input if starts with something that looks like a
-        * namespace. It is advisable to pass the namespace parameter in order to
-        * handle per-namespace capitalization settings.
-        * @param string $titlePart Title part with spaces
-        * @param int $defaultNamespace Namespace to assume
-        * @return string Title part with underscores
+        * Convert an input title or title prefix into a dbkey.
+        *
+        * $namespace should always be specified in order to handle per-namespace
+        * capitalization settings.
+        *
+        * @param string $titlePart Title part
+        * @param int $defaultNamespace Namespace of the title
+        * @return string DBkey (no namespace prefix)
         */
-       public function titlePartToKey( $titlePart, $defaultNamespace = NS_MAIN ) {
-               $t = Title::makeTitleSafe( $defaultNamespace, $titlePart . 'x' );
+       public function titlePartToKey( $titlePart, $namespace = NS_MAIN ) {
+               $t = Title::makeTitleSafe( $namespace, $titlePart . 'x' );
                if ( !$t ) {
                        $this->dieUsageMsg( array( 'invalidtitle', $titlePart ) );
                }
-               if ( $defaultNamespace != $t->getNamespace() || $t->isExternal() ) {
+               if ( $namespace != $t->getNamespace() || $t->isExternal() ) {
                        // This can happen in two cases. First, if you call titlePartToKey with a title part
                        // that looks like a namespace, but with $defaultNamespace = NS_MAIN. It would be very
                        // difficult to handle such a case. Such cases cannot exist and are therefore treated
@@ -499,15 +517,6 @@ abstract class ApiQueryBase extends ApiBase {
                return substr( $t->getDbKey(), 0, -1 );
        }
 
-       /**
-        * An alternative to keyToTitle() that doesn't trim trailing spaces
-        * @param string $keyPart Key part with spaces
-        * @return string Key part with underscores
-        */
-       public function keyPartToTitle( $keyPart ) {
-               return substr( $this->keyToTitle( $keyPart . 'x' ), 0, -1 );
-       }
-
        /**
         * Gets the personalised direction parameter description
         *
@@ -524,94 +533,122 @@ abstract class ApiQueryBase extends ApiBase {
        }
 
        /**
-        * @param string $query
-        * @param string $protocol
-        * @return null|string
+        * @param string $hash
+        * @return bool
         */
-       public function prepareUrlQuerySearchString( $query = null, $protocol = null ) {
-               $db = $this->getDb();
-               if ( !is_null( $query ) || $query != '' ) {
-                       if ( is_null( $protocol ) ) {
-                               $protocol = 'http://';
-                       }
+       public function validateSha1Hash( $hash ) {
+               return preg_match( '/^[a-f0-9]{40}$/', $hash );
+       }
 
-                       $likeQuery = LinkFilter::makeLikeArray( $query, $protocol );
-                       if ( !$likeQuery ) {
-                               $this->dieUsage( 'Invalid query', 'bad_query' );
-                       }
+       /**
+        * @param string $hash
+        * @return bool
+        */
+       public function validateSha1Base36Hash( $hash ) {
+               return preg_match( '/^[a-z0-9]{31}$/', $hash );
+       }
 
-                       $likeQuery = LinkFilter::keepOneWildcard( $likeQuery );
+       /**
+        * Check whether the current user has permission to view revision-deleted
+        * fields.
+        * @return bool
+        */
+       public function userCanSeeRevDel() {
+               return $this->getUser()->isAllowedAny(
+                       'deletedhistory',
+                       'deletedtext',
+                       'suppressrevision',
+                       'viewsuppressed'
+               );
+       }
 
-                       return 'el_index ' . $db->buildLike( $likeQuery );
-               } elseif ( !is_null( $protocol ) ) {
-                       return 'el_index ' . $db->buildLike( "$protocol", $db->anyString() );
-               }
+       /**@}*/
 
-               return null;
-       }
+       /************************************************************************//**
+        * @name   Deprecated
+        * @{
+        */
 
        /**
-        * Filters hidden users (where the user doesn't have the right to view them)
-        * Also adds relevant block information
-        *
-        * @param bool $showBlockInfo
-        * @return void
+        * Estimate the row count for the SELECT query that would be run if we
+        * called select() right now, and check if it's acceptable.
+        * @deprecated since 1.24
+        * @return bool True if acceptable, false otherwise
         */
-       public function showHiddenUsersAddBlockInfo( $showBlockInfo ) {
-               $this->addTables( 'ipblocks' );
-               $this->addJoinConds( array(
-                       'ipblocks' => array( 'LEFT JOIN', 'ipb_user=user_id' ),
-               ) );
-
-               $this->addFields( 'ipb_deleted' );
+       protected function checkRowCount() {
+               wfDeprecated( __METHOD__, '1.24' );
+               $db = $this->getDB();
+               $this->profileDBIn();
+               $rowcount = $db->estimateRowCount(
+                       $this->tables,
+                       $this->fields,
+                       $this->where,
+                       __METHOD__,
+                       $this->options
+               );
+               $this->profileDBOut();
 
-               if ( $showBlockInfo ) {
-                       $this->addFields( array( 'ipb_id', 'ipb_by', 'ipb_by_text', 'ipb_reason', 'ipb_expiry' ) );
+               if ( $rowcount > $this->getConfig()->get( 'APIMaxDBRows' ) ) {
+                       return false;
                }
 
-               // Don't show hidden names
-               if ( !$this->getUser()->isAllowed( 'hideuser' ) ) {
-                       $this->addWhere( 'ipb_deleted = 0 OR ipb_deleted IS NULL' );
-               }
+               return true;
        }
 
        /**
-        * @param string $hash
-        * @return bool
+        * Convert a title to a DB key
+        * @deprecated since 1.24, past uses of this were always incorrect and should
+        *   have used self::titlePartToKey() instead
+        * @param string $title Page title with spaces
+        * @return string Page title with underscores
         */
-       public function validateSha1Hash( $hash ) {
-               return preg_match( '/^[a-f0-9]{40}$/', $hash );
-       }
+       public function titleToKey( $title ) {
+               wfDeprecated( __METHOD__, '1.24' );
+               // Don't throw an error if we got an empty string
+               if ( trim( $title ) == '' ) {
+                       return '';
+               }
+               $t = Title::newFromText( $title );
+               if ( !$t ) {
+                       $this->dieUsageMsg( array( 'invalidtitle', $title ) );
+               }
 
-       /**
-        * @param string $hash
-        * @return bool
-        */
-       public function validateSha1Base36Hash( $hash ) {
-               return preg_match( '/^[a-z0-9]{31}$/', $hash );
+               return $t->getPrefixedDBkey();
        }
 
        /**
-        * @return array
+        * The inverse of titleToKey()
+        * @deprecated since 1.24, unused and probably never needed
+        * @param string $key Page title with underscores
+        * @return string Page title with spaces
         */
-       public function getPossibleErrors() {
-               $errors = parent::getPossibleErrors();
-               $errors = array_merge( $errors, array(
-                       array( 'invalidtitle', 'title' ),
-                       array( 'invalidtitle', 'key' ),
-               ) );
+       public function keyToTitle( $key ) {
+               wfDeprecated( __METHOD__, '1.24' );
+               // Don't throw an error if we got an empty string
+               if ( trim( $key ) == '' ) {
+                       return '';
+               }
+               $t = Title::newFromDBkey( $key );
+               // This really shouldn't happen but we gotta check anyway
+               if ( !$t ) {
+                       $this->dieUsageMsg( array( 'invalidtitle', $key ) );
+               }
 
-               return $errors;
+               return $t->getPrefixedText();
        }
 
        /**
-        * Check whether the current user has permission to view revision-deleted
-        * fields.
-        * @return bool
+        * Inverse of titlePartToKey()
+        * @deprecated since 1.24, unused and probably never needed
+        * @param string $keyPart DBkey, with prefix
+        * @return string Key part with underscores
         */
-       public function userCanSeeRevDel() {
-               return $this->getUser()->isAllowedAny( 'deletedhistory', 'deletedtext', 'suppressrevision' );
+       public function keyPartToTitle( $keyPart ) {
+               wfDeprecated( __METHOD__, '1.24' );
+               return substr( $this->keyToTitle( $keyPart . 'x' ), 0, -1 );
        }
+
+       /**@}*/
 }
 
 /**
@@ -649,7 +686,7 @@ abstract class ApiQueryGeneratorBase extends ApiQueryBase {
        }
 
        /**
-        * Overrides base class to prepend 'g' to every generator parameter
+        * Overrides ApiBase to prepend 'g' to every generator parameter
         * @param string $paramName Parameter name
         * @return string Prefixed parameter name
         */