$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
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
*/
}
/**
- * 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
$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
}
/**
- * 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
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
*
);
}
- /**
- * @param string $query
- * @param string $protocol
- * @return null|string
- */
- public function prepareUrlQuerySearchString( $query = null, $protocol = null ) {
- $db = $this->getDb();
- if ( !is_null( $query ) || $query != '' ) {
- if ( is_null( $protocol ) ) {
- $protocol = 'http://';
- }
-
- $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 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' );
- }
- }
-
/**
* @param string $hash
* @return bool
'viewsuppressed'
);
}
+
+ /**@}*/
+
+ /************************************************************************//**
+ * @name Deprecated
+ * @{
+ */
+
+ /**
+ * 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
+ */
+ 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 ( $rowcount > $this->getConfig()->get( 'APIMaxDBRows' ) ) {
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * 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 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 ) );
+ }
+
+ return $t->getPrefixedDBkey();
+ }
+
+ /**
+ * 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 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 $t->getPrefixedText();
+ }
+
+ /**
+ * 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 keyPartToTitle( $keyPart ) {
+ wfDeprecated( __METHOD__, 1.24 );
+ return substr( $this->keyToTitle( $keyPart . 'x' ), 0, -1 );
+ }
+
+ /**@}*/
}
/**
}
/**
- * 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
*/