33 use Wikimedia\Assert\Assert;
128 $ns =
$title->getNamespace();
131 throw new MWException(
"NS_MEDIA is a virtual namespace; use NS_FILE." );
132 } elseif ( $ns < 0 ) {
133 throw new MWException(
"Invalid or virtual namespace $ns given." );
165 public static function newFromID( $id, $from =
'fromdb' ) {
174 $row = $db->selectRow(
175 $pageQuery[
'tables'], $pageQuery[
'fields'], [
'page_id' => $id ], __METHOD__,
176 [], $pageQuery[
'joins']
195 public static function newFromRow( $row, $from =
'fromdb' ) {
197 $page->loadFromRow( $row, $from );
210 return self::READ_NORMAL;
212 return self::READ_LATEST;
225 return MediaWikiServices::getInstance()->getRevisionStore();
232 return MediaWikiServices::getInstance()->getRevisionRenderer();
239 return MediaWikiServices::getInstance()->getParserCache();
246 return MediaWikiServices::getInstance()->getDBLoadBalancer();
285 $this->mDataLoaded =
false;
297 $this->mRedirectTarget =
null;
298 $this->mLastRevision =
null;
299 $this->mTouched =
'19700101000000';
300 $this->mLinksUpdated =
'19700101000000';
301 $this->mTimestamp =
'';
302 $this->mIsRedirect =
false;
303 $this->mLatest =
false;
316 $this->mPreparedEdit =
false;
340 'page_links_updated',
346 $fields[] =
'page_content_model';
350 $fields[] =
'page_lang';
369 'tables' => [
'page' ],
379 'page_links_updated',
387 $ret[
'fields'][] =
'page_content_model';
391 $ret[
'fields'][] =
'page_lang';
411 &$wikiPage, &$pageQuery[
'fields'], &$pageQuery[
'tables'], &$pageQuery[
'joins']
414 $row =
$dbr->selectRow(
415 $pageQuery[
'tables'],
416 $pageQuery[
'fields'],
423 Hooks::run(
'ArticlePageDataAfter', [ &$wikiPage, &$row ] );
439 'page_namespace' =>
$title->getNamespace(),
469 if ( is_int( $from ) && $from <= $this->mDataLoadedFrom ) {
474 if ( is_int( $from ) ) {
477 $db = $loadBalancer->getConnection( $index );
482 && $loadBalancer->getServerCount() > 1
483 && $loadBalancer->hasOrMadeRecentMasterChanges()
485 $from = self::READ_LATEST;
487 $db = $loadBalancer->getConnection( $index );
493 $from = self::READ_NORMAL;
515 if ( !is_int( $from ) ) {
517 $from = self::READ_NORMAL;
520 if ( is_int( $from ) && $from <= $this->mDataLoadedFrom ) {
539 $lc = MediaWikiServices::getInstance()->getLinkCache();
540 $lc->clearLink( $this->mTitle );
543 $lc->addGoodLinkObjFromRow( $this->mTitle, $data );
545 $this->mTitle->loadFromRow( $data );
548 $this->mTitle->loadRestrictions( $data->page_restrictions );
550 $this->mId = intval( $data->page_id );
551 $this->mTouched =
wfTimestamp( TS_MW, $data->page_touched );
553 $this->mIsRedirect = intval( $data->page_is_redirect );
554 $this->mLatest = intval( $data->page_latest );
557 if ( $this->mLastRevision && $this->mLastRevision->getId() !=
$this->mLatest ) {
558 $this->mLastRevision =
null;
559 $this->mTimestamp =
'';
562 $lc->addBadLinkObj( $this->mTitle );
564 $this->mTitle->loadFromRow(
false );
571 $this->mDataLoaded =
true;
579 if ( !$this->mDataLoaded ) {
589 if ( !$this->mDataLoaded ) {
592 return $this->mId > 0;
604 return $this->mTitle->isKnown();
613 if ( !$this->mDataLoaded ) {
634 return $cache->getWithSetCallback(
635 $cache->makeKey(
'page-content-model', $this->getLatest() ),
641 return $rev->getContentModel();
643 $title = $this->mTitle->getPrefixedDBkey();
644 wfWarn(
"Page $title exists but has no (visible) revisions!" );
645 return $this->mTitle->getContentModel();
652 return $this->mTitle->getContentModel();
660 if ( !$this->mDataLoaded ) {
663 return ( $this->mId && !$this->mIsRedirect );
671 if ( !$this->mDataLoaded ) {
682 if ( !$this->mDataLoaded ) {
693 if ( !$this->mDataLoaded ) {
705 $rev = $this->mTitle->getFirstRevision();
717 if ( $this->mLastRevision !==
null ) {
726 if ( $this->mDataLoadedFrom == self::READ_LOCKING ) {
736 } elseif ( $this->mDataLoadedFrom == self::READ_LATEST ) {
740 $flags = Revision::READ_LATEST;
757 $this->mLastRevision = $revision;
767 if ( $this->mLastRevision ) {
779 if ( $this->mLastRevision ) {
780 return $this->mLastRevision->getRevisionRecord();
800 if ( $this->mLastRevision ) {
801 return $this->mLastRevision->getContent( $audience,
$user );
811 if ( !$this->mTimestamp ) {
838 if ( $this->mLastRevision ) {
839 return $this->mLastRevision->getUser( $audience,
$user );
858 $userName = $revision->getUserText( $audience,
$user );
876 if ( $this->mLastRevision ) {
877 return $this->mLastRevision->getUserText( $audience,
$user );
894 if ( $this->mLastRevision ) {
895 return $this->mLastRevision->getComment( $audience,
$user );
908 if ( $this->mLastRevision ) {
909 return $this->mLastRevision->isMinor();
928 if ( !$this->mTitle->isContentPage() ) {
953 $hasLinks = (bool)
count( $editInfo->output->getLinks() );
957 [
'pl_from' => $this->
getId() ], __METHOD__ );
961 return $content->isCountable( $hasLinks );
972 if ( !$this->mTitle->isRedirect() ) {
976 if ( $this->mRedirectTarget !==
null ) {
982 $row =
$dbr->selectRow(
'redirect',
983 [
'rd_namespace',
'rd_title',
'rd_fragment',
'rd_interwiki' ],
984 [
'rd_from' => $this->
getId() ],
989 if ( $row && !is_null( $row->rd_fragment ) && !is_null( $row->rd_interwiki ) ) {
993 if ( $row->rd_namespace ==
NS_MEDIA ) {
996 $namespace = $row->rd_namespace;
999 $namespace, $row->rd_title,
1000 $row->rd_fragment, $row->rd_interwiki
1045 $dbw->startAtomic( __METHOD__ );
1051 'rd_from' => $this->
getId(),
1068 $dbw->endAtomic( __METHOD__ );
1092 if ( $rt->isExternal() ) {
1093 if ( $rt->isLocal() ) {
1097 $source = $this->mTitle->getFullURL(
'redirect=no' );
1098 return $rt->getFullURL( [
'rdfrom' =>
$source ] );
1106 if ( $rt->isSpecialPage() ) {
1110 if ( $rt->isValidRedirectTarget() ) {
1111 return $rt->getFullURL();
1131 $actorQuery = $actorMigration->getJoin(
'rev_user' );
1133 $tables = array_merge( [
'revision' ], $actorQuery[
'tables'], [
'user' ] );
1136 'user_id' => $actorQuery[
'fields'][
'rev_user'],
1137 'user_name' => $actorQuery[
'fields'][
'rev_user_text'],
1138 'actor_id' => $actorQuery[
'fields'][
'rev_actor'],
1139 'user_real_name' =>
'MIN(user_real_name)',
1140 'timestamp' =>
'MAX(rev_timestamp)',
1143 $conds = [
'rev_page' => $this->
getId() ];
1150 $conds[] =
'NOT(' . $actorMigration->getWhere(
$dbr,
'rev_user',
$user )[
'conds'] .
')';
1153 $conds[] =
"{$dbr->bitAnd( 'rev_deleted', Revision::DELETED_USER )} = 0";
1156 'user' => [
'LEFT JOIN', $actorQuery[
'fields'][
'rev_user'] .
' = user_id' ],
1157 ] + $actorQuery[
'joins'];
1160 'GROUP BY' => [ $fields[
'user_id'], $fields[
'user_name'] ],
1161 'ORDER BY' =>
'timestamp DESC',
1178 && ( $oldId ===
null || $oldId === 0 || $oldId === $this->
getLatest() )
1198 ParserOptions $parserOptions, $oldid =
null, $forceParse =
false
1203 if ( $useParserCache && !$parserOptions->
isSafeToCache() ) {
1204 throw new InvalidArgumentException(
1205 'The supplied ParserOptions are not safe to cache. Fix the options or set $forceParse = true.'
1210 ': using parser cache: ' . ( $useParserCache ?
'yes' :
'no' ) .
"\n" );
1215 if ( $useParserCache ) {
1217 ->get( $this, $parserOptions );
1218 if ( $parserOutput !==
false ) {
1219 return $parserOutput;
1223 if ( $oldid ===
null || $oldid === 0 ) {
1230 return $pool->getParserOutput();
1246 function ()
use (
$user, $oldid ) {
1249 $user->clearNotification( $this->mTitle, $oldid );
1265 if ( !
Hooks::run(
'ArticlePurge', [ &$wikiPage ] ) ) {
1269 $this->mTitle->invalidateCache();
1281 $messageCache->updateMessageOverride( $this->mTitle, $this->
getContent() );
1304 $pageIdForInsert = $pageId ? [
'page_id' => $pageId ] : [];
1308 'page_namespace' => $this->mTitle->getNamespace(),
1309 'page_title' => $this->mTitle->getDBkey(),
1310 'page_restrictions' =>
'',
1311 'page_is_redirect' => 0,
1314 'page_touched' => $dbw->timestamp(),
1317 ] + $pageIdForInsert,
1322 if ( $dbw->affectedRows() > 0 ) {
1323 $newid = $pageId ? (int)$pageId : $dbw->insertId();
1324 $this->mId = $newid;
1325 $this->mTitle->resetArticleID( $newid );
1349 $lastRevIsRedirect =
null
1358 if ( (
int)$revision->getId() === 0 ) {
1359 throw new InvalidArgumentException(
1360 __METHOD__ .
': Revision has ID ' . var_export( $revision->getId(), 1 )
1364 $content = $revision->getContent();
1368 $conditions = [
'page_id' => $this->
getId() ];
1370 if ( !is_null( $lastRevision ) ) {
1372 $conditions[
'page_latest'] = $lastRevision;
1375 $revId = $revision->getId();
1376 Assert::parameter( $revId > 0,
'$revision->getId()',
'must be > 0' );
1379 'page_latest' => $revId,
1380 'page_touched' => $dbw->timestamp( $revision->getTimestamp() ),
1381 'page_is_new' => ( $lastRevision === 0 ) ? 1 : 0,
1382 'page_is_redirect' => $rt !==
null ? 1 : 0,
1387 $row[
'page_content_model'] = $revision->getContentModel();
1390 $dbw->update(
'page',
1395 $result = $dbw->affectedRows() > 0;
1399 $this->mLatest = $revision->getId();
1400 $this->mIsRedirect = (bool)$rt;
1402 $linkCache = MediaWikiServices::getInstance()->getLinkCache();
1403 $linkCache->addGoodLinkObj(
1409 $revision->getContentModel()
1431 $isRedirect = !is_null( $redirectTitle );
1433 if ( !$isRedirect && $lastRevIsRedirect ===
false ) {
1437 if ( $isRedirect ) {
1441 $where = [
'rd_from' => $this->
getId() ];
1442 $dbw->delete(
'redirect', $where, __METHOD__ );
1449 return ( $dbw->affectedRows() != 0 );
1463 $row = $dbw->selectRow(
1464 [
'revision',
'page' ],
1465 [
'rev_id',
'rev_timestamp',
'page_is_redirect' ],
1467 'page_id' => $this->
getId(),
1468 'page_latest=rev_id' ],
1472 if (
wfTimestamp( TS_MW, $row->rev_timestamp ) >= $revision->getTimestamp() ) {
1475 $prev = $row->rev_id;
1476 $lastRevIsRedirect = (bool)$row->page_is_redirect;
1480 $lastRevIsRedirect =
null;
1503 $changedRoles = $aSlots->getRolesWithDifferentContent( $bSlots );
1505 return ( $changedRoles !== [ SlotRecord::MAIN ] && $changedRoles !== [] );
1522 if ( self::hasDifferencesOutsideMainSlot( $undo, $undoafter ) ) {
1560 $sectionId,
Content $sectionContent, $sectionTitle =
'', $edittime =
null
1563 if ( $edittime && $sectionId !==
'new' ) {
1571 && $lb->getServerCount() > 1
1572 && $lb->hasOrMadeRecentMasterChanges()
1578 $baseRevId =
$rev->getId();
1582 return $this->
replaceSectionAtRev( $sectionId, $sectionContent, $sectionTitle, $baseRevId );
1599 $sectionTitle =
'', $baseRevId =
null
1601 if ( strval( $sectionId ) ===
'' ) {
1603 $newContent = $sectionContent;
1606 throw new MWException(
"sections not supported for content model " .
1611 if ( is_null( $baseRevId ) || $sectionId ===
'new' ) {
1616 wfDebug( __METHOD__ .
" asked for bogus section (page: " .
1617 $this->
getId() .
"; section: $sectionId)\n" );
1621 $oldContent =
$rev->getContent();
1624 if ( !$oldContent ) {
1625 wfDebug( __METHOD__ .
": no page text\n" );
1629 $newContent = $oldContent->replaceSection( $sectionId, $sectionContent, $sectionTitle );
1669 MediaWikiServices::getInstance()->getContentLanguage(),
1670 MediaWikiServices::getInstance()->getDBLoadBalancerFactory()
1707 User $forUser =
null,
1712 if ( !$forRevision && !$forUpdate ) {
1715 $this->derivedDataUpdater =
null;
1718 if ( $this->derivedDataUpdater && !$this->derivedDataUpdater->isContentPrepared() ) {
1722 $this->derivedDataUpdater =
null;
1729 if ( $this->derivedDataUpdater
1730 && !$this->derivedDataUpdater->isReusableFor(
1734 $forEdit ? $this->getLatest() : null
1737 $this->derivedDataUpdater =
null;
1740 if ( !$this->derivedDataUpdater ) {
1777 return $pageUpdater;
1844 User $user =
null, $serialFormat =
null, $tags = [], $undidRevId = 0
1864 $slotsUpdate->modifyContent( SlotRecord::MAIN,
$content );
1871 $updater->setOriginalRevisionId( $originalRevId );
1872 $updater->setUndidRevisionId( $undidRevId );
1879 if ( $needsPatrol && $this->
getTitle()->userCan(
'autopatrol',
$user ) ) {
1897 $this->mLatest = $revRec->getId();
1920 if ( $this->
getTitle()->isConversionTable() ) {
1923 $options->disableContentConversion();
1953 $serialFormat =
null,
1962 if ( !is_object( $revision ) ) {
1966 if ( $revid !==
null ) {
1967 wfDeprecated( __METHOD__ .
' with $revision = revision ID',
'1.25' );
1969 $revision = $store->getRevisionById( $revid, Revision::READ_LATEST );
1973 } elseif ( $revision instanceof
Revision ) {
1974 $revision = $revision->getRevisionRecord();
1977 $slots = RevisionSlotsUpdate::newFromContent( [ SlotRecord::MAIN =>
$content ] );
1980 if ( !
$updater->isUpdatePrepared() ) {
1987 'causeAction' =>
'prepare-edit',
1988 'causeAgent' =>
$user->getName(),
1994 return $updater->getPreparedEdit();
2026 'causeAction' =>
'edit-page',
2027 'causeAgent' =>
$user->getName(),
2054 if ( !$revision || !$revision->getId() ) {
2055 LoggerFactory::getInstance(
'wikipage' )->info(
2056 __METHOD__ .
'called with ' . ( $revision ?
'unsaved' :
'no' ) .
' revision'
2096 if ( !$revision || !$revision->getId() ) {
2097 LoggerFactory::getInstance(
'wikipage' )->info(
2098 __METHOD__ .
'called with ' . ( $revision ?
'unsaved' :
'no' ) .
' revision'
2124 &$cascade, $reason,
User $user, $tags =
null
2133 $restrictionTypes = $this->mTitle->getRestrictionTypes();
2134 $id = $this->
getId();
2145 $isProtected =
false;
2151 foreach ( $restrictionTypes
as $action ) {
2152 if ( !isset( $expiry[$action] ) || $expiry[$action] === $dbw->getInfinity() ) {
2153 $expiry[$action] =
'infinity';
2155 if ( !isset( $limit[$action] ) ) {
2156 $limit[$action] =
'';
2157 } elseif ( $limit[$action] !=
'' ) {
2162 $current = implode(
'', $this->mTitle->getRestrictions( $action ) );
2163 if ( $current !=
'' ) {
2164 $isProtected =
true;
2167 if ( $limit[$action] != $current ) {
2169 } elseif ( $limit[$action] !=
'' ) {
2173 if ( $this->mTitle->getRestrictionExpiry( $action ) != $expiry[$action] ) {
2179 if ( !$changed && $protect && $this->mTitle->areRestrictionsCascading() != $cascade ) {
2189 $revCommentMsg =
'unprotectedarticle-comment';
2190 $logAction =
'unprotect';
2191 } elseif ( $isProtected ) {
2192 $revCommentMsg =
'modifiedarticleprotection-comment';
2193 $logAction =
'modify';
2195 $revCommentMsg =
'protectedarticle-comment';
2196 $logAction =
'protect';
2199 $logRelationsValues = [];
2200 $logRelationsField =
null;
2201 $logParamsDetails = [];
2204 $nullRevision =
null;
2210 if ( !
Hooks::run(
'ArticleProtect', [ &$wikiPage, &
$user, $limit, $reason ] ) ) {
2215 $editrestriction = isset( $limit[
'edit'] )
2216 ? [ $limit[
'edit'] ]
2217 : $this->mTitle->getRestrictions(
'edit' );
2218 foreach ( array_keys( $editrestriction,
'sysop' )
as $key ) {
2219 $editrestriction[$key] =
'editprotected';
2221 foreach ( array_keys( $editrestriction,
'autoconfirmed' )
as $key ) {
2222 $editrestriction[$key] =
'editsemiprotected';
2226 foreach ( array_keys( $cascadingRestrictionLevels,
'sysop' )
as $key ) {
2227 $cascadingRestrictionLevels[$key] =
'editprotected';
2229 foreach ( array_keys( $cascadingRestrictionLevels,
'autoconfirmed' )
as $key ) {
2230 $cascadingRestrictionLevels[$key] =
'editsemiprotected';
2234 if ( !array_intersect( $editrestriction, $cascadingRestrictionLevels ) ) {
2249 if ( $nullRevision ===
null ) {
2250 return Status::newFatal(
'no-null-revision', $this->mTitle->getPrefixedText() );
2253 $logRelationsField =
'pr_id';
2256 foreach ( $limit
as $action => $restrictions ) {
2258 'page_restrictions',
2261 'pr_type' => $action
2265 if ( $restrictions !=
'' ) {
2266 $cascadeValue = ( $cascade && $action ==
'edit' ) ? 1 : 0;
2268 'page_restrictions',
2271 'pr_type' => $action,
2272 'pr_level' => $restrictions,
2273 'pr_cascade' => $cascadeValue,
2274 'pr_expiry' => $dbw->encodeExpiry( $expiry[$action] )
2278 $logRelationsValues[] = $dbw->insertId();
2279 $logParamsDetails[] = [
2281 'level' => $restrictions,
2282 'expiry' => $expiry[$action],
2283 'cascade' => (bool)$cascadeValue,
2291 [
'page_restrictions' =>
'' ],
2292 [
'page_id' => $id ],
2300 [ $this, $nullRevision, $latest,
$user ] );
2301 Hooks::run(
'ArticleProtectComplete', [ &$wikiPage, &
$user, $limit, $reason ] );
2306 if ( $limit[
'create'] !=
'' ) {
2308 $dbw->replace(
'protected_titles',
2309 [ [
'pt_namespace',
'pt_title' ] ],
2311 'pt_namespace' => $this->mTitle->getNamespace(),
2312 'pt_title' => $this->mTitle->getDBkey(),
2313 'pt_create_perm' => $limit[
'create'],
2314 'pt_timestamp' => $dbw->timestamp(),
2315 'pt_expiry' => $dbw->encodeExpiry( $expiry[
'create'] ),
2316 'pt_user' =>
$user->getId(),
2317 ] + $commentFields, __METHOD__
2319 $logParamsDetails[] = [
2321 'level' => $limit[
'create'],
2322 'expiry' => $expiry[
'create'],
2325 $dbw->delete(
'protected_titles',
2327 'pt_namespace' => $this->mTitle->getNamespace(),
2328 'pt_title' => $this->mTitle->getDBkey()
2334 $this->mTitle->flushRestrictions();
2337 if ( $logAction ==
'unprotect' ) {
2342 '4::description' => $protectDescriptionLog,
2343 '5:bool:cascade' => $cascade,
2344 'details' => $logParamsDetails,
2350 $logEntry->setTarget( $this->mTitle );
2351 $logEntry->setComment( $reason );
2352 $logEntry->setPerformer(
$user );
2353 $logEntry->setParameters(
$params );
2354 if ( !is_null( $nullRevision ) ) {
2355 $logEntry->setAssociatedRevId( $nullRevision->getId() );
2357 $logEntry->setTags( $tags );
2358 if ( $logRelationsField !==
null &&
count( $logRelationsValues ) ) {
2359 $logEntry->setRelations( [ $logRelationsField => $logRelationsValues ] );
2361 $logId = $logEntry->insert();
2362 $logEntry->publish( $logId );
2379 array $expiry, $cascade, $reason,
$user =
null
2386 $this->mTitle->getPrefixedText(),
2388 )->inContentLanguage()->text();
2390 $editComment .=
wfMessage(
'colon-separator' )->inContentLanguage()->text() . $reason;
2393 if ( $protectDescription ) {
2394 $editComment .=
wfMessage(
'word-separator' )->inContentLanguage()->text();
2395 $editComment .=
wfMessage(
'parentheses' )->params( $protectDescription )
2396 ->inContentLanguage()->text();
2399 $editComment .=
wfMessage(
'word-separator' )->inContentLanguage()->text();
2400 $editComment .=
wfMessage(
'brackets' )->params(
2401 wfMessage(
'protect-summary-cascade' )->inContentLanguage()->
text()
2402 )->inContentLanguage()->text();
2407 $nullRev->insertOn( $dbw );
2410 $oldLatest = $nullRev->getParentId();
2422 if ( $expiry !=
'infinity' ) {
2423 $contLang = MediaWikiServices::getInstance()->getContentLanguage();
2426 $contLang->timeanddate( $expiry,
false,
false ),
2427 $contLang->date( $expiry,
false,
false ),
2428 $contLang->time( $expiry,
false,
false )
2429 )->inContentLanguage()->text();
2431 return wfMessage(
'protect-expiry-indefinite' )
2432 ->inContentLanguage()->text();
2444 $protectDescription =
'';
2446 foreach ( array_filter( $limit )
as $action => $restrictions ) {
2447 # $action is one of $wgRestrictionTypes = [ 'create', 'edit', 'move', 'upload' ].
2448 # All possible message keys are listed here for easier grepping:
2449 # * restriction-create
2450 # * restriction-edit
2451 # * restriction-move
2452 # * restriction-upload
2453 $actionText =
wfMessage(
'restriction-' . $action )->inContentLanguage()->text();
2454 # $restrictions is one of $wgRestrictionLevels = [ '', 'autoconfirmed', 'sysop' ],
2455 # with '' filtered out. All possible message keys are listed below:
2456 # * protect-level-autoconfirmed
2457 # * protect-level-sysop
2458 $restrictionsText =
wfMessage(
'protect-level-' . $restrictions )
2459 ->inContentLanguage()->text();
2463 if ( $protectDescription !==
'' ) {
2464 $protectDescription .=
wfMessage(
'word-separator' )->inContentLanguage()->text();
2466 $protectDescription .=
wfMessage(
'protect-summary-desc' )
2467 ->params( $actionText, $restrictionsText, $expiryText )
2468 ->inContentLanguage()->text();
2471 return $protectDescription;
2486 $protectDescriptionLog =
'';
2488 $dirMark = MediaWikiServices::getInstance()->getContentLanguage()->getDirMark();
2489 foreach ( array_filter( $limit )
as $action => $restrictions ) {
2491 $protectDescriptionLog .=
2493 "[$action=$restrictions] ($expiryText)";
2496 return trim( $protectDescriptionLog );
2509 if ( !is_array( $limit ) ) {
2510 throw new MWException( __METHOD__ .
' given non-array restriction set' );
2516 foreach ( array_filter( $limit )
as $action => $restrictions ) {
2517 $bits[] =
"$action=$restrictions";
2520 return implode(
':', $bits );
2540 $revCount += $safetyMargin;
2565 $reason, $suppress =
false, $u1 =
null, $u2 =
null, &$error =
'',
User $user =
null,
2569 [],
'delete', $immediate );
2598 $reason, $suppress =
false, $u1 =
null, $u2 =
null, &$error =
'',
User $deleter =
null,
2599 $tags = [], $logsubtype =
'delete', $immediate =
false
2610 $deleter = is_null( $deleter ) ? $wgUser : $deleter;
2612 [ &$wikiPage, &$deleter, &$reason, &$error, &
$status, $suppress ]
2616 $status->fatal(
'delete-hook-aborted' );
2622 $logsubtype, $immediate );
2634 $reason, $suppress,
User $deleter, $tags,
2635 $logsubtype, $immediate =
false, $webRequestId =
null
2642 $dbw->startAtomic( __METHOD__ );
2645 $id = $this->
getId();
2651 if ( $id == 0 || $this->
getLatest() != $lockedLatest ) {
2652 $dbw->endAtomic( __METHOD__ );
2654 $status->error(
'cannotdelete',
2668 }
catch ( Exception $ex ) {
2669 wfLogWarning( __METHOD__ .
': failed to load content during deletion! '
2670 . $ex->getMessage() );
2677 $explictTrxLogged =
false;
2680 if ( $done || !$immediate ) {
2683 $dbw->endAtomic( __METHOD__ );
2684 if ( $dbw->explicitTrxActive() ) {
2686 if ( !$explictTrxLogged ) {
2687 $explictTrxLogged =
true;
2688 LoggerFactory::getInstance(
'wfDebug' )->debug(
2689 'explicit transaction active in ' . __METHOD__ .
' while deleting {title}', [
2690 'title' => $this->
getTitle()->getText(),
2695 if ( $dbw->trxLevel() ) {
2698 $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
2699 $lbFactory->waitForReplication();
2700 $dbw->startAtomic( __METHOD__ );
2705 $dbw->endAtomic( __METHOD__ );
2708 'wikiPageId' => $id,
2710 'reason' => $reason,
2711 'suppress' => $suppress,
2712 'userId' => $deleter->
getId(),
2713 'tags' => json_encode( $tags ),
2714 'logsubtype' => $logsubtype,
2720 $status->warning(
'delete-scheduled',
2730 $archivedRevisionCount = $dbw->selectField(
2731 'archive',
'COUNT(*)',
2733 'ar_namespace' => $this->
getTitle()->getNamespace(),
2734 'ar_title' => $this->
getTitle()->getDBkey(),
2742 $wikiPageBeforeDelete = clone $this;
2745 $dbw->delete(
'page', [
'page_id' => $id ], __METHOD__ );
2748 $logtype = $suppress ?
'suppress' :
'delete';
2751 $logEntry->setPerformer( $deleter );
2752 $logEntry->setTarget( $logTitle );
2753 $logEntry->setComment( $reason );
2754 $logEntry->setTags( $tags );
2755 $logid = $logEntry->insert();
2757 $dbw->onTransactionPreCommitOrIdle(
2758 function ()
use ( $logEntry, $logid ) {
2760 $logEntry->publish( $logid );
2765 $dbw->endAtomic( __METHOD__ );
2770 &$wikiPageBeforeDelete,
2776 $archivedRevisionCount
2781 $cache = MediaWikiServices::getInstance()->getMainObjectStash();
2782 $key =
$cache->makeKey(
'page-recent-delete', md5( $logTitle->getPrefixedText() ) );
2783 $cache->set( $key, 1, $cache::TTL_DAY );
2804 $namespace = $this->
getTitle()->getNamespace();
2805 $dbKey = $this->
getTitle()->getDBkey();
2830 $dbw->lockForUpdate(
2833 [
'revision',
'revision_comment_temp',
'revision_actor_temp' ]
2835 [
'rev_page' => $id ],
2848 $revQuery[
'fields'][] =
'rev_content_model';
2849 $revQuery[
'fields'][] =
'rev_content_format';
2855 $res = $dbw->select(
2858 [
'rev_page' => $id ],
2872 foreach (
$res as $row ) {
2878 $comment = $commentStore->getComment(
'rev_comment', $row );
2881 'ar_namespace' => $namespace,
2882 'ar_title' => $dbKey,
2883 'ar_timestamp' => $row->rev_timestamp,
2884 'ar_minor_edit' => $row->rev_minor_edit,
2885 'ar_rev_id' => $row->rev_id,
2886 'ar_parent_id' => $row->rev_parent_id,
2895 'ar_len' => $row->rev_len,
2896 'ar_page_id' => $id,
2897 'ar_deleted' => $suppress ? $bitfield : $row->rev_deleted,
2898 'ar_sha1' => $row->rev_sha1,
2899 ] + $commentStore->insert( $dbw,
'ar_comment', $comment )
2900 + $actorMigration->getInsertValues( $dbw,
'ar_user',
$user );
2903 $rowInsert[
'ar_text_id'] = $row->rev_text_id;
2906 $rowInsert[
'ar_content_model'] = $row->rev_content_model;
2907 $rowInsert[
'ar_content_format'] = $row->rev_content_format;
2911 $rowsInsert[] = $rowInsert;
2912 $revids[] = $row->rev_id;
2916 if ( (
int)$row->rev_user === 0 &&
IP::isValid( $row->rev_user_text ) ) {
2917 $ipRevIds[] = $row->rev_id;
2922 if (
count( $revids ) > 0 ) {
2924 $dbw->insert(
'archive', $rowsInsert, __METHOD__ );
2926 $dbw->delete(
'revision', [
'rev_id' => $revids ], __METHOD__ );
2928 $dbw->delete(
'revision_comment_temp', [
'revcomment_rev' => $revids ], __METHOD__ );
2931 $dbw->delete(
'revision_actor_temp', [
'revactor_rev' => $revids ], __METHOD__ );
2935 if (
count( $ipRevIds ) > 0 ) {
2936 $dbw->delete(
'ip_changes', [
'ipc_rev_id' => $ipRevIds ], __METHOD__ );
2954 'page_id' => $this->
getId(),
2957 'page_namespace' => $this->
getTitle()->getNamespace(),
2958 'page_title' => $this->
getTitle()->getDBkey()
2980 if ( $id !== $this->
getId() ) {
2981 throw new InvalidArgumentException(
'Mismatching page ID' );
2986 }
catch ( Exception $ex ) {
2994 [
'edits' => 1,
'articles' => -$countable,
'pages' => -1 ]
2999 $revision ? $revision->getRevisionRecord() :
$content
3001 foreach ( $updates
as $update ) {
3005 $causeAgent =
$user ?
$user->getName() :
'unknown';
3008 $this->mTitle,
'templatelinks',
'delete-page', $causeAgent );
3010 if ( $this->mTitle->getNamespace() ==
NS_FILE ) {
3012 $this->mTitle,
'imagelinks',
'delete-page', $causeAgent );
3018 $this->mTitle, $revision,
null,
wfWikiID()
3058 $fromP, $summary, $token, $bot, &$resultDetails,
User $user, $tags =
null
3060 $resultDetails =
null;
3063 $editErrors = $this->mTitle->getUserPermissionsErrors(
'edit',
$user );
3064 $rollbackErrors = $this->mTitle->getUserPermissionsErrors(
'rollback',
$user );
3065 $errors = array_merge( $editErrors,
wfArrayDiff2( $rollbackErrors, $editErrors ) );
3067 if ( !
$user->matchEditToken( $token,
'rollback' ) ) {
3068 $errors[] = [
'sessionfailure' ];
3071 if (
$user->pingLimiter(
'rollback' ) ||
$user->pingLimiter() ) {
3072 $errors[] = [
'actionthrottledtext' ];
3076 if ( !empty( $errors ) ) {
3104 &$resultDetails,
User $guser, $tags =
null
3111 return [ [
'readonlytext' ] ];
3117 $current =
$updater->grabParentRevision();
3119 if ( is_null( $current ) ) {
3121 return [ [
'notanarticle' ] ];
3124 $currentEditorForPublic = $current->getUser( RevisionRecord::FOR_PUBLIC );
3125 $legacyCurrent =
new Revision( $current );
3126 $from = str_replace(
'_',
' ', $fromP );
3130 if ( $from !== ( $currentEditorForPublic ? $currentEditorForPublic->getName() :
'' ) ) {
3131 $resultDetails = [
'current' => $legacyCurrent ];
3132 return [ [
'alreadyrolled',
3133 htmlspecialchars( $this->mTitle->getPrefixedText() ),
3134 htmlspecialchars( $fromP ),
3135 htmlspecialchars( $currentEditorForPublic ? $currentEditorForPublic->getName() :
'' )
3144 $current->getUser( RevisionRecord::RAW )
3147 $s = $dbw->selectRow(
3148 [
'revision' ] + $actorWhere[
'tables'],
3149 [
'rev_id',
'rev_timestamp',
'rev_deleted' ],
3151 'rev_page' => $current->getPageId(),
3152 'NOT(' . $actorWhere[
'conds'] .
')',
3156 'USE INDEX' => [
'revision' =>
'page_timestamp' ],
3157 'ORDER BY' =>
'rev_timestamp DESC'
3159 $actorWhere[
'joins']
3161 if (
$s ===
false ) {
3163 return [ [
'cantrollback' ] ];
3164 } elseif (
$s->rev_deleted & RevisionRecord::DELETED_TEXT
3165 ||
$s->rev_deleted & RevisionRecord::DELETED_USER
3168 return [ [
'notvisiblerev' ] ];
3174 RevisionStore::READ_LATEST
3176 if ( empty( $summary ) ) {
3177 if ( !$currentEditorForPublic ) {
3178 $summary =
wfMessage(
'revertpage-nouser' );
3183 $legacyTarget =
new Revision( $target );
3184 $targetEditorForPublic = $target->getUser( RevisionRecord::FOR_PUBLIC );
3187 $contLang = MediaWikiServices::getInstance()->getContentLanguage();
3189 $targetEditorForPublic ? $targetEditorForPublic->getName() :
null,
3190 $currentEditorForPublic ? $currentEditorForPublic->getName() :
null,
3192 $contLang->timeanddate(
wfTimestamp( TS_MW,
$s->rev_timestamp ) ),
3194 $contLang->timeanddate( $current->getTimestamp() )
3196 if ( $summary instanceof Message ) {
3197 $summary = $summary->params(
$args )->inContentLanguage()->text();
3203 $summary = trim( $summary );
3208 if ( $guser->
isAllowed(
'minoredit' ) ) {
3212 if ( $bot && ( $guser->
isAllowedAny(
'markbotedits',
'bot' ) ) ) {
3217 $currentContent = $current->getContent( SlotRecord::MAIN );
3218 $targetContent = $target->getContent( SlotRecord::MAIN );
3219 $changingContentModel = $targetContent->getModel() !== $currentContent->getModel();
3222 $tags[] =
'mw-rollback';
3228 foreach ( $target->getSlots()->getSlots()
as $slot ) {
3234 foreach ( $current->getSlotRoles()
as $role ) {
3235 if ( !$target->hasSlot( $role ) ) {
3240 $updater->setOriginalRevisionId( $target->getId() );
3260 if ( $bot && $guser->
isAllowed(
'markbotedits' ) ) {
3270 if (
count( $set ) ) {
3274 $current->getUser( RevisionRecord::RAW ),
3277 $dbw->update(
'recentchanges', $set,
3279 'rc_cur_id' => $current->getPageId(),
3280 'rc_timestamp > ' . $dbw->addQuotes(
$s->rev_timestamp ),
3281 $actorWhere[
'conds'],
3287 if ( !
$updater->wasSuccessful() ) {
3288 return $updater->getStatus()->getErrorsArray();
3293 $resultDetails = [
'current' => $legacyCurrent ];
3294 return [ [
'alreadyrolled',
3295 htmlspecialchars( $this->mTitle->getPrefixedText() ),
3296 htmlspecialchars( $fromP ),
3297 htmlspecialchars( $targetEditorForPublic ? $targetEditorForPublic->getName() :
'' )
3301 if ( $changingContentModel ) {
3305 $log->setPerformer( $guser );
3306 $log->setTarget( $this->mTitle );
3307 $log->setComment( $summary );
3308 $log->setParameters( [
3309 '4::oldmodel' => $currentContent->getModel(),
3310 '5::newmodel' => $targetContent->getModel(),
3313 $logId = $log->insert( $dbw );
3314 $log->publish( $logId );
3317 $revId =
$rev->getId();
3319 Hooks::run(
'ArticleRollbackComplete', [ $this, $guser, $legacyTarget, $legacyCurrent ] );
3322 'summary' => $summary,
3323 'current' => $legacyCurrent,
3324 'target' => $legacyTarget,
3348 $other =
$title->getOtherPage();
3350 $other->purgeSquid();
3354 $title->deleteTitleProtection();
3356 MediaWikiServices::getInstance()->getLinkCache()->invalidateTitle(
$title );
3383 $other =
$title->getOtherPage();
3385 $other->purgeSquid();
3390 MediaWikiServices::getInstance()->getLinkCache()->invalidateTitle(
$title );
3412 $user->setNewtalk(
false );
3434 $slotsChanged =
null
3438 if ( $slotsChanged ===
null || in_array( SlotRecord::MAIN, $slotsChanged ) ) {
3452 MediaWikiServices::getInstance()->getLinkCache()->invalidateTitle(
$title );
3460 $revid = $revision ? $revision->getId() :
null;
3484 $cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
3501 $id = $this->
getId();
3507 $res =
$dbr->select(
'categorylinks',
3508 [
'cl_to AS page_title, ' .
NS_CATEGORY .
' AS page_namespace' ],
3511 [
'cl_from' => $id ],
3525 $id = $this->
getId();
3532 $res =
$dbr->select( [
'categorylinks',
'page_props',
'page' ],
3534 [
'cl_from' => $id,
'pp_page=page_id',
'pp_propname' =>
'hiddencat',
3535 'page_namespace' =>
NS_CATEGORY,
'page_title=cl_to' ],
3538 if (
$res !==
false ) {
3539 foreach (
$res as $row ) {
3569 $id = $id ?: $this->
getId();
3572 $addFields = [
'cat_pages = cat_pages + 1' ];
3573 $removeFields = [
'cat_pages = cat_pages - 1' ];
3574 if (
$type !==
'page' ) {
3575 $addFields[] =
"cat_{$type}s = cat_{$type}s + 1";
3576 $removeFields[] =
"cat_{$type}s = cat_{$type}s - 1";
3581 if (
count( $added ) ) {
3582 $existingAdded = $dbw->selectFieldValues(
3585 [
'cat_title' => $added ],
3592 if (
count( $existingAdded ) ) {
3596 [
'cat_title' => $existingAdded ],
3601 $missingAdded = array_diff( $added, $existingAdded );
3602 if (
count( $missingAdded ) ) {
3604 foreach ( $missingAdded
as $cat ) {
3606 'cat_title' => $cat,
3608 'cat_subcats' => (
$type ===
'subcat' ) ? 1 : 0,
3609 'cat_files' => (
$type ===
'file' ) ? 1 : 0,
3622 if (
count( $deleted ) ) {
3626 [
'cat_title' => $deleted ],
3631 foreach ( $added
as $catName ) {
3633 Hooks::run(
'CategoryAfterPageAdded', [ $cat, $this ] );
3636 foreach ( $deleted
as $catName ) {
3638 Hooks::run(
'CategoryAfterPageRemoved', [ $cat, $this, $id ] );
3641 $cat->refreshCountsIfEmpty();
3657 if ( !
Hooks::run(
'OpportunisticLinksUpdate',
3658 [ $this, $this->mTitle, $parserOutput ]
3666 'isOpportunistic' =>
true,
3670 if ( $this->mTitle->areRestrictionsCascading() ) {
3675 } elseif ( !$config->get(
'MiserMode' ) && $parserOutput->
hasDynamicContent() ) {
3686 $key =
$cache->makeKey(
'dynamic-linksupdate',
'last', $this->
getId() );
3688 if (
$cache->add( $key, time(), $ttl ) ) {
3708 wfDeprecated( __METHOD__ .
' without a RevisionRecord',
'1.32' );
3712 }
catch ( Exception $ex ) {
3717 wfDebug( __METHOD__ .
' failed to load current revision of page ' . $this->
getId() );
3724 wfDeprecated( __METHOD__ .
' with a Content object instead of a RevisionRecord',
'1.32' );
3726 $slotContent = [ SlotRecord::MAIN =>
$rev ];
3728 $slotContent = array_map(
function (
SlotRecord $slot ) {
3730 },
$rev->getSlots()->getSlots() );
3739 foreach ( $slotContent
as $role =>
$content ) {
3742 $updates =
$handler->getDeletionUpdates(
3746 $allUpdates = array_merge( $allUpdates, $updates );
3749 $legacyUpdates =
$content->getDeletionUpdates( $this );
3752 $legacyUpdates = array_filter( $legacyUpdates,
function ( $update ) {
3756 $allUpdates = array_merge( $allUpdates, $legacyUpdates );
3800 return $this->
getTitle()->getCanonicalURL();
3809 $linkCache = MediaWikiServices::getInstance()->getLinkCache();
3811 return $linkCache->getMutableCacheKeys(
$cache, $this->
getTitle() );