MediaWiki  1.33.0
ImportReporter.php
Go to the documentation of this file.
1 <?php
22 
28  private $reason = false;
29  private $logTags = [];
30  private $mOriginalLogCallback = null;
31  private $mOriginalPageOutCallback = null;
32  private $mLogItemCount = 0;
33 
40  function __construct( $importer, $upload, $interwiki, $reason = false ) {
41  $this->mOriginalPageOutCallback =
42  $importer->setPageOutCallback( [ $this, 'reportPage' ] );
43  $this->mOriginalLogCallback =
44  $importer->setLogItemCallback( [ $this, 'reportLogItem' ] );
45  $importer->setNoticeCallback( [ $this, 'reportNotice' ] );
46  $this->mPageCount = 0;
47  $this->mIsUpload = $upload;
48  $this->mInterwiki = $interwiki;
49  $this->reason = $reason;
50  }
51 
58  public function setChangeTags( array $tags ) {
59  $this->logTags = $tags;
60  }
61 
62  function open() {
63  $this->getOutput()->addHTML( "<ul>\n" );
64  }
65 
66  function reportNotice( $msg, array $params ) {
67  $this->getOutput()->addHTML(
68  Html::element( 'li', [], $this->msg( $msg, $params )->text() )
69  );
70  }
71 
72  function reportLogItem( /* ... */ ) {
73  $this->mLogItemCount++;
74  if ( is_callable( $this->mOriginalLogCallback ) ) {
75  call_user_func_array( $this->mOriginalLogCallback, func_get_args() );
76  }
77  }
78 
87  public function reportPage( $title, $foreignTitle, $revisionCount,
88  $successCount, $pageInfo ) {
89  $args = func_get_args();
90  call_user_func_array( $this->mOriginalPageOutCallback, $args );
91 
92  if ( $title === null ) {
93  # Invalid or non-importable title; a notice is already displayed
94  return;
95  }
96 
97  $this->mPageCount++;
98  $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
99  if ( $successCount > 0 ) {
100  // <bdi> prevents jumbling of the versions count
101  // in RTL wikis in case the page title is LTR
102  $this->getOutput()->addHTML(
103  "<li>" . $linkRenderer->makeLink( $title ) . " " .
104  "<bdi>" .
105  $this->msg( 'import-revision-count' )->numParams( $successCount )->escaped() .
106  "</bdi>" .
107  "</li>\n"
108  );
109 
110  $logParams = [ '4:number:count' => $successCount ];
111  if ( $this->mIsUpload ) {
112  $detail = $this->msg( 'import-logentry-upload-detail' )->numParams(
113  $successCount )->inContentLanguage()->text();
114  $action = 'upload';
115  } else {
116  $pageTitle = $foreignTitle->getFullText();
117  $fullInterwikiPrefix = $this->mInterwiki;
118  Hooks::run( 'ImportLogInterwikiLink', [ &$fullInterwikiPrefix, &$pageTitle ] );
119 
120  $interwikiTitleStr = $fullInterwikiPrefix . ':' . $pageTitle;
121  $interwiki = '[[:' . $interwikiTitleStr . ']]';
122  $detail = $this->msg( 'import-logentry-interwiki-detail' )->numParams(
123  $successCount )->params( $interwiki )->inContentLanguage()->text();
124  $action = 'interwiki';
125  $logParams['5:title-link:interwiki'] = $interwikiTitleStr;
126  }
127  if ( $this->reason ) {
128  $detail .= $this->msg( 'colon-separator' )->inContentLanguage()->text()
129  . $this->reason;
130  }
131 
132  $comment = $detail; // quick
133  $dbw = wfGetDB( DB_MASTER );
134  $latest = $title->getLatestRevID();
135  $nullRevision = Revision::newNullRevision(
136  $dbw,
137  $title->getArticleID(),
138  $comment,
139  true,
140  $this->getUser()
141  );
142 
143  $nullRevId = null;
144  if ( !is_null( $nullRevision ) ) {
145  $nullRevId = $nullRevision->insertOn( $dbw );
146  $page = WikiPage::factory( $title );
147  # Update page record
148  $page->updateRevisionOn( $dbw, $nullRevision );
149  Hooks::run(
150  'NewRevisionFromEditComplete',
151  [ $page, $nullRevision, $latest, $this->getUser() ]
152  );
153  }
154 
155  // Create the import log entry
156  $logEntry = new ManualLogEntry( 'import', $action );
157  $logEntry->setTarget( $title );
158  $logEntry->setComment( $this->reason );
159  $logEntry->setPerformer( $this->getUser() );
160  $logEntry->setParameters( $logParams );
161  // Make sure the null revision will be tagged as well
162  $logEntry->setAssociatedRevId( $nullRevId );
163  if ( count( $this->logTags ) ) {
164  $logEntry->setTags( $this->logTags );
165  }
166  $logid = $logEntry->insert();
167  $logEntry->publish( $logid );
168  } else {
169  $this->getOutput()->addHTML( "<li>" . $linkRenderer->makeKnownLink( $title ) . " " .
170  $this->msg( 'import-nonewrevisions' )->escaped() . "</li>\n" );
171  }
172  }
173 
174  function close() {
175  $out = $this->getOutput();
176  if ( $this->mLogItemCount > 0 ) {
177  $msg = $this->msg( 'imported-log-entries' )->numParams( $this->mLogItemCount )->parse();
178  $out->addHTML( Xml::tags( 'li', null, $msg ) );
179  } elseif ( $this->mPageCount == 0 && $this->mLogItemCount == 0 ) {
180  $out->addHTML( "</ul>\n" );
181 
182  return Status::newFatal( 'importnopages' );
183  }
184  $out->addHTML( "</ul>\n" );
185 
186  return Status::newGood( $this->mPageCount );
187  }
188 }
captcha-old.count
count
Definition: captcha-old.py:249
ContextSource\msg
msg( $key)
Get a Message object with context set Parameters are the same as wfMessage()
Definition: ContextSource.php:168
ImportReporter\$mOriginalPageOutCallback
$mOriginalPageOutCallback
Definition: ImportReporter.php:31
$out
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not it can be in the form of< username >< more info > e g for bot passwords intended to be added to log contexts Fields it might only if the login was with a bot password it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out
Definition: hooks.txt:780
StatusValue\newFatal
static newFatal( $message)
Factory function for fatal errors.
Definition: StatusValue.php:68
$params
$params
Definition: styleTest.css.php:44
$linkRenderer
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing after in associative array form before processing starts Return false to skip default processing and return $ret $linkRenderer
Definition: hooks.txt:1985
ImportReporter
Reporting callback.
Definition: ImportReporter.php:27
ContextSource\getUser
getUser()
Definition: ContextSource.php:120
php
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
Definition: injection.txt:35
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:925
WikiPage\factory
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
Definition: WikiPage.php:138
ImportReporter\$logTags
$logTags
Definition: ImportReporter.php:29
ImportReporter\reportLogItem
reportLogItem()
Definition: ImportReporter.php:72
ImportReporter\reportPage
reportPage( $title, $foreignTitle, $revisionCount, $successCount, $pageInfo)
Definition: ImportReporter.php:87
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2636
ContextSource\getOutput
getOutput()
Definition: ContextSource.php:112
ContextSource
The simplest way of implementing IContextSource is to hold a RequestContext as a member variable and ...
Definition: ContextSource.php:29
use
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
Definition: MIT-LICENSE.txt:10
ImportReporter\__construct
__construct( $importer, $upload, $interwiki, $reason=false)
Definition: ImportReporter.php:40
DB_MASTER
const DB_MASTER
Definition: defines.php:26
array
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
ImportReporter\$mOriginalLogCallback
$mOriginalLogCallback
Definition: ImportReporter.php:30
ImportReporter\reportNotice
reportNotice( $msg, array $params)
Definition: ImportReporter.php:66
StatusValue\newGood
static newGood( $value=null)
Factory function for good results.
Definition: StatusValue.php:81
Xml\tags
static tags( $element, $attribs, $contents)
Same as Xml::element(), but does not escape contents.
Definition: Xml.php:130
ImportReporter\close
close()
Definition: ImportReporter.php:174
ImportReporter\$reason
$reason
Definition: ImportReporter.php:28
ImportReporter\$mLogItemCount
$mLogItemCount
Definition: ImportReporter.php:32
text
This list may contain false positives That usually means there is additional text with links below the first Each row contains links to the first and second as well as the first line of the second redirect text
Definition: All_system_messages.txt:1267
$args
if( $line===false) $args
Definition: cdb.php:64
reason
c Accompany it with the information you received as to the offer to distribute corresponding source complete source code means all the source code for all modules it plus any associated interface definition plus the scripts used to control compilation and installation of the executable as a special the source code distributed need not include anything that is normally and so on of the operating system on which the executable unless that component itself accompanies the executable If distribution of executable or object code is made by offering access to copy from a designated then offering equivalent access to copy the source code from the same place counts as distribution of the source even though third parties are not compelled to copy the source along with the object code You may not or distribute the Program except as expressly provided under this License Any attempt otherwise to sublicense or distribute the Program is and will automatically terminate your rights under this License parties who have received or from you under this License will not have their licenses terminated so long as such parties remain in full compliance You are not required to accept this since you have not signed it nothing else grants you permission to modify or distribute the Program or its derivative works These actions are prohibited by law if you do not accept this License by modifying or distributing the you indicate your acceptance of this License to do and all its terms and conditions for distributing or modifying the Program or works based on it Each time you redistribute the the recipient automatically receives a license from the original licensor to distribute or modify the Program subject to these terms and conditions You may not impose any further restrictions on the recipients exercise of the rights granted herein You are not responsible for enforcing compliance by third parties to this License as a consequence of a court judgment or allegation of patent infringement or for any other reason(not limited to patent issues)
ImportReporter\setChangeTags
setChangeTags(array $tags)
Sets change tags to apply to the import log entry and null revision.
Definition: ImportReporter.php:58
ManualLogEntry
Class for creating new log entries and inserting them into the database.
Definition: LogEntry.php:441
Revision\newNullRevision
static newNullRevision( $dbw, $pageId, $summary, $minor, $user=null)
Create a new null-revision for insertion into a page's history.
Definition: Revision.php:1198
ImportReporter\open
open()
Definition: ImportReporter.php:62
MediaWikiServices
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
Definition: injection.txt:23
Hooks\run
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:200