121 $ns =
$title->getNamespace();
124 throw new MWException(
"NS_MEDIA is a virtual namespace; use NS_FILE." );
125 } elseif ( $ns < 0 ) {
126 throw new MWException(
"Invalid or virtual namespace $ns given." );
158 public static function newFromID( $id, $from =
'fromdb' ) {
166 $row = $db->selectRow(
167 'page', self::selectFields(), [
'page_id' => $id ], __METHOD__ );
185 public static function newFromRow( $row, $from =
'fromdb' ) {
187 $page->loadFromRow( $row, $from );
200 return self::READ_NORMAL;
202 return self::READ_LATEST;
246 $this->mDataLoaded =
false;
258 $this->mRedirectTarget =
null;
259 $this->mLastRevision =
null;
260 $this->mTouched =
'19700101000000';
261 $this->mLinksUpdated =
'19700101000000';
262 $this->mTimestamp =
'';
263 $this->mIsRedirect =
false;
264 $this->mLatest =
false;
277 $this->mPreparedEdit =
false;
287 global $wgContentHandlerUseDB, $wgPageLanguageUseDB;
298 'page_links_updated',
303 if ( $wgContentHandlerUseDB ) {
304 $fields[] =
'page_content_model';
307 if ( $wgPageLanguageUseDB ) {
308 $fields[] =
'page_lang';
327 Hooks::run(
'ArticlePageDataBefore', [ &$wikiPage, &$fields ] );
329 $row =
$dbr->selectRow(
'page', $fields, $conditions, __METHOD__,
$options );
331 Hooks::run(
'ArticlePageDataAfter', [ &$wikiPage, &$row ] );
347 'page_namespace' =>
$title->getNamespace(),
377 if ( is_int( $from ) && $from <= $this->mDataLoadedFrom ) {
382 if ( is_int( $from ) ) {
388 &&
wfGetLB()->getServerCount() > 1
389 &&
wfGetLB()->hasOrMadeRecentMasterChanges()
391 $from = self::READ_LATEST;
398 $from = self::READ_NORMAL;
417 $lc->clearLink( $this->mTitle );
420 $lc->addGoodLinkObjFromRow( $this->mTitle, $data );
422 $this->mTitle->loadFromRow( $data );
425 $this->mTitle->loadRestrictions( $data->page_restrictions );
427 $this->mId = intval( $data->page_id );
428 $this->mTouched =
wfTimestamp( TS_MW, $data->page_touched );
430 $this->mIsRedirect = intval( $data->page_is_redirect );
431 $this->mLatest = intval( $data->page_latest );
434 if ( $this->mLastRevision && $this->mLastRevision->getId() !=
$this->mLatest ) {
435 $this->mLastRevision =
null;
436 $this->mTimestamp =
'';
439 $lc->addBadLinkObj( $this->mTitle );
441 $this->mTitle->loadFromRow(
false );
448 $this->mDataLoaded =
true;
456 if ( !$this->mDataLoaded ) {
466 if ( !$this->mDataLoaded ) {
469 return $this->mId > 0;
481 return $this->mTitle->isKnown();
490 if ( !$this->mDataLoaded ) {
511 return $cache->getWithSetCallback(
512 $cache->makeKey(
'page',
'content-model', $this->getLatest() ),
518 return $rev->getContentModel();
520 $title = $this->mTitle->getPrefixedDBkey();
521 wfWarn(
"Page $title exists but has no (visible) revisions!" );
522 return $this->mTitle->getContentModel();
529 return $this->mTitle->getContentModel();
537 if ( !$this->mDataLoaded ) {
540 return ( $this->mId && !$this->mIsRedirect );
548 if ( !$this->mDataLoaded ) {
559 if ( !$this->mDataLoaded ) {
570 if ( !$this->mDataLoaded ) {
582 $rev = $this->mTitle->getFirstRevision();
594 if ( $this->mLastRevision !==
null ) {
603 if ( $this->mDataLoadedFrom == self::READ_LOCKING ) {
613 } elseif ( $this->mDataLoadedFrom == self::READ_LATEST ) {
617 $flags = Revision::READ_LATEST;
634 $this->mLastRevision = $revision;
644 if ( $this->mLastRevision ) {
665 if ( $this->mLastRevision ) {
666 return $this->mLastRevision->getContent( $audience,
$user );
676 if ( !$this->mTimestamp ) {
703 if ( $this->mLastRevision ) {
704 return $this->mLastRevision->getUser( $audience,
$user );
723 $userName = $revision->getUserText( $audience,
$user );
741 if ( $this->mLastRevision ) {
742 return $this->mLastRevision->getUserText( $audience,
$user );
759 if ( $this->mLastRevision ) {
760 return $this->mLastRevision->getComment( $audience,
$user );
773 if ( $this->mLastRevision ) {
774 return $this->mLastRevision->isMinor();
789 global $wgArticleCountMethod;
791 if ( !$this->mTitle->isContentPage() ) {
807 if ( $wgArticleCountMethod ===
'link' ) {
815 $hasLinks = (bool)
count( $editInfo->output->getLinks() );
818 [
'pl_from' => $this->
getId() ], __METHOD__ );
822 return $content->isCountable( $hasLinks );
833 if ( !$this->mTitle->isRedirect() ) {
837 if ( $this->mRedirectTarget !==
null ) {
843 $row =
$dbr->selectRow(
'redirect',
844 [
'rd_namespace',
'rd_title',
'rd_fragment',
'rd_interwiki' ],
845 [
'rd_from' => $this->
getId() ],
850 if ( $row && !is_null( $row->rd_fragment ) && !is_null( $row->rd_interwiki ) ) {
852 $row->rd_namespace, $row->rd_title,
853 $row->rd_fragment, $row->rd_interwiki
883 $that->insertRedirectEntry(
$retval, $latest );
899 $dbw->startAtomic( __METHOD__ );
905 'rd_from' => $this->
getId(),
922 $dbw->endAtomic( __METHOD__ );
946 if ( $rt->isExternal() ) {
947 if ( $rt->isLocal() ) {
951 $source = $this->mTitle->getFullURL(
'redirect=no' );
952 return $rt->getFullURL( [
'rdfrom' =>
$source ] );
960 if ( $rt->isSpecialPage() ) {
964 if ( $rt->isValidRedirectTarget() ) {
965 return $rt->getFullURL();
984 if (
$dbr->implicitGroupby() ) {
985 $realNameField =
'user_real_name';
987 $realNameField =
'MIN(user_real_name) AS user_real_name';
990 $tables = [
'revision',
'user' ];
993 'user_id' =>
'rev_user',
994 'user_name' =>
'rev_user_text',
996 'timestamp' =>
'MAX(rev_timestamp)',
999 $conds = [
'rev_page' => $this->
getId() ];
1005 $conds[] =
"rev_user != $user";
1007 $conds[] =
"rev_user_text != {$dbr->addQuotes( $this->getUserText() )}";
1011 $conds[] =
"{$dbr->bitAnd( 'rev_deleted', Revision::DELETED_USER )} = 0";
1014 'user' => [
'LEFT JOIN',
'rev_user = user_id' ],
1018 'GROUP BY' => [
'rev_user',
'rev_user_text' ],
1019 'ORDER BY' =>
'timestamp DESC',
1036 && ( $oldId ===
null || $oldId === 0 || $oldId === $this->
getLatest() )
1054 ParserOptions $parserOptions, $oldid =
null, $forceParse =
false
1059 ': using parser cache: ' . ( $useParserCache ?
'yes' :
'no' ) .
"\n" );
1064 if ( $useParserCache ) {
1071 if ( $oldid ===
null || $oldid === 0 ) {
1078 return $pool->getParserOutput();
1094 $user->clearNotification( $this->mTitle, $oldid );
1111 if ( !
Hooks::run(
'ArticlePurge', [ &$wikiPage ] ) ) {
1115 $this->mTitle->invalidateCache();
1127 $messageCache->updateMessageOverride( $this->mTitle, $this->
getContent() );
1160 $pageIdForInsert = $pageId ?: $dbw->nextSequenceValue(
'page_page_id_seq' );
1164 'page_id' => $pageIdForInsert,
1165 'page_namespace' => $this->mTitle->getNamespace(),
1166 'page_title' => $this->mTitle->getDBkey(),
1167 'page_restrictions' =>
'',
1168 'page_is_redirect' => 0,
1171 'page_touched' => $dbw->timestamp(),
1179 if ( $dbw->affectedRows() > 0 ) {
1180 $newid = $pageId ?: $dbw->insertId();
1181 $this->mId = $newid;
1182 $this->mTitle->resetArticleID( $newid );
1204 $lastRevIsRedirect =
null
1206 global $wgContentHandlerUseDB;
1209 if ( (
int)$revision->getId() === 0 ) {
1210 throw new InvalidArgumentException(
1211 __METHOD__ .
': Revision has ID ' . var_export( $revision->getId(), 1 )
1215 $content = $revision->getContent();
1219 $conditions = [
'page_id' => $this->
getId() ];
1221 if ( !is_null( $lastRevision ) ) {
1223 $conditions[
'page_latest'] = $lastRevision;
1227 'page_latest' => $revision->getId(),
1228 'page_touched' => $dbw->timestamp( $revision->getTimestamp() ),
1229 'page_is_new' => ( $lastRevision === 0 ) ? 1 : 0,
1230 'page_is_redirect' => $rt !==
null ? 1 : 0,
1234 if ( $wgContentHandlerUseDB ) {
1235 $row[
'page_content_model'] = $revision->getContentModel();
1238 $dbw->update(
'page',
1243 $result = $dbw->affectedRows() > 0;
1247 $this->mLatest = $revision->getId();
1248 $this->mIsRedirect = (bool)$rt;
1256 $revision->getContentModel()
1278 $isRedirect = !is_null( $redirectTitle );
1280 if ( !$isRedirect && $lastRevIsRedirect ===
false ) {
1284 if ( $isRedirect ) {
1288 $where = [
'rd_from' => $this->
getId() ];
1289 $dbw->delete(
'redirect', $where, __METHOD__ );
1296 return ( $dbw->affectedRows() != 0 );
1311 $row = $dbw->selectRow(
1312 [
'revision',
'page' ],
1313 [
'rev_id',
'rev_timestamp',
'page_is_redirect' ],
1315 'page_id' => $this->
getId(),
1316 'page_latest=rev_id' ],
1320 if (
wfTimestamp( TS_MW, $row->rev_timestamp ) >= $revision->getTimestamp() ) {
1323 $prev = $row->rev_id;
1324 $lastRevIsRedirect = (bool)$row->page_is_redirect;
1328 $lastRevIsRedirect =
null;
1384 if ( $edittime && $sectionId !==
'new' ) {
1391 &&
wfGetLB()->getServerCount() > 1
1392 &&
wfGetLB()->hasOrMadeRecentMasterChanges()
1398 $baseRevId =
$rev->getId();
1419 $sectionTitle =
'', $baseRevId =
null
1422 if ( strval( $sectionId ) ===
'' ) {
1427 throw new MWException(
"sections not supported for content model " .
1432 if ( is_null( $baseRevId ) || $sectionId ===
'new' ) {
1437 wfDebug( __METHOD__ .
" asked for bogus section (page: " .
1438 $this->
getId() .
"; section: $sectionId)\n" );
1442 $oldContent =
$rev->getContent();
1445 if ( !$oldContent ) {
1446 wfDebug( __METHOD__ .
": no page text\n" );
1450 $newContent = $oldContent->replaceSection( $sectionId,
$sectionContent, $sectionTitle );
1533 User $user =
null, $serialFormat =
null, $tags = [], $undidRevId = 0
1538 if ( $tags ===
null ) {
1543 if ( $this->mTitle->getText() ===
'' ) {
1544 throw new MWException(
'Something is trying to edit an article with an empty title' );
1547 if ( !
$content->getContentHandler()->canBeUsedOn( $this->mTitle ) ) {
1550 $this->mTitle->getPrefixedText()
1570 if ( !
Hooks::run(
'PageContentSave', $hook_args ) ) {
1571 if ( $hookStatus->isOK() ) {
1573 $hookStatus->fatal(
'edit-hook-aborted' );
1582 if ( $old_content && $old_content->getModel() !==
$content->getModel() ) {
1583 $tags[] =
'mw-contentmodelchange';
1601 $pstContent = $editInfo->pstContent;
1605 'serialized' => $editInfo->pst,
1606 'serialFormat' => $serialFormat,
1607 'baseRevId' => $baseRevId,
1608 'oldRevision' => $old_revision,
1609 'oldContent' => $old_content,
1613 'tags' => ( $tags !== null ) ? (
array)$tags : [],
1614 'undidRevId' => $undidRevId
1626 $user->addAutopromoteOnceGroups(
'onEdit' );
1627 $user->addAutopromoteOnceGroups(
'onView' );
1655 $oldid = $meta[
'oldId'];
1657 $oldContent = $meta[
'oldContent'];
1662 $status->fatal(
'edit-gone-missing' );
1665 } elseif ( !$oldContent ) {
1667 throw new MWException(
"Could not find text for current revision {$oldid}." );
1672 'page' => $this->
getId(),
1673 'title' => $this->mTitle,
1674 'comment' => $summary,
1675 'minor_edit' => $meta[
'minor'],
1676 'text' => $meta[
'serialized'],
1678 'parent_id' => $oldid,
1679 'user' =>
$user->getId(),
1680 'user_text' =>
$user->getName(),
1681 'timestamp' => $now,
1682 'content_model' =>
$content->getModel(),
1683 'content_format' => $meta[
'serialFormat'],
1686 $changed = !
$content->equals( $oldContent );
1692 $status->merge( $prepStatus );
1697 $dbw->startAtomic( __METHOD__ );
1702 if ( $latestNow != $oldid ) {
1703 $dbw->endAtomic( __METHOD__ );
1705 $status->fatal(
'edit-conflict' );
1716 $revisionId = $revision->insertOn( $dbw );
1718 if ( !$this->
updateRevisionOn( $dbw, $revision,
null, $meta[
'oldIsRedirect'] ) ) {
1719 throw new MWException(
"Failed to update page row to use new revision." );
1723 [ $this, $revision, $meta[
'baseRevId'],
$user ] );
1728 $patrolled = $wgUseRCPatrol && !
count(
1729 $this->mTitle->getUserPermissionsErrors(
'autopatrol',
$user ) );
1734 $revision->isMinor(),
1741 $oldContent ? $oldContent->getSize() : 0,
1749 $user->incEditCount();
1751 $dbw->endAtomic( __METHOD__ );
1752 $this->mTimestamp = $now;
1757 $revision->setUserIdAndName(
1765 $status->value[
'revision'] = $revision;
1767 $status->warning(
'edit-no-change' );
1770 $this->mTitle->invalidateCache( $now );
1787 'changed' => $changed,
1788 'oldcountable' => $meta[
'oldCountable'],
1789 'oldrevision' => $meta[
'oldRevision']
1796 null,
null, &
$flags, $revision, &
$status, $meta[
'baseRevId'],
1797 $meta[
'undidRevId'] ];
1822 global $wgUseRCPatrol, $wgUseNPPatrol;
1829 $status->merge( $prepStatus );
1835 $dbw->startAtomic( __METHOD__ );
1839 if ( $newid ===
false ) {
1840 $dbw->endAtomic( __METHOD__ );
1841 $status->fatal(
'edit-already-exists' );
1854 'title' => $this->mTitle,
1855 'comment' => $summary,
1856 'minor_edit' => $meta[
'minor'],
1857 'text' => $meta[
'serialized'],
1859 'user' =>
$user->getId(),
1860 'user_text' =>
$user->getName(),
1861 'timestamp' => $now,
1862 'content_model' =>
$content->getModel(),
1863 'content_format' => $meta[
'serialFormat'],
1867 $revisionId = $revision->
insertOn( $dbw );
1870 throw new MWException(
"Failed to update page row to use new revision." );
1873 Hooks::run(
'NewRevisionFromEditComplete', [ $this, $revision,
false,
$user ] );
1878 $patrolled = ( $wgUseRCPatrol || $wgUseNPPatrol ) &&
1879 !
count( $this->mTitle->getUserPermissionsErrors(
'autopatrol',
$user ) );
1884 $revision->isMinor(),
1896 $user->incEditCount();
1898 $dbw->endAtomic( __METHOD__ );
1899 $this->mTimestamp = $now;
1902 $status->value[
'revision'] = $revision;
1948 if ( $this->
getTitle()->isConversionTable() ) {
1951 $options->disableContentConversion();
1974 $serialFormat =
null, $useCache =
true
1978 if ( is_object( $revision ) ) {
1979 $revid = $revision->getId();
1984 if ( $revid !==
null ) {
1995 if ( $serialFormat ===
null ) {
1996 $serialFormat =
$content->getContentHandler()->getDefaultFormat();
1999 if ( $this->mPreparedEdit
2000 && isset( $this->mPreparedEdit->newContent )
2001 && $this->mPreparedEdit->newContent->equals(
$content )
2002 && $this->mPreparedEdit->revid == $revid
2003 && $this->mPreparedEdit->format == $serialFormat
2011 $cachedEdit = $useCache && $wgAjaxEditStash
2016 Hooks::run(
'ArticlePrepareTextForEdit', [ $this, $popts ] );
2019 if ( $cachedEdit ) {
2020 $edit->timestamp = $cachedEdit->timestamp;
2025 $edit->revid = $revid;
2027 if ( $cachedEdit ) {
2028 $edit->pstContent = $cachedEdit->pstContent;
2031 ?
$content->preSaveTransform( $this->mTitle,
$user, $popts )
2035 $edit->format = $serialFormat;
2037 if ( $cachedEdit ) {
2038 $edit->output = $cachedEdit->output;
2045 $oldCallback = $edit->popts->getCurrentRevisionCallback();
2046 $edit->popts->setCurrentRevisionCallback(
2048 if (
$title->equals( $revision->getTitle() ) ) {
2057 $dbIndex = ( $this->mDataLoadedFrom & self::READ_LATEST ) === self::READ_LATEST
2061 $edit->popts->setSpeculativeRevIdCallback(
function ()
use ( $dbIndex ) {
2062 return 1 + (int)
wfGetDB( $dbIndex )->selectField(
2070 $edit->output = $edit->pstContent
2071 ? $edit->pstContent->getParserOutput( $this->mTitle, $revid, $edit->popts )
2079 $edit->newText = $edit->newContent
2082 $edit->oldText = $edit->oldContent
2085 $edit->pst = $edit->pstContent ? $edit->pstContent->serialize( $serialFormat ) :
'';
2087 if ( $edit->output ) {
2092 $this->mPreparedEdit = $edit;
2119 global $wgRCWatchCategoryMembership;
2125 'restored' =>
false,
2126 'oldrevision' =>
null,
2127 'oldcountable' => null
2131 $logger = LoggerFactory::getInstance(
'SaveParse' );
2135 if ( !$this->mPreparedEdit ) {
2136 $logger->debug( __METHOD__ .
": No prepared edit...\n" );
2137 } elseif ( $this->mPreparedEdit->output->getFlag(
'vary-revision' ) ) {
2138 $logger->info( __METHOD__ .
": Prepared edit has vary-revision...\n" );
2139 } elseif ( $this->mPreparedEdit->output->getFlag(
'vary-revision-id' )
2140 && $this->mPreparedEdit->output->getSpeculativeRevIdUsed() !== $revision->
getId()
2142 $logger->info( __METHOD__ .
": Prepared edit has vary-revision-id with wrong ID...\n" );
2143 } elseif ( $this->mPreparedEdit->output->getFlag(
'vary-user' ) && !
$options[
'changed'] ) {
2144 $logger->info( __METHOD__ .
": Prepared edit has vary-user and is null...\n" );
2146 wfDebug( __METHOD__ .
": Using prepared edit...\n" );
2160 $editInfo->output, $this, $editInfo->popts,
2167 $updates =
$content->getSecondaryDataUpdates(
2168 $this->
getTitle(),
null, $recursive, $editInfo->output
2170 foreach ( $updates
as $update ) {
2172 $update->setRevision( $revision );
2173 $update->setTriggeringUser(
$user );
2177 if ( $wgRCWatchCategoryMembership
2188 'pageId' => $this->
getId(),
2200 if (
Hooks::run(
'ArticleEditUpdatesDeleteFromRecentchanges', [ &$wikiPage ] ) ) {
2202 if ( mt_rand( 0, 9 ) == 0 ) {
2207 if ( !$this->
exists() ) {
2211 $id = $this->
getId();
2212 $title = $this->mTitle->getPrefixedDBkey();
2213 $shortTitle = $this->mTitle->getDBkey();
2215 if (
$options[
'oldcountable'] ===
'no-change' ||
2221 } elseif (
$options[
'oldcountable'] !==
null ) {
2226 $edits =
$options[
'changed'] ? 1 : 0;
2227 $total =
$options[
'created'] ? 1 : 0;
2237 && $shortTitle !=
$user->getTitleKey()
2238 && !( $revision->
isMinor() &&
$user->isAllowed(
'nominornewtalk' ) )
2241 if ( !$recipient ) {
2242 wfDebug( __METHOD__ .
": invalid username\n" );
2249 if (
Hooks::run(
'ArticleEditUpdateNewTalk', [ &$wikiPage, $recipient ] ) ) {
2252 $recipient->setNewtalk(
true, $revision );
2253 } elseif ( $recipient->isLoggedIn() ) {
2254 $recipient->setNewtalk(
true, $revision );
2256 wfDebug( __METHOD__ .
": don't need to notify a nonexistent user\n" );
2292 &$cascade, $reason,
User $user, $tags =
null
2301 $restrictionTypes = $this->mTitle->getRestrictionTypes();
2302 $id = $this->
getId();
2313 $isProtected =
false;
2319 foreach ( $restrictionTypes
as $action ) {
2320 if ( !isset( $expiry[$action] ) || $expiry[$action] === $dbw->getInfinity() ) {
2321 $expiry[$action] =
'infinity';
2323 if ( !isset(
$limit[$action] ) ) {
2325 } elseif (
$limit[$action] !=
'' ) {
2330 $current = implode(
'', $this->mTitle->getRestrictions( $action ) );
2331 if ( $current !=
'' ) {
2332 $isProtected =
true;
2335 if (
$limit[$action] != $current ) {
2337 } elseif (
$limit[$action] !=
'' ) {
2341 if ( $this->mTitle->getRestrictionExpiry( $action ) != $expiry[$action] ) {
2347 if ( !$changed && $protect && $this->mTitle->areRestrictionsCascading() != $cascade ) {
2357 $revCommentMsg =
'unprotectedarticle-comment';
2358 $logAction =
'unprotect';
2359 } elseif ( $isProtected ) {
2360 $revCommentMsg =
'modifiedarticleprotection-comment';
2361 $logAction =
'modify';
2363 $revCommentMsg =
'protectedarticle-comment';
2364 $logAction =
'protect';
2370 $logRelationsValues = [];
2371 $logRelationsField =
null;
2372 $logParamsDetails = [];
2375 $nullRevision =
null;
2386 $editrestriction = isset(
$limit[
'edit'] )
2388 : $this->mTitle->getRestrictions(
'edit' );
2389 foreach ( array_keys( $editrestriction,
'sysop' )
as $key ) {
2390 $editrestriction[$key] =
'editprotected';
2392 foreach ( array_keys( $editrestriction,
'autoconfirmed' )
as $key ) {
2393 $editrestriction[$key] =
'editsemiprotected';
2396 $cascadingRestrictionLevels = $wgCascadingRestrictionLevels;
2397 foreach ( array_keys( $cascadingRestrictionLevels,
'sysop' )
as $key ) {
2398 $cascadingRestrictionLevels[$key] =
'editprotected';
2400 foreach ( array_keys( $cascadingRestrictionLevels,
'autoconfirmed' )
as $key ) {
2401 $cascadingRestrictionLevels[$key] =
'editsemiprotected';
2405 if ( !array_intersect( $editrestriction, $cascadingRestrictionLevels ) ) {
2420 if ( $nullRevision ===
null ) {
2421 return Status::newFatal(
'no-null-revision', $this->mTitle->getPrefixedText() );
2424 $logRelationsField =
'pr_id';
2427 foreach (
$limit as $action => $restrictions ) {
2429 'page_restrictions',
2432 'pr_type' => $action
2436 if ( $restrictions !=
'' ) {
2437 $cascadeValue = ( $cascade && $action ==
'edit' ) ? 1 : 0;
2439 'page_restrictions',
2441 'pr_id' => $dbw->nextSequenceValue(
'page_restrictions_pr_id_seq' ),
2443 'pr_type' => $action,
2444 'pr_level' => $restrictions,
2445 'pr_cascade' => $cascadeValue,
2446 'pr_expiry' => $dbw->encodeExpiry( $expiry[$action] )
2450 $logRelationsValues[] = $dbw->insertId();
2451 $logParamsDetails[] = [
2453 'level' => $restrictions,
2454 'expiry' => $expiry[$action],
2455 'cascade' => (bool)$cascadeValue,
2463 [
'page_restrictions' =>
'' ],
2464 [
'page_id' => $id ],
2472 [ $this, $nullRevision, $latest,
$user ] );
2478 if (
$limit[
'create'] !=
'' ) {
2479 $dbw->replace(
'protected_titles',
2480 [ [
'pt_namespace',
'pt_title' ] ],
2482 'pt_namespace' => $this->mTitle->getNamespace(),
2483 'pt_title' => $this->mTitle->getDBkey(),
2484 'pt_create_perm' =>
$limit[
'create'],
2485 'pt_timestamp' => $dbw->timestamp(),
2486 'pt_expiry' => $dbw->encodeExpiry( $expiry[
'create'] ),
2487 'pt_user' =>
$user->getId(),
2488 'pt_reason' => $reason,
2491 $logParamsDetails[] = [
2493 'level' =>
$limit[
'create'],
2494 'expiry' => $expiry[
'create'],
2497 $dbw->delete(
'protected_titles',
2499 'pt_namespace' => $this->mTitle->getNamespace(),
2500 'pt_title' => $this->mTitle->getDBkey()
2506 $this->mTitle->flushRestrictions();
2509 if ( $logAction ==
'unprotect' ) {
2514 '4::description' => $protectDescriptionLog,
2515 '5:bool:cascade' => $cascade,
2516 'details' => $logParamsDetails,
2522 $logEntry->setTarget( $this->mTitle );
2523 $logEntry->setComment( $reason );
2524 $logEntry->setPerformer(
$user );
2525 $logEntry->setParameters(
$params );
2526 if ( !is_null( $nullRevision ) ) {
2527 $logEntry->setAssociatedRevId( $nullRevision->getId() );
2529 $logEntry->setTags( $tags );
2530 if ( $logRelationsField !==
null &&
count( $logRelationsValues ) ) {
2531 $logEntry->setRelations( [ $logRelationsField => $logRelationsValues ] );
2533 $logId = $logEntry->insert();
2534 $logEntry->publish( $logId );
2551 array $expiry, $cascade, $reason,
$user =
null
2558 $this->mTitle->getPrefixedText(),
2560 )->inContentLanguage()->text();
2562 $editComment .=
wfMessage(
'colon-separator' )->inContentLanguage()->text() . $reason;
2565 if ( $protectDescription ) {
2566 $editComment .=
wfMessage(
'word-separator' )->inContentLanguage()->text();
2567 $editComment .=
wfMessage(
'parentheses' )->params( $protectDescription )
2568 ->inContentLanguage()->text();
2571 $editComment .=
wfMessage(
'word-separator' )->inContentLanguage()->text();
2572 $editComment .=
wfMessage(
'brackets' )->params(
2573 wfMessage(
'protect-summary-cascade' )->inContentLanguage()->
text()
2574 )->inContentLanguage()->text();
2579 $nullRev->insertOn( $dbw );
2582 $oldLatest = $nullRev->getParentId();
2596 if ( $expiry !=
'infinity' ) {
2599 $wgContLang->timeanddate( $expiry,
false,
false ),
2602 )->inContentLanguage()->text();
2604 return wfMessage(
'protect-expiry-indefinite' )
2605 ->inContentLanguage()->text();
2617 $protectDescription =
'';
2619 foreach ( array_filter(
$limit )
as $action => $restrictions ) {
2620 # $action is one of $wgRestrictionTypes = [ 'create', 'edit', 'move', 'upload' ].
2621 # All possible message keys are listed here for easier grepping:
2622 # * restriction-create
2623 # * restriction-edit
2624 # * restriction-move
2625 # * restriction-upload
2626 $actionText =
wfMessage(
'restriction-' . $action )->inContentLanguage()->text();
2627 # $restrictions is one of $wgRestrictionLevels = [ '', 'autoconfirmed', 'sysop' ],
2628 # with '' filtered out. All possible message keys are listed below:
2629 # * protect-level-autoconfirmed
2630 # * protect-level-sysop
2631 $restrictionsText =
wfMessage(
'protect-level-' . $restrictions )
2632 ->inContentLanguage()->text();
2636 if ( $protectDescription !==
'' ) {
2637 $protectDescription .=
wfMessage(
'word-separator' )->inContentLanguage()->text();
2639 $protectDescription .=
wfMessage(
'protect-summary-desc' )
2640 ->params( $actionText, $restrictionsText, $expiryText )
2641 ->inContentLanguage()->text();
2644 return $protectDescription;
2661 $protectDescriptionLog =
'';
2663 foreach ( array_filter(
$limit )
as $action => $restrictions ) {
2665 $protectDescriptionLog .=
$wgContLang->getDirMark() .
2666 "[$action=$restrictions] ($expiryText)";
2669 return trim( $protectDescriptionLog );
2682 if ( !is_array(
$limit ) ) {
2683 throw new MWException( __METHOD__ .
' given non-array restriction set' );
2689 foreach ( array_filter(
$limit )
as $action => $restrictions ) {
2690 $bits[] =
"$action=$restrictions";
2693 return implode(
':', $bits );
2713 $reason, $suppress =
false, $u1 =
null, $u2 =
null, &$error =
'',
User $user =
null
2738 $reason, $suppress =
false, $u1 =
null, $u2 =
null, &$error =
'',
User $user =
null,
2739 $tags = [], $logsubtype =
'delete'
2747 if ( $this->mTitle->getDBkey() ===
'' ) {
2748 $status->error(
'cannotdelete',
2758 [ &$wikiPage, &
$user, &$reason, &$error, &
$status, $suppress ]
2762 $status->fatal(
'delete-hook-aborted' );
2768 $dbw->startAtomic( __METHOD__ );
2771 $id = $this->
getId();
2777 if ( $id == 0 || $this->
getLatest() != $lockedLatest ) {
2778 $dbw->endAtomic( __METHOD__ );
2780 $status->error(
'cannotdelete',
2786 $namespace = $this->
getTitle()->getNamespace();
2787 $dbKey = $this->
getTitle()->getDBkey();
2798 }
catch ( Exception $ex ) {
2799 wfLogWarning( __METHOD__ .
': failed to load content during deletion! '
2800 . $ex->getMessage() );
2811 $fields = array_diff( $fields, [
'rev_deleted' ] );
2822 $res = $dbw->select(
2825 [
'rev_page' => $id ],
2831 foreach (
$res as $row ) {
2833 'ar_namespace' => $namespace,
2834 'ar_title' => $dbKey,
2835 'ar_comment' => $row->rev_comment,
2836 'ar_user' => $row->rev_user,
2837 'ar_user_text' => $row->rev_user_text,
2838 'ar_timestamp' => $row->rev_timestamp,
2839 'ar_minor_edit' => $row->rev_minor_edit,
2840 'ar_rev_id' => $row->rev_id,
2841 'ar_parent_id' => $row->rev_parent_id,
2842 'ar_text_id' => $row->rev_text_id,
2845 'ar_len' => $row->rev_len,
2846 'ar_page_id' => $id,
2847 'ar_deleted' => $suppress ? $bitfield : $row->rev_deleted,
2848 'ar_sha1' => $row->rev_sha1,
2850 if ( $wgContentHandlerUseDB ) {
2851 $rowInsert[
'ar_content_model'] = $row->rev_content_model;
2852 $rowInsert[
'ar_content_format'] = $row->rev_content_format;
2854 $rowsInsert[] = $rowInsert;
2857 $dbw->insert(
'archive', $rowsInsert, __METHOD__ );
2859 $archivedRevisionCount = $dbw->affectedRows();
2864 $wikiPageBeforeDelete = clone $this;
2867 $dbw->delete(
'page', [
'page_id' => $id ], __METHOD__ );
2868 $dbw->delete(
'revision', [
'rev_page' => $id ], __METHOD__ );
2871 $logtype = $suppress ?
'suppress' :
'delete';
2874 $logEntry->setPerformer(
$user );
2875 $logEntry->setTarget( $logTitle );
2876 $logEntry->setComment( $reason );
2877 $logEntry->setTags( $tags );
2878 $logid = $logEntry->insert();
2880 $dbw->onTransactionPreCommitOrIdle(
2881 function ()
use ( $dbw, $logEntry, $logid ) {
2883 $logEntry->publish( $logid );
2888 $dbw->endAtomic( __METHOD__ );
2893 &$wikiPageBeforeDelete,
2899 $archivedRevisionCount
2905 $key =
wfMemcKey(
'page-recent-delete', md5( $logTitle->getPrefixedText() ) );
2906 $cache->set( $key, 1, $cache::TTL_DAY );
2922 'page_id' => $this->
getId(),
2925 'page_namespace' => $this->
getTitle()->getNamespace(),
2926 'page_title' => $this->
getTitle()->getDBkey()
2945 }
catch ( Exception $ex ) {
2956 foreach ( $updates
as $update ) {
2964 if ( $this->mTitle->getNamespace() ==
NS_FILE ) {
2971 $this->mTitle, $revision,
null,
wfWikiID()
3011 $fromP, $summary, $token, $bot, &$resultDetails,
User $user, $tags =
null
3013 $resultDetails =
null;
3016 $editErrors = $this->mTitle->getUserPermissionsErrors(
'edit',
$user );
3017 $rollbackErrors = $this->mTitle->getUserPermissionsErrors(
'rollback',
$user );
3018 $errors = array_merge( $editErrors,
wfArrayDiff2( $rollbackErrors, $editErrors ) );
3020 if ( !
$user->matchEditToken( $token,
'rollback' ) ) {
3021 $errors[] = [
'sessionfailure' ];
3024 if (
$user->pingLimiter(
'rollback' ) ||
$user->pingLimiter() ) {
3025 $errors[] = [
'actionthrottledtext' ];
3029 if ( !empty( $errors ) ) {
3057 &$resultDetails,
User $guser, $tags =
null
3064 return [ [
'readonlytext' ] ];
3069 if ( is_null( $current ) ) {
3071 return [ [
'notanarticle' ] ];
3074 $from = str_replace(
'_',
' ', $fromP );
3077 if ( $from != $current->getUserText() ) {
3078 $resultDetails = [
'current' => $current ];
3079 return [ [
'alreadyrolled',
3080 htmlspecialchars( $this->mTitle->getPrefixedText() ),
3081 htmlspecialchars( $fromP ),
3082 htmlspecialchars( $current->getUserText() )
3089 $user_text = $dbw->addQuotes( $current->getUserText(
Revision::RAW ) );
3090 $s = $dbw->selectRow(
'revision',
3091 [
'rev_id',
'rev_timestamp',
'rev_deleted' ],
3092 [
'rev_page' => $current->getPage(),
3093 "rev_user != {$user} OR rev_user_text != {$user_text}"
3095 [
'USE INDEX' =>
'page_timestamp',
3096 'ORDER BY' =>
'rev_timestamp DESC' ]
3098 if (
$s ===
false ) {
3100 return [ [
'cantrollback' ] ];
3105 return [ [
'notvisiblerev' ] ];
3110 if ( empty( $summary ) ) {
3111 if ( $from ==
'' ) {
3112 $summary =
wfMessage(
'revertpage-nouser' );
3120 $target->getUserText(), $from,
$s->rev_id,
3122 $current->getId(),
$wgContLang->timeanddate( $current->getTimestamp() )
3124 if ( $summary instanceof Message ) {
3125 $summary = $summary->params(
$args )->inContentLanguage()->text();
3131 $summary = trim( $summary );
3134 $summary =
$wgContLang->truncate( $summary, 255 );
3139 if ( $guser->
isAllowed(
'minoredit' ) ) {
3143 if ( $bot && ( $guser->
isAllowedAny(
'markbotedits',
'bot' ) ) ) {
3147 $targetContent = $target->getContent();
3148 $changingContentModel = $targetContent->getModel() !== $current->getContentModel();
3164 if ( $bot && $guser->
isAllowed(
'markbotedits' ) ) {
3169 if ( $wgUseRCPatrol ) {
3171 $set[
'rc_patrolled'] = 1;
3174 if (
count( $set ) ) {
3175 $dbw->update(
'recentchanges', $set,
3177 'rc_cur_id' => $current->getPage(),
3178 'rc_user_text' => $current->getUserText(),
3179 'rc_timestamp > ' . $dbw->addQuotes(
$s->rev_timestamp ),
3186 return $status->getErrorsArray();
3190 $statusRev = isset(
$status->value[
'revision'] )
3193 if ( !( $statusRev instanceof
Revision ) ) {
3194 $resultDetails = [
'current' => $current ];
3195 return [ [
'alreadyrolled',
3196 htmlspecialchars( $this->mTitle->getPrefixedText() ),
3197 htmlspecialchars( $fromP ),
3198 htmlspecialchars( $current->getUserText() )
3202 if ( $changingContentModel ) {
3206 $log->setPerformer( $guser );
3207 $log->setTarget( $this->mTitle );
3208 $log->setComment( $summary );
3209 $log->setParameters( [
3210 '4::oldmodel' => $current->getContentModel(),
3211 '5::newmodel' => $targetContent->getModel(),
3214 $logId = $log->insert( $dbw );
3215 $log->publish( $logId );
3218 $revId = $statusRev->getId();
3220 Hooks::run(
'ArticleRollbackComplete', [ $this, $guser, $target, $current ] );
3223 'summary' => $summary,
3224 'current' => $current,
3225 'target' => $target,
3245 $other =
$title->getOtherPage();
3247 $other->purgeSquid();
3251 $title->deleteTitleProtection();
3253 MediaWikiServices::getInstance()->getLinkCache()->invalidateTitle(
$title );
3274 $other =
$title->getOtherPage();
3276 $other->purgeSquid();
3281 MediaWikiServices::getInstance()->getLinkCache()->invalidateTitle(
$title );
3301 $user->setNewtalk(
false );
3322 MediaWikiServices::getInstance()->getLinkCache()->invalidateTitle(
$title );
3329 $revid = $revision ? $revision->getId() :
null;
3344 $id = $this->
getId();
3350 $res =
$dbr->select(
'categorylinks',
3351 [
'cl_to AS page_title, ' .
NS_CATEGORY .
' AS page_namespace' ],
3354 [
'cl_from' => $id ],
3368 $id = $this->
getId();
3375 $res =
$dbr->select( [
'categorylinks',
'page_props',
'page' ],
3377 [
'cl_from' => $id,
'pp_page=page_id',
'pp_propname' =>
'hiddencat',
3378 'page_namespace' =>
NS_CATEGORY,
'page_title=cl_to' ],
3381 if (
$res !==
false ) {
3382 foreach (
$res as $row ) {
3412 $id = $id ?: $this->
getId();
3413 $ns = $this->
getTitle()->getNamespace();
3415 $addFields = [
'cat_pages = cat_pages + 1' ];
3416 $removeFields = [
'cat_pages = cat_pages - 1' ];
3418 $addFields[] =
'cat_subcats = cat_subcats + 1';
3419 $removeFields[] =
'cat_subcats = cat_subcats - 1';
3421 $addFields[] =
'cat_files = cat_files + 1';
3422 $removeFields[] =
'cat_files = cat_files - 1';
3427 if (
count( $added ) ) {
3428 $existingAdded = $dbw->selectFieldValues(
3431 [
'cat_title' => $added ],
3438 if (
count( $existingAdded ) ) {
3442 [
'cat_title' => $existingAdded ],
3447 $missingAdded = array_diff( $added, $existingAdded );
3448 if (
count( $missingAdded ) ) {
3450 foreach ( $missingAdded
as $cat ) {
3452 'cat_title' => $cat,
3455 'cat_files' => ( $ns ==
NS_FILE ) ? 1 : 0,
3468 if (
count( $deleted ) ) {
3472 [
'cat_title' => $deleted ],
3477 foreach ( $added
as $catName ) {
3479 Hooks::run(
'CategoryAfterPageAdded', [ $cat, $this ] );
3482 foreach ( $deleted
as $catName ) {
3484 Hooks::run(
'CategoryAfterPageRemoved', [ $cat, $this, $id ] );
3490 if (
count( $deleted ) ) {
3491 $rows = $dbw->select(
3493 [
'cat_id',
'cat_title',
'cat_pages',
'cat_subcats',
'cat_files' ],
3494 [
'cat_title' => $deleted,
'cat_pages <= 0' ],
3497 foreach ( $rows
as $row ) {
3501 $cat->refreshCounts();
3518 if ( !
Hooks::run(
'OpportunisticLinksUpdate',
3527 'isOpportunistic' =>
true,
3531 if ( $this->mTitle->areRestrictionsCascading() ) {
3536 } elseif ( !$config->get(
'MiserMode' ) &&
$parserOutput->hasDynamicContent() ) {
3547 $key =
$cache->makeKey(
'dynamic-linksupdate',
'last', $this->
getId() );
3549 if (
$cache->add( $key, time(), $ttl ) ) {
3573 }
catch ( Exception $ex ) {
3584 $updates =
$content->getDeletionUpdates( $this );
3625 return $this->
getTitle()->getCanonicalURL();
3634 $linkCache = MediaWikiServices::getInstance()->getLinkCache();
3636 return $linkCache->getMutableCacheKeys(
$cache, $this->
getTitle()->getTitleValue() );