API:
authorRoan Kattouw <catrope@users.mediawiki.org>
Fri, 4 Apr 2008 11:22:58 +0000 (11:22 +0000)
committerRoan Kattouw <catrope@users.mediawiki.org>
Fri, 4 Apr 2008 11:22:58 +0000 (11:22 +0000)
* Cleaned up ApiPageSet::getRedirectTargets(), now uses the redirect table rather than the pagelinks table (this fixes bug 13965)
* Added possibility to obtain all external links through list=exturlusage (per MinuteElectron's request on the mediawiki-api list)

RELEASE-NOTES
includes/api/ApiPageSet.php
includes/api/ApiQueryExtLinksUsage.php

index afa8778..7aae02e 100644 (file)
@@ -187,6 +187,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * Added fallback8bitEncoding field to meta=siteinfo&siprop=general output
 * (bug 13544) Added prop=revid to action=parse
 * (bug 13603) Added siprop=usergroups to meta=siteinfo
+* Cleaned up redirect resolution
+* Added possibility to obtain all external links through list=exturlusage
 
 === Languages updated in 1.13 ===
 
index 24e9b2d..1acfb2b 100644 (file)
@@ -512,68 +512,33 @@ class ApiPageSet extends ApiQueryBase {
        }
 
        private function getRedirectTargets() {
-
-               $linkBatch = new LinkBatch();
+               $lb = new LinkBatch();
                $db = $this->getDB();
 
-               // find redirect targets for all redirect pages
                $this->profileDBIn();
-               $res = $db->select('pagelinks', array (
-                       'pl_from',
-                       'pl_namespace',
-                       'pl_title'
-               ), array (
-                       'pl_from' => array_keys($this->mPendingRedirectIDs
-               )), __METHOD__);
+               $res = $db->select('redirect', array(
+                               'rd_from',
+                               'rd_namespace',
+                               'rd_title'
+                       ), array('rd_from' => array_keys($this->mPendingRedirectIDs)),
+                       __METHOD__
+               );
                $this->profileDBOut();
 
-               while ($row = $db->fetchObject($res)) {
-
-                       $plfrom = intval($row->pl_from);
-
-                       // Bug 7304 workaround 
-                       // ( http://bugzilla.wikipedia.org/show_bug.cgi?id=7304 )
-                       // A redirect page may have more than one link.
-                       // This code will only use the first link returned. 
-                       if (isset ($this->mPendingRedirectIDs[$plfrom])) { // remove line when bug 7304 is fixed 
-
-                               $titleStrFrom = $this->mPendingRedirectIDs[$plfrom]->getPrefixedText();
-                               $titleStrTo = Title :: makeTitle($row->pl_namespace, $row->pl_title)->getPrefixedText();
-                               unset ($this->mPendingRedirectIDs[$plfrom]); // remove line when bug 7304 is fixed
-
-                               // Avoid an infinite loop by checking if we have already processed this target
-                               if (!isset ($this->mAllPages[$row->pl_namespace][$row->pl_title])) {
-                                       $linkBatch->add($row->pl_namespace, $row->pl_title);
-                               }
-                       } else {
-                               // This redirect page has more than one link.
-                               // This is very slow, but safer until bug 7304 is resolved
-                               $title = Title :: newFromID($plfrom);
-                               $titleStrFrom = $title->getPrefixedText();
-
-                               $article = new Article($title);
-                               $text = $article->getContent();
-                               $titleTo = Title :: newFromRedirect($text);
-                               $titleStrTo = $titleTo->getPrefixedText();
-
-                               if (is_null($titleStrTo))
-                                       ApiBase :: dieDebug(__METHOD__, 'Bug7304 workaround: redir target from {$title->getPrefixedText()} not found');
-
-                               // Avoid an infinite loop by checking if we have already processed this target
-                               if (!isset ($this->mAllPages[$titleTo->getNamespace()][$titleTo->getDBkey()])) {
-                                       $linkBatch->addObj($titleTo);
-                               }
-                       }
-
-                       $this->mRedirectTitles[$titleStrFrom] = $titleStrTo;
+               while($row = $db->fetchObject($res))
+               {
+                       $rdfrom = intval($row->rd_from);
+                       $from = Title::newFromId($row->rd_from)->getPrefixedText();
+                       $to = Title::makeTitle($row->rd_namespace, $row->rd_title)->getPrefixedText();
+                       unset($this->mPendingRedirectIDs[$rdfrom]);
+                       if(!isset($this->mAllPages[$row->rd_namespace][$row->rd_title]))
+                               $lb->add($row->rd_namespace, $row->rd_title);
+                       $this->mRedirectTitles[$from] = $to;
                }
                $db->freeResult($res);
-
-               // All IDs must exist in the page table
-               if (!empty($this->mPendingRedirectIDs[$plfrom]))
+               if(!empty($this->mPendingRedirectIDs))
                        ApiBase :: dieDebug(__METHOD__, 'Invalid redirect IDs were found');
-
-               return $linkBatch;
+               return $lb;
        }
 
        /**
index 2c9b3be..2919adb 100644 (file)
@@ -51,31 +51,34 @@ class ApiQueryExtLinksUsage extends ApiQueryGeneratorBase {
 
                $protocol = $params['protocol'];
                $query = $params['query'];
-               if (is_null($query))
-                       $this->dieUsage('Missing required query parameter', 'params');
                
                // Find the right prefix
                global $wgUrlProtocols;
-               foreach ($wgUrlProtocols as $p) {
-                       if( substr( $p, 0, strlen( $protocol ) ) === $protocol ) {
-                               $protocol = $p;
-                               break;
+               if(!is_null($protocol) && $protocol != '' && !in_array($protocol, $wgUrlProtocols))
+               {
+                       foreach ($wgUrlProtocols as $p) {
+                               if( substr( $p, 0, strlen( $protocol ) ) === $protocol ) {
+                                       $protocol = $p;
+                                       break;
+                               }
                        }
                }
                
-               $likeQuery = LinkFilter::makeLike($query , $protocol);
-               if (!$likeQuery)
-                       $this->dieUsage('Invalid query', 'bad_query');
-               $likeQuery = substr($likeQuery, 0, strpos($likeQuery,'%')+1);
-
+               $db = $this->getDb();
                $this->addTables(array('page','externallinks'));        // must be in this order for 'USE INDEX' 
                $this->addOption('USE INDEX', 'el_index');
-
-               $db = $this->getDB();
                $this->addWhere('page_id=el_from');
-               $this->addWhere('el_index LIKE ' . $db->addQuotes( $likeQuery ));
                $this->addWhereFld('page_namespace', $params['namespace']);
 
+               if(!is_null($query) || $query != '')
+               {
+                       $likeQuery = LinkFilter::makeLike($query , $protocol);
+                       if (!$likeQuery)
+                               $this->dieUsage('Invalid query', 'bad_query');
+                       $likeQuery = substr($likeQuery, 0, strpos($likeQuery,'%')+1);
+                       $this->addWhere('el_index LIKE ' . $db->addQuotes( $likeQuery ));
+               }
+
                $prop = array_flip($params['prop']);
                $fld_ids = isset($prop['ids']);
                $fld_title = isset($prop['title']);
@@ -178,7 +181,7 @@ class ApiQueryExtLinksUsage extends ApiQueryGeneratorBase {
                        'prop' => 'What pieces of information to include',
                        'offset' => 'Used for paging. Use the value returned for "continue"',
                        'protocol' => 'Protocol of the url',
-                       'query' => 'Search string without protocol. See [[Special:LinkSearch]]',
+                       'query' => 'Search string without protocol. See [[Special:LinkSearch]]. Leave empty to list all external links (euprotocol will be ignored)',
                        'namespace' => 'The page namespace(s) to enumerate.',
                        'limit' => 'How many entries to return.'
                );