00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 if (!defined('MEDIAWIKI')) {
00027
00028 require_once ("ApiQueryBase.php");
00029 }
00030
00036 class ApiQueryExternalLinks extends ApiQueryBase {
00037
00038 public function __construct($query, $moduleName) {
00039 parent :: __construct($query, $moduleName, 'el');
00040 }
00041
00042 public function execute() {
00043 if ( $this->getPageSet()->getGoodTitleCount() == 0 )
00044 return;
00045
00046 $params = $this->extractRequestParams();
00047 $this->addFields(array (
00048 'el_from',
00049 'el_to'
00050 ));
00051
00052 $this->addTables('externallinks');
00053 $this->addWhereFld('el_from', array_keys($this->getPageSet()->getGoodTitles()));
00054 # Don't order by el_from if it's constant in the WHERE clause
00055 if(count($this->getPageSet()->getGoodTitles()) != 1)
00056 $this->addOption('ORDER BY', 'el_from');
00057 $this->addOption('LIMIT', $params['limit'] + 1);
00058 if(!is_null($params['offset']))
00059 $this->addOption('OFFSET', $params['offset']);
00060
00061 $db = $this->getDB();
00062 $res = $this->select(__METHOD__);
00063
00064 $count = 0;
00065 while ($row = $db->fetchObject($res)) {
00066 if (++$count > $params['limit']) {
00067
00068
00069 $this->setContinueEnumParameter('offset', @$params['offset'] + $params['limit']);
00070 break;
00071 }
00072 $entry = array();
00073 ApiResult :: setContent($entry, $row->el_to);
00074 $fit = $this->addPageSubItem($row->el_from, $entry);
00075 if(!$fit)
00076 {
00077 $this->setContinueEnumParameter('offset', @$params['offset'] + $count - 1);
00078 break;
00079 }
00080 }
00081 $db->freeResult($res);
00082 }
00083
00084 public function getAllowedParams() {
00085 return array(
00086 'limit' => array(
00087 ApiBase :: PARAM_DFLT => 10,
00088 ApiBase :: PARAM_TYPE => 'limit',
00089 ApiBase :: PARAM_MIN => 1,
00090 ApiBase :: PARAM_MAX => ApiBase :: LIMIT_BIG1,
00091 ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2
00092 ),
00093 'offset' => null,
00094 );
00095 }
00096
00097 public function getParamDescription () {
00098 return array(
00099 'limit' => 'How many links to return',
00100 'offset' => 'When more results are available, use this to continue',
00101 );
00102 }
00103
00104 public function getDescription() {
00105 return 'Returns all external urls (not interwikies) from the given page(s)';
00106 }
00107
00108 protected function getExamples() {
00109 return array (
00110 "Get a list of external links on the [[Main Page]]:",
00111 " api.php?action=query&prop=extlinks&titles=Main%20Page",
00112 );
00113 }
00114
00115 public function getVersion() {
00116 return __CLASS__ . ': $Id: ApiQueryExternalLinks.php 46845 2009-02-05 14:30:59Z catrope $';
00117 }
00118 }