<?php
-
/**
- * Created on July 7, 2007
*
- * API for MediaWiki 1.8+
+ *
+ * Created on July 7, 2007
*
* Copyright © 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
*
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
*/
if ( !defined( 'MEDIAWIKI' ) ) {
$this->run();
}
+ public function getCacheMode( $params ) {
+ return 'public';
+ }
+
public function executeGenerator( $resultPageSet ) {
$this->run( $resultPageSet );
}
+ /**
+ * @param $resultPageSet ApiPageSet
+ * @return void
+ */
private function run( $resultPageSet = null ) {
$params = $this->extractRequestParams();
- $protocol = $params['protocol'];
$query = $params['query'];
+ $protocol = self::getProtocolPrefix( $params['protocol'] );
- // Find the right prefix
- global $wgUrlProtocols;
- if ( $protocol && !in_array( $protocol, $wgUrlProtocols ) ) {
- foreach ( $wgUrlProtocols as $p ) {
- if ( substr( $p, 0, strlen( $protocol ) ) === $protocol ) {
- $protocol = $p;
- break;
- }
- }
- } else {
- $protocol = null;
- }
-
- $db = $this->getDB();
$this->addTables( array( 'page', 'externallinks' ) ); // must be in this order for 'USE INDEX'
$this->addOption( 'USE INDEX', 'el_index' );
$this->addWhere( 'page_id=el_from' );
- $this->addWhereFld( 'page_namespace', $params['namespace'] );
- if ( !is_null( $query ) || $query != '' ) {
- if ( is_null( $protocol ) ) {
- $protocol = 'http://';
- }
+ global $wgMiserMode;
+ $miser_ns = array();
+ if ( $wgMiserMode ) {
+ $miser_ns = $params['namespace'];
+ } else {
+ $this->addWhereFld( 'page_namespace', $params['namespace'] );
+ }
- $likeQuery = LinkFilter::makeLikeArray( $query, $protocol );
- if ( !$likeQuery ) {
- $this->dieUsage( 'Invalid query', 'bad_query' );
- }
+ $whereQuery = $this->prepareUrlQuerySearchString( $query, $protocol );
- $likeQuery = LinkFilter::keepOneWildcard( $likeQuery );
- $this->addWhere( 'el_index ' . $db->buildLike( $likeQuery ) );
- } elseif ( !is_null( $protocol ) ) {
- $this->addWhere( 'el_index ' . $db->buildLike( "$protocol", $db->anyString() ) );
+ if ( $whereQuery !== null ) {
+ $this->addWhere( $whereQuery );
}
$prop = array_flip( $params['prop'] );
$result = $this->getResult();
$count = 0;
- while ( $row = $db->fetchObject( $res ) ) {
+ foreach ( $res as $row ) {
if ( ++ $count > $limit ) {
// We've reached the one extra which shows that there are additional pages to be had. Stop here...
$this->setContinueEnumParameter( 'offset', $offset + $limit );
break;
}
+ if ( count( $miser_ns ) && !in_array( $row->page_namespace, $miser_ns ) ) {
+ continue;
+ }
+
if ( is_null( $resultPageSet ) ) {
$vals = array();
if ( $fld_ids ) {
}
public function getAllowedParams() {
- global $wgUrlProtocols;
- $protocols = array( '' );
- foreach ( $wgUrlProtocols as $p ) {
- $protocols[] = substr( $p, 0, strpos( $p, ':' ) );
- }
-
return array(
'prop' => array(
ApiBase::PARAM_ISMULTI => true,
ApiBase::PARAM_TYPE => 'integer'
),
'protocol' => array(
- ApiBase::PARAM_TYPE => $protocols,
+ ApiBase::PARAM_TYPE => self::prepareProtocols(),
ApiBase::PARAM_DFLT => '',
),
'query' => null,
);
}
+ public static function prepareProtocols() {
+ global $wgUrlProtocols;
+ $protocols = array( '' );
+ foreach ( $wgUrlProtocols as $p ) {
+ $protocols[] = substr( $p, 0, strpos( $p, ':' ) );
+ }
+ return $protocols;
+ }
+
+ public static function getProtocolPrefix( $protocol ) {
+ // Find the right prefix
+ global $wgUrlProtocols;
+ if ( $protocol && !in_array( $protocol, $wgUrlProtocols ) ) {
+ foreach ( $wgUrlProtocols as $p ) {
+ if ( substr( $p, 0, strlen( $protocol ) ) === $protocol ) {
+ $protocol = $p;
+ break;
+ }
+ }
+
+ return $protocol;
+ } else {
+ return null;
+ }
+ }
+
public function getParamDescription() {
+ global $wgMiserMode;
$p = $this->getModulePrefix();
- return array(
- 'prop' => 'What pieces of information to include',
+ $desc = array(
+ 'prop' => array(
+ 'What pieces of information to include',
+ ' ids - Adds the ID of page',
+ ' title - Adds the title and namespace ID of the page',
+ ' url - Adds the URL used in the page',
+ ),
'offset' => 'Used for paging. Use the value returned for "continue"',
'protocol' => array(
"Protocol of the url. If empty and {$p}query set, the protocol is http.",
'namespace' => 'The page namespace(s) to enumerate.',
'limit' => 'How many pages to return.'
);
+
+ if ( $wgMiserMode ) {
+ $desc['namespace'] = array(
+ $desc['namespace'],
+ "NOTE: Due to \$wgMiserMode, using this may result in fewer than \"{$p}limit\" results",
+ 'returned before continuing; in extreme cases, zero results may be returned',
+ );
+ }
+
+ return $desc;
}
public function getDescription() {
public function getVersion() {
return __CLASS__ . ': $Id$';
}
-}
\ No newline at end of file
+}