Merge "escape HTML elements in docblock with double quotes"
[lhc/web/wiklou.git] / includes / api / ApiQueryExtLinksUsage.php
index 050f4ef..42b398b 100644 (file)
@@ -4,7 +4,7 @@
  *
  * Created on July 7, 2007
  *
- * Copyright © 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
+ * Copyright © 2006 Yuri Astrakhan "<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
  * @file
  */
 
-if ( !defined( 'MEDIAWIKI' ) ) {
-       // Eclipse helper - will be ignored in production
-       require_once( 'ApiQueryBase.php' );
-}
-
 /**
  * @ingroup API
  */
@@ -60,7 +55,6 @@ class ApiQueryExtLinksUsage extends ApiQueryGeneratorBase {
                $query = $params['query'];
                $protocol = self::getProtocolPrefix( $params['protocol'] );
 
-               $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' );
@@ -73,7 +67,7 @@ class ApiQueryExtLinksUsage extends ApiQueryGeneratorBase {
                        $this->addWhereFld( 'page_namespace', $params['namespace'] );
                }
 
-               $whereQuery = $this->prepareUrlQuerySearchString( $db, $query, $protocol );
+               $whereQuery = $this->prepareUrlQuerySearchString( $query, $protocol );
 
                if ( $whereQuery !== null ) {
                        $this->addWhere( $whereQuery );
@@ -127,6 +121,7 @@ class ApiQueryExtLinksUsage extends ApiQueryGeneratorBase {
                                        ApiQueryBase::addTitleInfo( $vals, $title );
                                }
                                if ( $fld_url ) {
+                                       // We *could* run this through wfExpandUrl() but I think it's better to output the link verbatim, even if it's protocol-relative --Roan
                                        $vals['url'] = $row->el_to;
                                }
                                $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $vals );
@@ -182,9 +177,11 @@ class ApiQueryExtLinksUsage extends ApiQueryGeneratorBase {
                global $wgUrlProtocols;
                $protocols = array( '' );
                foreach ( $wgUrlProtocols as $p ) {
-                       $protocols[] = substr( $p, 0, strpos( $p, ':' ) );
+                       if ( $p !== '//' ) {
+                               $protocols[] = substr( $p, 0, strpos( $p, ':' ) );
+                       }
                }
-           return $protocols;
+               return $protocols;
        }
 
        public static function getProtocolPrefix( $protocol ) {
@@ -235,6 +232,21 @@ class ApiQueryExtLinksUsage extends ApiQueryGeneratorBase {
                return $desc;
        }
 
+       public function getResultProperties() {
+               return array(
+                       'ids' => array(
+                               'pageid' => 'integer'
+                       ),
+                       'title' => array(
+                               'ns' => 'namespace',
+                               'title' => 'string'
+                       ),
+                       'url' => array(
+                               'url' => 'string'
+                       )
+               );
+       }
+
        public function getDescription() {
                return 'Enumerate pages that contain a given URL';
        }
@@ -245,12 +257,16 @@ class ApiQueryExtLinksUsage extends ApiQueryGeneratorBase {
                ) );
        }
 
-       protected function getExamples() {
+       public function getExamples() {
                return array(
                        'api.php?action=query&list=exturlusage&euquery=www.mediawiki.org'
                );
        }
 
+       public function getHelpUrls() {
+               return 'https://www.mediawiki.org/wiki/API:Exturlusage';
+       }
+
        public function getVersion() {
                return __CLASS__ . ': $Id$';
        }