MediaWiki REL1_29
LinkBatch.php
Go to the documentation of this file.
1<?php
27
34class LinkBatch {
38 public $data = [];
39
43 protected $caller;
44
49 public function __construct( $arr = [] ) {
50 foreach ( $arr as $item ) {
51 $this->addObj( $item );
52 }
53 }
54
62 public function setCaller( $caller ) {
63 $this->caller = $caller;
64 }
65
69 public function addObj( $linkTarget ) {
70 if ( is_object( $linkTarget ) ) {
71 $this->add( $linkTarget->getNamespace(), $linkTarget->getDBkey() );
72 } else {
73 wfDebug( "Warning: LinkBatch::addObj got invalid LinkTarget object\n" );
74 }
75 }
76
81 public function add( $ns, $dbkey ) {
82 if ( $ns < 0 || $dbkey === '' ) {
83 return; // T137083
84 }
85 if ( !array_key_exists( $ns, $this->data ) ) {
86 $this->data[$ns] = [];
87 }
88
89 $this->data[$ns][strtr( $dbkey, ' ', '_' )] = 1;
90 }
91
98 public function setArray( $array ) {
99 $this->data = $array;
100 }
101
107 public function isEmpty() {
108 return $this->getSize() == 0;
109 }
110
116 public function getSize() {
117 return count( $this->data );
118 }
119
125 public function execute() {
126 $linkCache = MediaWikiServices::getInstance()->getLinkCache();
127
128 return $this->executeInto( $linkCache );
129 }
130
138 protected function executeInto( &$cache ) {
139 $res = $this->doQuery();
140 $this->doGenderQuery();
141 $ids = $this->addResultToCache( $cache, $res );
142
143 return $ids;
144 }
145
156 public function addResultToCache( $cache, $res ) {
157 if ( !$res ) {
158 return [];
159 }
160
161 $titleFormatter = MediaWikiServices::getInstance()->getTitleFormatter();
162 // For each returned entry, add it to the list of good links, and remove it from $remaining
163
164 $ids = [];
165 $remaining = $this->data;
166 foreach ( $res as $row ) {
167 $title = new TitleValue( (int)$row->page_namespace, $row->page_title );
168 $cache->addGoodLinkObjFromRow( $title, $row );
169 $pdbk = $titleFormatter->getPrefixedDBkey( $title );
170 $ids[$pdbk] = $row->page_id;
171 unset( $remaining[$row->page_namespace][$row->page_title] );
172 }
173
174 // The remaining links in $data are bad links, register them as such
175 foreach ( $remaining as $ns => $dbkeys ) {
176 foreach ( $dbkeys as $dbkey => $unused ) {
177 $title = new TitleValue( (int)$ns, (string)$dbkey );
178 $cache->addBadLinkObj( $title );
179 $pdbk = $titleFormatter->getPrefixedDBkey( $title );
180 $ids[$pdbk] = 0;
181 }
182 }
183
184 return $ids;
185 }
186
191 public function doQuery() {
192 if ( $this->isEmpty() ) {
193 return false;
194 }
195
196 // This is similar to LinkHolderArray::replaceInternal
198 $table = 'page';
199 $fields = array_merge(
200 LinkCache::getSelectFields(),
201 [ 'page_namespace', 'page_title' ]
202 );
203
204 $conds = $this->constructSet( 'page', $dbr );
205
206 // Do query
207 $caller = __METHOD__;
208 if ( strval( $this->caller ) !== '' ) {
209 $caller .= " (for {$this->caller})";
210 }
211 $res = $dbr->select( $table, $fields, $conds, $caller );
212
213 return $res;
214 }
215
221 public function doGenderQuery() {
222 if ( $this->isEmpty() ) {
223 return false;
224 }
225
227 if ( !$wgContLang->needsGenderDistinction() ) {
228 return false;
229 }
230
231 $genderCache = MediaWikiServices::getInstance()->getGenderCache();
232 $genderCache->doLinkBatch( $this->data, $this->caller );
233
234 return true;
235 }
236
244 public function constructSet( $prefix, $db ) {
245 return $db->makeWhereFrom2d( $this->data, "{$prefix}_namespace", "{$prefix}_title" );
246 }
247}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Class representing a list of titles The execute() method checks them all for existence and adds them ...
Definition LinkBatch.php:34
doGenderQuery()
Do (and cache) {{GENDER:...}} information for userpages in this LinkBatch.
add( $ns, $dbkey)
Definition LinkBatch.php:81
$data
2-d array, first index namespace, second index dbkey, value arbitrary
Definition LinkBatch.php:38
getSize()
Returns the size of the batch.
__construct( $arr=[])
LinkBatch constructor.
Definition LinkBatch.php:49
addResultToCache( $cache, $res)
Add a ResultWrapper containing IDs and titles to a LinkCache object.
$caller
For debugging which method is using this class.
Definition LinkBatch.php:43
isEmpty()
Returns true if no pages have been added, false otherwise.
setCaller( $caller)
Use ->setCaller( METHOD ) to indicate which code is using this class.
Definition LinkBatch.php:62
constructSet( $prefix, $db)
Construct a WHERE clause which will match all the given titles.
execute()
Do the query and add the results to the LinkCache object.
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:98
executeInto(&$cache)
Do the query and add the results to a given LinkCache object Return an array mapping PDBK to ID.
addObj( $linkTarget)
Definition LinkBatch.php:69
doQuery()
Perform the existence test query, return a ResultWrapper with page_id fields.
MediaWikiServices is the service locator for the application scope of MediaWiki.
Represents a page (or page fragment) title within MediaWiki.
Result wrapper for grabbing data queried from an IDatabase object.
$res
Definition database.txt:21
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 local content language as $wgContLang
Definition design.txt:57
when a variable name is used in a it is silently declared as a new local masking the global
Definition design.txt:95
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
namespace and then decline to actually register it file or subcat img or subcat $title
Definition hooks.txt:964
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:40
$cache
Definition mcc.php:33
This document describes the state of Postgres support in and is fairly well maintained The main code is very well while extensions are very hit and miss it is probably the most supported database after MySQL Much of the work in making MediaWiki database agnostic came about through the work of creating Postgres as and are nearing end of but without copying over all the usage comments General notes on the but these can almost always be programmed around *Although Postgres has a true BOOLEAN boolean columns are always mapped to as the code does not always treat the column as a and VARBINARY columns should simply be TEXT The only exception is when VARBINARY is used to store true binary data
Definition postgres.txt:43
const DB_REPLICA
Definition defines.php:25