X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2Fpage%2FWikiPage.php;h=7f923f88a514a2d7f0a9e25dba9cc247fc27e0dd;hp=af906fb44fa41f3c4b6508ab6bb3ea770be817bd;hb=c1f342c675822509429aa02057c2950af1d0db3c;hpb=c61c1ac00079c654a0e1a68bf5c25c1f5bef031a diff --git a/includes/page/WikiPage.php b/includes/page/WikiPage.php index af906fb44f..7f923f88a5 100644 --- a/includes/page/WikiPage.php +++ b/includes/page/WikiPage.php @@ -878,11 +878,10 @@ class WikiPage implements Page, IDBAccessObject { } // Update the DB post-send if the page has not cached since now - $that = $this; $latest = $this->getLatest(); DeferredUpdates::addCallableUpdate( - function () use ( $that, $retval, $latest ) { - $that->insertRedirectEntry( $retval, $latest ); + function () use ( $retval, $latest ) { + $this->insertRedirectEntry( $retval, $latest ); }, DeferredUpdates::POSTSEND, wfGetDB( DB_MASTER ) @@ -1047,9 +1046,9 @@ class WikiPage implements Page, IDBAccessObject { * * @since 1.19 * @param ParserOptions $parserOptions ParserOptions to use for the parse operation - * @param null|int $oldid Revision ID to get the text from, passing null or 0 will - * get the current revision (default value) - * @param bool $forceParse Force reindexing, regardless of cache settings + * @param null|int $oldid Revision ID to get the text from, passing null or 0 will + * get the current revision (default value) + * @param bool $forceParse Force reindexing, regardless of cache settings * @return bool|ParserOutput ParserOutput or false if the revision was not found */ public function getParserOutput( @@ -1071,7 +1070,8 @@ class WikiPage implements Page, IDBAccessObject { } if ( $useParserCache ) { - $parserOutput = ParserCache::singleton()->get( $this, $parserOptions ); + $parserOutput = MediaWikiServices::getInstance()->getParserCache() + ->get( $this, $parserOptions ); if ( $parserOutput !== false ) { return $parserOutput; } @@ -1166,11 +1166,10 @@ class WikiPage implements Page, IDBAccessObject { * page ID is already in use. */ public function insertOn( $dbw, $pageId = null ) { - $pageIdForInsert = $pageId ?: $dbw->nextSequenceValue( 'page_page_id_seq' ); + $pageIdForInsert = $pageId ? [ 'page_id' => $pageId ] : []; $dbw->insert( 'page', [ - 'page_id' => $pageIdForInsert, 'page_namespace' => $this->mTitle->getNamespace(), 'page_title' => $this->mTitle->getDBkey(), 'page_restrictions' => '', @@ -1180,7 +1179,7 @@ class WikiPage implements Page, IDBAccessObject { 'page_touched' => $dbw->timestamp(), 'page_latest' => 0, // Fill this in shortly... 'page_len' => 0, // Fill this in shortly... - ], + ] + $pageIdForInsert, __METHOD__, 'IGNORE' ); @@ -1638,7 +1637,7 @@ class WikiPage implements Page, IDBAccessObject { /** * @param Content $content Pre-save transform content - * @param integer $flags + * @param int $flags * @param User $user * @param string $summary * @param array $meta @@ -1659,7 +1658,7 @@ class WikiPage implements Page, IDBAccessObject { // Convenience variables $now = wfTimestampNow(); $oldid = $meta['oldId']; - /** @var $oldContent Content|null */ + /** @var Content|null $oldContent */ $oldContent = $meta['oldContent']; $newsize = $content->getSize(); @@ -1812,7 +1811,7 @@ class WikiPage implements Page, IDBAccessObject { /** * @param Content $content Pre-save transform content - * @param integer $flags + * @param int $flags * @param User $user * @param string $summary * @param array $meta @@ -1990,6 +1989,7 @@ class WikiPage implements Page, IDBAccessObject { // This code path is deprecated, and nothing is known to // use it, so performance here shouldn't be a worry. if ( $revid !== null ) { + wfDeprecated( __METHOD__ . ' with $revision = revision ID', '1.25' ); $revision = Revision::newFromId( $revid, Revision::READ_LATEST ); } else { $revision = null; @@ -2111,13 +2111,13 @@ class WikiPage implements Page, IDBAccessObject { * @param Revision $revision * @param User $user User object that did the revision * @param array $options Array of options, following indexes are used: - * - changed: boolean, whether the revision changed the content (default true) - * - created: boolean, whether the revision created the page (default false) - * - moved: boolean, whether the page was moved (default false) - * - restored: boolean, whether the page was undeleted (default false) + * - changed: bool, whether the revision changed the content (default true) + * - created: bool, whether the revision created the page (default false) + * - moved: bool, whether the page was moved (default false) + * - restored: bool, whether the page was undeleted (default false) * - oldrevision: Revision object for the pre-update revision (default null) - * - oldcountable: boolean, null, or string 'no-change' (default null): - * - boolean: whether the page was counted as an article before that + * - oldcountable: bool, null, or string 'no-change' (default null): + * - bool: whether the page was counted as an article before that * revision, only used in changed is true and created is false * - null: if created is false, don't update the article count; if created * is true, do update the article count @@ -2164,7 +2164,7 @@ class WikiPage implements Page, IDBAccessObject { // Save it to the parser cache. // Make sure the cache time matches page_touched to avoid double parsing. - ParserCache::singleton()->save( + MediaWikiServices::getInstance()->getParserCache()->save( $editInfo->output, $this, $editInfo->popts, $revision->getTimestamp(), $editInfo->revid ); @@ -2299,10 +2299,10 @@ class WikiPage implements Page, IDBAccessObject { public function doUpdateRestrictions( array $limit, array $expiry, &$cascade, $reason, User $user, $tags = null ) { - global $wgCascadingRestrictionLevels, $wgContLang; + global $wgCascadingRestrictionLevels; if ( wfReadOnly() ) { - return Status::newFatal( 'readonlytext', wfReadOnlyReason() ); + return Status::newFatal( wfMessage( 'readonlytext', wfReadOnlyReason() ) ); } $this->loadPageData( 'fromdbmaster' ); @@ -2372,9 +2372,6 @@ class WikiPage implements Page, IDBAccessObject { $logAction = 'protect'; } - // Truncate for whole multibyte characters - $reason = $wgContLang->truncate( $reason, 255 ); - $logRelationsValues = []; $logRelationsField = null; $logParamsDetails = []; @@ -2446,7 +2443,6 @@ class WikiPage implements Page, IDBAccessObject { $dbw->insert( 'page_restrictions', [ - 'pr_id' => $dbw->nextSequenceValue( 'page_restrictions_pr_id_seq' ), 'pr_page' => $id, 'pr_type' => $action, 'pr_level' => $restrictions, @@ -2484,6 +2480,7 @@ class WikiPage implements Page, IDBAccessObject { $cascade = false; if ( $limit['create'] != '' ) { + $commentFields = CommentStore::newKey( 'pt_reason' )->insert( $dbw, $reason ); $dbw->replace( 'protected_titles', [ [ 'pt_namespace', 'pt_title' ] ], [ @@ -2493,8 +2490,7 @@ class WikiPage implements Page, IDBAccessObject { 'pt_timestamp' => $dbw->timestamp(), 'pt_expiry' => $dbw->encodeExpiry( $expiry['create'] ), 'pt_user' => $user->getId(), - 'pt_reason' => $reason, - ], __METHOD__ + ] + $commentFields, __METHOD__ ); $logParamsDetails[] = [ 'type' => 'create', @@ -2746,7 +2742,7 @@ class WikiPage implements Page, IDBAccessObject { $reason, $suppress = false, $u1 = null, $u2 = null, &$error = '', User $user = null, $tags = [], $logsubtype = 'delete' ) { - global $wgUser, $wgContentHandlerUseDB; + global $wgUser, $wgContentHandlerUseDB, $wgCommentTableSchemaMigrationStage; wfDebug( __METHOD__ . "\n" ); @@ -2810,6 +2806,9 @@ class WikiPage implements Page, IDBAccessObject { $content = null; } + $revCommentStore = new CommentStore( 'rev_comment' ); + $arCommentStore = new CommentStore( 'ar_comment' ); + $fields = Revision::selectFields(); $bitfield = false; @@ -2827,20 +2826,28 @@ class WikiPage implements Page, IDBAccessObject { // the rev_deleted field, which is reserved for this purpose. // Get all of the page revisions + $commentQuery = $revCommentStore->getJoin(); $res = $dbw->select( - 'revision', - $fields, + [ 'revision' ] + $commentQuery['tables'], + $fields + $commentQuery['fields'], [ 'rev_page' => $id ], __METHOD__, - 'FOR UPDATE' + 'FOR UPDATE', + $commentQuery['joins'] ); + // Build their equivalent archive rows $rowsInsert = []; + $revids = []; + + /** @var int[] Revision IDs of edits that were made by IPs */ + $ipRevIds = []; + foreach ( $res as $row ) { + $comment = $revCommentStore->getComment( $row ); $rowInsert = [ 'ar_namespace' => $namespace, 'ar_title' => $dbKey, - 'ar_comment' => $row->rev_comment, 'ar_user' => $row->rev_user, 'ar_user_text' => $row->rev_user_text, 'ar_timestamp' => $row->rev_timestamp, @@ -2854,12 +2861,19 @@ class WikiPage implements Page, IDBAccessObject { 'ar_page_id' => $id, 'ar_deleted' => $suppress ? $bitfield : $row->rev_deleted, 'ar_sha1' => $row->rev_sha1, - ]; + ] + $arCommentStore->insert( $dbw, $comment ); if ( $wgContentHandlerUseDB ) { $rowInsert['ar_content_model'] = $row->rev_content_model; $rowInsert['ar_content_format'] = $row->rev_content_format; } $rowsInsert[] = $rowInsert; + $revids[] = $row->rev_id; + + // Keep track of IP edits, so that the corresponding rows can + // be deleted in the ip_changes table. + if ( (int)$row->rev_user === 0 && IP::isValid( $row->rev_user_text ) ) { + $ipRevIds[] = $row->rev_id; + } } // Copy them into the archive table $dbw->insert( 'archive', $rowsInsert, __METHOD__ ); @@ -2874,6 +2888,14 @@ class WikiPage implements Page, IDBAccessObject { // Now that it's safely backed up, delete it $dbw->delete( 'page', [ 'page_id' => $id ], __METHOD__ ); $dbw->delete( 'revision', [ 'rev_page' => $id ], __METHOD__ ); + if ( $wgCommentTableSchemaMigrationStage > MIGRATION_OLD ) { + $dbw->delete( 'revision_comment_temp', [ 'revcomment_rev' => $revids ], __METHOD__ ); + } + + // Also delete records from ip_changes as applicable. + if ( count( $ipRevIds ) > 0 ) { + $dbw->delete( 'ip_changes', [ 'ipc_rev_id' => $ipRevIds ], __METHOD__ ); + } // Log the deletion, if the page was suppressed, put it in the suppression log instead $logtype = $suppress ? 'suppress' : 'delete'; @@ -2919,7 +2941,7 @@ class WikiPage implements Page, IDBAccessObject { /** * Lock the page row for this title+id and return page_latest (or 0) * - * @return integer Returns 0 if no row was found with this title+id + * @return int Returns 0 if no row was found with this title+id * @since 1.27 */ public function lockAndGetLatest() { @@ -3001,7 +3023,7 @@ class WikiPage implements Page, IDBAccessObject { * @param string $token Rollback token. * @param bool $bot If true, mark all reverted edits as bot. * - * @param array $resultDetails Array contains result-specific array of additional values + * @param array &$resultDetails Array contains result-specific array of additional values * 'alreadyrolled' : 'current' (rev) * success : 'summary' (str), 'current' (rev), 'target' (rev) * @@ -3053,7 +3075,7 @@ class WikiPage implements Page, IDBAccessObject { * @param string $summary Custom summary. Set to default summary if empty. * @param bool $bot If true, mark all reverted edits as bot. * - * @param array $resultDetails Contains result-specific array of additional values + * @param array &$resultDetails Contains result-specific array of additional values * @param User $guser The user performing the rollback * @param array|null $tags Change tags to apply to the rollback * Callers are responsible for permission checks @@ -3138,9 +3160,6 @@ class WikiPage implements Page, IDBAccessObject { // Trim spaces on user supplied text $summary = trim( $summary ); - // Truncate for whole multibyte characters. - $summary = $wgContLang->truncate( $summary, 255 ); - // Save $flags = EDIT_UPDATE | EDIT_INTERNAL; @@ -3414,7 +3433,7 @@ class WikiPage implements Page, IDBAccessObject { * * @param array $added The names of categories that were added * @param array $deleted The names of categories that were deleted - * @param integer $id Page ID (this should be the original deleted page ID) + * @param int $id Page ID (this should be the original deleted page ID) */ public function updateCategoryCounts( array $added, array $deleted, $id = 0 ) { $id = $id ?: $this->getId(); @@ -3633,7 +3652,7 @@ class WikiPage implements Page, IDBAccessObject { return $this->getTitle()->getCanonicalURL(); } - /* + /** * @param WANObjectCache $cache * @return string[] * @since 1.28