22 use MediaWiki\HookContainer\ProtectedHookAccessorTrait;
34 use ProtectedHookAccessorTrait;
37 private $logTags = [];
38 private $mOriginalLogCallback;
39 private $mOriginalPageOutCallback;
40 private $mLogItemCount = 0;
41 private $mPageCount = 0;
51 public function __construct( $importer, $upload, $interwiki, $reason =
"" ) {
52 $this->mOriginalPageOutCallback =
53 $importer->setPageOutCallback( [ $this,
'reportPage' ] );
54 $this->mOriginalLogCallback =
55 $importer->setLogItemCallback( [ $this,
'reportLogItem' ] );
56 $importer->setNoticeCallback( [ $this,
'reportNotice' ] );
57 $this->mIsUpload = $upload;
58 $this->mInterwiki = $interwiki;
59 $this->reason = is_string( $reason ) ? $reason :
"";
69 $this->logTags = $tags;
78 Html::element(
'li', [], $this->
msg( $msg, $params )->text() )
83 $this->mLogItemCount++;
84 if ( is_callable( $this->mOriginalLogCallback ) ) {
85 call_user_func_array( $this->mOriginalLogCallback, $args );
98 $successCount, $pageInfo ) {
99 call_user_func_array( $this->mOriginalPageOutCallback, func_get_args() );
101 if ( $pageIdentity ===
null ) {
102 # Invalid or non-importable title; a notice is already displayed
107 $services = MediaWikiServices::getInstance();
108 $linkRenderer = $services->getLinkRenderer();
109 if ( $successCount > 0 ) {
113 "<li>" . $linkRenderer->makeLink( $pageIdentity ) .
" " .
115 $this->msg(
'import-revision-count' )->numParams( $successCount )->escaped() .
120 $logParams = [
'4:number:count' => $successCount ];
121 if ( $this->mIsUpload ) {
122 $detail = $this->
msg(
'import-logentry-upload-detail' )->numParams(
123 $successCount )->inContentLanguage()->text();
126 $pageTitle = $foreignTitle->getFullText();
127 $fullInterwikiPrefix = $this->mInterwiki;
128 $this->getHookRunner()->onImportLogInterwikiLink(
129 $fullInterwikiPrefix, $pageTitle );
131 $interwikiTitleStr = $fullInterwikiPrefix .
':' . $pageTitle;
132 $interwiki =
'[[:' . $interwikiTitleStr .
']]';
133 $detail = $this->
msg(
'import-logentry-interwiki-detail' )->numParams(
134 $successCount )->params( $interwiki )->inContentLanguage()->text();
135 $action =
'interwiki';
136 $logParams[
'5:title-link:interwiki'] = $interwikiTitleStr;
138 if ( $this->reason ) {
139 $detail .= $this->
msg(
'colon-separator' )->inContentLanguage()->text()
143 $comment = CommentStoreComment::newUnsavedComment( $detail );
145 $revStore = $services->getRevisionStore();
146 $nullRevRecord = $revStore->newNullRevision(
155 if ( $nullRevRecord !==
null ) {
156 $inserted = $revStore->insertRevisionOn( $nullRevRecord, $dbw );
157 $nullRevId = $inserted->getId();
158 $parentRevId = $inserted->getParentId();
159 $page = $services->getWikiPageFactory()->newFromTitle( $pageIdentity );
162 $page->updateRevisionOn( $dbw, $inserted );
165 $this->getHookRunner()->onRevisionFromEditComplete(
166 $page, $inserted, $parentRevId, $this->
getUser(), $fakeTags
172 $logEntry->setTarget( $pageIdentity );
173 $logEntry->setComment( $this->reason );
174 $logEntry->setPerformer( $this->
getUser() );
175 $logEntry->setParameters( $logParams );
178 $logEntry->setAssociatedRevId( $nullRevId );
179 if ( count( $this->logTags ) ) {
180 $logEntry->addTags( $this->logTags );
182 $logid = $logEntry->insert();
183 $logEntry->publish( $logid );
185 $this->
getOutput()->addHTML(
"<li>" . $linkRenderer->makeKnownLink( $pageIdentity ) .
" " .
186 $this->msg(
'import-nonewrevisions' )->escaped() .
"</li>\n" );
192 if ( $this->mLogItemCount > 0 ) {
193 $msg = $this->
msg(
'imported-log-entries' )->numParams( $this->mLogItemCount )->parse();
194 $out->addHTML(
Xml::tags(
'li',
null, $msg ) );
195 } elseif ( $this->mPageCount == 0 && $this->mLogItemCount == 0 ) {
196 $out->addHTML(
"</ul>\n" );
198 return Status::newFatal(
'importnopages' );
200 $out->addHTML(
"</ul>\n" );
202 return Status::newGood( $this->mPageCount );
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
The simplest way of implementing IContextSource is to hold a RequestContext as a member variable and ...
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
reportNotice( $msg, array $params)
reportPage(?PageIdentity $pageIdentity, $foreignTitle, $revisionCount, $successCount, $pageInfo)
setChangeTags(array $tags)
Sets change tags to apply to the import log entry and null revision.
__construct( $importer, $upload, $interwiki, $reason="")
Class for creating new log entries and inserting them into the database.
static tags( $element, $attribs, $contents)
Same as Xml::element(), but does not escape contents.
Interface for objects (potentially) representing an editable wiki page.