X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiQueryBase.php;h=29fdfea6793d170e193292ff3bb7e0e50ad6cacd;hb=23c92cf78866cadc96d9c1e5275e85caab755858;hp=89e92b8a9425b6c6e303050e6e17b3119e415fba;hpb=9e18610457ce599db51d3b14af83c31053ea0ace;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiQueryBase.php b/includes/api/ApiQueryBase.php index 89e92b8a94..29fdfea679 100644 --- a/includes/api/ApiQueryBase.php +++ b/includes/api/ApiQueryBase.php @@ -317,7 +317,7 @@ abstract class ApiQueryBase extends ApiBase { * @param bool $sort */ protected function addTimestampWhereRange( $field, $dir, $start, $end, $sort = true ) { - $db = $this->getDb(); + $db = $this->getDB(); $this->addWhereRange( $field, $dir, $db->timestampOrNull( $start ), $db->timestampOrNull( $end ), $sort ); } @@ -384,7 +384,7 @@ abstract class ApiQueryBase extends ApiBase { * @return null|string */ public function prepareUrlQuerySearchString( $query = null, $protocol = null ) { - $db = $this->getDb(); + $db = $this->getDB(); if ( !is_null( $query ) || $query != '' ) { if ( is_null( $protocol ) ) { $protocol = 'http://'; @@ -421,7 +421,14 @@ abstract class ApiQueryBase extends ApiBase { $this->addFields( 'ipb_deleted' ); if ( $showBlockInfo ) { - $this->addFields( array( 'ipb_id', 'ipb_by', 'ipb_by_text', 'ipb_reason', 'ipb_expiry', 'ipb_timestamp' ) ); + $this->addFields( array( + 'ipb_id', + 'ipb_by', + 'ipb_by_text', + 'ipb_reason', + 'ipb_expiry', + 'ipb_timestamp' + ) ); } // Don't show hidden names @@ -504,7 +511,7 @@ abstract class ApiQueryBase extends ApiBase { * capitalization settings. * * @param string $titlePart Title part - * @param int $defaultNamespace Namespace of the title + * @param int $namespace Namespace of the title * @return string DBkey (no namespace prefix) */ public function titlePartToKey( $titlePart, $namespace = NS_MAIN ) { @@ -522,7 +529,25 @@ abstract class ApiQueryBase extends ApiBase { $this->dieUsageMsg( array( 'invalidtitle', $titlePart ) ); } - return substr( $t->getDbKey(), 0, -1 ); + return substr( $t->getDBkey(), 0, -1 ); + } + + /** + * Convert an input title or title prefix into a namespace constant and dbkey. + * + * @since 1.26 + * @param string $titlePart Title part + * @param int $defaultNamespace Default namespace if none is given + * @return array (int, string) Namespace number and DBkey + */ + public function prefixedTitlePartToKey( $titlePart, $defaultNamespace = NS_MAIN ) { + $t = Title::newFromText( $titlePart . 'x', $defaultNamespace ); + if ( !$t || $t->hasFragment() || $t->isExternal() ) { + // Invalid title (e.g. bad chars) or contained a '#'. + $this->dieUsageMsg( array( 'invalidtitle', $titlePart ) ); + } + + return array( $t->getNamespace(), substr( $t->getDBkey(), 0, -1 ) ); } /**