X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiQueryAllLinks.php;h=6b8fe57f390c089b20f2e4e0f6643f714e53a1d2;hb=bb52be9f3da314361cdb90642f941aea669a1d3e;hp=340aea37dfd3f26806fd96985d34f82dcad67b87;hpb=43ca814f40307b311bdcc395a877709cc456130f;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiQueryAllLinks.php b/includes/api/ApiQueryAllLinks.php index 340aea37df..6b8fe57f39 100644 --- a/includes/api/ApiQueryAllLinks.php +++ b/includes/api/ApiQueryAllLinks.php @@ -1,9 +1,8 @@ @gmail.com * @@ -21,13 +20,10 @@ * 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' ); -} - /** * Query module to enumerate links from all pages together. * @@ -43,10 +39,18 @@ class ApiQueryAllLinks extends ApiQueryGeneratorBase { $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 ) { $db = $this->getDB(); $params = $this->extractRequestParams(); @@ -72,38 +76,39 @@ class ApiQueryAllLinks extends ApiQueryGeneratorBase { $this->dieUsage( 'alcontinue and alfrom cannot be used together', 'params' ); } if ( !is_null( $params['continue'] ) ) { - $arr = explode( '|', $params['continue'] ); - if ( count( $arr ) != 2 ) { + $continueArr = explode( '|', $params['continue'] ); + if ( count( $continueArr ) != 2 ) { $this->dieUsage( 'Invalid continue parameter', 'badcontinue' ); } - $from = $this->getDB()->strencode( $this->titleToKey( $arr[0] ) ); - $id = intval( $arr[1] ); + $continueTitle = $db->addQuotes( $this->titleToKey( $continueArr[0] ) ); + $continueFrom = intval( $continueArr[1] ); $this->addWhere( - "pl_title > '$from' OR " . - "(pl_title = '$from' AND " . - "pl_from > $id)" + "pl_title > $continueTitle OR " . + "(pl_title = $continueTitle AND " . + "pl_from > $continueFrom)" ); } - if ( !is_null( $params['from'] ) ) { - $this->addWhere( 'pl_title>=' . $db->addQuotes( $this->titlePartToKey( $params['from'] ) ) ); - } + $from = ( is_null( $params['from'] ) ? null : $this->titlePartToKey( $params['from'] ) ); + $to = ( is_null( $params['to'] ) ? null : $this->titlePartToKey( $params['to'] ) ); + $this->addWhereRange( 'pl_title', 'newer', $from, $to ); + if ( isset( $params['prefix'] ) ) { $this->addWhere( 'pl_title' . $db->buildLike( $this->titlePartToKey( $params['prefix'] ), $db->anyString() ) ); } - $this->addFields( array( - 'pl_title', - ) ); + $this->addFields( 'pl_title' ); $this->addFieldsIf( 'pl_from', !$params['unique'] ); $this->addOption( 'USE INDEX', 'pl_namespace' ); $limit = $params['limit']; $this->addOption( 'LIMIT', $limit + 1 ); - if ( $params['unique'] ) { - $this->addOption( 'ORDER BY', 'pl_title' ); - } else { - $this->addOption( 'ORDER BY', 'pl_title, pl_from' ); + + if ( !$params['unique'] ) { + $this->addOption( 'ORDER BY', array( + 'pl_title', + 'pl_from' + )); } $res = $this->select( __METHOD__ ); @@ -157,6 +162,7 @@ class ApiQueryAllLinks extends ApiQueryGeneratorBase { return array( 'continue' => null, 'from' => null, + 'to' => null, 'prefix' => null, 'unique' => false, 'prop' => array( @@ -185,6 +191,7 @@ class ApiQueryAllLinks extends ApiQueryGeneratorBase { $p = $this->getModulePrefix(); return array( 'from' => 'The page title to start enumerating from', + 'to' => 'The page title to stop enumerating at', 'prefix' => 'Search for all page titles that begin with this value', 'unique' => "Only show unique links. Cannot be used with generator or {$p}prop=ids", 'prop' => array( @@ -198,6 +205,18 @@ class ApiQueryAllLinks extends ApiQueryGeneratorBase { ); } + public function getResultProperties() { + return array( + 'ids' => array( + 'fromid' => 'integer' + ), + 'title' => array( + 'ns' => 'namespace', + 'title' => 'string' + ) + ); + } + public function getDescription() { return 'Enumerate all links that point to a given namespace'; } @@ -212,13 +231,17 @@ class ApiQueryAllLinks extends ApiQueryGeneratorBase { ) ); } - protected function getExamples() { + public function getExamples() { return array( - 'api.php?action=query&list=alllinks&alunique&alfrom=B', + 'api.php?action=query&list=alllinks&alunique=&alfrom=B', ); } + public function getHelpUrls() { + return 'https://www.mediawiki.org/wiki/API:Alllinks'; + } + public function getVersion() { return __CLASS__ . ': $Id$'; } -} \ No newline at end of file +}