X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiQueryLangBacklinks.php;h=c7639ee5f30550e996c26f9f3c7ce2d969970e25;hb=af6a3bc49e46ef9b3cf53fc53faf85aa76ceacc6;hp=4233560b1756aef40485998a4c6fd70cce9033cf;hpb=7f04814796855df90816087a60a5c8b1759ff609;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiQueryLangBacklinks.php b/includes/api/ApiQueryLangBacklinks.php index 4233560b17..c7639ee5f3 100644 --- a/includes/api/ApiQueryLangBacklinks.php +++ b/includes/api/ApiQueryLangBacklinks.php @@ -61,15 +61,17 @@ class ApiQueryLangBacklinks 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( - "ll_lang > '$prefix' OR " . - "(ll_lang = '$prefix' AND " . - "(ll_title > '$title' OR " . - "(ll_title = '$title' AND " . - "ll_from >= $from)))" + "ll_lang $op $prefix OR " . + "(ll_lang = $prefix AND " . + "(ll_title $op $title OR " . + "(ll_title = $title AND " . + "ll_from $op= $from)))" ); } @@ -83,22 +85,23 @@ class ApiQueryLangBacklinks extends ApiQueryGeneratorBase { $this->addFields( array( 'page_id', 'page_title', 'page_namespace', 'page_is_redirect', 'll_from', 'll_lang', 'll_title' ) ); + $sort = ( $params['dir'] == 'descending' ? ' DESC' : '' ); if ( isset( $params['lang'] ) ) { $this->addWhereFld( 'll_lang', $params['lang'] ); if ( isset( $params['title'] ) ) { $this->addWhereFld( 'll_title', $params['title'] ); - $this->addOption( 'ORDER BY', 'll_from' ); + $this->addOption( 'ORDER BY', 'll_from' . $sort ); } else { $this->addOption( 'ORDER BY', array( - 'll_title', - 'll_from' + 'll_title' . $sort, + 'll_from' . $sort )); } } else { $this->addOption( 'ORDER BY', array( - 'll_lang', - 'll_title', - 'll_from' + 'll_lang' . $sort, + 'll_title' . $sort, + 'll_from' . $sort )); } @@ -177,6 +180,13 @@ class ApiQueryLangBacklinks extends ApiQueryGeneratorBase { 'lltitle', ), ), + 'dir' => array( + ApiBase::PARAM_DFLT => 'ascending', + ApiBase::PARAM_TYPE => array( + 'ascending', + 'descending' + ) + ), ); } @@ -191,6 +201,24 @@ class ApiQueryLangBacklinks extends ApiQueryGeneratorBase { ' lltitle - Adds the title of the language ink', ), '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' + ), + 'lllang' => array( + 'lllang' => 'string' + ), + 'lltitle' => array( + 'lltitle' => 'string' + ) ); }