<?php
/**
- * API for MediaWiki 1.8+
+ *
*
* Created on Sep 27, 2008
*
- * Copyright © 2008 Roan Kattouw <Firstname>,<Lastname>@gmail.com
+ * Copyright © 2008 Roan Kattouw <Firstname>.<Lastname>@gmail.com
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* @file
*/
-if ( !defined( 'MEDIAWIKI' ) ) {
- // Eclipse helper - will be ignored in production
- require_once( "ApiQueryBase.php" );
-}
-
/**
* A query module to list duplicates of the given file(s)
*
$this->run( $resultPageSet );
}
+ /**
+ * @param $resultPageSet ApiPageSet
+ * @return
+ */
private function run( $resultPageSet = null ) {
$params = $this->extractRequestParams();
$namespaces = $this->getPageSet()->getAllTitlesByNamespace();
$this->dieUsage( 'Invalid continue param. You should pass the ' .
'original value returned by the previous query', '_badcontinue' );
}
- $orig = $this->getDB()->strencode( $this->titleTokey( $cont[0] ) );
- $dup = $this->getDB()->strencode( $this->titleToKey( $cont[1] ) );
+ $op = $params['dir'] == 'descending' ? '<' : '>';
+ $db = $this->getDB();
+ $orig = $db->addQuotes( $this->titleTokey( $cont[0] ) );
+ $dup = $db->addQuotes( $this->titleToKey( $cont[1] ) );
$this->addWhere(
- "i1.img_name > '$orig' OR " .
- "(i1.img_name = '$orig' AND " .
- "i2.img_name >= '$dup')"
+ "i1.img_name $op $orig OR " .
+ "(i1.img_name = $orig AND " .
+ "i2.img_name $op= $dup)"
);
}
- $this->addOption( 'ORDER BY', 'i1.img_name' );
+ $sort = ( $params['dir'] == 'descending' ? ' DESC' : '' );
+ // Don't order by i1.img_name if it's constant in the WHERE clause
+ if ( count( $this->getPageSet()->getGoodTitles() ) == 1 ) {
+ $this->addOption( 'ORDER BY', 'i2.img_name' . $sort );
+ } else {
+ $this->addOption( 'ORDER BY', array(
+ 'i1.img_name' . $sort,
+ 'i2.img_name' . $sort
+ ));
+ }
$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',
+ );
+ }
+
+ public function getResultProperties() {
+ return array(
+ '' => array(
+ 'name' => 'string',
+ 'user' => 'string',
+ 'timestamp' => 'timestamp'
+ )
);
}
) );
}
- protected function getExamples() {
+ public function getExamples() {
return array(
'api.php?action=query&titles=File:Albert_Einstein_Head.jpg&prop=duplicatefiles',
'api.php?action=query&generator=allimages&prop=duplicatefiles',
);
}
+ public function getHelpUrls() {
+ return 'https://www.mediawiki.org/wiki/API:Properties#duplicatefiles_.2F_df';
+ }
+
public function getVersion() {
return __CLASS__ . ': $Id$';
}