Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
70.20% covered (warning)
70.20%
735 / 1047
38.14% covered (danger)
38.14%
37 / 97
CRAP
0.00% covered (danger)
0.00%
0 / 1
WikiPage
70.20% covered (warning)
70.20%
735 / 1047
38.14% covered (danger)
38.14%
37 / 97
2923.05
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
2
 __clone
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 convertSelectType
85.71% covered (warning)
85.71%
6 / 7
0.00% covered (danger)
0.00%
0 / 1
5.07
 getPageUpdaterFactory
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getRevisionStore
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getDBLoadBalancer
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getActionOverrides
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getContentHandler
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getTitle
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 clear
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 clearCacheFields
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
1
 clearPreparedEdit
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getQueryInfo
95.45% covered (success)
95.45%
21 / 22
0.00% covered (danger)
0.00%
0 / 1
2
 pageData
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
1 / 1
1
 pageDataFromTitle
90.00% covered (success)
90.00%
9 / 10
0.00% covered (danger)
0.00%
0 / 1
4.02
 pageDataFromId
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 loadPageData
80.00% covered (warning)
80.00%
16 / 20
0.00% covered (danger)
0.00%
0 / 1
9.65
 wasLoadedFrom
83.33% covered (warning)
83.33%
5 / 6
0.00% covered (danger)
0.00%
0 / 1
3.04
 loadFromRow
95.65% covered (success)
95.65%
22 / 23
0.00% covered (danger)
0.00%
0 / 1
5
 getId
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
 exists
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 hasViewableContent
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isRedirect
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
2
 isNew
66.67% covered (warning)
66.67%
2 / 3
0.00% covered (danger)
0.00%
0 / 1
2.15
 getContentModel
68.00% covered (warning)
68.00%
17 / 25
0.00% covered (danger)
0.00%
0 / 1
3.29
 checkTouched
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
6
 getTouched
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 getLanguage
66.67% covered (warning)
66.67%
2 / 3
0.00% covered (danger)
0.00%
0 / 1
2.15
 getLinksTimestamp
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
 getLatest
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
 loadLastEdit
85.71% covered (warning)
85.71%
12 / 14
0.00% covered (danger)
0.00%
0 / 1
6.10
 setLastEdit
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 getRevisionRecord
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getContent
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
 getTimestamp
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 setTimestamp
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getUser
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
12
 getCreator
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
 getUserText
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
12
 getComment
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
12
 getMinorEdit
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
 isCountable
95.45% covered (success)
95.45%
21 / 22
0.00% covered (danger)
0.00%
0 / 1
8
 getRedirectTarget
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 insertRedirectEntry
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 followRedirect
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getRedirectURL
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 1
56
 getContributors
0.00% covered (danger)
0.00%
0 / 28
0.00% covered (danger)
0.00%
0 / 1
6
 shouldCheckParserCache
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
30
 getParserOutput
91.67% covered (success)
91.67%
11 / 12
0.00% covered (danger)
0.00%
0 / 1
6.02
 doViewUpdates
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 1
6
 doPurge
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
12
 insertOn
100.00% covered (success)
100.00%
21 / 21
100.00% covered (success)
100.00%
1 / 1
4
 updateRevisionOn
97.56% covered (success)
97.56%
40 / 41
0.00% covered (danger)
0.00%
0 / 1
8
 hasDifferencesOutsideMainSlot
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
 supportsSections
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 replaceSectionContent
25.00% covered (danger)
25.00%
3 / 12
0.00% covered (danger)
0.00%
0 / 1
27.67
 replaceSectionAtRev
61.11% covered (warning)
61.11%
11 / 18
0.00% covered (danger)
0.00%
0 / 1
9.88
 checkFlags
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
20
 getDerivedDataUpdater
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
1 / 1
9
 newPageUpdater
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
2
 doUserEditContent
96.67% covered (success)
96.67%
29 / 30
0.00% covered (danger)
0.00%
0 / 1
11
 makeParserOptions
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 makeParserOptionsFromTitleAndModel
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
2
 prepareContentForEdit
46.15% covered (danger)
46.15%
6 / 13
0.00% covered (danger)
0.00%
0 / 1
4.41
 doEditUpdates
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
1
 updateParserCache
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
20
 doSecondaryDataUpdates
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
20
 doUpdateRestrictions
91.93% covered (success)
91.93%
148 / 161
0.00% covered (danger)
0.00%
0 / 1
37.72
 getCurrentUpdate
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
 insertNullProtectionRevision
84.85% covered (warning)
84.85%
28 / 33
0.00% covered (danger)
0.00%
0 / 1
5.09
 formatExpiry
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
1 / 1
2
 protectDescription
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
1 / 1
3
 protectDescriptionLog
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
2
 isBatchedDelete
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
2
 doDeleteArticleReal
94.44% covered (success)
94.44%
17 / 18
0.00% covered (danger)
0.00%
0 / 1
4.00
 lockAndGetLatest
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
1 / 1
1
 onArticleCreate
92.86% covered (success)
92.86%
13 / 14
0.00% covered (danger)
0.00%
0 / 1
2.00
 onArticleDelete
70.00% covered (warning)
70.00%
14 / 20
0.00% covered (danger)
0.00%
0 / 1
4.43
 onArticleEdit
100.00% covered (success)
100.00%
19 / 19
100.00% covered (success)
100.00%
1 / 1
3
 queueBacklinksJobs
36.00% covered (danger)
36.00%
9 / 25
0.00% covered (danger)
0.00%
0 / 1
24.78
 purgeInterwikiCheckKey
28.57% covered (danger)
28.57%
4 / 14
0.00% covered (danger)
0.00%
0 / 1
3.46
 getCategories
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
6
 getHiddenCategories
0.00% covered (danger)
0.00%
0 / 15
0.00% covered (danger)
0.00%
0 / 1
12
 getAutoDeleteReason
75.00% covered (warning)
75.00%
3 / 4
0.00% covered (danger)
0.00%
0 / 1
2.06
 updateCategoryCounts
87.93% covered (warning)
87.93%
51 / 58
0.00% covered (danger)
0.00%
0 / 1
12.25
 triggerOpportunisticLinksUpdate
0.00% covered (danger)
0.00%
0 / 25
0.00% covered (danger)
0.00%
0 / 1
72
 isLocal
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getWikiDisplayName
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 getSourceURL
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 __wakeup
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getNamespace
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getDBkey
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getWikiId
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 canExist
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 __toString
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 isSamePageAs
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
12
 toPageRecord
94.74% covered (success)
94.74%
18 / 19
0.00% covered (danger)
0.00%
0 / 1
4.00
1<?php
2/**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 */
20
21use MediaWiki\Category\Category;
22use MediaWiki\CommentStore\CommentStoreComment;
23use MediaWiki\Context\IContextSource;
24use MediaWiki\DAO\WikiAwareEntityTrait;
25use MediaWiki\Deferred\DeferredUpdates;
26use MediaWiki\Edit\PreparedEdit;
27use MediaWiki\HookContainer\ProtectedHookAccessorTrait;
28use MediaWiki\Linker\LinkTarget;
29use MediaWiki\Logger\LoggerFactory;
30use MediaWiki\MainConfigNames;
31use MediaWiki\MediaWikiServices;
32use MediaWiki\Page\DeletePage;
33use MediaWiki\Page\ExistingPageRecord;
34use MediaWiki\Page\PageIdentity;
35use MediaWiki\Page\PageRecord;
36use MediaWiki\Page\PageReference;
37use MediaWiki\Page\PageStoreRecord;
38use MediaWiki\Page\ParserOutputAccess;
39use MediaWiki\Parser\ParserOutput;
40use MediaWiki\Permissions\Authority;
41use MediaWiki\Revision\RevisionRecord;
42use MediaWiki\Revision\RevisionStore;
43use MediaWiki\Revision\SlotRecord;
44use MediaWiki\Status\Status;
45use MediaWiki\Storage\DerivedPageDataUpdater;
46use MediaWiki\Storage\EditResult;
47use MediaWiki\Storage\PageUpdater;
48use MediaWiki\Storage\PageUpdaterFactory;
49use MediaWiki\Storage\PageUpdateStatus;
50use MediaWiki\Storage\PreparedUpdate;
51use MediaWiki\Storage\RevisionSlotsUpdate;
52use MediaWiki\Title\Title;
53use MediaWiki\Title\TitleArrayFromResult;
54use MediaWiki\User\User;
55use MediaWiki\User\UserArrayFromResult;
56use MediaWiki\User\UserIdentity;
57use MediaWiki\Utils\MWTimestamp;
58use MediaWiki\WikiMap\WikiMap;
59use Wikimedia\Assert\Assert;
60use Wikimedia\Assert\PreconditionException;
61use Wikimedia\NonSerializable\NonSerializableTrait;
62use Wikimedia\Rdbms\FakeResultWrapper;
63use Wikimedia\Rdbms\IDatabase;
64use Wikimedia\Rdbms\ILoadBalancer;
65use Wikimedia\Rdbms\IReadableDatabase;
66use Wikimedia\Rdbms\RawSQLValue;
67use Wikimedia\Rdbms\SelectQueryBuilder;
68
69/**
70 * @defgroup Page Page
71 */
72
73/**
74 * Base representation for an editable wiki page.
75 *
76 * Some fields are public only for backwards-compatibility. Use accessor methods.
77 * In the past, this class was part of Article.php and everything was public.
78 *
79 * @ingroup Page
80 */
81class WikiPage implements Stringable, Page, PageRecord {
82    use NonSerializableTrait;
83    use ProtectedHookAccessorTrait;
84    use WikiAwareEntityTrait;
85
86    // Constants for $mDataLoadedFrom and related
87
88    /**
89     * @var Title
90     * @note for access by subclasses only
91     */
92    protected $mTitle;
93
94    /**
95     * @var bool
96     * @note for access by subclasses only
97     */
98    protected $mDataLoaded = false;
99
100    /**
101     * A cache of the page_is_redirect field, loaded with page data
102     * @var bool
103     */
104    private $mPageIsRedirectField = false;
105
106    /**
107     * @var bool
108     */
109    private $mIsNew = false;
110
111    /**
112     * @var int|false False means "not loaded"
113     * @note for access by subclasses only
114     */
115    protected $mLatest = false;
116
117    /**
118     * @var PreparedEdit|false Map of cache fields (text, parser output, ect) for a proposed/new edit
119     * @note for access by subclasses only
120     */
121    protected $mPreparedEdit = false;
122
123    /**
124     * @var int|null
125     */
126    protected $mId = null;
127
128    /**
129     * @var int One of the READ_* constants
130     */
131    protected $mDataLoadedFrom = IDBAccessObject::READ_NONE;
132
133    /**
134     * @var RevisionRecord|null
135     */
136    private $mLastRevision = null;
137
138    /**
139     * @var string Timestamp of the current revision or empty string if not loaded
140     */
141    protected $mTimestamp = '';
142
143    /**
144     * @var string
145     */
146    protected $mTouched = '19700101000000';
147
148    /**
149     * @var string|null
150     */
151    protected $mLanguage = null;
152
153    /**
154     * @var string
155     */
156    protected $mLinksUpdated = '19700101000000';
157
158    /**
159     * @var DerivedPageDataUpdater|null
160     */
161    private $derivedDataUpdater = null;
162
163    /**
164     * @param PageIdentity $pageIdentity
165     */
166    public function __construct( PageIdentity $pageIdentity ) {
167        $pageIdentity->assertWiki( PageIdentity::LOCAL );
168
169        // TODO: remove the need for casting to Title.
170        $title = Title::newFromPageIdentity( $pageIdentity );
171        if ( !$title->canExist() ) {
172            throw new InvalidArgumentException( "WikiPage constructed on a Title that cannot exist as a page: $title" );
173        }
174
175        $this->mTitle = $title;
176    }
177
178    /**
179     * Makes sure that the mTitle object is cloned
180     * to the newly cloned WikiPage.
181     */
182    public function __clone() {
183        $this->mTitle = clone $this->mTitle;
184    }
185
186    /**
187     * Convert 'fromdb', 'fromdbmaster' and 'forupdate' to READ_* constants.
188     *
189     * @param stdClass|string|int $type
190     * @return mixed
191     */
192    public static function convertSelectType( $type ) {
193        switch ( $type ) {
194            case 'fromdb':
195                return IDBAccessObject::READ_NORMAL;
196            case 'fromdbmaster':
197                return IDBAccessObject::READ_LATEST;
198            case 'forupdate':
199                return IDBAccessObject::READ_LOCKING;
200            default:
201                // It may already be an integer or whatever else
202                return $type;
203        }
204    }
205
206    /**
207     * @return PageUpdaterFactory
208     */
209    private function getPageUpdaterFactory(): PageUpdaterFactory {
210        return MediaWikiServices::getInstance()->getPageUpdaterFactory();
211    }
212
213    /**
214     * @return RevisionStore
215     */
216    private function getRevisionStore() {
217        return MediaWikiServices::getInstance()->getRevisionStore();
218    }
219
220    /**
221     * @return ILoadBalancer
222     */
223    private function getDBLoadBalancer() {
224        return MediaWikiServices::getInstance()->getDBLoadBalancer();
225    }
226
227    /**
228     * @todo Move this UI stuff somewhere else
229     *
230     * @see ContentHandler::getActionOverrides
231     * @return array
232     */
233    public function getActionOverrides() {
234        return $this->getContentHandler()->getActionOverrides();
235    }
236
237    /**
238     * Returns the ContentHandler instance to be used to deal with the content of this WikiPage.
239     *
240     * Shorthand for ContentHandler::getForModelID( $this->getContentModel() );
241     *
242     * @return ContentHandler
243     *
244     * @since 1.21
245     */
246    public function getContentHandler() {
247        $factory = MediaWikiServices::getInstance()->getContentHandlerFactory();
248        return $factory->getContentHandler( $this->getContentModel() );
249    }
250
251    /**
252     * Get the title object of the article
253     * @return Title Title object of this page
254     */
255    public function getTitle(): Title {
256        return $this->mTitle;
257    }
258
259    /**
260     * Clear the object
261     * @return void
262     */
263    public function clear() {
264        $this->mDataLoaded = false;
265        $this->mDataLoadedFrom = IDBAccessObject::READ_NONE;
266
267        $this->clearCacheFields();
268    }
269
270    /**
271     * Clear the object cache fields
272     * @return void
273     */
274    protected function clearCacheFields() {
275        $this->mId = null;
276        $this->mPageIsRedirectField = false;
277        $this->mLastRevision = null; // Latest revision
278        $this->mTouched = '19700101000000';
279        $this->mLanguage = null;
280        $this->mLinksUpdated = '19700101000000';
281        $this->mTimestamp = '';
282        $this->mIsNew = false;
283        $this->mLatest = false;
284        // T59026: do not clear $this->derivedDataUpdater since getDerivedDataUpdater() already
285        // checks the requested rev ID and content against the cached one. For most
286        // content types, the output should not change during the lifetime of this cache.
287        // Clearing it can cause extra parses on edit for no reason.
288    }
289
290    /**
291     * Clear the mPreparedEdit cache field, as may be needed by mutable content types
292     * @return void
293     * @since 1.23
294     */
295    public function clearPreparedEdit() {
296        $this->mPreparedEdit = false;
297    }
298
299    /**
300     * Return the tables, fields, and join conditions to be selected to create
301     * a new page object.
302     * @since 1.31
303     * @return array[] With three keys:
304     *   - tables: (string[]) to include in the `$table` to `IReadableDatabase->select()` or
305     *     `SelectQueryBuilder::tables`
306     *   - fields: (string[]) to include in the `$vars` to `IReadableDatabase->select()` or
307     *     `SelectQueryBuilder::fields`
308     *   - joins: (array) to include in the `$join_conds` to `IReadableDatabase->select()` or
309     *     `SelectQueryBuilder::joinConds`
310     * @phan-return array{tables:string[],fields:string[],joins:array}
311     */
312    public static function getQueryInfo() {
313        $pageLanguageUseDB = MediaWikiServices::getInstance()->getMainConfig()->get(
314            MainConfigNames::PageLanguageUseDB );
315
316        $ret = [
317            'tables' => [ 'page' ],
318            'fields' => [
319                'page_id',
320                'page_namespace',
321                'page_title',
322                'page_is_redirect',
323                'page_is_new',
324                'page_random',
325                'page_touched',
326                'page_links_updated',
327                'page_latest',
328                'page_len',
329                'page_content_model',
330            ],
331            'joins' => [],
332        ];
333
334        if ( $pageLanguageUseDB ) {
335            $ret['fields'][] = 'page_lang';
336        }
337
338        return $ret;
339    }
340
341    /**
342     * Fetch a page record with the given conditions
343     * @param IReadableDatabase $dbr
344     * @param array $conditions
345     * @param array $options
346     * @return stdClass|false Database result resource, or false on failure
347     */
348    protected function pageData( $dbr, $conditions, $options = [] ) {
349        $pageQuery = self::getQueryInfo();
350
351        $this->getHookRunner()->onArticlePageDataBefore(
352            $this, $pageQuery['fields'], $pageQuery['tables'], $pageQuery['joins'] );
353
354        $row = $dbr->newSelectQueryBuilder()
355            ->queryInfo( $pageQuery )
356            ->where( $conditions )
357            ->caller( __METHOD__ )
358            ->options( $options )
359            ->fetchRow();
360
361        $this->getHookRunner()->onArticlePageDataAfter( $this, $row );
362
363        return $row;
364    }
365
366    /**
367     * Fetch a page record matching the Title object's namespace and title
368     * using a sanitized title string
369     *
370     * @param IReadableDatabase $dbr
371     * @param Title $title
372     * @param int $recency
373     * @return stdClass|false Database result resource, or false on failure
374     */
375    public function pageDataFromTitle( $dbr, $title, $recency = IDBAccessObject::READ_NORMAL ) {
376        if ( !$title->canExist() ) {
377            return false;
378        }
379        $options = [];
380        if ( ( $recency & IDBAccessObject::READ_EXCLUSIVE ) == IDBAccessObject::READ_EXCLUSIVE ) {
381            $options[] = 'FOR UPDATE';
382        } elseif ( ( $recency & IDBAccessObject::READ_LOCKING ) == IDBAccessObject::READ_LOCKING ) {
383            $options[] = 'LOCK IN SHARE MODE';
384        }
385
386        return $this->pageData( $dbr, [
387            'page_namespace' => $title->getNamespace(),
388            'page_title' => $title->getDBkey() ], $options );
389    }
390
391    /**
392     * Fetch a page record matching the requested ID
393     *
394     * @param IReadableDatabase $dbr
395     * @param int $id
396     * @param array $options
397     * @return stdClass|false Database result resource, or false on failure
398     */
399    public function pageDataFromId( $dbr, $id, $options = [] ) {
400        return $this->pageData( $dbr, [ 'page_id' => $id ], $options );
401    }
402
403    /**
404     * Load the object from a given source by title
405     *
406     * @param stdClass|string|int $from One of the following:
407     *   - A DB query result object.
408     *   - "fromdb" or IDBAccessObject::READ_NORMAL to get from a replica DB.
409     *   - "fromdbmaster" or IDBAccessObject::READ_LATEST to get from the primary DB.
410     *   - "forupdate"  or IDBAccessObject::READ_LOCKING to get from the primary DB
411     *     using SELECT FOR UPDATE.
412     *
413     * @return void
414     */
415    public function loadPageData( $from = 'fromdb' ) {