if ( $sort ) {
$order = $field . ( $isDirNewer ? '' : ' DESC' );
- if ( !isset( $this->options['ORDER BY'] ) ) {
- $this->addOption( 'ORDER BY', $order );
- } else {
- $this->addOption( 'ORDER BY', $this->options['ORDER BY'] . ', ' . $order );
- }
+ // Append ORDER BY
+ $optionOrderBy = isset( $this->options['ORDER BY'] ) ? (array)$this->options['ORDER BY'] : array();
+ $optionOrderBy[] = $order;
+ $this->addOption( 'ORDER BY', $optionOrderBy );
}
}
}
$this->addOption( 'USE INDEX', array( 'categorylinks' => 'cl_from' ) );
+
+ $dir = ( $params['dir'] == 'descending' ? ' DESC' : '' );
// Don't order by cl_from if it's constant in the WHERE clause
if ( count( $this->getPageSet()->getGoodTitles() ) == 1 ) {
- $this->addOption( 'ORDER BY', 'cl_to' );
+ $this->addOption( 'ORDER BY', 'cl_to' . $dir );
} else {
- $this->addOption( 'ORDER BY', "cl_from, cl_to" );
+ $this->addOption( 'ORDER BY', array(
+ 'cl_from' . $dir,
+ 'cl_to' . $dir
+ ));
}
$res = $this->select( __METHOD__ );
'categories' => array(
ApiBase::PARAM_ISMULTI => true,
),
+ 'dir' => array(
+ ApiBase::PARAM_DFLT => 'ascending',
+ ApiBase::PARAM_TYPE => array(
+ 'ascending',
+ 'descending'
+ )
+ ),
);
}
'show' => 'Which kind of categories to show',
'continue' => 'When more results are available, use this to continue',
'categories' => 'Only list these categories. Useful for checking whether a certain page is in a certain category',
+ 'dir' => 'The direction in which to list',
);
}
);
}
- $this->addOption( 'ORDER BY', 'i1.img_name' );
+ $dir = ( $params['dir'] == 'descending' ? ' DESC' : '' );
+ $this->addOption( 'ORDER BY', 'i1.img_name' . $dir );
$this->addOption( 'LIMIT', $params['limit'] + 1 );
$res = $this->select( __METHOD__ );
ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
),
'continue' => null,
+ 'dir' => array(
+ ApiBase::PARAM_DFLT => 'ascending',
+ ApiBase::PARAM_TYPE => array(
+ 'ascending',
+ 'descending'
+ )
+ ),
);
}
return array(
'limit' => 'How many files to return',
'continue' => 'When more results are available, use this to continue',
+ 'dir' => 'The direction in which to list',
);
}
);
}
+ $dir = ( $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' . $dir );
} else {
- $this->addOption( 'ORDER BY', 'iwl_title, iwl_from' );
+ $this->addOption( 'ORDER BY', array(
+ 'iwl_title' . $dir,
+ 'iwl_from' . $dir
+ ));
}
} else {
// Don't order by iwl_from if it's constant in the WHERE clause
if ( count( $this->getPageSet()->getGoodTitles() ) == 1 ) {
- $this->addOption( 'ORDER BY', 'iwl_prefix' );
+ $this->addOption( 'ORDER BY', 'iwl_prefix' . $dir );
} else {
- $this->addOption( 'ORDER BY', 'iwl_from, iwl_prefix' );
+ $this->addOption( 'ORDER BY', array (
+ 'iwl_from' . $dir,
+ 'iwl_prefix' . $dir
+ ));
}
}
'continue' => null,
'prefix' => null,
'title' => null,
+ 'dir' => array(
+ ApiBase::PARAM_DFLT => 'ascending',
+ ApiBase::PARAM_TYPE => array(
+ 'ascending',
+ 'descending'
+ )
+ ),
);
}
'continue' => 'When more results are available, use this to continue',
'prefix' => 'Prefix for the interwiki',
'title' => "Interwiki link to search for. Must be used with {$this->getModulePrefix()}prefix",
+ 'dir' => 'The direction in which to list',
);
}
);
}
+ $dir = ( $params['dir'] == 'descending' ? ' DESC' : '' );
// Don't order by il_from if it's constant in the WHERE clause
if ( count( $this->getPageSet()->getGoodTitles() ) == 1 ) {
- $this->addOption( 'ORDER BY', 'il_to' );
+ $this->addOption( 'ORDER BY', 'il_to' . $dir );
} else {
- $this->addOption( 'ORDER BY', 'il_from, il_to' );
+ $this->addOption( 'ORDER BY', array(
+ 'il_from' . $dir,
+ 'il_to' . $dir
+ ));
}
$this->addOption( 'LIMIT', $params['limit'] + 1 );
'continue' => null,
'images' => array(
ApiBase::PARAM_ISMULTI => true,
- )
+ ),
+ 'dir' => array(
+ ApiBase::PARAM_DFLT => 'ascending',
+ ApiBase::PARAM_TYPE => array(
+ 'ascending',
+ 'descending'
+ )
+ ),
);
}
'limit' => 'How many images to return',
'continue' => 'When more results are available, use this to continue',
'images' => 'Only list these images. Useful for checking whether a certain page has a certain Image.',
+ 'dir' => 'The direction in which to list',
);
}
);
}
+ $dir = ( $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' . $dir );
} else {
- $this->addOption( 'ORDER BY', 'll_title, ll_from' );
+ $this->addOption( 'ORDER BY', array(
+ 'll_title' . $dir,
+ 'll_from' . $dir
+ ));
}
} else {
// Don't order by ll_from if it's constant in the WHERE clause
if ( count( $this->getPageSet()->getGoodTitles() ) == 1 ) {
- $this->addOption( 'ORDER BY', 'll_lang' );
+ $this->addOption( 'ORDER BY', 'll_lang' . $dir );
} else {
- $this->addOption( 'ORDER BY', 'll_from, ll_lang' );
+ $this->addOption( 'ORDER BY', array(
+ 'll_from' . $dir,
+ 'll_lang' . $dir
+ ));
}
}
'url' => false,
'lang' => null,
'title' => null,
+ 'dir' => array(
+ ApiBase::PARAM_DFLT => 'ascending',
+ ApiBase::PARAM_TYPE => array(
+ 'ascending',
+ 'descending'
+ )
+ ),
);
}
'url' => 'Whether to get the full URL',
'lang' => 'Language code',
'title' => "Link to search for. Must be used with {$this->getModulePrefix()}lang",
+ 'dir' => 'The direction in which to list',
);
}
$this->prefix = 'pl';
$this->description = 'link';
$this->titlesParam = 'titles';
+ $this->titlesParamDescription = 'Only list links to these titles. Useful for checking whether a certain page links to a certain title.';
$this->helpUrl = 'http://www.mediawiki.org/wiki/API:Properties#links_.2F_pl';
break;
case self::TEMPLATES:
$this->prefix = 'tl';
$this->description = 'template';
$this->titlesParam = 'templates';
+ $this->titlesParamDescription = 'Only list these templates. Useful for checking whether a certain page uses a certain template.';
$this->helpUrl = 'http://www.mediawiki.org/wiki/API:Properties#templates_.2F_tl';
break;
default:
);
}
+ $dir = ( $params['dir'] == 'descending' ? ' DESC' : '' );
// Here's some MySQL craziness going on: if you use WHERE foo='bar'
// and later ORDER BY foo MySQL doesn't notice the ORDER BY is pointless
// but instead goes and filesorts, because the index for foo was used
// clause from the ORDER BY clause
$order = array();
if ( count( $this->getPageSet()->getGoodTitles() ) != 1 ) {
- $order[] = "{$this->prefix}_from";
+ $order[] = $this->prefix . '_from' . $dir;
}
if ( count( $params['namespace'] ) != 1 ) {
- $order[] = "{$this->prefix}_namespace";
+ $order[] = $this->prefix . '_namespace' . $dir;
}
- $order[] = "{$this->prefix}_title";
- $this->addOption( 'ORDER BY', implode( ', ', $order ) );
- $this->addOption( 'USE INDEX', "{$this->prefix}_from" );
+ $order[] = $this->prefix . "_title" . $dir;
+ $this->addOption( 'ORDER BY', $order );
+ $this->addOption( 'USE INDEX', $this->prefix . '_from' );
$this->addOption( 'LIMIT', $params['limit'] + 1 );
$res = $this->select( __METHOD__ );
$this->titlesParam => array(
ApiBase::PARAM_ISMULTI => true,
),
+ 'dir' => array(
+ ApiBase::PARAM_DFLT => 'ascending',
+ ApiBase::PARAM_TYPE => array(
+ 'ascending',
+ 'descending'
+ )
+ ),
);
}
public function getParamDescription() {
$desc = $this->description;
- $arr = array(
+ return array(
'namespace' => "Show {$desc}s in this namespace(s) only",
'limit' => "How many {$desc}s to return",
'continue' => 'When more results are available, use this to continue',
+ $this->titlesParam => $this->titlesParamDescription,
+ 'dir' => 'The direction in which to list',
);
- if ( $this->getModuleName() == self::LINKS ) {
- $arr[$this->titlesParam] = 'Only list links to these titles. Useful for checking whether a certain page links to a certain title.';
- } elseif ( $this->getModuleName() == self::TEMPLATES ) {
- $arr[$this->titlesParam] = 'Only list these templates. Useful for checking whether a certain page uses a certain template.';
- }
- return $arr;
}
public function getDescription() {