}
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;
}
/**
$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']);
'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.'
);