Go to the documentation of this file.
43 throw new MWException( __METHOD__ .
' given a null title.' );
47 wfDebug( __METHOD__ .
' did not have a Config object passed to it' );
48 $config = MediaWikiServices::getInstance()->getMainConfig();
88 $termMain = $termDb =
$term;
92 $engine = MediaWikiServices::getInstance()->newSearchEngine();
94 $engine->setNamespaces( [ $ns ] );
95 $results =
$engine->searchArchiveTitle( $termMain );
96 if ( !$results->isOK() ) {
99 $results = $results->getValue();
108 $condTitles = array_unique( array_map(
function (
Title $t ) {
109 return $t->getDBkey();
112 'ar_namespace' => $ns,
113 $dbr->makeList( [
'ar_title' => $condTitles ],
LIST_OR ) .
" OR ar_title " .
114 $dbr->buildLike( $termDb,
$dbr->anyString() )
142 'ar_namespace' => $ns,
143 'ar_title' .
$dbr->buildLike( $prefix,
$dbr->anyString() ),
160 'count' =>
'COUNT(*)'
165 'GROUP BY' => [
'ar_namespace',
'ar_title' ],
166 'ORDER BY' => [
'ar_namespace',
'ar_title' ],
184 'ar_minor_edit',
'ar_timestamp',
'ar_user',
'ar_user_text',
185 'ar_comment',
'ar_len',
'ar_deleted',
'ar_rev_id',
'ar_sha1',
189 if ( $this->config->get(
'ContentHandlerUseDB' ) ) {
190 $fields[] =
'ar_content_format';
191 $fields[] =
'ar_content_model';
194 $conds = [
'ar_namespace' => $this->
title->getNamespace(),
195 'ar_title' => $this->
title->getDBkey() ];
197 $options = [
'ORDER BY' =>
'ar_timestamp DESC' ];
236 [
'fa_name' => $this->
title->getDBkey() ],
238 [
'ORDER BY' =>
'fa_timestamp DESC' ]
267 if ( $this->config->get(
'ContentHandlerUseDB' ) ) {
268 $fields[] =
'ar_content_format';
269 $fields[] =
'ar_content_model';
272 $row =
$dbr->selectRow(
'archive',
274 [
'ar_namespace' => $this->
title->getNamespace(),
275 'ar_title' => $this->
title->getDBkey(),
276 'ar_timestamp' =>
$dbr->timestamp( $timestamp ) ],
300 $row =
$dbr->selectRow(
'archive',
302 [
'ar_namespace' => $this->
title->getNamespace(),
303 'ar_title' => $this->
title->getDBkey(),
305 $dbr->addQuotes(
$dbr->timestamp( $timestamp ) ) ],
308 'ORDER BY' =>
'ar_timestamp DESC',
310 $prevDeleted = $row ?
wfTimestamp( TS_MW, $row->ar_timestamp ) :
false;
312 $row =
$dbr->selectRow( [
'page',
'revision' ],
313 [
'rev_id',
'rev_timestamp' ],
315 'page_namespace' => $this->
title->getNamespace(),
316 'page_title' => $this->
title->getDBkey(),
317 'page_id = rev_page',
319 $dbr->addQuotes(
$dbr->timestamp( $timestamp ) ) ],
322 'ORDER BY' =>
'rev_timestamp DESC',
324 $prevLive = $row ?
wfTimestamp( TS_MW, $row->rev_timestamp ) :
false;
325 $prevLiveId = $row ? intval( $row->rev_id ) :
null;
327 if ( $prevLive && $prevLive > $prevDeleted ) {
330 } elseif ( $prevDeleted ) {
346 if ( is_null( $row->ar_text_id ) ) {
354 $text =
$dbr->selectRow(
'text',
355 [
'old_text',
'old_flags' ],
356 [
'old_id' => $row->ar_text_id ],
372 $row =
$dbr->selectRow(
'archive',
373 [
'ar_text',
'ar_flags',
'ar_text_id' ],
374 [
'ar_namespace' => $this->
title->getNamespace(),
375 'ar_title' => $this->
title->getDBkey() ],
377 [
'ORDER BY' =>
'ar_timestamp DESC' ] );
393 $n =
$dbr->selectField(
'archive',
'COUNT(ar_title)',
394 [
'ar_namespace' => $this->
title->getNamespace(),
395 'ar_title' => $this->
title->getDBkey() ],
421 public function undelete( $timestamps, $comment =
'', $fileVersions = [],
422 $unsuppress =
false,
User $user =
null, $tags =
null
426 $restoreAll = empty( $timestamps ) && empty( $fileVersions );
428 $restoreText = $restoreAll || !empty( $timestamps );
429 $restoreFiles = $restoreAll || !empty( $fileVersions );
431 if ( $restoreFiles && $this->
title->getNamespace() ==
NS_FILE ) {
433 $img->load( File::READ_LATEST );
434 $this->fileStatus = $img->restore( $fileVersions, $unsuppress );
435 if ( !$this->fileStatus->isOK() ) {
438 $filesRestored = $this->fileStatus->successCount;
443 if ( $restoreText ) {
444 $this->revisionStatus = $this->
undeleteRevisions( $timestamps, $unsuppress, $comment );
445 if ( !$this->revisionStatus->isOK() ) {
449 $textRestored = $this->revisionStatus->getValue();
456 if ( !$textRestored && !$filesRestored ) {
457 wfDebug(
"Undelete: nothing undeleted...\n" );
462 if (
$user ===
null ) {
468 $logEntry->setPerformer(
$user );
469 $logEntry->setTarget( $this->
title );
470 $logEntry->setComment( $comment );
471 $logEntry->setTags( $tags );
472 $logEntry->setParameters( [
474 'revisions' => $textRestored,
475 'files' => $filesRestored,
481 $logid = $logEntry->insert();
482 $logEntry->publish( $logid );
484 return [ $textRestored, $filesRestored, $comment ];
504 $dbw->startAtomic( __METHOD__ );
506 $restoreAll = empty( $timestamps );
508 # Does this page already exist? We'll have to update it...
510 # Load latest data for the current page (T33179)
511 $article->loadPageData(
'fromdbmaster' );
512 $oldcountable =
$article->isCountable();
514 $page = $dbw->selectRow(
'page',
515 [
'page_id',
'page_latest' ],
516 [
'page_namespace' => $this->
title->getNamespace(),
517 'page_title' => $this->
title->getDBkey() ],
524 # Page already exists. Import the history, and if necessary
525 # we'll update the latest revision field in the record.
527 # Get the time span of this page
528 $previousTimestamp = $dbw->selectField(
'revision',
'rev_timestamp',
529 [
'rev_id' =>
$page->page_latest ],
532 if ( $previousTimestamp ===
false ) {
533 wfDebug( __METHOD__ .
": existing page refers to a page_latest that does not exist\n" );
536 $status->warning(
'undeleterevision-missing' );
537 $dbw->endAtomic( __METHOD__ );
542 # Have to create a new article...
544 $previousTimestamp = 0;
548 'ar_namespace' => $this->
title->getNamespace(),
549 'ar_title' => $this->
title->getDBkey(),
551 if ( !$restoreAll ) {
552 $oldWhere[
'ar_timestamp'] = array_map( [ &$dbw,
'timestamp' ], $timestamps );
573 if ( $this->config->get(
'ContentHandlerUseDB' ) ) {
574 $fields[] =
'ar_content_format';
575 $fields[] =
'ar_content_model';
582 [
'archive',
'revision' ],
587 [
'ORDER BY' =>
'ar_timestamp' ],
588 [
'revision' => [
'LEFT JOIN',
'ar_rev_id=rev_id' ] ]
591 $rev_count =
$result->numRows();
593 wfDebug( __METHOD__ .
": no revisions to restore\n" );
596 $status->warning(
"undelete-no-results" );
597 $dbw->endAtomic( __METHOD__ );
604 $restoreFailedArIds = [];
611 $allowedRevIdToArIdMap = [];
613 $latestRestorableRow =
null;
616 if ( $row->ar_rev_id ) {
618 if ( $row->ar_rev_id === $row->rev_id ) {
619 $restoreFailedArIds[] = $row->ar_id;
620 $allowedRevIdToArIdMap[$row->ar_rev_id] = -1;
625 if ( isset( $allowedRevIdToArIdMap[$row->ar_rev_id] ) ) {
626 $restoreFailedArIds[] = $row->ar_id;
628 $allowedRevIdToArIdMap[$row->ar_rev_id] = $row->ar_id;
629 $latestRestorableRow = $row;
635 $latestRestorableRow = $row;
642 if ( $latestRestorableRow !==
null ) {
643 $oldPageId = (int)$latestRestorableRow->ar_page_id;
657 $dbw->endAtomic( __METHOD__ );
669 if ( $latestRestorableRow ===
null ) {
670 $failedRevisionCount = $rev_count;
677 $dbw->endAtomic( __METHOD__ );
682 $newid =
$article->insertOn( $dbw, $latestRestorableRow->ar_page_id );
683 if ( $newid ===
false ) {
685 $newid =
$article->insertOn( $dbw );
690 if ( $latestRestorableRow->ar_timestamp > $previousTimestamp ) {
695 $dbw->endAtomic( __METHOD__ );
707 if ( $row->ar_rev_id && $allowedRevIdToArIdMap[$row->ar_rev_id] !== $row->ar_id ) {
715 'title' => $this->
title,
716 'deleted' => $unsuppress ? 0 : $row->ar_deleted
719 $revision->insertOn( $dbw );
723 [ &$this->
title, $revision, $row->ar_page_id ] );
724 $restoredPages[$row->ar_page_id] =
true;
729 $toDeleteConds = $oldWhere;
730 $failedRevisionCount =
count( $restoreFailedArIds );
731 if ( $failedRevisionCount > 0 ) {
732 $toDeleteConds[] =
'ar_id NOT IN ( ' . $dbw->makeList( $restoreFailedArIds ) .
' )';
735 $dbw->delete(
'archive',
742 if ( $failedRevisionCount > 0 ) {
744 wfMessage(
'undeleterevision-duplicate-revid', $failedRevisionCount ) );
749 $created = (bool)$newid;
751 $wasnew =
$article->updateIfNewerOn( $dbw, $revision );
752 if ( $created || $wasnew ) {
758 'created' => $created,
759 'oldcountable' => $oldcountable,
766 [ &$this->
title, $created, $comment, $oldPageId, $restoredPages ] );
772 $dbw->endAtomic( __METHOD__ );
Show an error when the wiki is locked/read-only and the user tries to do something that requires writ...
static newFromArchiveRow( $row, $overrides=[])
Make a fake revision object from an archive table row.
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
processing should stop and the error should be shown to the user * false
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist & $tables
static newFromId( $id, $flags=0)
Load a page revision from a given revision ID number.
Used to show archived pages and eventually restore them.
static listPages( $dbr, $condition)
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message. Please note the header message cannot receive/use parameters. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item. Return false to stop further processing of the tag $reader:XMLReader object $logInfo:Array of information 'ImportHandlePageXMLTag':When parsing a XML tag in a page. Return false to stop further processing of the tag $reader:XMLReader object & $pageInfo:Array of information 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision. Return false to stop further processing of the tag $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information 'ImportHandleToplevelXMLTag':When parsing a top level XML tag. Return false to stop further processing of the tag $reader:XMLReader object 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload. Return false to stop further processing of the tag $reader:XMLReader object $revisionInfo:Array of information 'ImportLogInterwikiLink':Hook to change the interwiki link used in log entries and edit summaries for transwiki imports. & $fullInterwikiPrefix:Interwiki prefix, may contain colons. & $pageTitle:String that contains page title. 'ImportSources':Called when reading from the $wgImportSources configuration variable. Can be used to lazy-load the import sources list. & $importSources:The value of $wgImportSources. Modify as necessary. See the comment in DefaultSettings.php for the detail of how to structure this array. 'InfoAction':When building information to display on the action=info page. $context:IContextSource object & $pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect. & $title:Title object for the current page & $request:WebRequest & $ignoreRedirect:boolean to skip redirect check & $target:Title/string of redirect target & $article:Article object 'InternalParseBeforeLinks':during Parser 's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InternalParseBeforeSanitize':during Parser 's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings. Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not. Return true without providing an interwiki to continue interwiki search. $prefix:interwiki prefix we are looking for. & $iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InvalidateEmailComplete':Called after a user 's email has been invalidated successfully. $user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification. Callee may modify $url and $query, URL will be constructed as $url . $query & $url:URL to index.php & $query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) & $article:article(object) being checked 'IsTrustedProxy':Override the result of IP::isTrustedProxy() & $ip:IP being check & $result:Change this value to override the result of IP::isTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from & $allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of Sanitizer::validateEmail(), for instance to return false if the domain name doesn 't match your organization. $addr:The e-mail address entered by the user & $result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user & $result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we 're looking for a messages file for & $file:The messages file path, you can override this to change the location. 'LanguageGetMagic':DEPRECATED! Use $magicWords in a file listed in $wgExtensionMessagesFiles instead. Use this to define synonyms of magic words depending of the language & $magicExtensions:associative array of magic words synonyms $lang:language code(string) 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces. Do not use this hook to add namespaces. Use CanonicalNamespaces for that. & $namespaces:Array of namespaces indexed by their numbers 'LanguageGetSpecialPageAliases':DEPRECATED! Use $specialPageAliases in a file listed in $wgExtensionMessagesFiles instead. Use to define aliases of special pages names depending of the language & $specialPageAliases:associative array of magic words synonyms $lang:language code(string) 'LanguageGetTranslatedLanguageNames':Provide translated language names. & $names:array of language code=> language name $code:language of the preferred translations 'LanguageLinks':Manipulate a page 's language links. This is called in various places to allow extensions to define the effective language links for a page. $title:The page 's Title. & $links:Array with elements of the form "language:title" in the order that they will be output. & $linkFlags:Associative array mapping prefixed links to arrays of flags. Currently unused, but planned to provide support for marking individual language links in the UI, e.g. for featured articles. 'LanguageSelector':Hook to change the language selector available on a page. $out:The output page. $cssClassName:CSS class name of the language selector. 'LinkBegin':DEPRECATED! Use HtmlPageLinkRendererBegin instead. Used when generating internal and interwiki links in Linker::link(), before processing starts. Return false to skip default processing and return $ret. See documentation for Linker::link() for details on the expected meanings of parameters. $skin:the Skin object $target:the Title that the link is pointing to & $html:the contents that the< a > tag should have(raw HTML) $result
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist and Watchlist you will want to construct new ChangesListBooleanFilter or ChangesListStringOptionsFilter objects When constructing you specify which group they belong to You can reuse existing or create your you must register them with $special registerFilterGroup removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set $status
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account $user
static addUpdate(DeferrableUpdate $update, $stage=self::POSTSEND)
Add an update to the deferred list to be run later by execute()
static newFatal( $message)
Factory function for fatal errors.
static listPagesByPrefix( $prefix)
List deleted pages recorded in the archive table matching the given title prefix.
wfReadOnly()
Check whether the wiki is in read-only mode.
static getRevisionText( $row, $prefix='old_', $wiki=false)
Get revision text associated with an old or archive row.
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
external whereas SearchGetNearMatch runs after $term
listFiles()
List the deleted file revisions for this page, if it's a file page.
static listPagesBySearch( $term)
List deleted pages recorded in the archive matching the given term, using search engine archive.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
isDeleted()
Quick check if any archived revisions are present for the page.
Generic operation result class Has warning/error list, boolean status and arbitrary value.
getDBkey()
Get the main part with underscores.
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
static listAllPages()
List all deleted pages recorded in the archive table.
getNamespace()
Get the namespace index, i.e.
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist and Watchlist you will want to construct new ChangesListBooleanFilter or ChangesListStringOptionsFilter objects When constructing you specify which group they belong to You can reuse existing or create your you must register them with $special registerFilterGroup removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content $content
undeleteRevisions( $timestamps, $unsuppress=false, $comment='')
This is the meaty bit – It restores archived revisions of the given page to the revision table.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached $page
listRevisions()
List the revisions of the given page.
the value to return A Title object or null for latest all implement SearchIndexField $engine
when a variable name is used in a it is silently declared as a new masking the global
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
Class to invalidate the HTML cache of all the pages linking to a given title.
getRevision( $timestamp)
Return a Revision object containing data for the deleted revision.
static newGood( $value=null)
Factory function for good results.
Represents a title within MediaWiki.
getLastRevisionText()
Fetch (and decompress if necessary) the stored text of the most recently edited deleted revision of t...
undelete( $timestamps, $comment='', $fileVersions=[], $unsuppress=false, User $user=null, $tags=null)
Restore the given (or all) text and file revisions for the page.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Using a hook running we can avoid having all this option specific stuff in our mainline code Using the function array $article
Class for creating log entries manually, to inject them into the database.
getTextFromRow( $row)
Get the text from an archive row containing ar_text, ar_flags and ar_text_id.
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock() - offset Set to overwrite offset parameter in $wgRequest set to '' to unset offset - wrap String Wrap the message in html(usually something like "<
static selectFields()
Fields in the filearchive table.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency MediaWikiServices
__construct( $title, Config $config=null)
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
wfLocalFile( $title)
Get an object referring to a locally registered file.
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
getText()
Get the text form (spaces not underscores) of the main part.
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist and Watchlist you will want to construct new ChangesListBooleanFilter or ChangesListStringOptionsFilter objects When constructing you specify which group they belong to You can reuse existing or create your you must register them with $special registerFilterGroup removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context $options
getPreviousRevision( $timestamp)
Return the most-previous revision, either live or deleted, against the deleted revision given by time...