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
00055
00056 if ( count( $this->getPageSet()->getGoodTitles() ) != 1 )
00057 $this->addOption( 'ORDER BY', 'el_from' );
00058
00059 $this->addOption( 'LIMIT', $params['limit'] + 1 );
00060 if ( !is_null( $params['offset'] ) )
00061 $this->addOption( 'OFFSET', $params['offset'] );
00062
00063 $db = $this->getDB();
00064 $res = $this->select( __METHOD__ );
00065
00066 $count = 0;
00067 while ( $row = $db->fetchObject( $res ) ) {
00068 if ( ++$count > $params['limit'] ) {
00069
00070
00071 $this->setContinueEnumParameter( 'offset', @$params['offset'] + $params['limit'] );
00072 break;
00073 }
00074 $entry = array();
00075 ApiResult :: setContent( $entry, $row->el_to );
00076 $fit = $this->addPageSubItem( $row->el_from, $entry );
00077 if ( !$fit )
00078 {
00079 $this->setContinueEnumParameter( 'offset', @$params['offset'] + $count - 1 );
00080 break;
00081 }
00082 }
00083 $db->freeResult( $res );
00084 }
00085
00086 public function getCacheMode( $params ) {
00087 return 'public';
00088 }
00089
00090 public function getAllowedParams() {
00091 return array(
00092 'limit' => array(
00093 ApiBase :: PARAM_DFLT => 10,
00094 ApiBase :: PARAM_TYPE => 'limit',
00095 ApiBase :: PARAM_MIN => 1,
00096 ApiBase :: PARAM_MAX => ApiBase :: LIMIT_BIG1,
00097 ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2
00098 ),
00099 'offset' => null,
00100 );
00101 }
00102
00103 public function getParamDescription () {
00104 return array(
00105 'limit' => 'How many links to return',
00106 'offset' => 'When more results are available, use this to continue',
00107 );
00108 }
00109
00110 public function getDescription() {
00111 return 'Returns all external urls (not interwikies) from the given page(s)';
00112 }
00113
00114 protected function getExamples() {
00115 return array (
00116 "Get a list of external links on the [[Main Page]]:",
00117 " api.php?action=query&prop=extlinks&titles=Main%20Page",
00118 );
00119 }
00120
00121 public function getVersion() {
00122 return __CLASS__ . ': $Id: ApiQueryExternalLinks.php 69932 2010-07-26 08:03:21Z tstarling $';
00123 }
00124 }