<?php
-
/**
- * Created on Oct 4, 2008
*
- * API for MediaWiki 1.8+
*
- * Copyright © 2008 Roan Kattouw <Firstname>.<Lastname>@home.nl
+ * Created on Oct 4, 2008
+ *
+ * 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
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
*/
-if ( !defined( 'MEDIAWIKI' ) ) {
- // Eclipse helper - will be ignored in production
- require_once( 'ApiQueryBase.php' );
-}
-
/**
* This query action allows clients to retrieve a list of pages
* on the logged-in user's watchlist.
$this->run( $resultPageSet );
}
+ /**
+ * @param $resultPageSet ApiPageSet
+ * @return void
+ */
private function run( $resultPageSet = null ) {
$this->selectNamedDB( 'watchlist', DB_SLAVE, 'watchlist' );
$prop = array_flip( (array)$params['prop'] );
$show = array_flip( (array)$params['show'] );
if ( isset( $show['changed'] ) && isset( $show['!changed'] ) ) {
- $this->dieUsageMsg( array( 'show' ) );
+ $this->dieUsageMsg( 'show' );
}
$this->addTables( 'watchlist' );
"original value returned by the previous query", "_badcontinue" );
}
$ns = intval( $cont[0] );
- $title = $this->getDB()->strencode( $this->titleToKey( $cont[1] ) );
+ $title = $this->getDB()->addQuotes( $this->titleToKey( $cont[1] ) );
+ $op = $params['dir'] == 'ascending' ? '>' : '<';
$this->addWhere(
- "wl_namespace > '$ns' OR " .
- "(wl_namespace = '$ns' AND " .
- "wl_title >= '$title')"
+ "wl_namespace $op $ns OR " .
+ "(wl_namespace = $ns AND " .
+ "wl_title $op= $title)"
);
}
+ $sort = ( $params['dir'] == 'descending' ? ' DESC' : '' );
// Don't ORDER BY wl_namespace if it's constant in the WHERE clause
if ( count( $params['namespace'] ) == 1 ) {
- $this->addOption( 'ORDER BY', 'wl_title' );
+ $this->addOption( 'ORDER BY', 'wl_title' . $sort );
} else {
- $this->addOption( 'ORDER BY', 'wl_namespace, wl_title' );
+ $this->addOption( 'ORDER BY', array(
+ 'wl_namespace' . $sort,
+ 'wl_title' . $sort
+ ));
}
$this->addOption( 'LIMIT', $params['limit'] + 1 );
$res = $this->select( __METHOD__ );
),
'token' => array(
ApiBase::PARAM_TYPE => 'string'
- )
+ ),
+ 'dir' => array(
+ ApiBase::PARAM_DFLT => 'ascending',
+ ApiBase::PARAM_TYPE => array(
+ 'ascending',
+ 'descending'
+ ),
+ ),
);
}
'show' => 'Only list items that meet these criteria',
'owner' => 'The name of the user whose watchlist you\'d like to access',
'token' => 'Give a security token (settable in preferences) to allow access to another user\'s watchlist',
+ 'dir' => 'Direction to sort the titles and namespaces in',
);
}
) );
}
- protected function getExamples() {
+ public function getExamples() {
return array(
'api.php?action=query&list=watchlistraw',
'api.php?action=query&generator=watchlistraw&gwrshow=changed&prop=revisions',
public function getVersion() {
return __CLASS__ . ': $Id$';
}
-}
\ No newline at end of file
+}