| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
use MediaWiki\Category\Category; |
| 22 |
use MediaWiki\CommentStore\CommentStoreComment; |
| 23 |
use MediaWiki\Content\Content; |
| 24 |
use MediaWiki\Content\ContentHandler; |
| 25 |
use MediaWiki\Context\IContextSource; |
| 26 |
use MediaWiki\DAO\WikiAwareEntityTrait; |
| 27 |
use MediaWiki\Deferred\DeferredUpdates; |
| 28 |
use MediaWiki\Edit\PreparedEdit; |
| 29 |
use MediaWiki\HookContainer\ProtectedHookAccessorTrait; |
| 30 |
use MediaWiki\Linker\LinkTarget; |
| 31 |
use MediaWiki\Logger\LoggerFactory; |
| 32 |
use MediaWiki\MainConfigNames; |
| 33 |
use MediaWiki\MediaWikiServices; |
| 34 |
use MediaWiki\Page\DeletePage; |
| 35 |
use MediaWiki\Page\ExistingPageRecord; |
| 36 |
use MediaWiki\Page\PageIdentity; |
| 37 |
use MediaWiki\Page\PageRecord; |
| 38 |
use MediaWiki\Page\PageReference; |
| 39 |
use MediaWiki\Page\PageStoreRecord; |
| 40 |
use MediaWiki\Page\ParserOutputAccess; |
| 41 |
use MediaWiki\Parser\ParserOptions; |
| 42 |
use MediaWiki\Parser\ParserOutput; |
| 43 |
use MediaWiki\Permissions\Authority; |
| 44 |
use MediaWiki\Revision\RevisionRecord; |
| 45 |
use MediaWiki\Revision\RevisionStore; |
| 46 |
use MediaWiki\Revision\SlotRecord; |
| 47 |
use MediaWiki\Status\Status; |
| 48 |
use MediaWiki\Storage\DerivedPageDataUpdater; |
| 49 |
use MediaWiki\Storage\EditResult; |
| 50 |
use MediaWiki\Storage\PageUpdater; |
| 51 |
use MediaWiki\Storage\PageUpdaterFactory; |
| 52 |
use MediaWiki\Storage\PageUpdateStatus; |
| 53 |
use MediaWiki\Storage\PreparedUpdate; |
| 54 |
use MediaWiki\Storage\RevisionSlotsUpdate; |
| 55 |
use MediaWiki\Title\Title; |
| 56 |
use MediaWiki\Title\TitleArrayFromResult; |
| 57 |
use MediaWiki\User\User; |
| 58 |
use MediaWiki\User\UserArrayFromResult; |
| 59 |
use MediaWiki\User\UserIdentity; |
| 60 |
use MediaWiki\Utils\MWTimestamp; |
| 61 |
use MediaWiki\WikiMap\WikiMap; |
| 62 |
use Wikimedia\Assert\Assert; |
| 63 |
use Wikimedia\Assert\PreconditionException; |
| 64 |
use Wikimedia\NonSerializable\NonSerializableTrait; |
| 65 |
use Wikimedia\Rdbms\FakeResultWrapper; |
| 66 |
use Wikimedia\Rdbms\IDatabase; |
| 67 |
use Wikimedia\Rdbms\IDBAccessObject; |
| 68 |
use Wikimedia\Rdbms\ILoadBalancer; |
| 69 |
use Wikimedia\Rdbms\IReadableDatabase; |
| 70 |
use Wikimedia\Rdbms\RawSQLValue; |
| 71 |
use Wikimedia\Rdbms\SelectQueryBuilder; |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
class WikiPage implements Stringable, Page, PageRecord { |
| 86 |
use NonSerializableTrait; |
| 87 |
use ProtectedHookAccessorTrait; |
| 88 |
use WikiAwareEntityTrait; |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
protected $mTitle; |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
protected $mDataLoaded = false; |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
private $mPageIsRedirectField = false; |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
private $mIsNew = false; |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
protected $mLatest = false; |
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
protected $mPreparedEdit = false; |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
protected $mId = null; |
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
protected $mDataLoadedFrom = IDBAccessObject::READ_NONE; |
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
private $mLastRevision = null; |
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
protected $mTimestamp = ''; |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
protected $mTouched = '19700101000000'; |
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
protected $mLanguage = null; |
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
protected $mLinksUpdated = '19700101000000'; |
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
private $derivedDataUpdater = null; |
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
public function __construct( PageIdentity $pageIdentity ) { |
| 171 |
$pageIdentity->assertWiki( PageIdentity::LOCAL ); |
| 172 |
|
| 173 |
|
| 174 |
$title = Title::newFromPageIdentity( $pageIdentity ); |
| 175 |
if ( !$title->canExist() ) { |
| 176 |
throw new InvalidArgumentException( "WikiPage constructed on a Title that cannot exist as a page: $title" ); |
| 177 |
} |
| 178 |
|
| 179 |
$this->mTitle = $title; |
| 180 |
} |
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
public function __clone() { |
| 187 |
$this->mTitle = clone $this->mTitle; |
| 188 |
} |
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
public static function convertSelectType( $type ) { |
| 197 |
switch ( $type ) { |
| 198 |
case 'fromdb': |
| 199 |
return IDBAccessObject::READ_NORMAL; |
| 200 |
case 'fromdbmaster': |
| 201 |
return IDBAccessObject::READ_LATEST; |
| 202 |
case 'forupdate': |
| 203 |
return IDBAccessObject::READ_LOCKING; |
| 204 |
default: |
| 205 |
|
| 206 |
return $type; |
| 207 |
} |
| 208 |
} |
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
private function getPageUpdaterFactory(): PageUpdaterFactory { |
| 214 |
return MediaWikiServices::getInstance()->getPageUpdaterFactory(); |
| 215 |
} |
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
private function getRevisionStore() { |
| 221 |
return MediaWikiServices::getInstance()->getRevisionStore(); |
| 222 |
} |
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
private function getDBLoadBalancer() { |
| 228 |
return MediaWikiServices::getInstance()->getDBLoadBalancer(); |
| 229 |
} |
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
public function getActionOverrides() { |
| 238 |
return $this->getContentHandler()->getActionOverrides(); |
| 239 |
} |
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
public function getContentHandler() { |
| 251 |
$factory = MediaWikiServices::getInstance()->getContentHandlerFactory(); |
| 252 |
return $factory->getContentHandler( $this->getContentModel() ); |
| 253 |
} |
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
public function getTitle(): Title { |
| 260 |
return $this->mTitle; |
| 261 |
} |
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
public function clear() { |
| 268 |
$this->mDataLoaded = false; |
| 269 |
$this->mDataLoadedFrom = IDBAccessObject::READ_NONE; |
| 270 |
|
| 271 |
$this->clearCacheFields(); |
| 272 |
} |
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
protected function clearCacheFields() { |
| 279 |
$this->mId = null; |
| 280 |
$this->mPageIsRedirectField = false; |
| 281 |
$this->mLastRevision = null; |
| 282 |
$this->mTouched = '19700101000000'; |
| 283 |
$this->mLanguage = null; |
| 284 |
$this->mLinksUpdated = '19700101000000'; |
| 285 |
$this->mTimestamp = ''; |
| 286 |
$this->mIsNew = false; |
| 287 |
$this->mLatest = false; |
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
} |
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
public function clearPreparedEdit() { |
| 300 |
$this->mPreparedEdit = false; |
| 301 |
} |
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
public static function getQueryInfo() { |
| 317 |
$pageLanguageUseDB = MediaWikiServices::getInstance()->getMainConfig()->get( |
| 318 |
MainConfigNames::PageLanguageUseDB ); |
| 319 |
|
| 320 |
$ret = [ |
| 321 |
'tables' => [ 'page' ], |
| 322 |
'fields' => [ |
| 323 |
'page_id', |
| 324 |
'page_namespace', |
| 325 |
'page_title', |
| 326 |
'page_is_redirect', |
| 327 |
'page_is_new', |
| 328 |
'page_random', |
| 329 |
'page_touched', |
| 330 |
'page_links_updated', |
| 331 |
'page_latest', |
| 332 |
'page_len', |
| 333 |
'page_content_model', |
| 334 |
], |
| 335 |
'joins' => [], |
| 336 |
]; |
| 337 |
|
| 338 |
if ( $pageLanguageUseDB ) { |
| 339 |
$ret['fields'][] = 'page_lang'; |
| 340 |
} |
| 341 |
|
| 342 |
return $ret; |
| 343 |
} |
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
protected function pageData( $dbr, $conditions, $options = [] ) { |
| 353 |
$pageQuery = self::getQueryInfo(); |
| 354 |
|
| 355 |
$this->getHookRunner()->onArticlePageDataBefore( |
| 356 |
$this, $pageQuery['fields'], $pageQuery['tables'], $pageQuery['joins'] ); |
| 357 |
|
| 358 |
$row = $dbr->newSelectQueryBuilder() |
| 359 |
->queryInfo( $pageQuery ) |
| 360 |
->where( $conditions ) |
| 361 |
->caller( __METHOD__ ) |
| 362 |
->options( $options ) |
| 363 |
->fetchRow(); |
| 364 |
|
| 365 |
$this->getHookRunner()->onArticlePageDataAfter( $this, $row ); |
| 366 |
|
| 367 |
return $row; |
| 368 |
} |
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
public function pageDataFromTitle( $dbr, $title, $recency = IDBAccessObject::READ_NORMAL ) { |
| 380 |
if ( !$title->canExist() ) { |
| 381 |
return false; |
| 382 |
} |
| 383 |
$options = []; |
| 384 |
if ( ( $recency & IDBAccessObject::READ_EXCLUSIVE ) == IDBAccessObject::READ_EXCLUSIVE ) { |
| 385 |
$options[] = 'FOR UPDATE'; |
| 386 |
} elseif ( ( $recency & IDBAccessObject::READ_LOCKING ) == IDBAccessObject::READ_LOCKING ) { |
| 387 |
$options[] = 'LOCK IN SHARE MODE'; |
| 388 |
} |
| 389 |
|
| 390 |
return $this->pageData( $dbr, [ |
| 391 |
'page_namespace' => $title->getNamespace(), |
| 392 |
'page_title' => $title->getDBkey() ], $options ); |
| 393 |
} |
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
public function pageDataFromId( $dbr, $id, $options = [] ) { |
| 404 |
return $this->pageData( $dbr, [ 'page_id' => $id ], $options ); |
| 405 |
} |
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
public function loadPageData( $from = 'fromdb' ) { |
| 420 |
$from = self::convertSelectType( $from ); |
| 421 |
if ( is_int( $from ) && $from <= $this->mDataLoadedFrom ) { |
| 422 |
|
| 423 |
return; |
| 424 |
} |
| 425 |
|
| 426 |
if ( is_int( $from ) ) { |
| 427 |
$loadBalancer = $this->getDBLoadBalancer(); |
| 428 |
if ( ( $from & IDBAccessObject::READ_LATEST ) == IDBAccessObject::READ_LATEST ) { |
| 429 |
$index = DB_PRIMARY; |
| 430 |
} else { |
| 431 |
$index = DB_REPLICA; |
| 432 |
} |
| 433 |
$db = $loadBalancer->getConnection( $index ); |
| 434 |
$data = $this->pageDataFromTitle( $db, $this->mTitle, $from ); |
| 435 |
|
| 436 |
if ( !$data |
| 437 |
&& $index == DB_REPLICA |
| 438 |
&& $loadBalancer->hasReplicaServers() |
| 439 |
&& $loadBalancer->hasOrMadeRecentPrimaryChanges() |
| 440 |
) { |
| 441 |
$from = IDBAccessObject::READ_LATEST; |
| 442 |
$db = $loadBalancer->getConnection( DB_PRIMARY ); |
| 443 |
$data = $this->pageDataFromTitle( $db, $this->mTitle, $from ); |
| 444 |
} |
| 445 |
} else { |
| 446 |
|
| 447 |
$data = $from; |
| 448 |
$from = IDBAccessObject::READ_NORMAL; |
| 449 |
} |
| 450 |
|
| 451 |
$this->loadFromRow( $data, $from ); |
| 452 |
} |
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
public function wasLoadedFrom( $from ) { |
| 468 |
$from = self::convertSelectType( $from ); |
| 469 |
|
| 470 |
if ( !is_int( $from ) ) { |
| 471 |
|
| 472 |
$from = IDBAccessObject::READ_NORMAL; |
| 473 |
} |
| 474 |
|
| 475 |
if ( $from <= $this->mDataLoadedFrom ) { |
| 476 |
return true; |
| 477 |
} |
| 478 |
|
| 479 |
return false; |
| 480 |
} |
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
public function loadFromRow( $data, $from ) { |
| 494 |
$lc = MediaWikiServices::getInstance()->getLinkCache(); |
| 495 |
$lc->clearLink( $this->mTitle ); |
| 496 |
|
| 497 |
if ( $data ) { |
| 498 |
$lc->addGoodLinkObjFromRow( $this->mTitle, $data ); |
| 499 |
|
| 500 |
$this->mTitle->loadFromRow( $data ); |
| 501 |
$this->mId = intval( $data->page_id ); |
| 502 |
$this->mTouched = MWTimestamp::convert( TS_MW, $data->page_touched ); |
| 503 |
$this->mLanguage = $data->page_lang ?? null; |
| 504 |
$this->mLinksUpdated = $data->page_links_updated === null |
| 505 |
? null |
| 506 |
: MWTimestamp::convert( TS_MW, $data->page_links_updated ); |
| 507 |
$this->mPageIsRedirectField = (bool)$data->page_is_redirect; |
| 508 |
$this->mIsNew = (bool)( $data->page_is_new ?? 0 ); |
| 509 |
$this->mLatest = intval( $data->page_latest ); |
| 510 |
|
| 511 |
|
| 512 |
if ( $this->mLastRevision && $this->mLastRevision->getId() != $this->mLatest ) { |
| 513 |
$this->mLastRevision = null; |
| 514 |
$this->mTimestamp = ''; |
| 515 |
} |
| 516 |
} else { |
| 517 |
$lc->addBadLinkObj( $this->mTitle ); |
| 518 |
|
| 519 |
$this->mTitle->loadFromRow( false ); |
| 520 |
|
| 521 |
$this->clearCacheFields(); |
| 522 |
|
| 523 |
$this->mId = 0; |
| 524 |
} |
| 525 |
|
| 526 |
$this->mDataLoaded = true; |
| 527 |
$this->mDataLoadedFrom = self::convertSelectType( $from ); |
| 528 |
} |
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
public function getId( $wikiId = self::LOCAL ): int { |
| 536 |
$this->assertWiki( $wikiId ); |
| 537 |
|
| 538 |
if ( !$this->mDataLoaded ) { |
| 539 |
$this->loadPageData(); |
| 540 |
} |
| 541 |
return $this->mId; |
| 542 |
} |
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
public function exists(): bool { |
| 548 |
if ( !$this->mDataLoaded ) { |
| 549 |
$this->loadPageData(); |
| 550 |
} |
| 551 |
return $this->mId > 0; |
| 552 |
} |
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
public function hasViewableContent() { |
| 563 |
return $this->mTitle->isKnown(); |
| 564 |
} |
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
public function isRedirect() { |
| 573 |
$this->loadPageData(); |
| 574 |
if ( $this->mPageIsRedirectField ) { |
| 575 |
return MediaWikiServices::getInstance()->getRedirectLookup() |
| 576 |
->getRedirectTarget( $this->getTitle() ) !== null; |
| 577 |
} |
| 578 |
|
| 579 |
return false; |
| 580 |
} |
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
public function isNew() { |
| 591 |
if ( !$this->mDataLoaded ) { |
| 592 |
$this->loadPageData(); |
| 593 |
} |
| 594 |
|
| 595 |
return $this->mIsNew; |
| 596 |
} |
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
public function getContentModel() { |
| 609 |
if ( $this->exists() ) { |
| 610 |
$cache = MediaWikiServices::getInstance()->getMainWANObjectCache(); |
| 611 |
|
| 612 |
return $cache->getWithSetCallback( |
| 613 |
$cache->makeKey( 'page-content-model', $this->getLatest() ), |
| 614 |
$cache::TTL_MONTH, |
| 615 |
function () { |
| 616 |
$rev = $this->getRevisionRecord(); |
| 617 |
if ( $rev ) { |
| 618 |
|
| 619 |
$slot = $rev->getSlot( |
| 620 |
SlotRecord::MAIN, |
| 621 |
RevisionRecord::RAW |
| 622 |
); |
| 623 |
return $slot->getModel(); |
| 624 |
} else { |
| 625 |
LoggerFactory::getInstance( 'wikipage' )->warning( |
| 626 |
'Page exists but has no (visible) revisions!', |
| 627 |
[ |
| 628 |
'page-title' => $this->mTitle->getPrefixedDBkey(), |
| 629 |
'page-id' => $this->getId(), |
| 630 |
] |
| 631 |
); |
| 632 |
return $this->mTitle->getContentModel(); |
| 633 |
} |
| 634 |
}, |
| 635 |
[ 'pcTTL' => $cache::TTL_PROC_LONG ] |
| 636 |
); |
| 637 |
} |
| 638 |
|
| 639 |
|
| 640 |
return $this->mTitle->getContentModel(); |
| 641 |
} |
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
public function checkTouched() { |
| 648 |
return ( $this->exists() && !$this->isRedirect() ); |
| 649 |
} |
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
public function getTouched() { |
| 656 |
if ( !$this->mDataLoaded ) { |
| 657 |
$this->loadPageData(); |
| 658 |
} |
| 659 |
return $this->mTouched; |
| 660 |
} |
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
public function getLanguage() { |
| 666 |
if ( !$this->mDataLoaded ) { |
| 667 |
$this->loadLastEdit(); |
| 668 |
} |
| 669 |
|
| 670 |
return $this->mLanguage; |
| 671 |
} |
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
public function getLinksTimestamp() { |
| 678 |
if ( !$this->mDataLoaded ) { |
| 679 |
$this->loadPageData(); |
| 680 |
} |
| 681 |
return $this->mLinksUpdated; |
| 682 |
} |
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
public function getLatest( $wikiId = self::LOCAL ) { |
| 690 |
$this->assertWiki( $wikiId ); |
| 691 |
|
| 692 |
if ( !$this->mDataLoaded ) { |
| 693 |
$this->loadPageData(); |
| 694 |
} |
| 695 |
return (int)$this->mLatest; |
| 696 |
} |
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
protected function loadLastEdit() { |
| 703 |
if ( $this->mLastRevision !== null ) { |
| 704 |
return; |
| 705 |
} |
| 706 |
|
| 707 |
$latest = $this->getLatest(); |
| 708 |
if ( !$latest ) { |
| 709 |
return; |
| 710 |
} |
| 711 |
|
| 712 |
if ( $this->mDataLoadedFrom == IDBAccessObject::READ_LOCKING ) { |
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
$revision = $this->getRevisionStore() |
| 721 |
->getRevisionByPageId( $this->getId(), $latest, IDBAccessObject::READ_LOCKING ); |
| 722 |
} elseif ( $this->mDataLoadedFrom == IDBAccessObject::READ_LATEST ) { |
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
$revision = $this->getRevisionStore() |
| 727 |
->getRevisionByPageId( $this->getId(), $latest, IDBAccessObject::READ_LATEST ); |
| 728 |
} else { |
| 729 |
$revision = $this->getRevisionStore()->getKnownCurrentRevision( $this->getTitle(), $latest ); |
| 730 |
} |
| 731 |
|
| 732 |
if ( $revision ) { |
| 733 |
$this->setLastEdit( $revision ); |
| 734 |
} |
| 735 |
} |
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
private function setLastEdit( RevisionRecord $revRecord ) { |
| 742 |
$this->mLastRevision = $revRecord; |
| 743 |
$this->mLatest = $revRecord->getId(); |
| 744 |
$this->mTimestamp = $revRecord->getTimestamp(); |
| 745 |
$this->mTouched = max( $this->mTouched, $revRecord->getTimestamp() ); |
| 746 |
} |
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
public function getRevisionRecord() { |
| 754 |
$this->loadLastEdit(); |
| 755 |
return $this->mLastRevision; |
| 756 |
} |
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
|
| 763 |
|
| 764 |
|
| 765 |
|
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
public function getContent( $audience = RevisionRecord::FOR_PUBLIC, ?Authority $performer = null ) { |
| 772 |
$this->loadLastEdit(); |
| 773 |
if ( $this->mLastRevision ) { |
| 774 |
return $this->mLastRevision->getContent( SlotRecord::MAIN, $audience, $performer ); |
| 775 |
} |
| 776 |
return null; |
| 777 |
} |
| 778 |
|
| 779 |
|
| 780 |
|
| 781 |
|
| 782 |
public function getTimestamp() { |
| 783 |
|
| 784 |
if ( !$this->mTimestamp ) { |
| 785 |
$this->loadLastEdit(); |
| 786 |
} |
| 787 |
|
| 788 |
return MWTimestamp::convert( TS_MW, $this->mTimestamp ); |
| 789 |
} |
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
|
| 796 |
public function setTimestamp( $ts ) { |
| 797 |
$this->mTimestamp = MWTimestamp::convert( TS_MW, $ts ); |
| 798 |
} |
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
|
| 805 |
|
| 806 |
|
| 807 |
|
| 808 |
|
| 809 |
|
| 810 |
public function getUser( $audience = RevisionRecord::FOR_PUBLIC, ?Authority $performer = null ) { |
| 811 |
$this->loadLastEdit(); |
| 812 |
if ( $this->mLastRevision ) { |
| 813 |
$revUser = $this->mLastRevision->getUser( $audience, $performer ); |
| 814 |
return $revUser ? $revUser->getId() : 0; |
| 815 |
} else { |
| 816 |
return -1; |
| 817 |
} |
| 818 |
} |
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
|
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
|
| 831 |
public function getCreator( $audience = RevisionRecord::FOR_PUBLIC, ?Authority $performer = null ) { |
| 832 |
$revRecord = $this->getRevisionStore()->getFirstRevision( $this->getTitle() ); |
| 833 |
if ( $revRecord ) { |
| 834 |
return $revRecord->getUser( $audience, $performer ); |
| 835 |
} else { |
| 836 |
return null; |
| 837 |
} |
| 838 |
} |
| 839 |
|
| 840 |
|
| 841 |
|
| 842 |
|
| 843 |
|
| 844 |
|
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
|
| 850 |
public function getUserText( $audience = RevisionRecord::FOR_PUBLIC, ?Authority $performer = null ) { |
| 851 |
$this->loadLastEdit(); |
| 852 |
if ( $this->mLastRevision ) { |
| 853 |
$revUser = $this->mLastRevision->getUser( $audience, $performer ); |
| 854 |
return $revUser ? $revUser->getName() : ''; |
| 855 |
} else { |
| 856 |
return ''; |
| 857 |
} |
| 858 |
} |
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
|
| 864 |
|
| 865 |
|
| 866 |
|
| 867 |
|
| 868 |
|
| 869 |
|
| 870 |
|
| 871 |
public function getComment( $audience = RevisionRecord::FOR_PUBLIC, ?Authority $performer = null ) { |
| 872 |
$this->loadLastEdit(); |
| 873 |
if ( $this->mLastRevision ) { |
| 874 |
$revComment = $this->mLastRevision->getComment( $audience, $performer ); |
| 875 |
return $revComment ? $revComment->text : ''; |
| 876 |
} else { |
| 877 |
return ''; |
| 878 |
} |
| 879 |
} |
| 880 |
|
| 881 |
|
| 882 |
|
| 883 |
|
| 884 |
|
| 885 |
|
| 886 |
public function getMinorEdit() { |
| 887 |
$this->loadLastEdit(); |
| 888 |
if ( $this->mLastRevision ) { |
| 889 |
return $this->mLastRevision->isMinor(); |
| 890 |
} else { |
| 891 |
return false; |
| 892 |
} |
| 893 |
} |
| 894 |
|
| 895 |
|
| 896 |
|
| 897 |
|
| 898 |
|
| 899 |
|
| 900 |
|
| 901 |
|
| 902 |
|
| 903 |
|
| 904 |
|
| 905 |
public function isCountable( $editInfo = false ) { |
| 906 |
$mwServices = MediaWikiServices::getInstance(); |
| 907 |
$articleCountMethod = $mwServices->getMainConfig()->get( MainConfigNames::ArticleCountMethod ); |
| 908 |
|
| 909 |
|
| 910 |
|
| 911 |
if ( !$this->mTitle->isContentPage() ) { |
| 912 |
return false; |
| 913 |
} |
| 914 |
|
| 915 |
if ( $editInfo instanceof PreparedEdit ) { |
| 916 |
|
| 917 |
$content = $editInfo->pstContent; |
| 918 |
} elseif ( $editInfo instanceof PreparedUpdate ) { |
| 919 |
|
| 920 |
$content = $editInfo->getRawContent( SlotRecord::MAIN ); |
| 921 |
} else { |
| 922 |
$content = $this->getContent(); |
| 923 |
} |
| 924 |
|
| 925 |
if ( !$content || $content->isRedirect() ) { |
| 926 |
return false; |
| 927 |
} |
| 928 |
|
| 929 |
$hasLinks = null; |
| 930 |
|
| 931 |
if ( $articleCountMethod === 'link' ) { |
| 932 |
|
| 933 |
|
| 934 |
if ( $editInfo ) { |
| 935 |
|
| 936 |
|
| 937 |
|
| 938 |
|
| 939 |
$hasLinks = (bool)count( $editInfo->output->getLinks() ); |
| 940 |
} else { |
| 941 |
|
| 942 |
|
| 943 |
$dbr = $mwServices->getConnectionProvider()->getReplicaDatabase(); |
| 944 |
$hasLinks = (bool)$dbr->newSelectQueryBuilder() |
| 945 |
->select( '1' ) |
| 946 |
->from( 'pagelinks' ) |
| 947 |
->where( [ 'pl_from' => $this->getId() ] ) |
| 948 |
->caller( __METHOD__ )->fetchField(); |
| 949 |
} |
| 950 |
} |
| 951 |
|
| 952 |
|
| 953 |
|
| 954 |
|
| 955 |
|
| 956 |
return $content->isCountable( $hasLinks ); |
| 957 |
} |
| 958 |
|
| 959 |
|
| 960 |
|
| 961 |
|
| 962 |
|
| 963 |
|
| 964 |
|
| 965 |
|
| 966 |
|
| 967 |
|
| 968 |
public function getRedirectTarget() { |
| 969 |
$target = MediaWikiServices::getInstance()->getRedirectLookup()->getRedirectTarget( $this ); |
| 970 |
return Title::castFromLinkTarget( $target ); |
| 971 |
} |
| 972 |
|
| 973 |
|
| 974 |
|
| 975 |
|
| 976 |
|
| 977 |
|
| 978 |
|
| 979 |
|
| 980 |
public function insertRedirectEntry( LinkTarget $rt, $oldLatest = null ) { |
| 981 |
return MediaWikiServices::getInstance()->getRedirectStore() |
| 982 |
->updateRedirectTarget( $this, $rt ); |
| 983 |
} |
| 984 |
|
| 985 |
|
| 986 |
|
| 987 |
|
| 988 |
|
| 989 |
|
| 990 |
public function followRedirect() { |
| 991 |
return $this->getRedirectURL( $this->getRedirectTarget() ); |
| 992 |
} |
| 993 |
|
| 994 |
|
| 995 |
|
| 996 |
|
| 997 |
|
| 998 |
|
| 999 |
|
| 1000 |
|
| 1001 |
public function getRedirectURL( $rt ) { |
| 1002 |
if ( !$rt ) { |
| 1003 |
return false; |
| 1004 |
} |
| 1005 |
|
| 1006 |
if ( $rt->isExternal() ) { |
| 1007 |
if ( $rt->isLocal() ) { |
| 1008 |
|
| 1009 |
|
| 1010 |
|
| 1011 |
$source = $this->mTitle->getFullURL( 'redirect=no' ); |
| 1012 |
return $rt->getFullURL( [ 'rdfrom' => $source ] ); |
| 1013 |
} else { |
| 1014 |
|
| 1015 |
|
| 1016 |
return false; |
| 1017 |
} |
| 1018 |
} |
| 1019 |
|
| 1020 |
if ( $rt->isSpecialPage() ) { |
| 1021 |
|
| 1022 |
|
| 1023 |
|
| 1024 |
if ( $rt->isValidRedirectTarget() ) { |
| 1025 |
return $rt->getFullURL(); |
| 1026 |
} else { |
| 1027 |
return false; |
| 1028 |
} |
| 1029 |
} elseif ( !$rt->isValidRedirectTarget() ) { |
| 1030 |
|
| 1031 |
return false; |
| 1032 |
} |
| 1033 |
|
| 1034 |
return $rt; |
| 1035 |
} |
| 1036 |
|
| 1037 |
|
| 1038 |
|
| 1039 |
|
| 1040 |
|
| 1041 |
|
| 1042 |
public function getContributors() { |
| 1043 |
|
| 1044 |
|
| 1045 |
$services = MediaWikiServices::getInstance(); |
| 1046 |
$dbr = $services->getConnectionProvider()->getReplicaDatabase(); |
| 1047 |
$actorNormalization = $services->getActorNormalization(); |
| 1048 |
$userIdentityLookup = $services->getUserIdentityLookup(); |
| 1049 |
|
| 1050 |
$user = $this->getUser() |
| 1051 |
? User::newFromId( $this->getUser() ) |
| 1052 |
: User::newFromName( $this->getUserText(), false ); |
| 1053 |
|
| 1054 |
$res = $dbr->newSelectQueryBuilder() |
| 1055 |
->select( [ |
| 1056 |
'user_id' => 'actor_user', |
| 1057 |
'user_name' => 'actor_name', |
| 1058 |
'actor_id' => 'MIN(rev_actor)', |
| 1059 |
'user_real_name' => 'MIN(user_real_name)', |
| 1060 |
'timestamp' => 'MAX(rev_timestamp)', |
| 1061 |
] ) |
| 1062 |
->from( 'revision' ) |
| 1063 |
->join( 'actor', null, 'rev_actor = actor_id' ) |
| 1064 |
->leftJoin( 'user', null, 'actor_user = user_id' ) |
| 1065 |
->where( [ |
| 1066 |
'rev_page' => $this->getId(), |
| 1067 |
|
| 1068 |
|
| 1069 |
$dbr->expr( 'rev_actor', '!=', $actorNormalization->findActorId( $user, $dbr ) ), |
| 1070 |
|
| 1071 |
$dbr->bitAnd( 'rev_deleted', RevisionRecord::DELETED_USER ) . ' = 0', |
| 1072 |
] ) |
| 1073 |
->groupBy( [ 'actor_user', 'actor_name' ] ) |
| 1074 |
->orderBy( 'timestamp', SelectQueryBuilder::SORT_DESC ) |
| 1075 |
->caller( __METHOD__ ) |
| 1076 |
->fetchResultSet(); |
| 1077 |
return new UserArrayFromResult( $res ); |
| 1078 |
} |
| 1079 |
|
| 1080 |
|
| 1081 |
|
| 1082 |
|
| 1083 |
|
| 1084 |
|
| 1085 |
|
| 1086 |
|
| 1087 |
public function shouldCheckParserCache( ParserOptions $parserOptions, $oldId ) { |
| 1088 |
|
| 1089 |
|
| 1090 |
return $this->exists() |
| 1091 |
&& ( $oldId === null || $oldId === 0 || $oldId === $this->getLatest() ) |
| 1092 |
&& $this->getContentHandler()->isParserCacheSupported(); |
| 1093 |
} |
| 1094 |
|
| 1095 |
|
| 1096 |
|
| 1097 |
|
| 1098 |
|
| 1099 |
|
| 1100 |
|
| 1101 |
|
| 1102 |
|
| 1103 |
|
| 1104 |
|
| 1105 |
|
| 1106 |
|
| 1107 |
|
| 1108 |
|
| 1109 |
|
| 1110 |
public function getParserOutput( |
| 1111 |
?ParserOptions $parserOptions = null, $oldid = null, $noCache = false |
| 1112 |
) { |
| 1113 |
if ( $oldid ) { |
| 1114 |
$revision = $this->getRevisionStore()->getRevisionByTitle( $this->getTitle(), $oldid ); |
| 1115 |
|
| 1116 |
if ( !$revision ) { |
| 1117 |
return false; |
| 1118 |
} |
| 1119 |
} else { |
| 1120 |
$revision = $this->getRevisionRecord(); |
| 1121 |
} |
| 1122 |
|
| 1123 |
if ( !$parserOptions ) { |
| 1124 |
$parserOptions = ParserOptions::newFromAnon(); |
| 1125 |
} |
| 1126 |
|
| 1127 |
$options = $noCache ? ParserOutputAccess::OPT_NO_CACHE : 0; |
| 1128 |
|
| 1129 |
$status = MediaWikiServices::getInstance()->getParserOutputAccess()->getParserOutput( |
| 1130 |
$this, $parserOptions, $revision, $options |
| 1131 |
); |
| 1132 |
return $status->isOK() ? $status->getValue() : false; |
| 1133 |
} |
| 1134 |
|
| 1135 |
|
| 1136 |
|
| 1137 |
|
| 1138 |
|
| 1139 |
|
| 1140 |
|
| 1141 |
public function doViewUpdates( |
| 1142 |
Authority $performer, |
| 1143 |
$oldid = 0, |
| 1144 |
?RevisionRecord $oldRev = null |
| 1145 |
) { |
| 1146 |
if ( MediaWikiServices::getInstance()->getReadOnlyMode()->isReadOnly() ) { |
| 1147 |
return; |
| 1148 |
} |
| 1149 |
|
| 1150 |
DeferredUpdates::addCallableUpdate( |
| 1151 |
function () use ( $performer ) { |
| 1152 |
|
| 1153 |
|
| 1154 |
|
| 1155 |
|
| 1156 |
|
| 1157 |
|
| 1158 |
|
| 1159 |
|
| 1160 |
|
| 1161 |
|
| 1162 |
|
| 1163 |
|
| 1164 |
|
| 1165 |
|
| 1166 |
|
| 1167 |
$legacyUser = MediaWikiServices::getInstance() |
| 1168 |
->getUserFactory() |
| 1169 |
->newFromAuthority( $performer ); |
| 1170 |
$this->getHookRunner()->onPageViewUpdates( $this, $legacyUser ); |
| 1171 |
}, |
| 1172 |
DeferredUpdates::PRESEND |
| 1173 |
); |
| 1174 |
|
| 1175 |
|
| 1176 |
MediaWikiServices::getInstance() |
| 1177 |
->getWatchlistManager() |
| 1178 |
->clearTitleUserNotifications( $performer, $this, $oldid, $oldRev ); |
| 1179 |
} |
| 1180 |
|
| 1181 |
|
| 1182 |
|
| 1183 |
|
| 1184 |
|
| 1185 |
|
| 1186 |
|
| 1187 |
public function doPurge() { |
| 1188 |
if ( !$this->getHookRunner()->onArticlePurge( $this ) ) { |
| 1189 |
return false; |
| 1190 |
} |
| 1191 |
|
| 1192 |
$this->mTitle->invalidateCache(); |
| 1193 |
|
| 1194 |
|
| 1195 |
$hcu = MediaWikiServices::getInstance()->getHtmlCacheUpdater(); |
| 1196 |
$hcu->purgeTitleUrls( $this->mTitle, $hcu::PURGE_PRESEND ); |
| 1197 |
|
| 1198 |
if ( $this->mTitle->getNamespace() === NS_MEDIAWIKI ) { |
| 1199 |
MediaWikiServices::getInstance()->getMessageCache() |
| 1200 |
->updateMessageOverride( $this->mTitle, $this->getContent() ); |
| 1201 |
} |
| 1202 |
InfoAction::invalidateCache( $this->mTitle, $this->getLatest() ); |
| 1203 |
|
| 1204 |
return true; |
| 1205 |
} |
| 1206 |
|
| 1207 |
|
| 1208 |
|
| 1209 |
|
| 1210 |
|
| 1211 |
|
| 1212 |
|
| 1213 |
|
| 1214 |
|
| 1215 |
|
| 1216 |
|
| 1217 |
|
| 1218 |
|
| 1219 |
|
| 1220 |
|
| 1221 |
|
| 1222 |
|
| 1223 |
public function insertOn( $dbw, $pageId = null ) { |
| 1224 |
$pageIdForInsert = $pageId ? [ 'page_id' => $pageId ] : []; |
| 1225 |
$dbw->newInsertQueryBuilder() |
| 1226 |
->insertInto( 'page' ) |
| 1227 |
->ignore() |
| 1228 |
->row( [ |
| 1229 |
'page_namespace' => $this->mTitle->getNamespace(), |
| 1230 |
'page_title' => $this->mTitle->getDBkey(), |
| 1231 |
'page_is_redirect' => 0, |
| 1232 |
'page_is_new' => 1, |
| 1233 |
'page_random' => wfRandom(), |
| 1234 |
'page_touched' => $dbw->timestamp(), |
| 1235 |
'page_latest' => 0, |
| 1236 |
'page_len' => 0, |
| 1237 |
] + $pageIdForInsert ) |
| 1238 |
->caller( __METHOD__ )->execute(); |
| 1239 |
|
| 1240 |
if ( $dbw->affectedRows() > 0 ) { |
| 1241 |
$newid = $pageId ? (int)$pageId : $dbw->insertId(); |
| 1242 |
$this->mId = $newid; |
| 1243 |
$this->mTitle->resetArticleID( $newid ); |
| 1244 |
|
| 1245 |
return $newid; |
| 1246 |
} else { |
| 1247 |
return false; |
| 1248 |
} |
| 1249 |
} |
| 1250 |
|
| 1251 |
|
| 1252 |
|
| 1253 |
|
| 1254 |
|
| 1255 |
|
| 1256 |
|
| 1257 |
|
| 1258 |
|
| 1259 |
|
| 1260 |
|
| 1261 |
|
| 1262 |
|
| 1263 |
|
| 1264 |
|
| 1265 |
|
| 1266 |
public function updateRevisionOn( |
| 1267 |
$dbw, |
| 1268 |
RevisionRecord $revision, |
| 1269 |
$lastRevision = null, |
| 1270 |
$lastRevIsRedirect = null |
| 1271 |
) { |
| 1272 |
|
| 1273 |
|
| 1274 |
|
| 1275 |
|
| 1276 |
$revId = $revision->getId(); |
| 1277 |
Assert::parameter( $revId > 0, '$revision->getId()', 'must be > 0' ); |
| 1278 |
|
| 1279 |
$content = $revision->getContent( SlotRecord::MAIN ); |
| 1280 |
$len = $content ? $content->getSize() : 0; |
| 1281 |
$rt = $content ? $content->getRedirectTarget() : null; |
| 1282 |
$isNew = $lastRevision === 0; |
| 1283 |
$isRedirect = $rt !== null; |
| 1284 |
|
| 1285 |
$conditions = [ 'page_id' => $this->getId() ]; |
| 1286 |
|
| 1287 |
if ( $lastRevision !== null ) { |
| 1288 |
|
| 1289 |
$conditions['page_latest'] = $lastRevision; |
| 1290 |
} |
| 1291 |
|
| 1292 |
$model = $revision->getSlot( SlotRecord::MAIN, RevisionRecord::RAW )->getModel(); |
| 1293 |
|
| 1294 |
$row = [ |
| 1295 |
'page_latest' => $revId, |
| 1296 |
'page_touched' => $dbw->timestamp( $revision->getTimestamp() ), |
| 1297 |
'page_is_new' => $isNew ? 1 : 0, |
| 1298 |
'page_is_redirect' => $isRedirect ? 1 : 0, |
| 1299 |
'page_len' => $len, |
| 1300 |
'page_content_model' => $model, |
| 1301 |
]; |
| 1302 |
|
| 1303 |
$dbw->newUpdateQueryBuilder() |
| 1304 |
->update( 'page' ) |
| 1305 |
->set( $row ) |
| 1306 |
->where( $conditions ) |
| 1307 |
->caller( __METHOD__ )->execute(); |
| 1308 |
|
| 1309 |
$result = $dbw->affectedRows() > 0; |
| 1310 |
if ( $result ) { |
| 1311 |
$insertedRow = $this->pageData( $dbw, [ 'page_id' => $this->getId() ] ); |
| 1312 |
|
| 1313 |
if ( !$insertedRow ) { |
| 1314 |
throw new RuntimeException( 'Failed to load freshly inserted row' ); |
| 1315 |
} |
| 1316 |
|
| 1317 |
$this->mTitle->loadFromRow( $insertedRow ); |
| 1318 |
MediaWikiServices::getInstance()->getRedirectStore() |
| 1319 |
->updateRedirectTarget( $this, $rt, $lastRevIsRedirect ); |
| 1320 |
$this->setLastEdit( $revision ); |
| 1321 |
$this->mPageIsRedirectField = (bool)$rt; |
| 1322 |
$this->mIsNew = $isNew; |
| 1323 |
|
| 1324 |
|
| 1325 |
$linkCache = MediaWikiServices::getInstance()->getLinkCache(); |
| 1326 |
$linkCache->addGoodLinkObjFromRow( |
| 1327 |
$this->mTitle, |
| 1328 |
$insertedRow |
| 1329 |
); |
| 1330 |
} |
| 1331 |
|
| 1332 |
return $result; |
| 1333 |
} |
| 1334 |
|
| 1335 |
|
| 1336 |
|
| 1337 |
|
| 1338 |
|
| 1339 |
|
| 1340 |
|
| 1341 |
|
| 1342 |
|
| 1343 |
|
| 1344 |
|
| 1345 |
|
| 1346 |
|
| 1347 |
public static function hasDifferencesOutsideMainSlot( RevisionRecord $a, RevisionRecord $b ) { |
| 1348 |
$aSlots = $a->getSlots(); |
| 1349 |
$bSlots = $b->getSlots(); |
| 1350 |
$changedRoles = $aSlots->getRolesWithDifferentContent( $bSlots ); |
| 1351 |
|
| 1352 |
return ( $changedRoles !== [ SlotRecord::MAIN ] && $changedRoles !== [] ); |
| 1353 |
} |
| 1354 |
|
| 1355 |
|
| 1356 |
|
| 1357 |
|
| 1358 |
|
| 1359 |
|
| 1360 |
|
| 1361 |
|
| 1362 |
|
| 1363 |
|
| 1364 |
|
| 1365 |
public function supportsSections() { |
| 1366 |
return $this->getContentHandler()->supportsSections(); |
| 1367 |
} |
| 1368 |
|
| 1369 |
|
| 1370 |
|
| 1371 |
|
| 1372 |
|
| 1373 |
|
| 1374 |
|
| 1375 |
|
| 1376 |
|
| 1377 |
|
| 1378 |
|
| 1379 |
|
| 1380 |
|
| 1381 |
|
| 1382 |
public function replaceSectionContent( |
| 1383 |
$sectionId, Content $sectionContent, $sectionTitle = '', $edittime = null |
| 1384 |
) { |
| 1385 |
$baseRevId = null; |
| 1386 |
if ( $edittime && $sectionId !== 'new' ) { |
| 1387 |
$lb = $this->getDBLoadBalancer(); |
| 1388 |
$rev = $this->getRevisionStore()->getRevisionByTimestamp( $this->mTitle, $edittime ); |
| 1389 |
|
| 1390 |
|
| 1391 |
|
| 1392 |
|
| 1393 |
if ( !$rev |
| 1394 |
&& $lb->hasReplicaServers() |
| 1395 |
&& $lb->hasOrMadeRecentPrimaryChanges() |
| 1396 |
) { |
| 1397 |
$rev = $this->getRevisionStore()->getRevisionByTimestamp( |
| 1398 |
$this->mTitle, $edittime, IDBAccessObject::READ_LATEST ); |
| 1399 |
} |
| 1400 |
if ( $rev ) { |
| 1401 |
$baseRevId = $rev->getId(); |
| 1402 |
} |
| 1403 |
} |
| 1404 |
|
| 1405 |
return $this->replaceSectionAtRev( $sectionId, $sectionContent, $sectionTitle, $baseRevId ); |
| 1406 |
} |
| 1407 |
|
| 1408 |
|
| 1409 |
|
| 1410 |
|
| 1411 |
|
| 1412 |
|
| 1413 |
|
| 1414 |
|
| 1415 |
|
| 1416 |
|
| 1417 |
|
| 1418 |
|
| 1419 |
|
| 1420 |
public function replaceSectionAtRev( $sectionId, Content $sectionContent, |
| 1421 |
$sectionTitle = '', $baseRevId = null |
| 1422 |
) { |
| 1423 |
if ( strval( $sectionId ) === '' ) { |
| 1424 |
|
| 1425 |
$newContent = $sectionContent; |
| 1426 |
} else { |
| 1427 |
if ( !$this->supportsSections() ) { |
| 1428 |
throw new BadMethodCallException( "sections not supported for content model " . |
| 1429 |
$this->getContentHandler()->getModelID() ); |
| 1430 |
} |
| 1431 |
|
| 1432 |
|
| 1433 |
if ( $baseRevId === null || $sectionId === 'new' ) { |
| 1434 |
$oldContent = $this->getContent(); |
| 1435 |
} else { |
| 1436 |
$revRecord = $this->getRevisionStore()->getRevisionById( $baseRevId ); |
| 1437 |
if ( !$revRecord ) { |
| 1438 |
wfDebug( __METHOD__ . " asked for bogus section (page: " . |
| 1439 |
$this->getId() . "; section: $sectionId)" ); |
| 1440 |
return null; |
| 1441 |
} |
| 1442 |
|
| 1443 |
$oldContent = $revRecord->getContent( SlotRecord::MAIN ); |
| 1444 |
} |
| 1445 |
|
| 1446 |
if ( !$oldContent ) { |
| 1447 |
wfDebug( __METHOD__ . ": no page text" ); |
| 1448 |
return null; |
| 1449 |
} |
| 1450 |
|
| 1451 |
$newContent = $oldContent->replaceSection( $sectionId, $sectionContent, $sectionTitle ); |
| 1452 |
} |
| 1453 |
|
| 1454 |
return $newContent; |
| 1455 |
} |
| 1456 |
|
| 1457 |
|
| 1458 |
|
| 1459 |
|
| 1460 |
|
| 1461 |
|
| 1462 |
|
| 1463 |
|
| 1464 |
|
| 1465 |
|
| 1466 |
public function checkFlags( $flags ) { |
| 1467 |
if ( !( $flags & EDIT_NEW ) && !( $flags & EDIT_UPDATE ) ) { |
| 1468 |
if ( $this->exists() ) { |
| 1469 |
$flags |= EDIT_UPDATE; |
| 1470 |
} else { |
| 1471 |
$flags |= EDIT_NEW; |
| 1472 |
} |
| 1473 |
} |
| 1474 |
|
| 1475 |
return $flags; |
| 1476 |
} |
| 1477 |
|
| 1478 |
|
| 1479 |
|
| 1480 |
|
| 1481 |
|
| 1482 |
|
| 1483 |
|
| 1484 |
|
| 1485 |
|
| 1486 |
|
| 1487 |
|
| 1488 |
|
| 1489 |
|
| 1490 |
|
| 1491 |
|
| 1492 |
|
| 1493 |
|
| 1494 |
|
| 1495 |
|
| 1496 |
|
| 1497 |
|
| 1498 |
|
| 1499 |
|
| 1500 |
|
| 1501 |
|
| 1502 |
|
| 1503 |
|
| 1504 |
|
| 1505 |
private function getDerivedDataUpdater( |
| 1506 |
?UserIdentity $forUser = null, |
| 1507 |
?RevisionRecord $forRevision = null, |
| 1508 |
?RevisionSlotsUpdate $forUpdate = null, |
| 1509 |
$forEdit = false |
| 1510 |
) { |
| 1511 |
if ( !$forRevision && !$forUpdate ) { |
| 1512 |
|
| 1513 |
|
| 1514 |
$this->derivedDataUpdater = null; |
| 1515 |
} |
| 1516 |
|
| 1517 |
if ( $this->derivedDataUpdater && !$this->derivedDataUpdater->isContentPrepared() ) { |
| 1518 |
|
| 1519 |
|
| 1520 |
|
| 1521 |
$this->derivedDataUpdater = null; |
| 1522 |
} |
| 1523 |
|
| 1524 |
|
| 1525 |
|
| 1526 |
|
| 1527 |
|
| 1528 |
if ( $this->derivedDataUpdater |
| 1529 |
&& !$this->derivedDataUpdater->isReusableFor( |
| 1530 |
$forUser, |
| 1531 |
$forRevision, |
| 1532 |
$forUpdate, |
| 1533 |
$forEdit ? $this->getLatest() : null |
| 1534 |
) |
| 1535 |
) { |
| 1536 |
$this->derivedDataUpdater = null; |
| 1537 |
} |
| 1538 |
|
| 1539 |
if ( !$this->derivedDataUpdater ) { |
| 1540 |
$this->derivedDataUpdater = |
| 1541 |
$this->getPageUpdaterFactory()->newDerivedPageDataUpdater( $this ); |
| 1542 |
} |
| 1543 |
|
| 1544 |
return $this->derivedDataUpdater; |
| 1545 |
} |
| 1546 |
|
| 1547 |
|
| 1548 |
|
| 1549 |
|
| 1550 |
|
| 1551 |
|
| 1552 |
|
| 1553 |
|
| 1554 |
|
| 1555 |
|
| 1556 |
|
| 1557 |
|
| 1558 |
|
| 1559 |
|
| 1560 |
|
| 1561 |
|
| 1562 |
|
| 1563 |
|
| 1564 |
|
| 1565 |
|
| 1566 |
|
| 1567 |
public function newPageUpdater( $performer, ?RevisionSlotsUpdate $forUpdate = null ) { |
| 1568 |
if ( $performer instanceof Authority ) { |
| 1569 |
|
| 1570 |
$performer = $performer->getUser(); |
| 1571 |
} |
| 1572 |
|
| 1573 |
$pageUpdater = $this->getPageUpdaterFactory()->newPageUpdaterForDerivedPageDataUpdater( |
| 1574 |
$this, |
| 1575 |
$performer, |
| 1576 |
$this->getDerivedDataUpdater( $performer, null, $forUpdate, true ) |
| 1577 |
); |
| 1578 |
|
| 1579 |
return $pageUpdater; |
| 1580 |
} |
| 1581 |
|
| 1582 |
|
| 1583 |
|
| 1584 |
|
| 1585 |
|
| 1586 |
|
| 1587 |
|
| 1588 |
|
| 1589 |
|
| 1590 |
|
| 1591 |
|
| 1592 |
|
| 1593 |
|
| 1594 |
|
| 1595 |
|
| 1596 |
|
| 1597 |
|
| 1598 |
|
| 1599 |
|
| 1600 |
|
| 1601 |
|
| 1602 |
|
| 1603 |
|
| 1604 |
|
| 1605 |
|
| 1606 |
|
| 1607 |
|
| 1608 |
|
| 1609 |
|
| 1610 |
|
| 1611 |
|
| 1612 |
|
| 1613 |
|
| 1614 |
|
| 1615 |
|
| 1616 |
|
| 1617 |
|
| 1618 |
|
| 1619 |
|
| 1620 |
|
| 1621 |
|
| 1622 |
|
| 1623 |
|
| 1624 |
|
| 1625 |
|
| 1626 |
|
| 1627 |
|
| 1628 |
|
| 1629 |
|
| 1630 |
|
| 1631 |
|
| 1632 |
|
| 1633 |
|
| 1634 |
|
| 1635 |
|
| 1636 |
|
| 1637 |
|
| 1638 |
|
| 1639 |
|
| 1640 |
|
| 1641 |
|
| 1642 |
public function doUserEditContent( |
| 1643 |
Content $content, |
| 1644 |
Authority $performer, |
| 1645 |
$summary, |
| 1646 |
$flags = 0, |
| 1647 |
$originalRevId = false, |
| 1648 |
$tags = [], |
| 1649 |
$undidRevId = 0 |
| 1650 |
): PageUpdateStatus { |
| 1651 |
$useNPPatrol = MediaWikiServices::getInstance()->getMainConfig()->get( |
| 1652 |
MainConfigNames::UseNPPatrol ); |
| 1653 |
$useRCPatrol = MediaWikiServices::getInstance()->getMainConfig()->get( |
| 1654 |
MainConfigNames::UseRCPatrol ); |
| 1655 |
if ( !( $summary instanceof CommentStoreComment ) ) { |
| 1656 |
$summary = CommentStoreComment::newUnsavedComment( trim( $summary ) ); |
| 1657 |
} |
| 1658 |
|
| 1659 |
|
| 1660 |
|
| 1661 |
|
| 1662 |
if ( ( $flags & EDIT_MINOR ) && !$performer->isAllowed( 'minoredit' ) ) { |
| 1663 |
$flags &= ~EDIT_MINOR; |
| 1664 |
} |
| 1665 |
|
| 1666 |
$slotsUpdate = new RevisionSlotsUpdate(); |
| 1667 |
$slotsUpdate->modifyContent( SlotRecord::MAIN, $content ); |
| 1668 |
|
| 1669 |
|
| 1670 |
|
| 1671 |
|
| 1672 |
$updater = $this->newPageUpdater( $performer, $slotsUpdate ) |
| 1673 |
->setContent( SlotRecord::MAIN, $content ) |
| 1674 |
->setOriginalRevisionId( $originalRevId ); |
| 1675 |
if ( $undidRevId ) { |
| 1676 |
$updater->markAsRevert( |
| 1677 |
EditResult::REVERT_UNDO, |
| 1678 |
$undidRevId, |
| 1679 |
$originalRevId ?: null |
| 1680 |
); |
| 1681 |
} |
| 1682 |
|
| 1683 |
$needsPatrol = $useRCPatrol || ( $useNPPatrol && !$this->exists() ); |
| 1684 |
|
| 1685 |
|
| 1686 |
|
| 1687 |
|
| 1688 |
|
| 1689 |
if ( $needsPatrol && $performer->authorizeWrite( 'autopatrol', $this->getTitle() ) ) { |
| 1690 |
$updater->setRcPatrolStatus( RecentChange::PRC_AUTOPATROLLED ); |
| 1691 |
} |
| 1692 |
|
| 1693 |
$updater->addTags( $tags ); |
| 1694 |
|
| 1695 |
$revRec = $updater->saveRevision( |
| 1696 |
$summary, |
| 1697 |
$flags |
| 1698 |
); |
| 1699 |
|
| 1700 |
|
| 1701 |
|
| 1702 |
if ( $revRec ) { |
| 1703 |
|
| 1704 |
|
| 1705 |
|
| 1706 |
$this->setLastEdit( $revRec ); |
| 1707 |
} |
| 1708 |
|
| 1709 |
return $updater->getStatus(); |
| 1710 |
} |
| 1711 |
|
| 1712 |
|
| 1713 |
|
| 1714 |
|
| 1715 |
|
| 1716 |
|
| 1717 |
|
| 1718 |
|
| 1719 |
|
| 1720 |
|
| 1721 |
|
| 1722 |
|
| 1723 |
|
| 1724 |
|
| 1725 |
|
| 1726 |
public function makeParserOptions( $context ) { |
| 1727 |
return self::makeParserOptionsFromTitleAndModel( |
| 1728 |
$this->getTitle(), $this->getContentModel(), $context |
| 1729 |
); |
| 1730 |
} |
| 1731 |
|
| 1732 |
|
| 1733 |
|
| 1734 |
|
| 1735 |
|
| 1736 |
|
| 1737 |
|
| 1738 |
|
| 1739 |
|
| 1740 |
public static function makeParserOptionsFromTitleAndModel( |
| 1741 |
PageReference $pageRef, string $contentModel, $context |
| 1742 |
) { |
| 1743 |
$options = ParserOptions::newCanonical( $context ); |
| 1744 |
|
| 1745 |
$title = Title::newFromPageReference( $pageRef ); |
| 1746 |
if ( $title->isConversionTable() ) { |
| 1747 |
|
| 1748 |
|
| 1749 |
$options->disableContentConversion(); |
| 1750 |
} |
| 1751 |
|
| 1752 |
return $options; |
| 1753 |
} |
| 1754 |
|
| 1755 |
|
| 1756 |
|
| 1757 |
|
| 1758 |
|
| 1759 |
|
| 1760 |
|
| 1761 |
|
| 1762 |
|
| 1763 |
|
| 1764 |
|
| 1765 |
|
| 1766 |
|
| 1767 |
|
| 1768 |
|
| 1769 |
|
| 1770 |
|
| 1771 |
|
| 1772 |
|
| 1773 |
|
| 1774 |
|
| 1775 |
public function prepareContentForEdit( |
| 1776 |
Content $content, |
| 1777 |
?RevisionRecord $revision, |
| 1778 |
UserIdentity $user, |
| 1779 |
$serialFormat = null, |
| 1780 |
$useStash = true |
| 1781 |
) { |
| 1782 |
$slots = RevisionSlotsUpdate::newFromContent( [ SlotRecord::MAIN => $content ] ); |
| 1783 |
$updater = $this->getDerivedDataUpdater( $user, $revision, $slots ); |
| 1784 |
|
| 1785 |
if ( !$updater->isUpdatePrepared() ) { |
| 1786 |
$updater->prepareContent( $user, $slots, $useStash ); |
| 1787 |
|
| 1788 |
if ( $revision ) { |
| 1789 |
$updater->prepareUpdate( |
| 1790 |
$revision, |
| 1791 |
[ |
| 1792 |
'causeAction' => 'prepare-edit', |
| 1793 |
'causeAgent' => $user->getName(), |
| 1794 |
] |
| 1795 |
); |
| 1796 |
} |
| 1797 |
} |
| 1798 |
|
| 1799 |
return $updater->getPreparedEdit(); |
| 1800 |
} |
| 1801 |
|
| 1802 |
|
| 1803 |
|
| 1804 |
|
| 1805 |
|
| 1806 |
|
| 1807 |
|
| 1808 |
|
| 1809 |
|
| 1810 |
|
| 1811 |
|
| 1812 |
|
| 1813 |
|
| 1814 |
|
| 1815 |
|
| 1816 |
|
| 1817 |
|
| 1818 |
|
| 1819 |
|
| 1820 |
|
| 1821 |
|
| 1822 |
|
| 1823 |
|
| 1824 |
|
| 1825 |
|
| 1826 |
|
| 1827 |
|
| 1828 |
|
| 1829 |
|
| 1830 |
public function doEditUpdates( |
| 1831 |
RevisionRecord $revisionRecord, |
| 1832 |
UserIdentity $user, |
| 1833 |
array $options = [] |
| 1834 |
) { |
| 1835 |
$options += [ |
| 1836 |
'causeAction' => 'edit-page', |
| 1837 |
'causeAgent' => $user->getName(), |
| 1838 |
]; |
| 1839 |
|
| 1840 |
$updater = $this->getDerivedDataUpdater( $user, $revisionRecord ); |
| 1841 |
|
| 1842 |
$updater->prepareUpdate( $revisionRecord, $options ); |
| 1843 |
|
| 1844 |
$updater->doUpdates(); |
| 1845 |
} |
| 1846 |
|
| 1847 |
|
| 1848 |
|
| 1849 |
|
| 1850 |
|
| 1851 |
|
| 1852 |
|
| 1853 |
|
| 1854 |
|
| 1855 |
|
| 1856 |
|
| 1857 |
|
| 1858 |
|
| 1859 |
public function updateParserCache( array $options = [] ) { |
| 1860 |
$revision = $this->getRevisionRecord(); |
| 1861 |
if ( !$revision || !$revision->getId() ) { |
| 1862 |
LoggerFactory::getInstance( 'wikipage' )->info( |
| 1863 |
__METHOD__ . ' called with ' . ( $revision ? 'unsaved' : 'no' ) . ' revision' |
| 1864 |
); |
| 1865 |
return; |
| 1866 |
} |
| 1867 |
$userIdentity = $revision->getUser( RevisionRecord::RAW ); |
| 1868 |
|
| 1869 |
$updater = $this->getDerivedDataUpdater( $userIdentity, $revision ); |
| 1870 |
$updater->prepareUpdate( $revision, $options ); |
| 1871 |
$updater->doParserCacheUpdate(); |
| 1872 |
} |
| 1873 |
|
| 1874 |
|
| 1875 |
|
| 1876 |
|
| 1877 |
|
| 1878 |
|
| 1879 |
|
| 1880 |
|
| 1881 |
|
| 1882 |
|
| 1883 |
|
| 1884 |
|
| 1885 |
|
| 1886 |
|
| 1887 |
|
| 1888 |
|
| 1889 |
|
| 1890 |
|
| 1891 |
|
| 1892 |
|
| 1893 |
|
| 1894 |
|
| 1895 |
|
| 1896 |
|
| 1897 |
|
| 1898 |
|
| 1899 |
|
| 1900 |
|
| 1901 |
|
| 1902 |
public function doSecondaryDataUpdates( array $options = [] ) { |
| 1903 |
$options['recursive'] ??= true; |
| 1904 |
$revision = $this->getRevisionRecord(); |
| 1905 |
if ( !$revision || !$revision->getId() ) { |
| 1906 |
LoggerFactory::getInstance( 'wikipage' )->info( |
| 1907 |
__METHOD__ . ' called with ' . ( $revision ? 'unsaved' : 'no' ) . ' revision' |
| 1908 |
); |
| 1909 |
return; |
| 1910 |
} |
| 1911 |
$userIdentity = $revision->getUser( RevisionRecord::RAW ); |
| 1912 |
|
| 1913 |
$updater = $this->getDerivedDataUpdater( $userIdentity, $revision ); |
| 1914 |
$updater->prepareUpdate( $revision, $options ); |
| 1915 |
$updater->doSecondaryDataUpdates( $options ); |
| 1916 |
} |
| 1917 |
|
| 1918 |
|
| 1919 |
|
| 1920 |
|
| 1921 |
|
| 1922 |
|
| 1923 |
|
| 1924 |
|
| 1925 |
|
| 1926 |
|
| 1927 |
|
| 1928 |
|
| 1929 |
|
| 1930 |
|
| 1931 |
|
| 1932 |
public function doUpdateRestrictions( array $limit, array $expiry, |
| 1933 |
&$cascade, $reason, UserIdentity $user, $tags = [] |
| 1934 |
) { |
| 1935 |
$services = MediaWikiServices::getInstance(); |
| 1936 |
$readOnlyMode = $services->getReadOnlyMode(); |
| 1937 |
if ( $readOnlyMode->isReadOnly() ) { |
| 1938 |
return Status::newFatal( wfMessage( 'readonlytext', $readOnlyMode->getReason() ) ); |
| 1939 |
} |
| 1940 |
|
| 1941 |
$this->loadPageData( 'fromdbmaster' ); |
| 1942 |
$restrictionStore = $services->getRestrictionStore(); |
| 1943 |
$restrictionStore->loadRestrictions( $this->mTitle, IDBAccessObject::READ_LATEST ); |
| 1944 |
$restrictionTypes = $restrictionStore->listApplicableRestrictionTypes( $this->mTitle ); |
| 1945 |
$id = $this->getId(); |
| 1946 |
|
| 1947 |
if ( !$cascade ) { |
| 1948 |
$cascade = false; |
| 1949 |
} |
| 1950 |
|
| 1951 |
|
| 1952 |
Title::purgeExpiredRestrictions(); |
| 1953 |
|
| 1954 |
|
| 1955 |
|
| 1956 |
$isProtected = false; |
| 1957 |
$protect = false; |
| 1958 |
$changed = false; |
| 1959 |
|
| 1960 |
$dbw = $services->getConnectionProvider()->getPrimaryDatabase(); |
| 1961 |
|
| 1962 |
foreach ( $restrictionTypes as $action ) { |
| 1963 |
if ( !isset( $expiry[$action] ) || $expiry[$action] === $dbw->getInfinity() ) { |
| 1964 |
$expiry[$action] = 'infinity'; |
| 1965 |
} |
| 1966 |
if ( !isset( $limit[$action] ) ) { |
| 1967 |
$limit[$action] = ''; |
| 1968 |
} elseif ( $limit[$action] != '' ) { |
| 1969 |
$protect = true; |
| 1970 |
} |
| 1971 |
|
| 1972 |
|
| 1973 |
$current = implode( '', $restrictionStore->getRestrictions( $this->mTitle, $action ) ); |
| 1974 |
if ( $current != '' ) { |
| 1975 |
$isProtected = true; |
| 1976 |
} |
| 1977 |
|
| 1978 |
if ( $limit[$action] != $current ) { |
| 1979 |
$changed = true; |
| 1980 |
} elseif ( $limit[$action] != '' ) { |
| 1981 |
|
| 1982 |
|
| 1983 |
|
| 1984 |
if ( $restrictionStore->getRestrictionExpiry( $this->mTitle, $action ) != $expiry[$action] ) { |
| 1985 |
$changed = true; |
| 1986 |
} |
| 1987 |
} |
| 1988 |
} |
| 1989 |
|
| 1990 |
if ( !$changed && $protect && $restrictionStore->areRestrictionsCascading( $this->mTitle ) != $cascade ) { |
| 1991 |
$changed = true; |
| 1992 |
} |
| 1993 |
|
| 1994 |
|
| 1995 |
if ( !$changed ) { |
| 1996 |
return Status::newGood(); |
| 1997 |
} |
| 1998 |
|
| 1999 |
if ( !$protect ) { |
| 2000 |
$revCommentMsg = 'unprotectedarticle-comment'; |
| 2001 |
$logAction = 'unprotect'; |
| 2002 |
} elseif ( $isProtected ) { |
| 2003 |
$revCommentMsg = 'modifiedarticleprotection-comment'; |
| 2004 |
$logAction = 'modify'; |
| 2005 |
} else { |
| 2006 |
$revCommentMsg = 'protectedarticle-comment'; |
| 2007 |
$logAction = 'protect'; |
| 2008 |
} |
| 2009 |
|
| 2010 |
$logRelationsValues = []; |
| 2011 |
$logRelationsField = null; |
| 2012 |
$logParamsDetails = []; |
| 2013 |
|
| 2014 |
|
| 2015 |
$nullRevisionRecord = null; |
| 2016 |
|
| 2017 |
if ( $id ) { |
| 2018 |
$legacyUser = $services->getUserFactory()->newFromUserIdentity( $user ); |
| 2019 |
if ( !$this->getHookRunner()->onArticleProtect( $this, $legacyUser, $limit, $reason ) ) { |
| 2020 |
return Status::newGood(); |
| 2021 |
} |
| 2022 |
|
| 2023 |
|
| 2024 |
$editrestriction = isset( $limit['edit'] ) |
| 2025 |
? [ $limit['edit'] ] |
| 2026 |
: $restrictionStore->getRestrictions( $this->mTitle, 'edit' ); |
| 2027 |
foreach ( array_keys( $editrestriction, 'sysop' ) as $key ) { |
| 2028 |
$editrestriction[$key] = 'editprotected'; |
| 2029 |
} |
| 2030 |
foreach ( array_keys( $editrestriction, 'autoconfirmed' ) as $key ) { |
| 2031 |
$editrestriction[$key] = 'editsemiprotected'; |
| 2032 |
} |
| 2033 |
|
| 2034 |
$cascadingRestrictionLevels = $services->getMainConfig() |
| 2035 |
->get( MainConfigNames::CascadingRestrictionLevels ); |
| 2036 |
|
| 2037 |
foreach ( array_keys( $cascadingRestrictionLevels, 'sysop' ) as $key ) { |
| 2038 |
$cascadingRestrictionLevels[$key] = 'editprotected'; |
| 2039 |
} |
| 2040 |
foreach ( array_keys( $cascadingRestrictionLevels, 'autoconfirmed' ) as $key ) { |
| 2041 |
$cascadingRestrictionLevels[$key] = 'editsemiprotected'; |
| 2042 |
} |
| 2043 |
|
| 2044 |
|
| 2045 |
if ( !array_intersect( $editrestriction, $cascadingRestrictionLevels ) ) { |
| 2046 |
$cascade = false; |
| 2047 |
} |
| 2048 |
|
| 2049 |
|
| 2050 |
$latest = $this->getLatest(); |
| 2051 |
$nullRevisionRecord = $this->insertNullProtectionRevision( |
| 2052 |
$revCommentMsg, |
| 2053 |
$limit, |
| 2054 |
$expiry, |
| 2055 |
$cascade, |
| 2056 |
$reason, |
| 2057 |
$user |
| 2058 |
); |
| 2059 |
|
| 2060 |
if ( $nullRevisionRecord === null ) { |
| 2061 |
return Status::newFatal( 'no-null-revision', $this->mTitle->getPrefixedText() ); |
| 2062 |
} |
| 2063 |
|
| 2064 |
$logRelationsField = 'pr_id'; |
| 2065 |
|
| 2066 |
|
| 2067 |
|
| 2068 |
|
| 2069 |
|
| 2070 |
|
| 2071 |
$existingProtectionIds = $dbw->newSelectQueryBuilder() |
| 2072 |
->select( 'pr_id' ) |
| 2073 |
->from( 'page_restrictions' ) |
| 2074 |
->where( [ 'pr_page' => $id, 'pr_type' => array_map( 'strval', array_keys( $limit ) ) ] ) |
| 2075 |
->caller( __METHOD__ )->fetchFieldValues(); |
| 2076 |
|
| 2077 |
if ( $existingProtectionIds ) { |
| 2078 |
$dbw->newDeleteQueryBuilder() |
| 2079 |
->deleteFrom( 'page_restrictions' ) |
| 2080 |
->where( [ 'pr_id' => $existingProtectionIds ] ) |
| 2081 |
->caller( __METHOD__ )->execute(); |
| 2082 |
} |
| 2083 |
|
| 2084 |
|
| 2085 |
foreach ( $limit as $action => $restrictions ) { |
| 2086 |
if ( $restrictions != '' ) { |
| 2087 |
$cascadeValue = ( $cascade && $action == 'edit' ) ? 1 : 0; |
| 2088 |
$dbw->newInsertQueryBuilder() |
| 2089 |
->insertInto( 'page_restrictions' ) |
| 2090 |
->row( [ |
| 2091 |
'pr_page' => $id, |
| 2092 |
'pr_type' => $action, |
| 2093 |
'pr_level' => $restrictions, |
| 2094 |
'pr_cascade' => $cascadeValue, |
| 2095 |
'pr_expiry' => $dbw->encodeExpiry( $expiry[$action] ) |
| 2096 |
] ) |
| 2097 |
->caller( __METHOD__ )->execute(); |
| 2098 |
$logRelationsValues[] = $dbw->insertId(); |
| 2099 |
$logParamsDetails[] = [ |
| 2100 |
'type' => $action, |
| 2101 |
'level' => $restrictions, |
| 2102 |
'expiry' => $expiry[$action], |
| 2103 |
'cascade' => (bool)$cascadeValue, |
| 2104 |
]; |
| 2105 |
} |
| 2106 |
} |
| 2107 |
|
| 2108 |
$this->getHookRunner()->onRevisionFromEditComplete( |
| 2109 |
$this, $nullRevisionRecord, $latest, $user, $tags ); |
| 2110 |
|
| 2111 |
$this->getHookRunner()->onArticleProtectComplete( $this, $legacyUser, $limit, $reason ); |
| 2112 |
} else { |
| 2113 |
|
| 2114 |
$cascade = false; |
| 2115 |
|
| 2116 |
if ( $limit['create'] != '' ) { |
| 2117 |
$commentFields = $services->getCommentStore()->insert( $dbw, 'pt_reason', $reason ); |
| 2118 |
$dbw->newReplaceQueryBuilder() |
| 2119 |
->table( 'protected_titles' ) |
| 2120 |
->uniqueIndexFields( [ 'pt_namespace', 'pt_title' ] ) |
| 2121 |
->rows( [ |
| 2122 |
'pt_namespace' => $this->mTitle->getNamespace(), |
| 2123 |
'pt_title' => $this->mTitle->getDBkey(), |
| 2124 |
'pt_create_perm' => $limit['create'], |
| 2125 |
'pt_timestamp' => $dbw->timestamp(), |
| 2126 |
'pt_expiry' => $dbw->encodeExpiry( $expiry['create'] ), |
| 2127 |
'pt_user' => $user->getId(), |
| 2128 |
] + $commentFields ) |
| 2129 |
->caller( __METHOD__ )->execute(); |
| 2130 |
$logParamsDetails[] = [ |
| 2131 |
'type' => 'create', |
| 2132 |
'level' => $limit['create'], |
| 2133 |
'expiry' => $expiry['create'], |
| 2134 |
]; |
| 2135 |
} else { |
| 2136 |
$dbw->newDeleteQueryBuilder() |
| 2137 |
->deleteFrom( 'protected_titles' ) |
| 2138 |
->where( [ |
| 2139 |
'pt_namespace' => $this->mTitle->getNamespace(), |
| 2140 |
'pt_title' => $this->mTitle->getDBkey() |
| 2141 |
] ) |
| 2142 |
->caller( __METHOD__ )->execute(); |
| 2143 |
} |
| 2144 |
} |
| 2145 |
|
| 2146 |
$services->getRestrictionStore()->flushRestrictions( $this->mTitle ); |
| 2147 |
|
| 2148 |
InfoAction::invalidateCache( $this->mTitle ); |
| 2149 |
|
| 2150 |
if ( $logAction == 'unprotect' ) { |
| 2151 |
$params = []; |
| 2152 |
} else { |
| 2153 |
$protectDescriptionLog = $this->protectDescriptionLog( $limit, $expiry ); |
| 2154 |
$params = [ |
| 2155 |
'4::description' => $protectDescriptionLog, |
| 2156 |
'5:bool:cascade' => $cascade, |
| 2157 |
'details' => $logParamsDetails, |
| 2158 |
]; |
| 2159 |
} |
| 2160 |
|
| 2161 |
|
| 2162 |
$logEntry = new ManualLogEntry( 'protect', $logAction ); |
| 2163 |
$logEntry->setTarget( $this->mTitle ); |
| 2164 |
$logEntry->setComment( $reason ); |
| 2165 |
$logEntry->setPerformer( $user ); |
| 2166 |
$logEntry->setParameters( $params ); |
| 2167 |
if ( $nullRevisionRecord !== null ) { |
| 2168 |
$logEntry->setAssociatedRevId( $nullRevisionRecord->getId() ); |
| 2169 |
} |
| 2170 |
$logEntry->addTags( $tags ); |
| 2171 |
if ( $logRelationsField !== null && count( $logRelationsValues ) ) { |
| 2172 |
$logEntry->setRelations( [ $logRelationsField => $logRelationsValues ] ); |
| 2173 |
} |
| 2174 |
$logId = $logEntry->insert(); |
| 2175 |
$logEntry->publish( $logId ); |
| 2176 |
|
| 2177 |
return Status::newGood( $logId ); |
| 2178 |
} |
| 2179 |
|
| 2180 |
|
| 2181 |
|
| 2182 |
|
| 2183 |
|
| 2184 |
|
| 2185 |
|
| 2186 |
|
| 2187 |
|
| 2188 |
|
| 2189 |
|
| 2190 |
|
| 2191 |
|
| 2192 |
|
| 2193 |
|
| 2194 |
|
| 2195 |
|
| 2196 |
|
| 2197 |
|
| 2198 |
|
| 2199 |
|
| 2200 |
public function getCurrentUpdate(): PreparedUpdate { |
| 2201 |
Assert::precondition( |
| 2202 |
$this->derivedDataUpdater !== null, |
| 2203 |
'There is no ongoing update tracked by this instance of WikiPage!' |
| 2204 |
); |
| 2205 |
|
| 2206 |
return $this->derivedDataUpdater; |
| 2207 |
} |
| 2208 |
|
| 2209 |
|
| 2210 |
|
| 2211 |
|
| 2212 |
|
| 2213 |
|
| 2214 |
|
| 2215 |
|
| 2216 |
|
| 2217 |
|
| 2218 |
|
| 2219 |
|
| 2220 |
|
| 2221 |
|
| 2222 |
public function insertNullProtectionRevision( |
| 2223 |
string $revCommentMsg, |
| 2224 |
array $limit, |
| 2225 |
array $expiry, |
| 2226 |
bool $cascade, |
| 2227 |
string $reason, |
| 2228 |
UserIdentity $user |
| 2229 |
): ?RevisionRecord { |
| 2230 |
$dbw = MediaWikiServices::getInstance()->getConnectionProvider()->getPrimaryDatabase(); |
| 2231 |
|
| 2232 |
|
| 2233 |
$editComment = wfMessage( |
| 2234 |
$revCommentMsg, |
| 2235 |
$this->mTitle->getPrefixedText(), |
| 2236 |
$user->getName() |
| 2237 |
)->inContentLanguage()->text(); |
| 2238 |
if ( $reason ) { |
| 2239 |
$editComment .= wfMessage( 'colon-separator' )->inContentLanguage()->text() . $reason; |
| 2240 |
} |
| 2241 |
$protectDescription = $this->protectDescription( $limit, $expiry ); |
| 2242 |
if ( $protectDescription ) { |
| 2243 |
$editComment .= wfMessage( 'word-separator' )->inContentLanguage()->text(); |
| 2244 |
$editComment .= wfMessage( 'parentheses' )->params( $protectDescription ) |
| 2245 |
->inContentLanguage()->text(); |
| 2246 |
} |
| 2247 |
if ( $cascade ) { |
| 2248 |
$editComment .= wfMessage( 'word-separator' )->inContentLanguage()->text(); |
| 2249 |
$editComment .= wfMessage( 'brackets' )->params( |
| 2250 |
wfMessage( 'protect-summary-cascade' )->inContentLanguage()->text() |
| 2251 |
)->inContentLanguage()->text(); |
| 2252 |
} |
| 2253 |
|
| 2254 |
$revStore = $this->getRevisionStore(); |
| 2255 |
$comment = CommentStoreComment::newUnsavedComment( $editComment ); |
| 2256 |
$nullRevRecord = $revStore->newNullRevision( |
| 2257 |
$dbw, |
| 2258 |
$this->getTitle(), |
| 2259 |
$comment, |
| 2260 |
true, |
| 2261 |
$user |
| 2262 |
); |
| 2263 |
|
| 2264 |
if ( $nullRevRecord ) { |
| 2265 |
$inserted = $revStore->insertRevisionOn( $nullRevRecord, $dbw ); |
| 2266 |
|
| 2267 |
|
| 2268 |
$oldLatest = $inserted->getParentId(); |
| 2269 |
|
| 2270 |
$this->updateRevisionOn( $dbw, $inserted, $oldLatest ); |
| 2271 |
|
| 2272 |
return $inserted; |
| 2273 |
} else { |
| 2274 |
return null; |
| 2275 |
} |
| 2276 |
} |
| 2277 |
|
| 2278 |
|
| 2279 |
|
| 2280 |
|
| 2281 |
|
| 2282 |
protected function formatExpiry( $expiry ) { |
| 2283 |
if ( $expiry != 'infinity' ) { |
| 2284 |
$contLang = MediaWikiServices::getInstance()->getContentLanguage(); |
| 2285 |
return wfMessage( |
| 2286 |
'protect-expiring', |
| 2287 |
$contLang->timeanddate( $expiry, false, false ), |
| 2288 |
$contLang->date( $expiry, false, false ), |
| 2289 |
$contLang->time( $expiry, false, false ) |
| 2290 |
)->inContentLanguage()->text(); |
| 2291 |
} else { |
| 2292 |
return wfMessage( 'protect-expiry-indefinite' ) |
| 2293 |
->inContentLanguage()->text(); |
| 2294 |
} |
| 2295 |
} |
| 2296 |
|
| 2297 |
|
| 2298 |
|
| 2299 |
|
| 2300 |
|
| 2301 |
|
| 2302 |
|
| 2303 |
|
| 2304 |
public function protectDescription( array $limit, array $expiry ) { |
| 2305 |
$protectDescription = ''; |
| 2306 |
|
| 2307 |
foreach ( array_filter( $limit ) as $action => $restrictions ) { |
| 2308 |
|
| 2309 |
|
| 2310 |
|
| 2311 |
|
| 2312 |
|
| 2313 |
|
| 2314 |
$actionText = wfMessage( 'restriction-' . $action )->inContentLanguage()->text(); |
| 2315 |
|
| 2316 |
|
| 2317 |
|
| 2318 |
|
| 2319 |
$restrictionsText = wfMessage( 'protect-level-' . $restrictions ) |
| 2320 |
->inContentLanguage()->text(); |
| 2321 |
|
| 2322 |
$expiryText = $this->formatExpiry( $expiry[$action] ); |
| 2323 |
|
| 2324 |
if ( $protectDescription !== '' ) { |
| 2325 |
$protectDescription .= wfMessage( 'word-separator' )->inContentLanguage()->text(); |
| 2326 |
} |
| 2327 |
$protectDescription .= wfMessage( 'protect-summary-desc' ) |
| 2328 |
->params( $actionText, $restrictionsText, $expiryText ) |
| 2329 |
->inContentLanguage()->text(); |
| 2330 |
} |
| 2331 |
|
| 2332 |
return $protectDescription; |
| 2333 |
} |
| 2334 |
|
| 2335 |
|
| 2336 |
|
| 2337 |
|
| 2338 |
|
| 2339 |
|
| 2340 |
|
| 2341 |
|
| 2342 |
|
| 2343 |
|
| 2344 |
|
| 2345 |
|
| 2346 |
public function protectDescriptionLog( array $limit, array $expiry ) { |
| 2347 |
$protectDescriptionLog = ''; |
| 2348 |
|
| 2349 |
$dirMark = MediaWikiServices::getInstance()->getContentLanguage()->getDirMark(); |
| 2350 |
foreach ( array_filter( $limit ) as $action => $restrictions ) { |
| 2351 |
$expiryText = $this->formatExpiry( $expiry[$action] ); |
| 2352 |
$protectDescriptionLog .= |
| 2353 |
$dirMark . |
| 2354 |
"[$action=$restrictions] ($expiryText)"; |
| 2355 |
} |
| 2356 |
|
| 2357 |
return trim( $protectDescriptionLog ); |
| 2358 |
} |
| 2359 |
|
| 2360 |
|
| 2361 |
|
| 2362 |
|
| 2363 |
|
| 2364 |
|
| 2365 |
|
| 2366 |
|
| 2367 |
|
| 2368 |
|
| 2369 |
|
| 2370 |
|
| 2371 |
|
| 2372 |
|
| 2373 |
|
| 2374 |
public function isBatchedDelete( $safetyMargin = 0 ) { |
| 2375 |
$deleteRevisionsBatchSize = MediaWikiServices::getInstance() |
| 2376 |
->getMainConfig()->get( MainConfigNames::DeleteRevisionsBatchSize ); |
| 2377 |
|
| 2378 |
$dbr = MediaWikiServices::getInstance()->getConnectionProvider()->getReplicaDatabase(); |
| 2379 |
$revCount = $this->getRevisionStore()->countRevisionsByPageId( $dbr, $this->getId() ); |
| 2380 |
$revCount += $safetyMargin; |
| 2381 |
|
| 2382 |
return $revCount >= $deleteRevisionsBatchSize; |
| 2383 |
} |
| 2384 |
|
| 2385 |
|
| 2386 |
|
| 2387 |
|
| 2388 |
|
| 2389 |
|
| 2390 |
|
| 2391 |
|
| 2392 |
|
| 2393 |
|
| 2394 |
|
| 2395 |
|
| 2396 |
|
| 2397 |
|
| 2398 |
|
| 2399 |
|
| 2400 |
|
| 2401 |
|
| 2402 |
|
| 2403 |
|
| 2404 |
|
| 2405 |
|
| 2406 |
|
| 2407 |
|
| 2408 |
|
| 2409 |
|
| 2410 |
|
| 2411 |
|
| 2412 |
|
| 2413 |
public function doDeleteArticleReal( |
| 2414 |
$reason, UserIdentity $deleter, $suppress = false, $u1 = null, &$error = '', $u2 = null, |
| 2415 |
$tags = [], $logsubtype = 'delete', $immediate = false |
| 2416 |
) { |
| 2417 |
$services = MediaWikiServices::getInstance(); |
| 2418 |
$deletePage = $services->getDeletePageFactory()->newDeletePage( |
| 2419 |
$this, |
| 2420 |
$services->getUserFactory()->newFromUserIdentity( $deleter ) |
| 2421 |
); |
| 2422 |
|
| 2423 |
$status = $deletePage |
| 2424 |
->setSuppress( $suppress ) |
| 2425 |
->setTags( $tags ?: [] ) |
| 2426 |
->setLogSubtype( $logsubtype ) |
| 2427 |
->forceImmediate( $immediate ) |
| 2428 |
->keepLegacyHookErrorsSeparate() |
| 2429 |
->deleteUnsafe( $reason ); |
| 2430 |
$error = $deletePage->getLegacyHookErrors(); |
| 2431 |
if ( $status->isGood() ) { |
| 2432 |
|
| 2433 |
if ( $deletePage->deletionsWereScheduled()[DeletePage::PAGE_BASE] ) { |
| 2434 |
$status->warning( 'delete-scheduled', wfEscapeWikiText( $this->getTitle()->getPrefixedText() ) ); |
| 2435 |
} else { |
| 2436 |
$status->value = $deletePage->getSuccessfulDeletionsIDs()[DeletePage::PAGE_BASE]; |
| 2437 |
} |
| 2438 |
} |
| 2439 |
return $status; |
| 2440 |
} |
| 2441 |
|
| 2442 |
|
| 2443 |
|
| 2444 |
|
| 2445 |
|
| 2446 |
|
| 2447 |
|
| 2448 |
public function lockAndGetLatest() { |
| 2449 |
$dbw = MediaWikiServices::getInstance()->getConnectionProvider()->getPrimaryDatabase(); |
| 2450 |
return (int)$dbw->newSelectQueryBuilder() |
| 2451 |
->select( 'page_latest' ) |
| 2452 |
->forUpdate() |
| 2453 |
->from( 'page' ) |
| 2454 |
->where( [ |
| 2455 |
'page_id' => $this->getId(), |
| 2456 |
|
| 2457 |
|
| 2458 |
'page_namespace' => $this->getTitle()->getNamespace(), |
| 2459 |
'page_title' => $this->getTitle()->getDBkey() |
| 2460 |
] ) |
| 2461 |
->caller( __METHOD__ )->fetchField(); |
| 2462 |
} |
| 2463 |
|
| 2464 |
|
| 2465 |
|
| 2466 |
|
| 2467 |
|
| 2468 |
|
| 2469 |
|
| 2470 |
|
| 2471 |
|
| 2472 |
|
| 2473 |
|
| 2474 |
|
| 2475 |
|
| 2476 |
|
| 2477 |
public static function onArticleCreate( Title $title, $maybeIsRedirect = true ) { |
| 2478 |
|
| 2479 |
|
| 2480 |
|
| 2481 |
$other = $title->getOtherPage(); |
| 2482 |
|
| 2483 |
$services = MediaWikiServices::getInstance(); |
| 2484 |
$hcu = $services->getHtmlCacheUpdater(); |
| 2485 |
$hcu->purgeTitleUrls( [ $title, $other ], $hcu::PURGE_INTENT_TXROUND_REFLECTED ); |
| 2486 |
|
| 2487 |
$title->touchLinks(); |
| 2488 |
$title->deleteTitleProtection(); |
| 2489 |
|
| 2490 |
$services->getLinkCache()->invalidateTitle( $title ); |
| 2491 |
|
| 2492 |
DeferredUpdates::addCallableUpdate( |
| 2493 |
static function () use ( $title, $maybeIsRedirect ) { |
| 2494 |
self::queueBacklinksJobs( $title, true, $maybeIsRedirect, 'create-page' ); |
| 2495 |
} |
| 2496 |
); |
| 2497 |
|
| 2498 |
if ( $title->getNamespace() === NS_CATEGORY ) { |
| 2499 |
|
| 2500 |
|
| 2501 |
|
| 2502 |
|
| 2503 |
Category::newFromTitle( $title )->getID(); |
| 2504 |
} |
| 2505 |
} |
| 2506 |
|
| 2507 |
|
| 2508 |
|
| 2509 |
|
| 2510 |
|
| 2511 |
|
| 2512 |
public static function onArticleDelete( Title $title ) { |
| 2513 |
|
| 2514 |
|
| 2515 |
|
| 2516 |
$other = $title->getOtherPage(); |
| 2517 |
|
| 2518 |
$hcu = MediaWikiServices::getInstance()->getHtmlCacheUpdater(); |
| 2519 |
$hcu->purgeTitleUrls( [ $title, $other ], $hcu::PURGE_INTENT_TXROUND_REFLECTED ); |
| 2520 |
|
| 2521 |
$title->touchLinks(); |
| 2522 |
|
| 2523 |
$services = MediaWikiServices::getInstance(); |
| 2524 |
$services->getLinkCache()->invalidateTitle( $title ); |
| 2525 |
|
| 2526 |
InfoAction::invalidateCache( $title ); |
| 2527 |
|
| 2528 |
|
| 2529 |
if ( $title->getNamespace() === NS_MEDIAWIKI ) { |
| 2530 |
$services->getMessageCache()->updateMessageOverride( $title, null ); |
| 2531 |
} |
| 2532 |
|
| 2533 |
|
| 2534 |
DeferredUpdates::addCallableUpdate( static function () use ( $title ) { |
| 2535 |
self::queueBacklinksJobs( $title, true, true, 'delete-page' ); |
| 2536 |
} ); |
| 2537 |
|
| 2538 |
|
| 2539 |
if ( $title->getNamespace() === NS_USER_TALK ) { |
| 2540 |
$user = User::newFromName( $title->getText(), false ); |
| 2541 |
if ( $user ) { |
| 2542 |
MediaWikiServices::getInstance() |
| 2543 |
->getTalkPageNotificationManager() |
| 2544 |
->removeUserHasNewMessages( $user ); |
| 2545 |
} |
| 2546 |
} |
| 2547 |
|
| 2548 |
|
| 2549 |
$services->getRepoGroup()->getLocalRepo()->invalidateImageRedirect( $title ); |
| 2550 |
|
| 2551 |
|
| 2552 |
self::purgeInterwikiCheckKey( $title ); |
| 2553 |
} |
| 2554 |
|
| 2555 |
|
| 2556 |
|
| 2557 |
|
| 2558 |
|
| 2559 |
|
| 2560 |
|
| 2561 |
|
| 2562 |
|
| 2563 |
|
| 2564 |
|
| 2565 |
public static function onArticleEdit( |
| 2566 |
Title $title, |
| 2567 |
?RevisionRecord $revRecord = null, |
| 2568 |
$slotsChanged = null, |
| 2569 |
$maybeRedirectChanged = true |
| 2570 |
) { |
| 2571 |
|
| 2572 |
|
| 2573 |
DeferredUpdates::addCallableUpdate( |
| 2574 |
static function () use ( $title, $slotsChanged, $maybeRedirectChanged ) { |
| 2575 |
self::queueBacklinksJobs( |
| 2576 |
$title, |
| 2577 |
$slotsChanged === null || in_array( SlotRecord::MAIN, $slotsChanged ), |
| 2578 |
$maybeRedirectChanged, |
| 2579 |
'edit-page' |
| 2580 |
); |
| 2581 |
} |
| 2582 |
); |
| 2583 |
|
| 2584 |
$services = MediaWikiServices::getInstance(); |
| 2585 |
$services->getLinkCache()->invalidateTitle( $title ); |
| 2586 |
|
| 2587 |
$hcu = MediaWikiServices::getInstance()->getHtmlCacheUpdater(); |
| 2588 |
$hcu->purgeTitleUrls( $title, $hcu::PURGE_INTENT_TXROUND_REFLECTED ); |
| 2589 |
|
| 2590 |
|
| 2591 |
$revid = $revRecord ? $revRecord->getId() : null; |
| 2592 |
DeferredUpdates::addCallableUpdate( static function () use ( $title, $revid ) { |
| 2593 |
InfoAction::invalidateCache( $title, $revid ); |
| 2594 |
} ); |
| 2595 |
|
| 2596 |
|
| 2597 |
self::purgeInterwikiCheckKey( $title ); |
| 2598 |
} |
| 2599 |
|
| 2600 |
private static function queueBacklinksJobs( |
| 2601 |
Title $title, $mainSlotChanged, $maybeRedirectChanged, $causeAction |
| 2602 |
) { |
| 2603 |
$services = MediaWikiServices::getInstance(); |
| 2604 |
$backlinkCache = $services->getBacklinkCacheFactory()->getBacklinkCache( $title ); |
| 2605 |
|
| 2606 |
$jobs = []; |
| 2607 |
if ( $mainSlotChanged |
| 2608 |
&& $backlinkCache->hasLinks( 'templatelinks' ) |
| 2609 |
) { |
| 2610 |
|
| 2611 |
|
| 2612 |
|
| 2613 |
$jobs[] = HTMLCacheUpdateJob::newForBacklinks( |
| 2614 |
$title, |
| 2615 |
'templatelinks', |
| 2616 |
[ 'causeAction' => $causeAction ] |
| 2617 |
); |
| 2618 |
} |
| 2619 |
|
| 2620 |
if ( $maybeRedirectChanged && $title->getNamespace() === NS_FILE |
| 2621 |
&& $backlinkCache->hasLinks( 'imagelinks' ) |
| 2622 |
) { |
| 2623 |
|
| 2624 |
$jobs[] = HTMLCacheUpdateJob::newForBacklinks( |
| 2625 |
$title, |
| 2626 |
'imagelinks', |
| 2627 |
[ 'causeAction' => $causeAction ] |
| 2628 |
); |
| 2629 |
} |
| 2630 |
|
| 2631 |
if ( $backlinkCache->hasLinks( 'redirect' ) ) { |
| 2632 |
$jobs[] = HTMLCacheUpdateJob::newForBacklinks( |
| 2633 |
$title, |
| 2634 |
'redirect', |
| 2635 |
[ 'causeAction' => $causeAction ] |
| 2636 |
); |
| 2637 |
} |
| 2638 |
if ( $jobs ) { |
| 2639 |
$services->getJobQueueGroup()->push( $jobs ); |
| 2640 |
} |
| 2641 |
} |
| 2642 |
|
| 2643 |
|
| 2644 |
|
| 2645 |
|
| 2646 |
|
| 2647 |
|
| 2648 |
private static function purgeInterwikiCheckKey( Title $title ) { |
| 2649 |
$enableScaryTranscluding = MediaWikiServices::getInstance()->getMainConfig()->get( |
| 2650 |
MainConfigNames::EnableScaryTranscluding ); |
| 2651 |
|
| 2652 |
if ( !$enableScaryTranscluding ) { |
| 2653 |
return; |
| 2654 |
} |
| 2655 |
|
| 2656 |
DeferredUpdates::addCallableUpdate( static function () use ( $title ) { |
| 2657 |
$cache = MediaWikiServices::getInstance()->getMainWANObjectCache(); |
| 2658 |
$cache->resetCheckKey( |
| 2659 |
|
| 2660 |
|
| 2661 |
|
| 2662 |
$cache->makeGlobalKey( |
| 2663 |
'interwiki-page', |
| 2664 |
WikiMap::getCurrentWikiDbDomain()->getId(), |
| 2665 |
$title->getDBkey() |
| 2666 |
) |
| 2667 |
); |
| 2668 |
} ); |
| 2669 |
} |
| 2670 |
|
| 2671 |
|
| 2672 |
|
| 2673 |
|
| 2674 |
|
| 2675 |
|
| 2676 |
|
| 2677 |
public function getCategories() { |
| 2678 |
$services = MediaWikiServices::getInstance(); |
| 2679 |
$id = $this->getId(); |
| 2680 |
if ( $id == 0 ) { |
| 2681 |
return $services->getTitleFactory()->newTitleArrayFromResult( new FakeResultWrapper( [] ) ); |
| 2682 |
} |
| 2683 |
|
| 2684 |
$dbr = $services->getConnectionProvider()->getReplicaDatabase(); |
| 2685 |
$res = $dbr->newSelectQueryBuilder() |
| 2686 |
->select( [ 'page_title' => 'cl_to', 'page_namespace' => (string)NS_CATEGORY ] ) |
| 2687 |
->from( 'categorylinks' ) |
| 2688 |
->where( [ 'cl_from' => $id ] ) |
| 2689 |
->caller( __METHOD__ )->fetchResultSet(); |
| 2690 |
|
| 2691 |
return $services->getTitleFactory()->newTitleArrayFromResult( $res ); |
| 2692 |
} |
| 2693 |
|
| 2694 |
|
| 2695 |
|
| 2696 |
|
| 2697 |
|
| 2698 |
|
| 2699 |
|
| 2700 |
public function getHiddenCategories() { |
| 2701 |
$result = []; |
| 2702 |
$id = $this->getId(); |
| 2703 |
|
| 2704 |
if ( $id == 0 ) { |
| 2705 |
return []; |
| 2706 |
} |
| 2707 |
|
| 2708 |
$dbr = MediaWikiServices::getInstance()->getConnectionProvider()->getReplicaDatabase(); |
| 2709 |
$res = $dbr->newSelectQueryBuilder() |
| 2710 |
->select( [ 'cl_to' ] ) |
| 2711 |
->from( 'categorylinks' ) |
| 2712 |
->join( 'page', null, 'page_title=cl_to' ) |
| 2713 |
->join( 'page_props', null, 'pp_page=page_id' ) |
| 2714 |
->where( [ 'cl_from' => $id, 'pp_propname' => 'hiddencat', 'page_namespace' => NS_CATEGORY ] ) |
| 2715 |
->caller( __METHOD__ )->fetchResultSet(); |
| 2716 |
|
| 2717 |
foreach ( $res as $row ) { |
| 2718 |
$result[] = Title::makeTitle( NS_CATEGORY, $row->cl_to ); |
| 2719 |
} |
| 2720 |
|
| 2721 |
return $result; |
| 2722 |
} |
| 2723 |
|
| 2724 |
|
| 2725 |
|
| 2726 |
|
| 2727 |
|
| 2728 |
|
| 2729 |
|
| 2730 |
|
| 2731 |
public function getAutoDeleteReason( &$hasHistory = false ) { |
| 2732 |
if ( func_num_args() === 1 ) { |
| 2733 |
wfDeprecated( __METHOD__ . ': $hasHistory parameter', '1.38' ); |
| 2734 |
return $this->getContentHandler()->getAutoDeleteReason( $this->getTitle(), $hasHistory ); |
| 2735 |
} |
| 2736 |
return $this->getContentHandler()->getAutoDeleteReason( $this->getTitle() ); |
| 2737 |
} |
| 2738 |
|
| 2739 |
|
| 2740 |
|
| 2741 |
|
| 2742 |
|
| 2743 |
|
| 2744 |
|
| 2745 |
|
| 2746 |
|
| 2747 |
|
| 2748 |
|
| 2749 |
public function updateCategoryCounts( array $added, array $deleted, $id = 0 ) { |
| 2750 |
$id = $id ?: $this->getId(); |
| 2751 |
|
| 2752 |
$added = array_map( 'strval', $added ); |
| 2753 |
$deleted = array_map( 'strval', $deleted ); |
| 2754 |
$type = MediaWikiServices::getInstance()->getNamespaceInfo()-> |
| 2755 |
getCategoryLinkType( $this->getTitle()->getNamespace() ); |
| 2756 |
|
| 2757 |
$addFields = [ 'cat_pages' => new RawSQLValue( 'cat_pages + 1' ) ]; |
| 2758 |
$removeFields = [ 'cat_pages' => new RawSQLValue( 'cat_pages - 1' ) ]; |
| 2759 |
if ( $type !== 'page' ) { |
| 2760 |
$addFields["cat_{$type}s"] = new RawSQLValue( "cat_{$type}s + 1" ); |
| 2761 |
$removeFields["cat_{$type}s"] = new RawSQLValue( "cat_{$type}s - 1" ); |
| 2762 |
} |
| 2763 |
|
| 2764 |
$dbw = MediaWikiServices::getInstance()->getConnectionProvider()->getPrimaryDatabase(); |
| 2765 |
$res = $dbw->newSelectQueryBuilder() |
| 2766 |
->select( [ 'cat_id', 'cat_title' ] ) |
| 2767 |
->from( 'category' ) |
| 2768 |
->where( [ 'cat_title' => array_merge( $added, $deleted ) ] ) |
| 2769 |
->caller( __METHOD__ ) |
| 2770 |
->fetchResultSet(); |
| 2771 |
$existingCategories = []; |
| 2772 |
foreach ( $res as $row ) { |
| 2773 |
$existingCategories[$row->cat_id] = $row->cat_title; |
| 2774 |
} |
| 2775 |
$existingAdded = array_intersect( $existingCategories, $added ); |
| 2776 |
$existingDeleted = array_intersect( $existingCategories, $deleted ); |
| 2777 |
$missingAdded = array_diff( $added, $existingAdded ); |
| 2778 |
|
| 2779 |
|
| 2780 |
|
| 2781 |
|
| 2782 |
if ( $existingAdded ) { |
| 2783 |
$dbw->newUpdateQueryBuilder() |
| 2784 |
->update( 'category' ) |
| 2785 |
->set( $addFields ) |
| 2786 |
->where( [ 'cat_id' => array_keys( $existingAdded ) ] ) |
| 2787 |
->caller( __METHOD__ )->execute(); |
| 2788 |
} |
| 2789 |
|
| 2790 |
if ( $missingAdded ) { |
| 2791 |
$queryBuilder = $dbw->newInsertQueryBuilder() |
| 2792 |
->insertInto( 'category' ) |
| 2793 |
->onDuplicateKeyUpdate() |
| 2794 |
->uniqueIndexFields( [ 'cat_title' ] ) |
| 2795 |
->set( $addFields ); |
| 2796 |
foreach ( $missingAdded as $cat ) { |
| 2797 |
$queryBuilder->row( [ |
| 2798 |
'cat_title' => $cat, |
| 2799 |
'cat_pages' => 1, |
| 2800 |
'cat_subcats' => ( $type === 'subcat' ) ? 1 : 0, |
| 2801 |
'cat_files' => ( $type === 'file' ) ? 1 : 0, |
| 2802 |
] ); |
| 2803 |
} |
| 2804 |
$queryBuilder->caller( __METHOD__ )->execute(); |
| 2805 |
} |
| 2806 |
|
| 2807 |
if ( $existingDeleted ) { |
| 2808 |
$dbw->newUpdateQueryBuilder() |
| 2809 |
->update( 'category' ) |
| 2810 |
->set( $removeFields ) |
| 2811 |
->where( [ 'cat_id' => array_keys( $existingDeleted ) ] ) |
| 2812 |
->caller( __METHOD__ )->execute(); |
| 2813 |
} |
| 2814 |
|
| 2815 |
foreach ( $added as $catName ) { |
| 2816 |
$cat = Category::newFromName( $catName ); |
| 2817 |
$this->getHookRunner()->onCategoryAfterPageAdded( $cat, $this ); |
| 2818 |
} |
| 2819 |
|
| 2820 |
foreach ( $deleted as $catName ) { |
| 2821 |
$cat = Category::newFromName( $catName ); |
| 2822 |
$this->getHookRunner()->onCategoryAfterPageRemoved( $cat, $this, $id ); |
| 2823 |
|
| 2824 |
DeferredUpdates::addCallableUpdate( static function () use ( $cat ) { |
| 2825 |
$cat->refreshCountsIfEmpty(); |
| 2826 |
} ); |
| 2827 |
} |
| 2828 |
} |
| 2829 |
|
| 2830 |
|
| 2831 |
|
| 2832 |
|
| 2833 |
|
| 2834 |
|
| 2835 |
|
| 2836 |
|
| 2837 |
|
| 2838 |
|
| 2839 |
|
| 2840 |
|
| 2841 |
|
| 2842 |
public function triggerOpportunisticLinksUpdate( ParserOutput $parserOutput ) { |
| 2843 |
if ( MediaWikiServices::getInstance()->getReadOnlyMode()->isReadOnly() ) { |
| 2844 |
return; |
| 2845 |
} |
| 2846 |
|
| 2847 |
if ( !$this->getHookRunner()->onOpportunisticLinksUpdate( $this, |
| 2848 |
$this->mTitle, $parserOutput ) |
| 2849 |
) { |
| 2850 |
return; |
| 2851 |
} |
| 2852 |
|
| 2853 |
$config = MediaWikiServices::getInstance()->getMainConfig(); |
| 2854 |
|
| 2855 |
$params = [ |
| 2856 |
'isOpportunistic' => true, |
| 2857 |
'rootJobTimestamp' => $parserOutput->getCacheTime() |
| 2858 |
]; |
| 2859 |
|
| 2860 |
if ( MediaWikiServices::getInstance()->getRestrictionStore()->areRestrictionsCascading( $this->mTitle ) ) { |
| 2861 |
|
| 2862 |
|
| 2863 |
|
| 2864 |
|
| 2865 |
|
| 2866 |
|
| 2867 |
|
| 2868 |
|
| 2869 |
|
| 2870 |
|
| 2871 |
|
| 2872 |
|
| 2873 |
|
| 2874 |
MediaWikiServices::getInstance()->getJobQueueGroup()->lazyPush( |
| 2875 |
RefreshLinksJob::newPrioritized( $this->mTitle, $params ) |
| 2876 |
); |
| 2877 |
} elseif ( !$config->get( MainConfigNames::MiserMode ) && |
| 2878 |
$parserOutput->hasReducedExpiry() |
| 2879 |
) { |
| 2880 |
|
| 2881 |
|
| 2882 |
|
| 2883 |
|
| 2884 |
|
| 2885 |
|
| 2886 |
if ( $this->getLinksTimestamp() > $this->getTouched() ) { |
| 2887 |
|
| 2888 |
|
| 2889 |
$services = MediaWikiServices::getInstance()->getObjectCacheFactory(); |
| 2890 |
$cache = $services->getLocalClusterInstance(); |
| 2891 |
$key = $cache->makeKey( 'dynamic-linksupdate', 'last', $this->getId() ); |
| 2892 |
$ttl = max( $parserOutput->getCacheExpiry(), 3600 ); |
| 2893 |
if ( $cache->add( $key, time(), $ttl ) ) { |
| 2894 |
MediaWikiServices::getInstance()->getJobQueueGroup()->lazyPush( |
| 2895 |
RefreshLinksJob::newDynamic( $this->mTitle, $params ) |
| 2896 |
); |
| 2897 |
} |
| 2898 |
} |
| 2899 |
} |
| 2900 |
} |
| 2901 |
|
| 2902 |
|
| 2903 |
|
| 2904 |
|
| 2905 |
|
| 2906 |
|
| 2907 |
|
| 2908 |
|
| 2909 |
public function isLocal() { |
| 2910 |
return true; |
| 2911 |
} |
| 2912 |
|
| 2913 |
|
| 2914 |
|
| 2915 |
|
| 2916 |
|
| 2917 |
|
| 2918 |
|
| 2919 |
|
| 2920 |
|
| 2921 |
|
| 2922 |
public function getWikiDisplayName() { |
| 2923 |
$sitename = MediaWikiServices::getInstance()->getMainConfig()->get( |
| 2924 |
MainConfigNames::Sitename ); |
| 2925 |
return $sitename; |
| 2926 |
} |
| 2927 |
|
| 2928 |
|
| 2929 |
|
| 2930 |
|
| 2931 |
|
| 2932 |
|
| 2933 |
|
| 2934 |
|
| 2935 |
|
| 2936 |
public function getSourceURL() { |
| 2937 |
return $this->getTitle()->getCanonicalURL(); |
| 2938 |
} |
| 2939 |
|
| 2940 |
|
| 2941 |
|
| 2942 |
|
| 2943 |
|
| 2944 |
|
| 2945 |
|
| 2946 |
public function __wakeup() { |
| 2947 |
|
| 2948 |
|
| 2949 |
|
| 2950 |
|
| 2951 |
|
| 2952 |
$this->clear(); |
| 2953 |
} |
| 2954 |
|
| 2955 |
|
| 2956 |
|
| 2957 |
|
| 2958 |
|
| 2959 |
public function getNamespace(): int { |
| 2960 |
return $this->getTitle()->getNamespace(); |
| 2961 |
} |
| 2962 |
|
| 2963 |
|
| 2964 |
|
| 2965 |
|
| 2966 |
|
| 2967 |
public function getDBkey(): string { |
| 2968 |
return $this->getTitle()->getDBkey(); |
| 2969 |
} |
| 2970 |
|
| 2971 |
|
| 2972 |
|
| 2973 |
|
| 2974 |
|
| 2975 |
public function getWikiId() { |
| 2976 |
return $this->getTitle()->getWikiId(); |
| 2977 |
} |
| 2978 |
|
| 2979 |
|
| 2980 |
|
| 2981 |
|
| 2982 |
|
| 2983 |
public function canExist(): bool { |
| 2984 |
return true; |
| 2985 |
} |
| 2986 |
|
| 2987 |
|
| 2988 |
|
| 2989 |
|
| 2990 |
|
| 2991 |
public function __toString(): string { |
| 2992 |
return $this->mTitle->__toString(); |
| 2993 |
} |
| 2994 |
|
| 2995 |
|
| 2996 |
|
| 2997 |
|
| 2998 |
|
| 2999 |
public function isSamePageAs( PageReference $other ): bool { |
| 3000 |
|
| 3001 |
return $this->getWikiId() === $other->getWikiId() |
| 3002 |
&& $this->getNamespace() === $other->getNamespace() |
| 3003 |
&& $this->getDBkey() === $other->getDBkey(); |
| 3004 |
} |
| 3005 |
|
| 3006 |
|
| 3007 |
|
| 3008 |
|
| 3009 |
|
| 3010 |
|
| 3011 |
|
| 3012 |
|
| 3013 |
|
| 3014 |
|
| 3015 |
|
| 3016 |
|
| 3017 |
public function toPageRecord(): ExistingPageRecord { |
| 3018 |
|
| 3019 |
|
| 3020 |
if ( !$this->mDataLoaded ) { |
| 3021 |
$this->loadPageData(); |
| 3022 |
} |
| 3023 |
|
| 3024 |
Assert::precondition( |
| 3025 |
$this->exists(), |
| 3026 |
'This WikiPage instance does not represent an existing page: ' . $this->mTitle |
| 3027 |
); |
| 3028 |
|
| 3029 |
return new PageStoreRecord( |
| 3030 |
(object)[ |
| 3031 |
'page_id' => $this->getId(), |
| 3032 |
'page_namespace' => $this->mTitle->getNamespace(), |
| 3033 |
'page_title' => $this->mTitle->getDBkey(), |
| 3034 |
'page_latest' => $this->mLatest, |
| 3035 |
'page_is_new' => $this->mIsNew ? 1 : 0, |
| 3036 |
'page_is_redirect' => $this->mPageIsRedirectField ? 1 : 0, |
| 3037 |
'page_touched' => $this->getTouched(), |
| 3038 |
'page_lang' => $this->getLanguage() |
| 3039 |
], |
| 3040 |
PageIdentity::LOCAL |
| 3041 |
); |
| 3042 |
} |
| 3043 |
|
| 3044 |
} |