X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2Fpage%2FPageArchive.php;h=af936cc730240ad3c607525f286a810c79ab470a;hp=c2bfb07c625da849b4c095e6e303c2d234550f7b;hb=5e7fd24297cb886f2b59a1b9c83db7e2581f31fe;hpb=142e89424ea9c4ee5b87ba8d8e78714bca18c75d diff --git a/includes/page/PageArchive.php b/includes/page/PageArchive.php index c2bfb07c62..af936cc730 100644 --- a/includes/page/PageArchive.php +++ b/includes/page/PageArchive.php @@ -67,6 +67,56 @@ class PageArchive { return self::listPages( $dbr, '' ); } + /** + * List deleted pages recorded in the archive matching the + * given term, using search engine archive. + * Returns result wrapper with (ar_namespace, ar_title, count) fields. + * + * @param string $term Search term + * @return ResultWrapper + */ + public static function listPagesBySearch( $term ) { + $title = Title::newFromText( $term ); + if ( $title ) { + $ns = $title->getNamespace(); + $termMain = $title->getText(); + $termDb = $title->getDBkey(); + } else { + // Prolly won't work too good + // @todo handle bare namespace names cleanly? + $ns = 0; + $termMain = $termDb = $term; + } + + // Try search engine first + $engine = MediaWikiServices::getInstance()->newSearchEngine(); + $engine->setLimitOffset( 100 ); + $engine->setNamespaces( [ $ns ] ); + $results = $engine->searchArchiveTitle( $termMain ); + if ( !$results->isOK() ) { + $results = []; + } else { + $results = $results->getValue(); + } + + if ( !$results ) { + // Fall back to regular prefix search + return self::listPagesByPrefix( $term ); + } + + $dbr = wfGetDB( DB_REPLICA ); + $condTitles = array_unique( array_map( function ( Title $t ) { + return $t->getDBkey(); + }, $results ) ); + $conds = [ + 'ar_namespace' => $ns, + $dbr->makeList( [ 'ar_title' => $condTitles ], LIST_OR ) . " OR ar_title " . + $dbr->buildLike( $termDb, $dbr->anyString() ) + ]; + + return self::listPages( $dbr, $conds ); + } + /** * List deleted pages recorded in the archive table matching the * given title prefix. @@ -121,19 +171,21 @@ class PageArchive { /** * List the revisions of the given page. Returns result wrapper with - * (ar_minor_edit, ar_timestamp, ar_user, ar_user_text, ar_comment) fields. + * various archive table fields. * * @return ResultWrapper */ public function listRevisions() { $dbr = wfGetDB( DB_REPLICA ); + $commentQuery = CommentStore::newKey( 'ar_comment' )->getJoin(); - $tables = [ 'archive' ]; + $tables = [ 'archive' ] + $commentQuery['tables']; $fields = [ 'ar_minor_edit', 'ar_timestamp', 'ar_user', 'ar_user_text', - 'ar_comment', 'ar_len', 'ar_deleted', 'ar_rev_id', 'ar_sha1', - ]; + 'ar_len', 'ar_deleted', 'ar_rev_id', 'ar_sha1', + 'ar_page_id' + ] + $commentQuery['fields']; if ( $this->config->get( 'ContentHandlerUseDB' ) ) { $fields[] = 'ar_content_format'; @@ -145,7 +197,7 @@ class PageArchive { $options = [ 'ORDER BY' => 'ar_timestamp DESC' ]; - $join_conds = []; + $join_conds = [] + $commentQuery['joins']; ChangeTags::modifyDisplayQuery( $tables, @@ -197,11 +249,13 @@ class PageArchive { */ public function getRevision( $timestamp ) { $dbr = wfGetDB( DB_REPLICA ); + $commentQuery = CommentStore::newKey( 'ar_comment' )->getJoin(); + + $tables = [ 'archive' ] + $commentQuery['tables']; $fields = [ 'ar_rev_id', 'ar_text', - 'ar_comment', 'ar_user', 'ar_user_text', 'ar_timestamp', @@ -211,19 +265,27 @@ class PageArchive { 'ar_deleted', 'ar_len', 'ar_sha1', - ]; + ] + $commentQuery['fields']; if ( $this->config->get( 'ContentHandlerUseDB' ) ) { $fields[] = 'ar_content_format'; $fields[] = 'ar_content_model'; } - $row = $dbr->selectRow( 'archive', + $join_conds = [] + $commentQuery['joins']; + + $row = $dbr->selectRow( + $tables, $fields, - [ 'ar_namespace' => $this->title->getNamespace(), + [ + 'ar_namespace' => $this->title->getNamespace(), 'ar_title' => $this->title->getDBkey(), - 'ar_timestamp' => $dbr->timestamp( $timestamp ) ], - __METHOD__ ); + 'ar_timestamp' => $dbr->timestamp( $timestamp ) + ], + __METHOD__, + [], + $join_conds + ); if ( $row ) { return Revision::newFromArchiveRow( $row, [ 'title' => $this->title ] ); @@ -402,25 +464,12 @@ class PageArchive { // Touch the log! - if ( $textRestored && $filesRestored ) { - $reason = wfMessage( 'undeletedrevisions-files' ) - ->numParams( $textRestored, $filesRestored )->inContentLanguage()->text(); - } elseif ( $textRestored ) { - $reason = wfMessage( 'undeletedrevisions' )->numParams( $textRestored ) - ->inContentLanguage()->text(); - } elseif ( $filesRestored ) { - $reason = wfMessage( 'undeletedfiles' )->numParams( $filesRestored ) - ->inContentLanguage()->text(); - } else { + if ( !$textRestored && !$filesRestored ) { wfDebug( "Undelete: nothing undeleted...\n" ); return false; } - if ( trim( $comment ) != '' ) { - $reason .= wfMessage( 'colon-separator' )->inContentLanguage()->text() . $comment; - } - if ( $user === null ) { global $wgUser; $user = $wgUser; @@ -429,15 +478,21 @@ class PageArchive { $logEntry = new ManualLogEntry( 'delete', 'restore' ); $logEntry->setPerformer( $user ); $logEntry->setTarget( $this->title ); - $logEntry->setComment( $reason ); + $logEntry->setComment( $comment ); $logEntry->setTags( $tags ); + $logEntry->setParameters( [ + ':assoc:count' => [ + 'revisions' => $textRestored, + 'files' => $filesRestored, + ], + ] ); Hooks::run( 'ArticleUndeleteLogEntry', [ $this, &$logEntry, $user ] ); $logid = $logEntry->insert(); $logEntry->publish( $logid ); - return [ $textRestored, $filesRestored, $reason ]; + return [ $textRestored, $filesRestored, $comment ]; } /** @@ -508,12 +563,15 @@ class PageArchive { $oldWhere['ar_timestamp'] = array_map( [ &$dbw, 'timestamp' ], $timestamps ); } + $commentQuery = CommentStore::newKey( 'ar_comment' )->getJoin(); + + $tables = [ 'archive', 'revision' ] + $commentQuery['tables']; + $fields = [ 'ar_id', 'ar_rev_id', 'rev_id', 'ar_text', - 'ar_comment', 'ar_user', 'ar_user_text', 'ar_timestamp', @@ -524,24 +582,28 @@ class PageArchive { 'ar_page_id', 'ar_len', 'ar_sha1' - ]; + ] + $commentQuery['fields']; if ( $this->config->get( 'ContentHandlerUseDB' ) ) { $fields[] = 'ar_content_format'; $fields[] = 'ar_content_model'; } + $join_conds = [ + 'revision' => [ 'LEFT JOIN', 'ar_rev_id=rev_id' ], + ] + $commentQuery['joins']; + /** * Select each archived revision... */ $result = $dbw->select( - [ 'archive', 'revision' ], + $tables, $fields, $oldWhere, __METHOD__, /* options */ [ 'ORDER BY' => 'ar_timestamp' ], - [ 'revision' => [ 'LEFT JOIN', 'ar_rev_id=rev_id' ] ] + $join_conds ); $rev_count = $result->numRows(); @@ -620,7 +682,7 @@ class PageArchive { $restored = 0; // number of revisions restored /** @var Revision $revision */ $revision = null; - + $restoredPages = []; // If there are no restorable revisions, we can skip most of the steps. if ( $latestRestorableRow === null ) { $failedRevisionCount = $rev_count; @@ -672,11 +734,14 @@ class PageArchive { 'deleted' => $unsuppress ? 0 : $row->ar_deleted ] ); + // This will also copy the revision to ip_changes if it was an IP edit. $revision->insertOn( $dbw ); + $restored++; Hooks::run( 'ArticleRevisionUndeleted', [ &$this->title, $revision, $row->ar_page_id ] ); + $restoredPages[$row->ar_page_id] = true; } // Now that it's safely stored, take it out of the archive @@ -717,7 +782,8 @@ class PageArchive { ); } - Hooks::run( 'ArticleUndelete', [ &$this->title, $created, $comment, $oldPageId ] ); + Hooks::run( 'ArticleUndelete', + [ &$this->title, $created, $comment, $oldPageId, $restoredPages ] ); if ( $this->title->getNamespace() == NS_FILE ) { DeferredUpdates::addUpdate( new HTMLCacheUpdate( $this->title, 'imagelinks' ) ); }