MediaWiki  1.23.2
LinkBatch.php
Go to the documentation of this file.
1 <?php
30 class LinkBatch {
34  public $data = array();
35 
39  protected $caller;
40 
41  function __construct( $arr = array() ) {
42  foreach ( $arr as $item ) {
43  $this->addObj( $item );
44  }
45  }
46 
54  public function setCaller( $caller ) {
55  $this->caller = $caller;
56  }
57 
61  public function addObj( $title ) {
62  if ( is_object( $title ) ) {
63  $this->add( $title->getNamespace(), $title->getDBkey() );
64  } else {
65  wfDebug( "Warning: LinkBatch::addObj got invalid title object\n" );
66  }
67  }
68 
74  public function add( $ns, $dbkey ) {
75  if ( $ns < 0 ) {
76  return;
77  }
78  if ( !array_key_exists( $ns, $this->data ) ) {
79  $this->data[$ns] = array();
80  }
81 
82  $this->data[$ns][str_replace( ' ', '_', $dbkey )] = 1;
83  }
84 
91  public function setArray( $array ) {
92  $this->data = $array;
93  }
94 
100  public function isEmpty() {
101  return $this->getSize() == 0;
102  }
103 
109  public function getSize() {
110  return count( $this->data );
111  }
112 
118  public function execute() {
119  $linkCache = LinkCache::singleton();
120 
121  return $this->executeInto( $linkCache );
122  }
123 
131  protected function executeInto( &$cache ) {
132  wfProfileIn( __METHOD__ );
133  $res = $this->doQuery();
134  $this->doGenderQuery();
135  $ids = $this->addResultToCache( $cache, $res );
136  wfProfileOut( __METHOD__ );
137 
138  return $ids;
139  }
140 
151  public function addResultToCache( $cache, $res ) {
152  if ( !$res ) {
153  return array();
154  }
155 
156  // For each returned entry, add it to the list of good links, and remove it from $remaining
157 
158  $ids = array();
159  $remaining = $this->data;
160  foreach ( $res as $row ) {
161  $title = Title::makeTitle( $row->page_namespace, $row->page_title );
162  $cache->addGoodLinkObjFromRow( $title, $row );
163  $ids[$title->getPrefixedDBkey()] = $row->page_id;
164  unset( $remaining[$row->page_namespace][$row->page_title] );
165  }
166 
167  // The remaining links in $data are bad links, register them as such
168  foreach ( $remaining as $ns => $dbkeys ) {
169  foreach ( $dbkeys as $dbkey => $unused ) {
170  $title = Title::makeTitle( $ns, $dbkey );
171  $cache->addBadLinkObj( $title );
172  $ids[$title->getPrefixedDBkey()] = 0;
173  }
174  }
175 
176  return $ids;
177  }
178 
183  public function doQuery() {
184  if ( $this->isEmpty() ) {
185  return false;
186  }
187  wfProfileIn( __METHOD__ );
188 
189  // This is similar to LinkHolderArray::replaceInternal
190  $dbr = wfGetDB( DB_SLAVE );
191  $table = 'page';
192  $fields = array( 'page_id', 'page_namespace', 'page_title', 'page_len',
193  'page_is_redirect', 'page_latest' );
194  $conds = $this->constructSet( 'page', $dbr );
195 
196  // Do query
197  $caller = __METHOD__;
198  if ( strval( $this->caller ) !== '' ) {
199  $caller .= " (for {$this->caller})";
200  }
201  $res = $dbr->select( $table, $fields, $conds, $caller );
202  wfProfileOut( __METHOD__ );
203 
204  return $res;
205  }
206 
212  public function doGenderQuery() {
213  if ( $this->isEmpty() ) {
214  return false;
215  }
216 
218  if ( !$wgContLang->needsGenderDistinction() ) {
219  return false;
220  }
221 
222  $genderCache = GenderCache::singleton();
223  $genderCache->doLinkBatch( $this->data, $this->caller );
224 
225  return true;
226  }
227 
235  public function constructSet( $prefix, $db ) {
236  return $db->makeWhereFrom2d( $this->data, "{$prefix}_namespace", "{$prefix}_title" );
237  }
238 }
GenderCache\singleton
static singleton()
Definition: GenderCache.php:39
Title\makeTitle
static & makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:398
LinkBatch\__construct
__construct( $arr=array())
Definition: LinkBatch.php:41
data
and how to run hooks for an and one after Each event has a preferably in CamelCase For ArticleDelete hook A clump of code and data that should be run when an event happens This can be either a function and a chunk of data
Definition: hooks.txt:6
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
LinkBatch\doGenderQuery
doGenderQuery()
Do (and cache) {{GENDER:...}} information for userpages in this LinkBatch.
Definition: LinkBatch.php:212
LinkBatch
Class representing a list of titles The execute() method checks them all for existence and adds them ...
Definition: LinkBatch.php:30
LinkBatch\add
add( $ns, $dbkey)
Definition: LinkBatch.php:74
wfGetDB
& wfGetDB( $db, $groups=array(), $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:3650
LinkBatch\setCaller
setCaller( $caller)
Use ->setCaller( METHOD ) to indicate which code is using this class.
Definition: LinkBatch.php:54
wfProfileIn
wfProfileIn( $functionname)
Begin profiling of a function.
Definition: Profiler.php:33
$wgContLang
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the content language as $wgContLang
Definition: design.txt:56
LinkBatch\setArray
setArray( $array)
Set the link list to a given 2-d array First key is the namespace, second is the DB key,...
Definition: LinkBatch.php:91
LinkBatch\execute
execute()
Do the query and add the results to the LinkCache object.
Definition: LinkBatch.php:118
$dbr
$dbr
Definition: testCompression.php:48
LinkBatch\getSize
getSize()
Returns the size of the batch.
Definition: LinkBatch.php:109
LinkBatch\constructSet
constructSet( $prefix, $db)
Construct a WHERE clause which will match all the given titles.
Definition: LinkBatch.php:235
wfProfileOut
wfProfileOut( $functionname='missing')
Stop profiling of a function.
Definition: Profiler.php:46
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
LinkBatch\$caller
$caller
For debugging which method is using this class.
Definition: LinkBatch.php:39
LinkBatch\$data
$data
2-d array, first index namespace, second index dbkey, value arbitrary
Definition: LinkBatch.php:34
LinkBatch\doQuery
doQuery()
Perform the existence test query, return a ResultWrapper with page_id fields.
Definition: LinkBatch.php:183
wfDebug
wfDebug( $text, $dest='all')
Sends a line to the debug log if enabled or, optionally, to a comment in output.
Definition: GlobalFunctions.php:933
$title
presenting them properly to the user as errors is done by the caller $title
Definition: hooks.txt:1324
LinkBatch\executeInto
executeInto(&$cache)
Do the query and add the results to a given LinkCache object Return an array mapping PDBK to ID.
Definition: LinkBatch.php:131
LinkBatch\isEmpty
isEmpty()
Returns true if no pages have been added, false otherwise.
Definition: LinkBatch.php:100
DB_SLAVE
const DB_SLAVE
Definition: Defines.php:55
$cache
$cache
Definition: mcc.php:32
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
LinkBatch\addObj
addObj( $title)
Definition: LinkBatch.php:61
$res
$res
Definition: database.txt:21
LinkBatch\addResultToCache
addResultToCache( $cache, $res)
Add a ResultWrapper containing IDs and titles to a LinkCache object.
Definition: LinkBatch.php:151
LinkCache\singleton
static & singleton()
Get an instance of this class.
Definition: LinkCache.php:49