MediaWiki REL1_33
HistoryAction.php
Go to the documentation of this file.
1<?php
27
39 const DIR_PREV = 0;
40 const DIR_NEXT = 1;
41
43 public $message;
44
45 public function getName() {
46 return 'history';
47 }
48
49 public function requiresWrite() {
50 return false;
51 }
52
53 public function requiresUnblock() {
54 return false;
55 }
56
57 protected function getPageTitle() {
58 return $this->msg( 'history-title', $this->getTitle()->getPrefixedText() )->text();
59 }
60
61 protected function getDescription() {
62 // Creation of a subtitle link pointing to [[Special:Log]]
63 $linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
64 $subtitle = $linkRenderer->makeKnownLink(
65 SpecialPage::getTitleFor( 'Log' ),
66 $this->msg( 'viewpagelogs' )->text(),
67 [],
68 [ 'page' => $this->getTitle()->getPrefixedText() ]
69 );
70
71 $links = [];
72 // Allow extensions to add more links
73 Hooks::run( 'HistoryPageToolLinks', [ $this->getContext(), $linkRenderer, &$links ] );
74 if ( $links ) {
75 $subtitle .= ''
76 . $this->msg( 'word-separator' )->escaped()
77 . $this->msg( 'parentheses' )
78 ->rawParams( $this->getLanguage()->pipeList( $links ) )
79 ->escaped();
80 }
81 return Html::rawElement( 'div', [ 'class' => 'mw-history-subtitle' ], $subtitle );
82 }
83
87 public function getArticle() {
88 return $this->page;
89 }
90
95 private function preCacheMessages() {
96 // Precache various messages
97 if ( !isset( $this->message ) ) {
98 $msgs = [ 'cur', 'last', 'pipe-separator' ];
99 foreach ( $msgs as $msg ) {
100 $this->message[$msg] = $this->msg( $msg )->escaped();
101 }
102 }
103 }
104
108 function onView() {
109 $out = $this->getOutput();
110 $request = $this->getRequest();
111
115 if ( $out->checkLastModified( $this->page->getTouched() ) ) {
116 return; // Client cache fresh and headers sent, nothing more to do.
117 }
118
119 $this->preCacheMessages();
120 $config = $this->context->getConfig();
121
122 # Fill in the file cache if not set already
123 if ( HTMLFileCache::useFileCache( $this->getContext() ) ) {
124 $cache = new HTMLFileCache( $this->getTitle(), 'history' );
125 if ( !$cache->isCacheGood( /* Assume up to date */ ) ) {
126 ob_start( [ &$cache, 'saveToFileCache' ] );
127 }
128 }
129
130 // Setup page variables.
131 $out->setFeedAppendQuery( 'action=history' );
132 $out->addModules( 'mediawiki.action.history' );
133 $out->addModuleStyles( [
134 'mediawiki.interface.helpers.styles',
135 'mediawiki.action.history.styles',
136 'mediawiki.special.changeslist',
137 ] );
138 if ( $config->get( 'UseMediaWikiUIEverywhere' ) ) {
139 $out = $this->getOutput();
140 $out->addModuleStyles( [
141 'mediawiki.ui.input',
142 'mediawiki.ui.checkbox',
143 ] );
144 }
145
146 // Handle atom/RSS feeds.
147 $feedType = $request->getVal( 'feed' );
148 if ( $feedType ) {
149 $this->feed( $feedType );
150
151 return;
152 }
153
154 $this->addHelpLink( '//meta.wikimedia.org/wiki/Special:MyLanguage/Help:Page_history', true );
155
156 // Fail nicely if article doesn't exist.
157 if ( !$this->page->exists() ) {
158 global $wgSend404Code;
159 if ( $wgSend404Code ) {
160 $out->setStatusCode( 404 );
161 }
162 $out->addWikiMsg( 'nohistory' );
163
165
166 # show deletion/move log if there is an entry
168 $out,
169 [ 'delete', 'move', 'protect' ],
170 $this->getTitle(),
171 '',
172 [ 'lim' => 10,
173 'conds' => [ 'log_action != ' . $dbr->addQuotes( 'revision' ) ],
174 'showIfEmpty' => false,
175 'msgKey' => [ 'moveddeleted-notice' ]
176 ]
177 );
178
179 return;
180 }
181
185 $year = $request->getInt( 'year' );
186 $month = $request->getInt( 'month' );
187 $tagFilter = $request->getVal( 'tagfilter' );
188 $tagSelector = ChangeTags::buildTagFilterSelector( $tagFilter, false, $this->getContext() );
189
193 if ( $request->getBool( 'deleted' ) ) {
194 $conds = [ 'rev_deleted != 0' ];
195 } else {
196 $conds = [];
197 }
198 if ( $this->getUser()->isAllowed( 'deletedhistory' ) ) {
199 $checkDeleted = Xml::checkLabel( $this->msg( 'history-show-deleted' )->text(),
200 'deleted', 'mw-show-deleted-only', $request->getBool( 'deleted' ) ) . "\n";
201 } else {
202 $checkDeleted = '';
203 }
204
205 // Add the general form
206 $action = htmlspecialchars( wfScript() );
207 $content = Html::hidden( 'title', $this->getTitle()->getPrefixedDBkey() ) . "\n";
208 $content .= Html::hidden( 'action', 'history' ) . "\n";
209 $content .= Xml::dateMenu(
210 ( $year == null ? MWTimestamp::getLocalInstance()->format( 'Y' ) : $year ),
211 $month
212 ) . "\u{00A0}";
213 $content .= $tagSelector ? ( implode( "\u{00A0}", $tagSelector ) . "\u{00A0}" ) : '';
214 $content .= $checkDeleted . Html::submitButton(
215 $this->msg( 'historyaction-submit' )->text(),
216 [],
217 [ 'mw-ui-progressive' ]
218 );
219 $out->addHTML(
220 "<form action=\"$action\" method=\"get\" id=\"mw-history-searchform\">" .
221 Xml::fieldset(
222 $this->msg( 'history-fieldset-title' )->text(),
223 $content,
224 [ 'id' => 'mw-history-search' ]
225 ) .
226 '</form>'
227 );
228
229 Hooks::run( 'PageHistoryBeforeList', [ &$this->page, $this->getContext() ] );
230
231 // Create and output the list.
232 $pager = new HistoryPager( $this, $year, $month, $tagFilter, $conds );
233 $out->addHTML(
234 $pager->getNavigationBar() .
235 $pager->getBody() .
236 $pager->getNavigationBar()
237 );
238 $out->preventClickjacking( $pager->getPreventClickjacking() );
239 }
240
251 function fetchRevisions( $limit, $offset, $direction ) {
252 // Fail if article doesn't exist.
253 if ( !$this->getTitle()->exists() ) {
254 return new FakeResultWrapper( [] );
255 }
256
258
259 if ( $direction === self::DIR_PREV ) {
260 list( $dirs, $oper ) = [ "ASC", ">=" ];
261 } else { /* $direction === self::DIR_NEXT */
262 list( $dirs, $oper ) = [ "DESC", "<=" ];
263 }
264
265 if ( $offset ) {
266 $offsets = [ "rev_timestamp $oper " . $dbr->addQuotes( $dbr->timestamp( $offset ) ) ];
267 } else {
268 $offsets = [];
269 }
270
271 $page_id = $this->page->getId();
272
274 return $dbr->select(
275 $revQuery['tables'],
276 $revQuery['fields'],
277 array_merge( [ 'rev_page' => $page_id ], $offsets ),
278 __METHOD__,
279 [
280 'ORDER BY' => "rev_timestamp $dirs",
281 'USE INDEX' => [ 'revision' => 'page_timestamp' ],
282 'LIMIT' => $limit
283 ],
284 $revQuery['joins']
285 );
286 }
287
293 function feed( $type ) {
295 return;
296 }
297 $request = $this->getRequest();
298
299 $feedClasses = $this->context->getConfig()->get( 'FeedClasses' );
301 $feed = new $feedClasses[$type](
302 $this->getTitle()->getPrefixedText() . ' - ' .
303 $this->msg( 'history-feed-title' )->inContentLanguage()->text(),
304 $this->msg( 'history-feed-description' )->inContentLanguage()->text(),
305 $this->getTitle()->getFullURL( 'action=history' )
306 );
307
308 // Get a limit on number of feed entries. Provide a sane default
309 // of 10 if none is defined (but limit to $wgFeedLimit max)
310 $limit = $request->getInt( 'limit', 10 );
311 $limit = min(
312 max( $limit, 1 ),
313 $this->context->getConfig()->get( 'FeedLimit' )
314 );
315
316 $items = $this->fetchRevisions( $limit, 0, self::DIR_NEXT );
317
318 // Generate feed elements enclosed between header and footer.
319 $feed->outHeader();
320 if ( $items->numRows() ) {
321 foreach ( $items as $row ) {
322 $feed->outItem( $this->feedItem( $row ) );
323 }
324 } else {
325 $feed->outItem( $this->feedEmpty() );
326 }
327 $feed->outFooter();
328 }
329
330 function feedEmpty() {
331 return new FeedItem(
332 $this->msg( 'nohistory' )->inContentLanguage()->text(),
333 $this->msg( 'history-feed-empty' )->inContentLanguage()->parseAsBlock(),
334 $this->getTitle()->getFullURL(),
335 wfTimestamp( TS_MW ),
336 '',
337 $this->getTitle()->getTalkPage()->getFullURL()
338 );
339 }
340
349 function feedItem( $row ) {
350 $rev = new Revision( $row, 0, $this->getTitle() );
351
353 $this->getTitle(),
354 $this->getTitle()->getPreviousRevisionID( $rev->getId() ),
355 $rev->getId(),
356 $rev->getTimestamp(),
357 $rev->getComment()
358 );
359 if ( $rev->getComment() == '' ) {
360 $contLang = MediaWikiServices::getInstance()->getContentLanguage();
361 $title = $this->msg( 'history-feed-item-nocomment',
362 $rev->getUserText(),
363 $contLang->timeanddate( $rev->getTimestamp() ),
364 $contLang->date( $rev->getTimestamp() ),
365 $contLang->time( $rev->getTimestamp() )
366 )->inContentLanguage()->text();
367 } else {
368 $title = $rev->getUserText() .
369 $this->msg( 'colon-separator' )->inContentLanguage()->text() .
370 FeedItem::stripComment( $rev->getComment() );
371 }
372
373 return new FeedItem(
374 $title,
375 $text,
376 $this->getTitle()->getFullURL( 'diff=' . $rev->getId() . '&oldid=prev' ),
377 $rev->getTimestamp(),
378 $rev->getUserText(),
379 $this->getTitle()->getTalkPage()->getFullURL()
380 );
381 }
382}
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
target page
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
$wgSend404Code
Some web hosts attempt to rewrite all responses with a 404 (not found) status code,...
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
wfScript( $script='index')
Get the path to a specified script file, respecting file extensions; this is a wrapper around $wgScri...
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
$page
Page on which we're performing the action.
Definition Action.php:46
addHelpLink( $to, $overrideBaseUrl=false)
Adds help link with an icon via page indicators.
Definition Action.php:394
getTitle()
Shortcut to get the Title object from the page.
Definition Action.php:247
getContext()
Get the IContextSource in use here.
Definition Action.php:179
getOutput()
Get the OutputPage being used for this instance.
Definition Action.php:208
msg( $key)
Get a Message object with context set Parameters are the same as wfMessage()
Definition Action.php:257
getUser()
Shortcut to get the User being used for this instance.
Definition Action.php:218
static exists( $name)
Check if a given action is recognised, even if it's disabled.
Definition Action.php:170
getLanguage()
Shortcut to get the user Language being used for this instance.
Definition Action.php:237
getRequest()
Get the WebRequest being used for this instance.
Definition Action.php:198
static buildTagFilterSelector( $selected='', $ooui=false, IContextSource $context=null)
Build a text box to select a change tag.
A base class for basic support for outputting syndication feeds in RSS and other formats.
Definition Feed.php:38
static stripComment( $text)
Quickie hack... strip out wikilinks to more legible form from the comment.
Definition Feed.php:223
static checkFeedOutput( $type)
Check whether feeds can be used and that $type is a valid feed type.
Definition FeedUtils.php:57
static formatDiffRow( $title, $oldid, $newid, $timestamp, $comment, $actiontext='')
Really format a diff for the newsfeed.
An action which just does something, without showing a form first.
Page view caching in the file system.
static useFileCache(IContextSource $context, $mode=self::MODE_NORMAL)
Check if pages can be cached for this request/user.
This class handles printing the history page for an article.
onView()
Print the history page for an article.
feed( $type)
Output a subscription feed listing recent edits to this page.
preCacheMessages()
As we use the same small set of messages in various methods and that they are called often,...
array $message
Array of message keys and strings.
getName()
Return the name of the action this object responds to.
requiresWrite()
Whether this action requires the wiki not to be locked.
getPageTitle()
Returns the name that goes in the <h1> page title.
fetchRevisions( $limit, $offset, $direction)
Fetch an array of revisions, specified by a given limit, offset and direction.
feedItem( $row)
Generate a FeedItem object from a given revision table row Borrows Recent Changes' feed generation fu...
getDescription()
Returns the description that goes below the <h1> tag.
requiresUnblock()
Whether this action can still be executed by a blocked user.
static showLogExtract(&$out, $types=[], $page='', $user='', $param=[])
Show log extract.
MediaWikiServices is the service locator for the application scope of MediaWiki.
static getQueryInfo( $options=[])
Return the tables, fields, and join conditions to be selected to create a new revision object.
Definition Revision.php:511
Overloads the relevant methods of the real ResultsWrapper so it doesn't go anywhere near an actual da...
Result wrapper for grabbing data queried from an IDatabase object.
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition deferred.txt:11
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
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on $request
Definition hooks.txt:2843
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:855
namespace and then decline to actually register it file or subcat img or subcat $title
Definition hooks.txt:955
if the prop value should be in the metadata multi language array format
Definition hooks.txt:1651
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 use $formDescriptor instead 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 message
Definition hooks.txt:2162
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:2054
presenting them properly to the user as errors is done by the caller return true use this to change the list i e etc $rev
Definition hooks.txt:1779
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:37
$cache
Definition mcc.php:33
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))
$content
const DB_REPLICA
Definition defines.php:25