X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiQueryIWBacklinks.php;h=37f347d733854feb95034ad407d82b93e249e4c9;hb=e9cd4e461e56bbb5e691cffd867f5e62459c3052;hp=8ebe3ec569f28b5a1a079988b355b7659423e3ea;hpb=7201be76e70a1193cc8a1b4d06bcdc35a81c047c;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiQueryIWBacklinks.php b/includes/api/ApiQueryIWBacklinks.php index 8ebe3ec569..37f347d733 100644 --- a/includes/api/ApiQueryIWBacklinks.php +++ b/includes/api/ApiQueryIWBacklinks.php @@ -61,15 +61,17 @@ class ApiQueryIWBacklinks extends ApiQueryGeneratorBase { 'original value returned by the previous query', '_badcontinue' ); } - $prefix = $this->getDB()->strencode( $cont[0] ); - $title = $this->getDB()->strencode( $this->titleToKey( $cont[1] ) ); + $db = $this->getDB(); + $op = $params['dir'] == 'descending' ? '<' : '>'; + $prefix = $db->addQuotes( $cont[0] ); + $title = $db->addQuotes( $this->titleToKey( $cont[1] ) ); $from = intval( $cont[2] ); $this->addWhere( - "iwl_prefix > '$prefix' OR " . - "(iwl_prefix = '$prefix' AND " . - "(iwl_title > '$title' OR " . - "(iwl_title = '$title' AND " . - "iwl_from >= $from)))" + "iwl_prefix $op $prefix OR " . + "(iwl_prefix = $prefix AND " . + "(iwl_title $op $title OR " . + "(iwl_title = $title AND " . + "iwl_from $op= $from)))" ); } @@ -83,22 +85,23 @@ class ApiQueryIWBacklinks extends ApiQueryGeneratorBase { $this->addFields( array( 'page_id', 'page_title', 'page_namespace', 'page_is_redirect', 'iwl_from', 'iwl_prefix', 'iwl_title' ) ); + $sort = ( $params['dir'] == 'descending' ? ' DESC' : '' ); if ( isset( $params['prefix'] ) ) { $this->addWhereFld( 'iwl_prefix', $params['prefix'] ); if ( isset( $params['title'] ) ) { $this->addWhereFld( 'iwl_title', $params['title'] ); - $this->addOption( 'ORDER BY', 'iwl_from' ); + $this->addOption( 'ORDER BY', 'iwl_from' . $sort ); } else { $this->addOption( 'ORDER BY', array( - 'iwl_title', - 'iwl_from' + 'iwl_title' . $sort, + 'iwl_from' . $sort )); } } else { $this->addOption( 'ORDER BY', array( - 'iwl_prefix', - 'iwl_title', - 'iwl_from' + 'iwl_prefix' . $sort, + 'iwl_title' . $sort, + 'iwl_from' . $sort )); } @@ -177,6 +180,13 @@ class ApiQueryIWBacklinks extends ApiQueryGeneratorBase { 'iwtitle', ), ), + 'dir' => array( + ApiBase::PARAM_DFLT => 'ascending', + ApiBase::PARAM_TYPE => array( + 'ascending', + 'descending' + ) + ), ); } @@ -191,6 +201,24 @@ class ApiQueryIWBacklinks extends ApiQueryGeneratorBase { ' iwtitle - Adds the title of the interwiki', ), 'limit' => 'How many total pages to return', + 'dir' => 'The direction in which to list', + ); + } + + public function getResultProperties() { + return array( + '' => array( + 'pageid' => 'integer', + 'ns' => 'namespace', + 'title' => 'string', + 'redirect' => 'boolean' + ), + 'iwprefix' => array( + 'iwprefix' => 'string' + ), + 'iwtitle' => array( + 'iwtitle' => 'string' + ) ); }