2006-01-04 23:53:51 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class representing a list of titles
|
|
|
|
|
* The execute() method checks them all for existence and adds them to a LinkCache object
|
2007-05-06 22:18:17 +00:00
|
|
|
*
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @ingroup Cache
|
2006-01-04 23:53:51 +00:00
|
|
|
*/
|
|
|
|
|
class LinkBatch {
|
|
|
|
|
/**
|
|
|
|
|
* 2-d array, first index namespace, second index dbkey, value arbitrary
|
|
|
|
|
*/
|
2006-05-11 22:40:38 +00:00
|
|
|
var $data = array();
|
2006-01-04 23:53:51 +00:00
|
|
|
|
2010-07-08 08:11:14 +00:00
|
|
|
/**
|
|
|
|
|
* For debugging which method is using this class.
|
|
|
|
|
*/
|
|
|
|
|
protected $caller;
|
|
|
|
|
|
2007-01-20 13:34:31 +00:00
|
|
|
function __construct( $arr = array() ) {
|
2006-01-04 23:53:51 +00:00
|
|
|
foreach( $arr as $item ) {
|
|
|
|
|
$this->addObj( $item );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-08 08:11:14 +00:00
|
|
|
/**
|
|
|
|
|
* Use ->setCaller( __METHOD__ ) to indicate which code is using this
|
|
|
|
|
* class. Only used in debugging output.
|
|
|
|
|
* @since 1.17
|
|
|
|
|
*/
|
|
|
|
|
public function setCaller( $caller ) {
|
|
|
|
|
$this->caller = $caller;
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-05 02:52:04 +00:00
|
|
|
/**
|
|
|
|
|
* @param $title Title
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2008-04-09 13:02:34 +00:00
|
|
|
public function addObj( $title ) {
|
2006-01-04 23:53:51 +00:00
|
|
|
if ( is_object( $title ) ) {
|
|
|
|
|
$this->add( $title->getNamespace(), $title->getDBkey() );
|
|
|
|
|
} else {
|
|
|
|
|
wfDebug( "Warning: LinkBatch::addObj got invalid title object\n" );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-04-09 13:02:34 +00:00
|
|
|
public function add( $ns, $dbkey ) {
|
2006-01-04 23:53:51 +00:00
|
|
|
if ( $ns < 0 ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if ( !array_key_exists( $ns, $this->data ) ) {
|
|
|
|
|
$this->data[$ns] = array();
|
|
|
|
|
}
|
|
|
|
|
|
2007-12-03 16:19:47 +00:00
|
|
|
$this->data[$ns][str_replace( ' ', '_', $dbkey )] = 1;
|
2006-01-04 23:53:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set the link list to a given 2-d array
|
|
|
|
|
* First key is the namespace, second is the DB key, value arbitrary
|
|
|
|
|
*/
|
2008-04-09 13:02:34 +00:00
|
|
|
public function setArray( $array ) {
|
2006-01-04 23:53:51 +00:00
|
|
|
$this->data = $array;
|
|
|
|
|
}
|
2006-01-07 13:31:29 +00:00
|
|
|
|
2006-04-22 02:12:59 +00:00
|
|
|
/**
|
|
|
|
|
* Returns true if no pages have been added, false otherwise.
|
|
|
|
|
*/
|
2008-04-09 13:02:34 +00:00
|
|
|
public function isEmpty() {
|
2006-04-22 02:12:59 +00:00
|
|
|
return ($this->getSize() == 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the size of the batch.
|
|
|
|
|
*/
|
2008-04-09 13:02:34 +00:00
|
|
|
public function getSize() {
|
2006-04-22 02:12:59 +00:00
|
|
|
return count( $this->data );
|
|
|
|
|
}
|
|
|
|
|
|
2006-01-05 02:05:53 +00:00
|
|
|
/**
|
|
|
|
|
* Do the query and add the results to the LinkCache object
|
|
|
|
|
* Return an array mapping PDBK to ID
|
|
|
|
|
*/
|
2008-04-09 13:02:34 +00:00
|
|
|
public function execute() {
|
2008-04-09 18:23:34 +00:00
|
|
|
$linkCache = LinkCache::singleton();
|
2006-07-20 14:52:02 +00:00
|
|
|
return $this->executeInto( $linkCache );
|
2006-01-05 02:05:53 +00:00
|
|
|
}
|
2006-01-04 23:53:51 +00:00
|
|
|
|
|
|
|
|
/**
|
2006-01-05 02:05:53 +00:00
|
|
|
* Do the query and add the results to a given LinkCache object
|
2006-01-04 23:53:51 +00:00
|
|
|
* Return an array mapping PDBK to ID
|
|
|
|
|
*/
|
2008-04-09 13:02:34 +00:00
|
|
|
protected function executeInto( &$cache ) {
|
2008-02-20 08:53:12 +00:00
|
|
|
wfProfileIn( __METHOD__ );
|
2006-01-04 23:53:51 +00:00
|
|
|
$res = $this->doQuery();
|
2008-02-20 08:53:12 +00:00
|
|
|
$ids = $this->addResultToCache( $cache, $res );
|
2011-02-12 20:40:40 +00:00
|
|
|
$this->doGenderQuery();
|
2008-02-20 08:53:12 +00:00
|
|
|
wfProfileOut( __METHOD__ );
|
|
|
|
|
return $ids;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2008-04-09 05:34:54 +00:00
|
|
|
* Add a ResultWrapper containing IDs and titles to a LinkCache object.
|
2008-04-14 07:45:50 +00:00
|
|
|
* As normal, titles will go into the static Title cache field.
|
|
|
|
|
* This function *also* stores extra fields of the title used for link
|
2008-04-09 05:34:54 +00:00
|
|
|
* parsing to avoid extra DB queries.
|
2008-02-20 08:53:12 +00:00
|
|
|
*/
|
2008-04-09 13:02:34 +00:00
|
|
|
public function addResultToCache( $cache, $res ) {
|
2006-01-04 23:53:51 +00:00
|
|
|
if ( !$res ) {
|
|
|
|
|
return array();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// For each returned entry, add it to the list of good links, and remove it from $remaining
|
|
|
|
|
|
|
|
|
|
$ids = array();
|
|
|
|
|
$remaining = $this->data;
|
2010-10-13 23:11:40 +00:00
|
|
|
foreach ( $res as $row ) {
|
2008-04-09 12:15:44 +00:00
|
|
|
$title = Title::makeTitle( $row->page_namespace, $row->page_title );
|
2010-06-15 12:14:54 +00:00
|
|
|
$cache->addGoodLinkObj( $row->page_id, $title, $row->page_len, $row->page_is_redirect, $row->page_latest );
|
2006-01-04 23:53:51 +00:00
|
|
|
$ids[$title->getPrefixedDBkey()] = $row->page_id;
|
|
|
|
|
unset( $remaining[$row->page_namespace][$row->page_title] );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// The remaining links in $data are bad links, register them as such
|
|
|
|
|
foreach ( $remaining as $ns => $dbkeys ) {
|
2006-11-25 17:11:58 +00:00
|
|
|
foreach ( $dbkeys as $dbkey => $unused ) {
|
2006-01-04 23:53:51 +00:00
|
|
|
$title = Title::makeTitle( $ns, $dbkey );
|
|
|
|
|
$cache->addBadLinkObj( $title );
|
|
|
|
|
$ids[$title->getPrefixedDBkey()] = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $ids;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Perform the existence test query, return a ResultWrapper with page_id fields
|
|
|
|
|
*/
|
2008-04-09 13:02:34 +00:00
|
|
|
public function doQuery() {
|
2006-04-22 02:12:59 +00:00
|
|
|
if ( $this->isEmpty() ) {
|
2006-01-04 23:53:51 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
2008-02-20 08:53:12 +00:00
|
|
|
wfProfileIn( __METHOD__ );
|
2006-01-04 23:53:51 +00:00
|
|
|
|
2010-07-10 08:14:39 +00:00
|
|
|
// This is similar to LinkHolderArray::replaceInternal
|
2007-01-22 23:50:42 +00:00
|
|
|
$dbr = wfGetDB( DB_SLAVE );
|
2010-07-10 08:14:39 +00:00
|
|
|
$table = 'page';
|
|
|
|
|
$fields = array( 'page_id', 'page_namespace', 'page_title', 'page_len',
|
|
|
|
|
'page_is_redirect', 'page_latest' );
|
|
|
|
|
$conds = $this->constructSet( 'page', $dbr );
|
2006-01-04 23:53:51 +00:00
|
|
|
|
|
|
|
|
// Do query
|
2010-07-10 07:36:09 +00:00
|
|
|
$caller = __METHOD__;
|
|
|
|
|
if ( strval( $this->caller ) !== '' ) {
|
|
|
|
|
$caller .= " (for {$this->caller})";
|
|
|
|
|
}
|
2010-07-10 08:14:39 +00:00
|
|
|
$res = $dbr->select( $table, $fields, $conds, $caller );
|
2008-02-20 08:53:12 +00:00
|
|
|
wfProfileOut( __METHOD__ );
|
2006-01-04 23:53:51 +00:00
|
|
|
return $res;
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-12 20:40:40 +00:00
|
|
|
public function doGenderQuery() {
|
|
|
|
|
if ( $this->isEmpty() ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
global $wgContLang;
|
|
|
|
|
if ( !$wgContLang->needsGenderDistinction() ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$genderCache = GenderCache::singleton();
|
|
|
|
|
$genderCache->dolinkBatch( $this->data, $this->caller );
|
|
|
|
|
}
|
|
|
|
|
|
2006-01-04 23:53:51 +00:00
|
|
|
/**
|
|
|
|
|
* Construct a WHERE clause which will match all the given titles.
|
|
|
|
|
*
|
2010-03-15 21:51:12 +00:00
|
|
|
* @param $prefix String: the appropriate table's field name prefix ('page', 'pl', etc)
|
|
|
|
|
* @param $db DatabaseBase object to use
|
2010-04-16 01:40:05 +00:00
|
|
|
* @return mixed string with SQL where clause fragment, or false if no items.
|
2006-01-04 23:53:51 +00:00
|
|
|
*/
|
2010-04-16 01:40:05 +00:00
|
|
|
public function constructSet( $prefix, $db ) {
|
2010-07-10 08:14:39 +00:00
|
|
|
return $db->makeWhereFrom2d( $this->data, "{$prefix}_namespace", "{$prefix}_title" );
|
2006-01-04 23:53:51 +00:00
|
|
|
}
|
|
|
|
|
}
|