Index: trunk/phase3/includes/PageHistory.php |
— | — | @@ -1,715 +0,0 @@ |
2 | | -<?php |
3 | | -/** |
4 | | - * Page history |
5 | | - * |
6 | | - * Split off from Article.php and Skin.php, 2003-12-22 |
7 | | - * @file |
8 | | - */ |
9 | | - |
10 | | -/** |
11 | | - * This class handles printing the history page for an article. In order to |
12 | | - * be efficient, it uses timestamps rather than offsets for paging, to avoid |
13 | | - * costly LIMIT,offset queries. |
14 | | - * |
15 | | - * Construct it by passing in an Article, and call $h->history() to print the |
16 | | - * history. |
17 | | - * |
18 | | - */ |
19 | | -class PageHistory { |
20 | | - const DIR_PREV = 0; |
21 | | - const DIR_NEXT = 1; |
22 | | - |
23 | | - var $mArticle, $mTitle, $mSkin; |
24 | | - var $lastdate; |
25 | | - var $linesonpage; |
26 | | - var $mLatestId = null; |
27 | | - |
28 | | - private $mOldIdChecked = 0; |
29 | | - |
30 | | - /** |
31 | | - * Construct a new PageHistory. |
32 | | - * |
33 | | - * @param Article $article |
34 | | - * @returns nothing |
35 | | - */ |
36 | | - function __construct( $article ) { |
37 | | - global $wgUser; |
38 | | - $this->mArticle =& $article; |
39 | | - $this->mTitle =& $article->mTitle; |
40 | | - $this->mSkin = $wgUser->getSkin(); |
41 | | - $this->preCacheMessages(); |
42 | | - } |
43 | | - |
44 | | - function getArticle() { |
45 | | - return $this->mArticle; |
46 | | - } |
47 | | - |
48 | | - function getTitle() { |
49 | | - return $this->mTitle; |
50 | | - } |
51 | | - |
52 | | - /** |
53 | | - * As we use the same small set of messages in various methods and that |
54 | | - * they are called often, we call them once and save them in $this->message |
55 | | - */ |
56 | | - function preCacheMessages() { |
57 | | - // Precache various messages |
58 | | - if( !isset( $this->message ) ) { |
59 | | - foreach( explode(' ', 'cur last rev-delundel' ) as $msg ) { |
60 | | - $this->message[$msg] = wfMsgExt( $msg, array( 'escape') ); |
61 | | - } |
62 | | - } |
63 | | - } |
64 | | - |
65 | | - /** |
66 | | - * Print the history page for an article. |
67 | | - * |
68 | | - * @returns nothing |
69 | | - */ |
70 | | - function history() { |
71 | | - global $wgOut, $wgRequest, $wgScript; |
72 | | - |
73 | | - /* |
74 | | - * Allow client caching. |
75 | | - */ |
76 | | - if( $wgOut->checkLastModified( $this->mArticle->getTouched() ) ) |
77 | | - return; // Client cache fresh and headers sent, nothing more to do. |
78 | | - |
79 | | - wfProfileIn( __METHOD__ ); |
80 | | - |
81 | | - /* |
82 | | - * Setup page variables. |
83 | | - */ |
84 | | - $wgOut->setPageTitle( wfMsg( 'history-title', $this->mTitle->getPrefixedText() ) ); |
85 | | - $wgOut->setPageTitleActionText( wfMsg( 'history_short' ) ); |
86 | | - $wgOut->setArticleFlag( false ); |
87 | | - $wgOut->setArticleRelated( true ); |
88 | | - $wgOut->setRobotPolicy( 'noindex,nofollow' ); |
89 | | - $wgOut->setSyndicated( true ); |
90 | | - $wgOut->setFeedAppendQuery( 'action=history' ); |
91 | | - $wgOut->addScriptFile( 'history.js' ); |
92 | | - |
93 | | - $logPage = SpecialPage::getTitleFor( 'Log' ); |
94 | | - $logLink = $this->mSkin->link( |
95 | | - $logPage, |
96 | | - wfMsgHtml( 'viewpagelogs' ), |
97 | | - array(), |
98 | | - array( 'page' => $this->mTitle->getPrefixedText() ), |
99 | | - array( 'known', 'noclasses' ) |
100 | | - ); |
101 | | - $wgOut->setSubtitle( $logLink ); |
102 | | - |
103 | | - $feedType = $wgRequest->getVal( 'feed' ); |
104 | | - if( $feedType ) { |
105 | | - wfProfileOut( __METHOD__ ); |
106 | | - return $this->feed( $feedType ); |
107 | | - } |
108 | | - |
109 | | - /* |
110 | | - * Fail if article doesn't exist. |
111 | | - */ |
112 | | - if( !$this->mTitle->exists() ) { |
113 | | - $wgOut->addWikiMsg( 'nohistory' ); |
114 | | - wfProfileOut( __METHOD__ ); |
115 | | - return; |
116 | | - } |
117 | | - |
118 | | - /** |
119 | | - * Add date selector to quickly get to a certain time |
120 | | - */ |
121 | | - $year = $wgRequest->getInt( 'year' ); |
122 | | - $month = $wgRequest->getInt( 'month' ); |
123 | | - $tagFilter = $wgRequest->getVal( 'tagfilter' ); |
124 | | - $tagSelector = ChangeTags::buildTagFilterSelector( $tagFilter ); |
125 | | - |
126 | | - $action = htmlspecialchars( $wgScript ); |
127 | | - $wgOut->addHTML( |
128 | | - "<form action=\"$action\" method=\"get\" id=\"mw-history-searchform\">" . |
129 | | - Xml::fieldset( wfMsg( 'history-fieldset-title' ), false, array( 'id' => 'mw-history-search' ) ) . |
130 | | - Xml::hidden( 'title', $this->mTitle->getPrefixedDBKey() ) . "\n" . |
131 | | - Xml::hidden( 'action', 'history' ) . "\n" . |
132 | | - xml::dateMenu( $year, $month ) . ' ' . |
133 | | - ( $tagSelector ? ( implode( ' ', $tagSelector ) . ' ' ) : '' ) . |
134 | | - Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . "\n" . |
135 | | - '</fieldset></form>' |
136 | | - ); |
137 | | - |
138 | | - wfRunHooks( 'PageHistoryBeforeList', array( &$this->mArticle ) ); |
139 | | - |
140 | | - /** |
141 | | - * Do the list |
142 | | - */ |
143 | | - $pager = new PageHistoryPager( $this, $year, $month, $tagFilter ); |
144 | | - $this->linesonpage = $pager->getNumRows(); |
145 | | - $wgOut->addHTML( |
146 | | - $pager->getNavigationBar() . |
147 | | - $this->beginHistoryList() . |
148 | | - $pager->getBody() . |
149 | | - $this->endHistoryList() . |
150 | | - $pager->getNavigationBar() |
151 | | - ); |
152 | | - |
153 | | - wfProfileOut( __METHOD__ ); |
154 | | - } |
155 | | - |
156 | | - /** |
157 | | - * Creates begin of history list with a submit button |
158 | | - * |
159 | | - * @return string HTML output |
160 | | - */ |
161 | | - function beginHistoryList() { |
162 | | - global $wgUser, $wgScript, $wgEnableHtmlDiff; |
163 | | - $this->lastdate = ''; |
164 | | - $s = wfMsgExt( 'histlegend', array( 'parse') ); |
165 | | - if( $this->linesonpage > 1 && $wgUser->isAllowed('deleterevision') ) { |
166 | | - $revdel = SpecialPage::getTitleFor( 'Revisiondelete' ); |
167 | | - $s .= Xml::openElement( 'form', |
168 | | - array( |
169 | | - 'action' => $revdel->getLocalURL( array( |
170 | | - 'type' => 'revision', |
171 | | - 'target' => $this->mTitle->getPrefixedDbKey() |
172 | | - ) ), |
173 | | - 'method' => 'post', |
174 | | - 'id' => 'mw-history-revdeleteform', |
175 | | - 'style' => 'visibility:hidden;float:right;' |
176 | | - ) |
177 | | - ); |
178 | | - $s .= Xml::hidden( 'ids', '', array('id'=>'revdel-oldid') ); |
179 | | - $s .= Xml::submitButton( wfMsg( 'showhideselectedversions' ) ); |
180 | | - $s .= Xml::closeElement( 'form' ); |
181 | | - } |
182 | | - $s .= Xml::openElement( 'form', array( 'action' => $wgScript, |
183 | | - 'id' => 'mw-history-compare' ) ); |
184 | | - $s .= Xml::hidden( 'title', $this->mTitle->getPrefixedDbKey() ); |
185 | | - if( $wgEnableHtmlDiff ) { |
186 | | - $s .= $this->submitButton( wfMsg( 'visualcomparison'), |
187 | | - array( |
188 | | - 'name' => 'htmldiff', |
189 | | - 'class' => 'historysubmit', |
190 | | - 'accesskey' => wfMsg( 'accesskey-visualcomparison' ), |
191 | | - 'title' => wfMsg( 'tooltip-compareselectedversions' ), |
192 | | - ) |
193 | | - ); |
194 | | - $s .= $this->submitButton( wfMsg( 'wikicodecomparison'), |
195 | | - array( |
196 | | - 'class' => 'historysubmit', |
197 | | - 'accesskey' => wfMsg( 'accesskey-compareselectedversions' ), |
198 | | - 'title' => wfMsg( 'tooltip-compareselectedversions' ), |
199 | | - ) |
200 | | - ); |
201 | | - } else { |
202 | | - $s .= $this->submitButton( wfMsg( 'compareselectedversions'), |
203 | | - array( |
204 | | - 'class' => 'historysubmit', |
205 | | - 'accesskey' => wfMsg( 'accesskey-compareselectedversions' ), |
206 | | - 'title' => wfMsg( 'tooltip-compareselectedversions' ), |
207 | | - ) |
208 | | - ); |
209 | | - } |
210 | | - $s .= '<ul id="pagehistory">' . "\n"; |
211 | | - return $s; |
212 | | - } |
213 | | - |
214 | | - /** |
215 | | - * Creates end of history list with a submit button |
216 | | - * |
217 | | - * @return string HTML output |
218 | | - */ |
219 | | - function endHistoryList() { |
220 | | - global $wgEnableHtmlDiff; |
221 | | - $s = '</ul>'; |
222 | | - if( $wgEnableHtmlDiff ) { |
223 | | - $s .= $this->submitButton( wfMsg( 'visualcomparison'), |
224 | | - array( |
225 | | - 'name' => 'htmldiff', |
226 | | - 'class' => 'historysubmit', |
227 | | - 'accesskey' => wfMsg( 'accesskey-visualcomparison' ), |
228 | | - 'title' => wfMsg( 'tooltip-compareselectedversions' ), |
229 | | - ) |
230 | | - ); |
231 | | - $s .= $this->submitButton( wfMsg( 'wikicodecomparison'), |
232 | | - array( |
233 | | - 'class' => 'historysubmit', |
234 | | - 'accesskey' => wfMsg( 'accesskey-compareselectedversions' ), |
235 | | - 'title' => wfMsg( 'tooltip-compareselectedversions' ), |
236 | | - ) |
237 | | - ); |
238 | | - } else { |
239 | | - $s .= $this->submitButton( wfMsg( 'compareselectedversions'), |
240 | | - array( |
241 | | - 'class' => 'historysubmit', |
242 | | - 'accesskey' => wfMsg( 'accesskey-compareselectedversions' ), |
243 | | - 'title' => wfMsg( 'tooltip-compareselectedversions' ), |
244 | | - ) |
245 | | - ); |
246 | | - } |
247 | | - $s .= '</form>'; |
248 | | - return $s; |
249 | | - } |
250 | | - |
251 | | - /** |
252 | | - * Creates a submit button |
253 | | - * |
254 | | - * @param array $attributes attributes |
255 | | - * @return string HTML output for the submit button |
256 | | - */ |
257 | | - function submitButton($message, $attributes = array() ) { |
258 | | - # Disable submit button if history has 1 revision only |
259 | | - if( $this->linesonpage > 1 ) { |
260 | | - return Xml::submitButton( $message , $attributes ); |
261 | | - } else { |
262 | | - return ''; |
263 | | - } |
264 | | - } |
265 | | - |
266 | | - /** |
267 | | - * Returns a row from the history printout. |
268 | | - * |
269 | | - * @todo document some more, and maybe clean up the code (some params redundant?) |
270 | | - * |
271 | | - * @param Row $row The database row corresponding to the previous line. |
272 | | - * @param mixed $next The database row corresponding to the next line. |
273 | | - * @param int $counter Apparently a counter of what row number we're at, counted from the top row = 1. |
274 | | - * @param $notificationtimestamp |
275 | | - * @param bool $latest Whether this row corresponds to the page's latest revision. |
276 | | - * @param bool $firstInList Whether this row corresponds to the first displayed on this history page. |
277 | | - * @return string HTML output for the row |
278 | | - */ |
279 | | - function historyLine( $row, $next, $counter = '', $notificationtimestamp = false, |
280 | | - $latest = false, $firstInList = false ) |
281 | | - { |
282 | | - global $wgUser, $wgLang; |
283 | | - $rev = new Revision( $row ); |
284 | | - $rev->setTitle( $this->mTitle ); |
285 | | - |
286 | | - $curlink = $this->curLink( $rev, $latest ); |
287 | | - $lastlink = $this->lastLink( $rev, $next, $counter ); |
288 | | - $arbitrary = $this->diffButtons( $rev, $firstInList, $counter ); |
289 | | - $link = $this->revLink( $rev ); |
290 | | - $classes = array(); |
291 | | - |
292 | | - $s = "($curlink) ($lastlink) $arbitrary"; |
293 | | - |
294 | | - if( $wgUser->isAllowed( 'deleterevision' ) ) { |
295 | | - // Hide JS by default for non-JS browsing |
296 | | - $hidden = array( 'style' => 'display:none' ); |
297 | | - // If revision was hidden from sysops |
298 | | - if( !$rev->userCan( Revision::DELETED_RESTRICTED ) ) { |
299 | | - $del = Xml::check( 'deleterevisions', false, |
300 | | - $hidden + array('disabled' => 'disabled') ); |
301 | | - $del .= Xml::tags( 'span', array( 'class'=>'mw-revdelundel-link' ), |
302 | | - '(' . $this->message['rev-delundel'] . ')' ); |
303 | | - // Otherwise, show the link... |
304 | | - } else { |
305 | | - $id = $rev->getId(); |
306 | | - $jsCall = "updateShowHideForm($id,this.checked)"; |
307 | | - $del = Xml::check( 'showhiderevisions', false, |
308 | | - $hidden + array( |
309 | | - 'onchange' => $jsCall, |
310 | | - 'id' => "mw-revdel-$id" ) ); |
311 | | - $query = array( |
312 | | - 'type' => 'revision', |
313 | | - 'target' => $this->mTitle->getPrefixedDbkey(), |
314 | | - 'ids' => $rev->getId() ); |
315 | | - $del .= $this->mSkin->revDeleteLink( $query, |
316 | | - $rev->isDeleted( Revision::DELETED_RESTRICTED ) ); |
317 | | - } |
318 | | - $s .= " $del "; |
319 | | - } |
320 | | - |
321 | | - $s .= " $link"; |
322 | | - $s .= " <span class='history-user'>" . $this->mSkin->revUserTools( $rev, true ) . "</span>"; |
323 | | - |
324 | | - if( $rev->isMinor() ) { |
325 | | - $s .= ' ' . ChangesList::flag( 'minor' ); |
326 | | - } |
327 | | - |
328 | | - if( !is_null( $size = $rev->getSize() ) && !$rev->isDeleted( Revision::DELETED_TEXT ) ) { |
329 | | - $s .= ' ' . $this->mSkin->formatRevisionSize( $size ); |
330 | | - } |
331 | | - |
332 | | - $s .= $this->mSkin->revComment( $rev, false, true ); |
333 | | - |
334 | | - if( $notificationtimestamp && ($row->rev_timestamp >= $notificationtimestamp) ) { |
335 | | - $s .= ' <span class="updatedmarker">' . wfMsgHtml( 'updatedmarker' ) . '</span>'; |
336 | | - } |
337 | | - |
338 | | - $tools = array(); |
339 | | - |
340 | | - if( !is_null( $next ) && is_object( $next ) ) { |
341 | | - if( $latest && $this->mTitle->userCan( 'rollback' ) && $this->mTitle->userCan( 'edit' ) ) { |
342 | | - $tools[] = '<span class="mw-rollback-link">'. |
343 | | - $this->mSkin->buildRollbackLink( $rev ).'</span>'; |
344 | | - } |
345 | | - |
346 | | - if( $this->mTitle->quickUserCan( 'edit' ) |
347 | | - && !$rev->isDeleted( Revision::DELETED_TEXT ) |
348 | | - && !$next->rev_deleted & Revision::DELETED_TEXT ) |
349 | | - { |
350 | | - # Create undo tooltip for the first (=latest) line only |
351 | | - $undoTooltip = $latest |
352 | | - ? array( 'title' => wfMsg( 'tooltip-undo' ) ) |
353 | | - : array(); |
354 | | - $undolink = $this->mSkin->link( |
355 | | - $this->mTitle, |
356 | | - wfMsgHtml( 'editundo' ), |
357 | | - $undoTooltip, |
358 | | - array( 'action' => 'edit', 'undoafter' => $next->rev_id, 'undo' => $rev->getId() ), |
359 | | - array( 'known', 'noclasses' ) |
360 | | - ); |
361 | | - $tools[] = "<span class=\"mw-history-undo\">{$undolink}</span>"; |
362 | | - } |
363 | | - } |
364 | | - |
365 | | - if( $tools ) { |
366 | | - $s .= ' (' . $wgLang->pipeList( $tools ) . ')'; |
367 | | - } |
368 | | - |
369 | | - # Tags |
370 | | - list($tagSummary, $newClasses) = ChangeTags::formatSummaryRow( $row->ts_tags, 'history' ); |
371 | | - $classes = array_merge( $classes, $newClasses ); |
372 | | - $s .= " $tagSummary"; |
373 | | - |
374 | | - wfRunHooks( 'PageHistoryLineEnding', array( $this, &$row , &$s ) ); |
375 | | - |
376 | | - $classes = implode( ' ', $classes ); |
377 | | - |
378 | | - return "<li class=\"$classes\">$s</li>\n"; |
379 | | - } |
380 | | - |
381 | | - /** |
382 | | - * Create a link to view this revision of the page |
383 | | - * @param Revision $rev |
384 | | - * @returns string |
385 | | - */ |
386 | | - function revLink( $rev ) { |
387 | | - global $wgLang; |
388 | | - $date = $wgLang->timeanddate( wfTimestamp(TS_MW, $rev->getTimestamp()), true ); |
389 | | - $date = htmlspecialchars( $date ); |
390 | | - if( !$rev->isDeleted( Revision::DELETED_TEXT ) ) { |
391 | | - $link = $this->mSkin->link( |
392 | | - $this->mTitle, |
393 | | - $date, |
394 | | - array(), |
395 | | - array( 'oldid' => $rev->getId() ), |
396 | | - array( 'known', 'noclasses' ) |
397 | | - ); |
398 | | - } else { |
399 | | - $link = "<span class=\"history-deleted\">$date</span>"; |
400 | | - } |
401 | | - return $link; |
402 | | - } |
403 | | - |
404 | | - /** |
405 | | - * Create a diff-to-current link for this revision for this page |
406 | | - * @param Revision $rev |
407 | | - * @param Bool $latest, this is the latest revision of the page? |
408 | | - * @returns string |
409 | | - */ |
410 | | - function curLink( $rev, $latest ) { |
411 | | - $cur = $this->message['cur']; |
412 | | - if( $latest || !$rev->userCan( Revision::DELETED_TEXT ) ) { |
413 | | - return $cur; |
414 | | - } else { |
415 | | - return $this->mSkin->link( |
416 | | - $this->mTitle, |
417 | | - $cur, |
418 | | - array(), |
419 | | - array( |
420 | | - 'diff' => $this->mTitle->getLatestRevID(), |
421 | | - 'oldid' => $rev->getId() |
422 | | - ), |
423 | | - array( 'known', 'noclasses' ) |
424 | | - ); |
425 | | - } |
426 | | - } |
427 | | - |
428 | | - /** |
429 | | - * Create a diff-to-previous link for this revision for this page. |
430 | | - * @param Revision $prevRev, the previous revision |
431 | | - * @param mixed $next, the newer revision |
432 | | - * @param int $counter, what row on the history list this is |
433 | | - * @returns string |
434 | | - */ |
435 | | - function lastLink( $prevRev, $next, $counter ) { |
436 | | - $last = $this->message['last']; |
437 | | - # $next may either be a Row, null, or "unkown" |
438 | | - $nextRev = is_object($next) ? new Revision( $next ) : $next; |
439 | | - if( is_null($next) ) { |
440 | | - # Probably no next row |
441 | | - return $last; |
442 | | - } elseif( $next === 'unknown' ) { |
443 | | - # Next row probably exists but is unknown, use an oldid=prev link |
444 | | - return $this->mSkin->link( |
445 | | - $this->mTitle, |
446 | | - $last, |
447 | | - array(), |
448 | | - array( |
449 | | - 'diff' => $prevRev->getId(), |
450 | | - 'oldid' => 'prev' |
451 | | - ), |
452 | | - array( 'known', 'noclasses' ) |
453 | | - ); |
454 | | - } elseif( !$prevRev->userCan(Revision::DELETED_TEXT) || !$nextRev->userCan(Revision::DELETED_TEXT) ) { |
455 | | - return $last; |
456 | | - } else { |
457 | | - return $this->mSkin->link( |
458 | | - $this->mTitle, |
459 | | - $last, |
460 | | - array(), |
461 | | - array( |
462 | | - 'diff' => $prevRev->getId(), |
463 | | - 'oldid' => $next->rev_id |
464 | | - ), |
465 | | - array( 'known', 'noclasses' ) |
466 | | - ); |
467 | | - } |
468 | | - } |
469 | | - |
470 | | - /** |
471 | | - * Create radio buttons for page history |
472 | | - * |
473 | | - * @param object $rev Revision |
474 | | - * @param bool $firstInList Is this version the first one? |
475 | | - * @param int $counter A counter of what row number we're at, counted from the top row = 1. |
476 | | - * @return string HTML output for the radio buttons |
477 | | - */ |
478 | | - function diffButtons( $rev, $firstInList, $counter ) { |
479 | | - if( $this->linesonpage > 1 ) { |
480 | | - $id = $rev->getId(); |
481 | | - $radio = array( 'type' => 'radio', 'value' => $id ); |
482 | | - /** @todo: move title texts to javascript */ |
483 | | - if( $firstInList ) { |
484 | | - $first = Xml::element( 'input', |
485 | | - array_merge( $radio, array( |
486 | | - 'style' => 'visibility:hidden', |
487 | | - 'name' => 'oldid', |
488 | | - 'id' => 'mw-oldid-null' ) ) |
489 | | - ); |
490 | | - $checkmark = array( 'checked' => 'checked' ); |
491 | | - } else { |
492 | | - # Check visibility of old revisions |
493 | | - if( !$rev->userCan( Revision::DELETED_TEXT ) ) { |
494 | | - $radio['disabled'] = 'disabled'; |
495 | | - $checkmark = array(); // We will check the next possible one |
496 | | - } else if( $counter == 2 || !$this->mOldIdChecked ) { |
497 | | - $checkmark = array( 'checked' => 'checked' ); |
498 | | - $this->mOldIdChecked = $id; |
499 | | - } else { |
500 | | - $checkmark = array(); |
501 | | - } |
502 | | - $first = Xml::element( 'input', |
503 | | - array_merge( $radio, $checkmark, array( |
504 | | - 'name' => 'oldid', |
505 | | - 'id' => "mw-oldid-$id" ) ) ); |
506 | | - $checkmark = array(); |
507 | | - } |
508 | | - $second = Xml::element( 'input', |
509 | | - array_merge( $radio, $checkmark, array( |
510 | | - 'name' => 'diff', |
511 | | - 'id' => "mw-diff-$id" ) ) ); |
512 | | - return $first . $second; |
513 | | - } else { |
514 | | - return ''; |
515 | | - } |
516 | | - } |
517 | | - |
518 | | - /** |
519 | | - * Fetch an array of revisions, specified by a given limit, offset and |
520 | | - * direction. This is now only used by the feeds. It was previously |
521 | | - * used by the main UI but that's now handled by the pager. |
522 | | - */ |
523 | | - function fetchRevisions($limit, $offset, $direction) { |
524 | | - $dbr = wfGetDB( DB_SLAVE ); |
525 | | - |
526 | | - if( $direction == PageHistory::DIR_PREV ) |
527 | | - list($dirs, $oper) = array("ASC", ">="); |
528 | | - else /* $direction == PageHistory::DIR_NEXT */ |
529 | | - list($dirs, $oper) = array("DESC", "<="); |
530 | | - |
531 | | - if( $offset ) |
532 | | - $offsets = array("rev_timestamp $oper '$offset'"); |
533 | | - else |
534 | | - $offsets = array(); |
535 | | - |
536 | | - $page_id = $this->mTitle->getArticleID(); |
537 | | - |
538 | | - return $dbr->select( 'revision', |
539 | | - Revision::selectFields(), |
540 | | - array_merge(array("rev_page=$page_id"), $offsets), |
541 | | - __METHOD__, |
542 | | - array( 'ORDER BY' => "rev_timestamp $dirs", |
543 | | - 'USE INDEX' => 'page_timestamp', 'LIMIT' => $limit) |
544 | | - ); |
545 | | - } |
546 | | - |
547 | | - /** |
548 | | - * Output a subscription feed listing recent edits to this page. |
549 | | - * @param string $type |
550 | | - */ |
551 | | - function feed( $type ) { |
552 | | - global $wgFeedClasses, $wgRequest, $wgFeedLimit; |
553 | | - if( !FeedUtils::checkFeedOutput($type) ) { |
554 | | - return; |
555 | | - } |
556 | | - |
557 | | - $feed = new $wgFeedClasses[$type]( |
558 | | - $this->mTitle->getPrefixedText() . ' - ' . |
559 | | - wfMsgForContent( 'history-feed-title' ), |
560 | | - wfMsgForContent( 'history-feed-description' ), |
561 | | - $this->mTitle->getFullUrl( array( 'action' => 'history' ) ) |
562 | | - ); |
563 | | - |
564 | | - // Get a limit on number of feed entries. Provide a sane default |
565 | | - // of 10 if none is defined (but limit to $wgFeedLimit max) |
566 | | - $limit = $wgRequest->getInt( 'limit', 10 ); |
567 | | - if( $limit > $wgFeedLimit || $limit < 1 ) { |
568 | | - $limit = 10; |
569 | | - } |
570 | | - $items = $this->fetchRevisions($limit, 0, PageHistory::DIR_NEXT); |
571 | | - |
572 | | - $feed->outHeader(); |
573 | | - if( $items ) { |
574 | | - foreach( $items as $row ) { |
575 | | - $feed->outItem( $this->feedItem( $row ) ); |
576 | | - } |
577 | | - } else { |
578 | | - $feed->outItem( $this->feedEmpty() ); |
579 | | - } |
580 | | - $feed->outFooter(); |
581 | | - } |
582 | | - |
583 | | - function feedEmpty() { |
584 | | - global $wgOut; |
585 | | - return new FeedItem( |
586 | | - wfMsgForContent( 'nohistory' ), |
587 | | - $wgOut->parse( wfMsgForContent( 'history-feed-empty' ) ), |
588 | | - $this->mTitle->getFullUrl(), |
589 | | - wfTimestamp( TS_MW ), |
590 | | - '', |
591 | | - $this->mTitle->getTalkPage()->getFullUrl() |
592 | | - ); |
593 | | - } |
594 | | - |
595 | | - /** |
596 | | - * Generate a FeedItem object from a given revision table row |
597 | | - * Borrows Recent Changes' feed generation functions for formatting; |
598 | | - * includes a diff to the previous revision (if any). |
599 | | - * |
600 | | - * @param $row |
601 | | - * @return FeedItem |
602 | | - */ |
603 | | - function feedItem( $row ) { |
604 | | - $rev = new Revision( $row ); |
605 | | - $rev->setTitle( $this->mTitle ); |
606 | | - $text = FeedUtils::formatDiffRow( |
607 | | - $this->mTitle, |
608 | | - $this->mTitle->getPreviousRevisionID( $rev->getId() ), |
609 | | - $rev->getId(), |
610 | | - $rev->getTimestamp(), |
611 | | - $rev->getComment() |
612 | | - ); |
613 | | - if( $rev->getComment() == '' ) { |
614 | | - global $wgContLang; |
615 | | - $ts = $rev->getTimestamp(); |
616 | | - $title = wfMsgForContent( 'history-feed-item-nocomment', |
617 | | - $rev->getUserText(), |
618 | | - $wgContLang->timeanddate( $ts ), |
619 | | - $wgContLang->date( $ts ), |
620 | | - $wgContLang->time( $ts ) ); |
621 | | - } else { |
622 | | - $title = $rev->getUserText() . wfMsgForContent( 'colon-separator' ) . |
623 | | - FeedItem::stripComment( $rev->getComment() ); |
624 | | - } |
625 | | - return new FeedItem( |
626 | | - $title, |
627 | | - $text, |
628 | | - $this->mTitle->getFullUrl( array( |
629 | | - 'diff' => $rev->getId(), |
630 | | - 'oldid' => 'prev' |
631 | | - ) ), |
632 | | - $rev->getTimestamp(), |
633 | | - $rev->getUserText(), |
634 | | - $this->mTitle->getTalkPage()->getFullUrl() |
635 | | - ); |
636 | | - } |
637 | | -} |
638 | | - |
639 | | -/** |
640 | | - * @ingroup Pager |
641 | | - */ |
642 | | -class PageHistoryPager extends ReverseChronologicalPager { |
643 | | - public $mLastRow = false, $mPageHistory, $mTitle; |
644 | | - |
645 | | - function __construct( $pageHistory, $year='', $month='', $tagFilter = '' ) { |
646 | | - parent::__construct(); |
647 | | - $this->mPageHistory = $pageHistory; |
648 | | - $this->mTitle =& $this->mPageHistory->mTitle; |
649 | | - $this->tagFilter = $tagFilter; |
650 | | - $this->getDateCond( $year, $month ); |
651 | | - } |
652 | | - |
653 | | - function getQueryInfo() { |
654 | | - $queryInfo = array( |
655 | | - 'tables' => array('revision'), |
656 | | - 'fields' => array_merge( Revision::selectFields(), array('ts_tags') ), |
657 | | - 'conds' => array('rev_page' => $this->mPageHistory->mTitle->getArticleID() ), |
658 | | - 'options' => array( 'USE INDEX' => array('revision' => 'page_timestamp') ), |
659 | | - 'join_conds' => array( 'tag_summary' => array( 'LEFT JOIN', 'ts_rev_id=rev_id' ) ), |
660 | | - ); |
661 | | - ChangeTags::modifyDisplayQuery( $queryInfo['tables'], |
662 | | - $queryInfo['fields'], |
663 | | - $queryInfo['conds'], |
664 | | - $queryInfo['join_conds'], |
665 | | - $queryInfo['options'], |
666 | | - $this->tagFilter ); |
667 | | - wfRunHooks( 'PageHistoryPager::getQueryInfo', array( &$this, &$queryInfo ) ); |
668 | | - return $queryInfo; |
669 | | - } |
670 | | - |
671 | | - function getIndexField() { |
672 | | - return 'rev_timestamp'; |
673 | | - } |
674 | | - |
675 | | - function formatRow( $row ) { |
676 | | - if( $this->mLastRow ) { |
677 | | - $latest = $this->mCounter == 1 && $this->mIsFirst; |
678 | | - $firstInList = $this->mCounter == 1; |
679 | | - $s = $this->mPageHistory->historyLine( $this->mLastRow, $row, $this->mCounter++, |
680 | | - $this->mTitle->getNotificationTimestamp(), $latest, $firstInList ); |
681 | | - } else { |
682 | | - $s = ''; |
683 | | - } |
684 | | - $this->mLastRow = $row; |
685 | | - return $s; |
686 | | - } |
687 | | - |
688 | | - function getStartBody() { |
689 | | - $this->mLastRow = false; |
690 | | - $this->mCounter = 1; |
691 | | - return ''; |
692 | | - } |
693 | | - |
694 | | - function getEndBody() { |
695 | | - if( $this->mLastRow ) { |
696 | | - $latest = $this->mCounter == 1 && $this->mIsFirst; |
697 | | - $firstInList = $this->mCounter == 1; |
698 | | - if( $this->mIsBackwards ) { |
699 | | - # Next row is unknown, but for UI reasons, probably exists if an offset has been specified |
700 | | - if( $this->mOffset == '' ) { |
701 | | - $next = null; |
702 | | - } else { |
703 | | - $next = 'unknown'; |
704 | | - } |
705 | | - } else { |
706 | | - # The next row is the past-the-end row |
707 | | - $next = $this->mPastTheEndRow; |
708 | | - } |
709 | | - $s = $this->mPageHistory->historyLine( $this->mLastRow, $next, $this->mCounter++, |
710 | | - $this->mTitle->getNotificationTimestamp(), $latest, $firstInList ); |
711 | | - } else { |
712 | | - $s = ''; |
713 | | - } |
714 | | - return $s; |
715 | | - } |
716 | | -} |
Index: trunk/phase3/includes/HistoryPage.php |
— | — | @@ -0,0 +1,699 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Page history |
| 5 | + * |
| 6 | + * Split off from Article.php and Skin.php, 2003-12-22 |
| 7 | + * @file |
| 8 | + */ |
| 9 | + |
| 10 | +/** |
| 11 | + * This class handles printing the history page for an article. In order to |
| 12 | + * be efficient, it uses timestamps rather than offsets for paging, to avoid |
| 13 | + * costly LIMIT,offset queries. |
| 14 | + * |
| 15 | + * Construct it by passing in an Article, and call $h->history() to print the |
| 16 | + * history. |
| 17 | + * |
| 18 | + */ |
| 19 | +class HistoryPage { |
| 20 | + const DIR_PREV = 0; |
| 21 | + const DIR_NEXT = 1; |
| 22 | + |
| 23 | + var $article, $title, $skin; |
| 24 | + |
| 25 | + /** |
| 26 | + * Construct a new HistoryPage. |
| 27 | + * |
| 28 | + * @param Article $article |
| 29 | + * @returns nothing |
| 30 | + */ |
| 31 | + function __construct( $article ) { |
| 32 | + global $wgUser; |
| 33 | + $this->article =& $article; |
| 34 | + $this->title =& $article->getTitle(); |
| 35 | + $this->skin = $wgUser->getSkin(); |
| 36 | + $this->preCacheMessages(); |
| 37 | + } |
| 38 | + |
| 39 | + function getArticle() { |
| 40 | + return $this->article; |
| 41 | + } |
| 42 | + |
| 43 | + function getTitle() { |
| 44 | + return $this->title; |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * As we use the same small set of messages in various methods and that |
| 49 | + * they are called often, we call them once and save them in $this->message |
| 50 | + */ |
| 51 | + function preCacheMessages() { |
| 52 | + // Precache various messages |
| 53 | + if( !isset( $this->message ) ) { |
| 54 | + foreach( explode(' ', 'cur last rev-delundel' ) as $msg ) { |
| 55 | + $this->message[$msg] = wfMsgExt( $msg, array( 'escape') ); |
| 56 | + } |
| 57 | + } |
| 58 | + } |
| 59 | + |
| 60 | + /** |
| 61 | + * Print the history page for an article. |
| 62 | + * |
| 63 | + * @returns nothing |
| 64 | + */ |
| 65 | + function history() { |
| 66 | + global $wgOut, $wgRequest, $wgScript; |
| 67 | + |
| 68 | + /* |
| 69 | + * Allow client caching. |
| 70 | + */ |
| 71 | + if( $wgOut->checkLastModified( $this->article->getTouched() ) ) |
| 72 | + return; // Client cache fresh and headers sent, nothing more to do. |
| 73 | + |
| 74 | + wfProfileIn( __METHOD__ ); |
| 75 | + |
| 76 | + /* |
| 77 | + * Setup page variables. |
| 78 | + */ |
| 79 | + $wgOut->setPageTitle( wfMsg( 'history-title', $this->title->getPrefixedText() ) ); |
| 80 | + $wgOut->setPageTitleActionText( wfMsg( 'history_short' ) ); |
| 81 | + $wgOut->setArticleFlag( false ); |
| 82 | + $wgOut->setArticleRelated( true ); |
| 83 | + $wgOut->setRobotPolicy( 'noindex,nofollow' ); |
| 84 | + $wgOut->setSyndicated( true ); |
| 85 | + $wgOut->setFeedAppendQuery( 'action=history' ); |
| 86 | + $wgOut->addScriptFile( 'history.js' ); |
| 87 | + |
| 88 | + $logPage = SpecialPage::getTitleFor( 'Log' ); |
| 89 | + $logLink = $this->skin->link( |
| 90 | + $logPage, |
| 91 | + wfMsgHtml( 'viewpagelogs' ), |
| 92 | + array(), |
| 93 | + array( 'page' => $this->title->getPrefixedText() ), |
| 94 | + array( 'known', 'noclasses' ) |
| 95 | + ); |
| 96 | + $wgOut->setSubtitle( $logLink ); |
| 97 | + |
| 98 | + $feedType = $wgRequest->getVal( 'feed' ); |
| 99 | + if( $feedType ) { |
| 100 | + wfProfileOut( __METHOD__ ); |
| 101 | + return $this->feed( $feedType ); |
| 102 | + } |
| 103 | + |
| 104 | + /* |
| 105 | + * Fail if article doesn't exist. |
| 106 | + */ |
| 107 | + if( !$this->title->exists() ) { |
| 108 | + $wgOut->addWikiMsg( 'nohistory' ); |
| 109 | + wfProfileOut( __METHOD__ ); |
| 110 | + return; |
| 111 | + } |
| 112 | + |
| 113 | + /** |
| 114 | + * Add date selector to quickly get to a certain time |
| 115 | + */ |
| 116 | + $year = $wgRequest->getInt( 'year' ); |
| 117 | + $month = $wgRequest->getInt( 'month' ); |
| 118 | + $tagFilter = $wgRequest->getVal( 'tagfilter' ); |
| 119 | + $tagSelector = ChangeTags::buildTagFilterSelector( $tagFilter ); |
| 120 | + |
| 121 | + $action = htmlspecialchars( $wgScript ); |
| 122 | + $wgOut->addHTML( |
| 123 | + "<form action=\"$action\" method=\"get\" id=\"mw-history-searchform\">" . |
| 124 | + Xml::fieldset( wfMsg( 'history-fieldset-title' ), false, array( 'id' => 'mw-history-search' ) ) . |
| 125 | + Xml::hidden( 'title', $this->title->getPrefixedDBKey() ) . "\n" . |
| 126 | + Xml::hidden( 'action', 'history' ) . "\n" . |
| 127 | + xml::dateMenu( $year, $month ) . ' ' . |
| 128 | + ( $tagSelector ? ( implode( ' ', $tagSelector ) . ' ' ) : '' ) . |
| 129 | + Xml::submitButton( wfMsg( 'allpagessubmit' ) ) . "\n" . |
| 130 | + '</fieldset></form>' |
| 131 | + ); |
| 132 | + |
| 133 | + wfRunHooks( 'PageHistoryBeforeList', array( &$this->article ) ); |
| 134 | + |
| 135 | + /** |
| 136 | + * Do the list |
| 137 | + */ |
| 138 | + $pager = new HistoryPager( $this, $year, $month, $tagFilter ); |
| 139 | + $wgOut->addHTML( |
| 140 | + $pager->getNavigationBar() . |
| 141 | + $pager->getBody() . |
| 142 | + $pager->getNavigationBar() |
| 143 | + ); |
| 144 | + |
| 145 | + wfProfileOut( __METHOD__ ); |
| 146 | + } |
| 147 | + |
| 148 | + /** |
| 149 | + * Fetch an array of revisions, specified by a given limit, offset and |
| 150 | + * direction. This is now only used by the feeds. It was previously |
| 151 | + * used by the main UI but that's now handled by the pager. |
| 152 | + */ |
| 153 | + function fetchRevisions($limit, $offset, $direction) { |
| 154 | + $dbr = wfGetDB( DB_SLAVE ); |
| 155 | + |
| 156 | + if( $direction == HistoryPage::DIR_PREV ) |
| 157 | + list($dirs, $oper) = array("ASC", ">="); |
| 158 | + else /* $direction == HistoryPage::DIR_NEXT */ |
| 159 | + list($dirs, $oper) = array("DESC", "<="); |
| 160 | + |
| 161 | + if( $offset ) |
| 162 | + $offsets = array("rev_timestamp $oper '$offset'"); |
| 163 | + else |
| 164 | + $offsets = array(); |
| 165 | + |
| 166 | + $page_id = $this->title->getArticleID(); |
| 167 | + |
| 168 | + return $dbr->select( 'revision', |
| 169 | + Revision::selectFields(), |
| 170 | + array_merge(array("rev_page=$page_id"), $offsets), |
| 171 | + __METHOD__, |
| 172 | + array( 'ORDER BY' => "rev_timestamp $dirs", |
| 173 | + 'USE INDEX' => 'page_timestamp', 'LIMIT' => $limit) |
| 174 | + ); |
| 175 | + } |
| 176 | + |
| 177 | + /** |
| 178 | + * Output a subscription feed listing recent edits to this page. |
| 179 | + * @param string $type |
| 180 | + */ |
| 181 | + function feed( $type ) { |
| 182 | + global $wgFeedClasses, $wgRequest, $wgFeedLimit; |
| 183 | + if( !FeedUtils::checkFeedOutput($type) ) { |
| 184 | + return; |
| 185 | + } |
| 186 | + |
| 187 | + $feed = new $wgFeedClasses[$type]( |
| 188 | + $this->title->getPrefixedText() . ' - ' . |
| 189 | + wfMsgForContent( 'history-feed-title' ), |
| 190 | + wfMsgForContent( 'history-feed-description' ), |
| 191 | + $this->title->getFullUrl( 'action=history' ) ); |
| 192 | + |
| 193 | + // Get a limit on number of feed entries. Provide a sane default |
| 194 | + // of 10 if none is defined (but limit to $wgFeedLimit max) |
| 195 | + $limit = $wgRequest->getInt( 'limit', 10 ); |
| 196 | + if( $limit > $wgFeedLimit || $limit < 1 ) { |
| 197 | + $limit = 10; |
| 198 | + } |
| 199 | + $items = $this->fetchRevisions($limit, 0, HistoryPage::DIR_NEXT); |
| 200 | + |
| 201 | + $feed->outHeader(); |
| 202 | + if( $items ) { |
| 203 | + foreach( $items as $row ) { |
| 204 | + $feed->outItem( $this->feedItem( $row ) ); |
| 205 | + } |
| 206 | + } else { |
| 207 | + $feed->outItem( $this->feedEmpty() ); |
| 208 | + } |
| 209 | + $feed->outFooter(); |
| 210 | + } |
| 211 | + |
| 212 | + function feedEmpty() { |
| 213 | + global $wgOut; |
| 214 | + return new FeedItem( |
| 215 | + wfMsgForContent( 'nohistory' ), |
| 216 | + $wgOut->parse( wfMsgForContent( 'history-feed-empty' ) ), |
| 217 | + $this->title->getFullUrl(), |
| 218 | + wfTimestamp( TS_MW ), |
| 219 | + '', |
| 220 | + $this->title->getTalkPage()->getFullUrl() ); |
| 221 | + } |
| 222 | + |
| 223 | + /** |
| 224 | + * Generate a FeedItem object from a given revision table row |
| 225 | + * Borrows Recent Changes' feed generation functions for formatting; |
| 226 | + * includes a diff to the previous revision (if any). |
| 227 | + * |
| 228 | + * @param $row |
| 229 | + * @return FeedItem |
| 230 | + */ |
| 231 | + function feedItem( $row ) { |
| 232 | + $rev = new Revision( $row ); |
| 233 | + $rev->setTitle( $this->title ); |
| 234 | + $text = FeedUtils::formatDiffRow( $this->title, |
| 235 | + $this->title->getPreviousRevisionID( $rev->getId() ), |
| 236 | + $rev->getId(), |
| 237 | + $rev->getTimestamp(), |
| 238 | + $rev->getComment() ); |
| 239 | + |
| 240 | + if( $rev->getComment() == '' ) { |
| 241 | + global $wgContLang; |
| 242 | + $title = wfMsgForContent( 'history-feed-item-nocomment', |
| 243 | + $rev->getUserText(), |
| 244 | + $wgContLang->timeanddate( $rev->getTimestamp() ) ); |
| 245 | + } else { |
| 246 | + $title = $rev->getUserText() . wfMsgForContent( 'colon-separator' ) . FeedItem::stripComment( $rev->getComment() ); |
| 247 | + } |
| 248 | + |
| 249 | + return new FeedItem( |
| 250 | + $title, |
| 251 | + $text, |
| 252 | + $this->title->getFullUrl( 'diff=' . $rev->getId() . '&oldid=prev' ), |
| 253 | + $rev->getTimestamp(), |
| 254 | + $rev->getUserText(), |
| 255 | + $this->title->getTalkPage()->getFullUrl() ); |
| 256 | + } |
| 257 | +} |
| 258 | + |
| 259 | + |
| 260 | +/** |
| 261 | + * @ingroup Pager |
| 262 | + */ |
| 263 | +class HistoryPager extends ReverseChronologicalPager { |
| 264 | + public $lastRow = false, $counter, $historyPage, $title; |
| 265 | + protected $oldIdChecked; |
| 266 | + |
| 267 | + function __construct( $historyPage, $year='', $month='', $tagFilter = '' ) { |
| 268 | + parent::__construct(); |
| 269 | + $this->historyPage = $historyPage; |
| 270 | + $this->title = $this->historyPage->title; |
| 271 | + $this->tagFilter = $tagFilter; |
| 272 | + $this->getDateCond( $year, $month ); |
| 273 | + } |
| 274 | + |
| 275 | + function getQueryInfo() { |
| 276 | + $queryInfo = array( |
| 277 | + 'tables' => array('revision'), |
| 278 | + 'fields' => array_merge( Revision::selectFields(), array('ts_tags') ), |
| 279 | + 'conds' => array('rev_page' => $this->historyPage->title->getArticleID() ), |
| 280 | + 'options' => array( 'USE INDEX' => array('revision' => 'page_timestamp') ), |
| 281 | + 'join_conds' => array( 'tag_summary' => array( 'LEFT JOIN', 'ts_rev_id=rev_id' ) ), |
| 282 | + ); |
| 283 | + ChangeTags::modifyDisplayQuery( $queryInfo['tables'], |
| 284 | + $queryInfo['fields'], |
| 285 | + $queryInfo['conds'], |
| 286 | + $queryInfo['join_conds'], |
| 287 | + $queryInfo['options'], |
| 288 | + $this->tagFilter ); |
| 289 | + wfRunHooks( 'PageHistoryPager::getQueryInfo', array( &$this, &$queryInfo ) ); |
| 290 | + return $queryInfo; |
| 291 | + } |
| 292 | + |
| 293 | + function getIndexField() { |
| 294 | + return 'rev_timestamp'; |
| 295 | + } |
| 296 | + |
| 297 | + function formatRow( $row ) { |
| 298 | + if( $this->lastRow ) { |
| 299 | + $latest = $this->counter == 1 && $this->mIsFirst; |
| 300 | + $firstInList = $this->counter == 1; |
| 301 | + $s = $this->historyLine( $this->lastRow, $row, $this->counter++, |
| 302 | + $this->title->getNotificationTimestamp(), $latest, $firstInList ); |
| 303 | + } else { |
| 304 | + $s = ''; |
| 305 | + } |
| 306 | + $this->lastRow = $row; |
| 307 | + return $s; |
| 308 | + } |
| 309 | + |
| 310 | + /** |
| 311 | + * Creates begin of history list with a submit button |
| 312 | + * |
| 313 | + * @return string HTML output |
| 314 | + */ |
| 315 | + function getStartBody() { |
| 316 | + global $wgScript, $wgEnableHtmlDiff, $wgUser; |
| 317 | + $this->lastRow = false; |
| 318 | + $this->counter = 1; |
| 319 | + $this->oldIdChecked = 0; |
| 320 | + |
| 321 | + $s = wfMsgExt( 'histlegend', array( 'parse') ); |
| 322 | + if( $this->getNumRows() > 1 && $wgUser->isAllowed('deleterevision') ) { |
| 323 | + $revdel = SpecialPage::getTitleFor( 'Revisiondelete' ); |
| 324 | + $s .= Xml::openElement( 'form', |
| 325 | + array( |
| 326 | + 'action' => $revdel->getLocalURL( array( |
| 327 | + 'type' => 'revision', |
| 328 | + 'target' => $this->title->getPrefixedDbKey() |
| 329 | + ) ), |
| 330 | + 'method' => 'post', |
| 331 | + 'id' => 'mw-history-revdeleteform', |
| 332 | + 'style' => 'visibility:hidden;float:right;' |
| 333 | + ) |
| 334 | + ); |
| 335 | + $s .= Xml::hidden( 'ids', '', array('id'=>'revdel-oldid') ); |
| 336 | + $s .= Xml::submitButton( wfMsg( 'showhideselectedversions' ) ); |
| 337 | + $s .= Xml::closeElement( 'form' ); |
| 338 | + } |
| 339 | + $s .= Xml::openElement( 'form', array( 'action' => $wgScript, |
| 340 | + 'id' => 'mw-history-compare' ) ); |
| 341 | + $s .= Xml::hidden( 'title', $this->title->getPrefixedDbKey() ); |
| 342 | + if( $wgEnableHtmlDiff ) { |
| 343 | + $s .= $this->submitButton( wfMsg( 'visualcomparison'), |
| 344 | + array( |
| 345 | + 'name' => 'htmldiff', |
| 346 | + 'class' => 'historysubmit', |
| 347 | + 'accesskey' => wfMsg( 'accesskey-visualcomparison' ), |
| 348 | + 'title' => wfMsg( 'tooltip-compareselectedversions' ), |
| 349 | + ) |
| 350 | + ); |
| 351 | + $s .= $this->submitButton( wfMsg( 'wikicodecomparison'), |
| 352 | + array( |
| 353 | + 'class' => 'historysubmit', |
| 354 | + 'accesskey' => wfMsg( 'accesskey-compareselectedversions' ), |
| 355 | + 'title' => wfMsg( 'tooltip-compareselectedversions' ), |
| 356 | + ) |
| 357 | + ); |
| 358 | + } else { |
| 359 | + $s .= $this->submitButton( wfMsg( 'compareselectedversions'), |
| 360 | + array( |
| 361 | + 'class' => 'historysubmit', |
| 362 | + 'accesskey' => wfMsg( 'accesskey-compareselectedversions' ), |
| 363 | + 'title' => wfMsg( 'tooltip-compareselectedversions' ), |
| 364 | + ) |
| 365 | + ); |
| 366 | + } |
| 367 | + $s .= '<ul id="pagehistory">' . "\n"; |
| 368 | + return $s; |
| 369 | + } |
| 370 | + |
| 371 | + function getEndBody() { |
| 372 | + |
| 373 | + if( $this->lastRow ) { |
| 374 | + $latest = $this->counter == 1 && $this->mIsFirst; |
| 375 | + $firstInList = $this->counter == 1; |
| 376 | + if( $this->mIsBackwards ) { |
| 377 | + # Next row is unknown, but for UI reasons, probably exists if an offset has been specified |
| 378 | + if( $this->mOffset == '' ) { |
| 379 | + $next = null; |
| 380 | + } else { |
| 381 | + $next = 'unknown'; |
| 382 | + } |
| 383 | + } else { |
| 384 | + # The next row is the past-the-end row |
| 385 | + $next = $this->mPastTheEndRow; |
| 386 | + } |
| 387 | + $s = $this->historyLine( $this->lastRow, $next, $this->counter++, |
| 388 | + $this->title->getNotificationTimestamp(), $latest, $firstInList ); |
| 389 | + } else { |
| 390 | + $s = ''; |
| 391 | + } |
| 392 | + |
| 393 | + global $wgEnableHtmlDiff; |
| 394 | + $s .= '</ul>'; |
| 395 | + if( $wgEnableHtmlDiff ) { |
| 396 | + $s .= $this->submitButton( wfMsg( 'visualcomparison'), |
| 397 | + array( |
| 398 | + 'name' => 'htmldiff', |
| 399 | + 'class' => 'historysubmit', |
| 400 | + 'accesskey' => wfMsg( 'accesskey-visualcomparison' ), |
| 401 | + 'title' => wfMsg( 'tooltip-compareselectedversions' ), |
| 402 | + ) |
| 403 | + ); |
| 404 | + $s .= $this->submitButton( wfMsg( 'wikicodecomparison'), |
| 405 | + array( |
| 406 | + 'class' => 'historysubmit', |
| 407 | + 'accesskey' => wfMsg( 'accesskey-compareselectedversions' ), |
| 408 | + 'title' => wfMsg( 'tooltip-compareselectedversions' ), |
| 409 | + ) |
| 410 | + ); |
| 411 | + } else { |
| 412 | + $s .= $this->submitButton( wfMsg( 'compareselectedversions'), |
| 413 | + array( |
| 414 | + 'class' => 'historysubmit', |
| 415 | + 'accesskey' => wfMsg( 'accesskey-compareselectedversions' ), |
| 416 | + 'title' => wfMsg( 'tooltip-compareselectedversions' ), |
| 417 | + ) |
| 418 | + ); |
| 419 | + } |
| 420 | + $s .= '</form>'; |
| 421 | + return $s; |
| 422 | + } |
| 423 | + |
| 424 | + /** |
| 425 | + * Creates a submit button |
| 426 | + * |
| 427 | + * @param array $attributes attributes |
| 428 | + * @return string HTML output for the submit button |
| 429 | + */ |
| 430 | + function submitButton($message, $attributes = array() ) { |
| 431 | + # Disable submit button if history has 1 revision only |
| 432 | + if( $this->getNumRows() > 1 ) { |
| 433 | + return Xml::submitButton( $message , $attributes ); |
| 434 | + } else { |
| 435 | + return ''; |
| 436 | + } |
| 437 | + } |
| 438 | + |
| 439 | + /** |
| 440 | + * Returns a row from the history printout. |
| 441 | + * |
| 442 | + * @todo document some more, and maybe clean up the code (some params redundant?) |
| 443 | + * |
| 444 | + * @param Row $row The database row corresponding to the previous line. |
| 445 | + * @param mixed $next The database row corresponding to the next line. |
| 446 | + * @param int $counter Apparently a counter of what row number we're at, counted from the top row = 1. |
| 447 | + * @param $notificationtimestamp |
| 448 | + * @param bool $latest Whether this row corresponds to the page's latest revision. |
| 449 | + * @param bool $firstInList Whether this row corresponds to the first displayed on this history page. |
| 450 | + * @return string HTML output for the row |
| 451 | + */ |
| 452 | + function historyLine( $row, $next, $counter = '', $notificationtimestamp = false, |
| 453 | + $latest = false, $firstInList = false ) |
| 454 | + { |
| 455 | + global $wgUser, $wgLang; |
| 456 | + $rev = new Revision( $row ); |
| 457 | + $rev->setTitle( $this->title ); |
| 458 | + |
| 459 | + $curlink = $this->curLink( $rev, $latest ); |
| 460 | + $lastlink = $this->lastLink( $rev, $next, $counter ); |
| 461 | + $diffButtons = $this->diffButtons( $rev, $firstInList, $counter ); |
| 462 | + $link = $this->revLink( $rev ); |
| 463 | + $classes = array(); |
| 464 | + |
| 465 | + $s = "($curlink) ($lastlink) $diffButtons"; |
| 466 | + |
| 467 | + if( $wgUser->isAllowed( 'deleterevision' ) ) { |
| 468 | + // Hide JS by default for non-JS browsing |
| 469 | + $hidden = array( 'style' => 'display:none' ); |
| 470 | + // If revision was hidden from sysops |
| 471 | + if( !$rev->userCan( Revision::DELETED_RESTRICTED ) ) { |
| 472 | + $del = Xml::check( 'deleterevisions', false, |
| 473 | + $hidden + array('disabled' => 'disabled') ); |
| 474 | + $del .= Xml::tags( 'span', array( 'class'=>'mw-revdelundel-link' ), |
| 475 | + '(' . $this->historyPage->message['rev-delundel'] . ')' ); |
| 476 | + // Otherwise, show the link... |
| 477 | + } else { |
| 478 | + $id = $rev->getId(); |
| 479 | + $jsCall = "updateShowHideForm($id,this.checked)"; |
| 480 | + $del = Xml::check( 'showhiderevisions', false, |
| 481 | + $hidden + array( |
| 482 | + 'onchange' => $jsCall, |
| 483 | + 'id' => "mw-revdel-$id" ) ); |
| 484 | + $query = array( |
| 485 | + 'type' => 'revision', |
| 486 | + 'target' => $this->title->getPrefixedDbkey(), |
| 487 | + 'ids' => $rev->getId() ); |
| 488 | + $del .= $this->getSkin()->revDeleteLink( $query, |
| 489 | + $rev->isDeleted( Revision::DELETED_RESTRICTED ) ); |
| 490 | + } |
| 491 | + $s .= " $del "; |
| 492 | + } |
| 493 | + |
| 494 | + $s .= " $link"; |
| 495 | + $s .= " <span class='history-user'>" . $this->getSkin()->revUserTools( $rev, true ) . "</span>"; |
| 496 | + |
| 497 | + if( $rev->isMinor() ) { |
| 498 | + $s .= ' ' . ChangesList::flag( 'minor' ); |
| 499 | + } |
| 500 | + |
| 501 | + if( !is_null( $size = $rev->getSize() ) && !$rev->isDeleted( Revision::DELETED_TEXT ) ) { |
| 502 | + $s .= ' ' . $this->getSkin()->formatRevisionSize( $size ); |
| 503 | + } |
| 504 | + |
| 505 | + $s .= $this->getSkin()->revComment( $rev, false, true ); |
| 506 | + |
| 507 | + if( $notificationtimestamp && ($row->rev_timestamp >= $notificationtimestamp) ) { |
| 508 | + $s .= ' <span class="updatedmarker">' . wfMsgHtml( 'updatedmarker' ) . '</span>'; |
| 509 | + } |
| 510 | + |
| 511 | + $tools = array(); |
| 512 | + |
| 513 | + if( !is_null( $next ) && is_object( $next ) ) { |
| 514 | + if( $latest && $this->title->userCan( 'rollback' ) && $this->title->userCan( 'edit' ) ) { |
| 515 | + $tools[] = '<span class="mw-rollback-link">'. |
| 516 | + $this->getSkin()->buildRollbackLink( $rev ).'</span>'; |
| 517 | + } |
| 518 | + |
| 519 | + if( $this->title->quickUserCan( 'edit' ) |
| 520 | + && !$rev->isDeleted( Revision::DELETED_TEXT ) |
| 521 | + && !$next->rev_deleted & Revision::DELETED_TEXT ) |
| 522 | + { |
| 523 | + # Create undo tooltip for the first (=latest) line only |
| 524 | + $undoTooltip = $latest |
| 525 | + ? array( 'title' => wfMsg( 'tooltip-undo' ) ) |
| 526 | + : array(); |
| 527 | + $undolink = $this->getSkin()->link( |
| 528 | + $this->title, |
| 529 | + wfMsgHtml( 'editundo' ), |
| 530 | + $undoTooltip, |
| 531 | + array( 'action' => 'edit', 'undoafter' => $next->rev_id, 'undo' => $rev->getId() ), |
| 532 | + array( 'known', 'noclasses' ) |
| 533 | + ); |
| 534 | + $tools[] = "<span class=\"mw-history-undo\">{$undolink}</span>"; |
| 535 | + } |
| 536 | + } |
| 537 | + |
| 538 | + if( $tools ) { |
| 539 | + $s .= ' (' . $wgLang->pipeList( $tools ) . ')'; |
| 540 | + } |
| 541 | + |
| 542 | + # Tags |
| 543 | + list($tagSummary, $newClasses) = ChangeTags::formatSummaryRow( $row->ts_tags, 'history' ); |
| 544 | + $classes = array_merge( $classes, $newClasses ); |
| 545 | + $s .= " $tagSummary"; |
| 546 | + |
| 547 | + wfRunHooks( 'PageHistoryLineEnding', array( $this, &$row , &$s ) ); |
| 548 | + |
| 549 | + $attribs = array(); |
| 550 | + if ( $classes ) { |
| 551 | + $attribs['class'] = implode( ' ', $classes ); |
| 552 | + } |
| 553 | + |
| 554 | + return Xml::tags( 'li', $attribs, $s ) . "\n"; |
| 555 | + } |
| 556 | + |
| 557 | + /** |
| 558 | + * Create a link to view this revision of the page |
| 559 | + * @param Revision $rev |
| 560 | + * @returns string |
| 561 | + */ |
| 562 | + function revLink( $rev ) { |
| 563 | + global $wgLang; |
| 564 | + $date = $wgLang->timeanddate( wfTimestamp(TS_MW, $rev->getTimestamp()), true ); |
| 565 | + $date = htmlspecialchars( $date ); |
| 566 | + if( !$rev->isDeleted( Revision::DELETED_TEXT ) ) { |
| 567 | + $link = $this->getSkin()->link( |
| 568 | + $this->title, |
| 569 | + $date, |
| 570 | + array(), |
| 571 | + array( 'oldid' => $rev->getId() ), |
| 572 | + array( 'known', 'noclasses' ) |
| 573 | + ); |
| 574 | + } else { |
| 575 | + $link = "<span class=\"history-deleted\">$date</span>"; |
| 576 | + } |
| 577 | + return $link; |
| 578 | + } |
| 579 | + |
| 580 | + /** |
| 581 | + * Create a diff-to-current link for this revision for this page |
| 582 | + * @param Revision $rev |
| 583 | + * @param Bool $latest, this is the latest revision of the page? |
| 584 | + * @returns string |
| 585 | + */ |
| 586 | + function curLink( $rev, $latest ) { |
| 587 | + $cur = $this->historyPage->message['cur']; |
| 588 | + if( $latest || !$rev->userCan( Revision::DELETED_TEXT ) ) { |
| 589 | + return $cur; |
| 590 | + } else { |
| 591 | + return $this->getSkin()->link( |
| 592 | + $this->title, |
| 593 | + $cur, |
| 594 | + array(), |
| 595 | + array( |
| 596 | + 'diff' => $this->title->getLatestRevID(), |
| 597 | + 'oldid' => $rev->getId() |
| 598 | + ), |
| 599 | + array( 'known', 'noclasses' ) |
| 600 | + ); |
| 601 | + } |
| 602 | + } |
| 603 | + |
| 604 | + /** |
| 605 | + * Create a diff-to-previous link for this revision for this page. |
| 606 | + * @param Revision $prevRev, the previous revision |
| 607 | + * @param mixed $next, the newer revision |
| 608 | + * @param int $counter, what row on the history list this is |
| 609 | + * @returns string |
| 610 | + */ |
| 611 | + function lastLink( $prevRev, $next, $counter ) { |
| 612 | + $last = $this->historyPage->message['last']; |
| 613 | + # $next may either be a Row, null, or "unkown" |
| 614 | + $nextRev = is_object($next) ? new Revision( $next ) : $next; |
| 615 | + if( is_null($next) ) { |
| 616 | + # Probably no next row |
| 617 | + return $last; |
| 618 | + } elseif( $next === 'unknown' ) { |
| 619 | + # Next row probably exists but is unknown, use an oldid=prev link |
| 620 | + return $this->getSkin()->link( |
| 621 | + $this->title, |
| 622 | + $last, |
| 623 | + array(), |
| 624 | + array( |
| 625 | + 'diff' => $prevRev->getId(), |
| 626 | + 'oldid' => 'prev' |
| 627 | + ), |
| 628 | + array( 'known', 'noclasses' ) |
| 629 | + ); |
| 630 | + } elseif( !$prevRev->userCan(Revision::DELETED_TEXT) || !$nextRev->userCan(Revision::DELETED_TEXT) ) { |
| 631 | + return $last; |
| 632 | + } else { |
| 633 | + return $this->getSkin()->link( |
| 634 | + $this->title, |
| 635 | + $last, |
| 636 | + array(), |
| 637 | + array( |
| 638 | + 'diff' => $prevRev->getId(), |
| 639 | + 'oldid' => $next->rev_id |
| 640 | + ), |
| 641 | + array( 'known', 'noclasses' ) |
| 642 | + ); |
| 643 | + } |
| 644 | + } |
| 645 | + |
| 646 | + /** |
| 647 | + * Create radio buttons for page history |
| 648 | + * |
| 649 | + * @param object $rev Revision |
| 650 | + * @param bool $firstInList Is this version the first one? |
| 651 | + * @param int $counter A counter of what row number we're at, counted from the top row = 1. |
| 652 | + * @return string HTML output for the radio buttons |
| 653 | + */ |
| 654 | + function diffButtons( $rev, $firstInList, $counter ) { |
| 655 | + if( $this->getNumRows() > 1 ) { |
| 656 | + $id = $rev->getId(); |
| 657 | + $radio = array( 'type' => 'radio', 'value' => $id ); |
| 658 | + /** @todo: move title texts to javascript */ |
| 659 | + if( $firstInList ) { |
| 660 | + $first = Xml::element( 'input', |
| 661 | + array_merge( $radio, array( |
| 662 | + 'style' => 'visibility:hidden', |
| 663 | + 'name' => 'oldid', |
| 664 | + 'id' => 'mw-oldid-null' ) ) |
| 665 | + ); |
| 666 | + $checkmark = array( 'checked' => 'checked' ); |
| 667 | + } else { |
| 668 | + # Check visibility of old revisions |
| 669 | + if( !$rev->userCan( Revision::DELETED_TEXT ) ) { |
| 670 | + $radio['disabled'] = 'disabled'; |
| 671 | + $checkmark = array(); // We will check the next possible one |
| 672 | + } else if( $counter == 2 || !$this->oldIdChecked ) { |
| 673 | + $checkmark = array( 'checked' => 'checked' ); |
| 674 | + $this->oldIdChecked = $id; |
| 675 | + } else { |
| 676 | + $checkmark = array(); |
| 677 | + } |
| 678 | + $first = Xml::element( 'input', |
| 679 | + array_merge( $radio, $checkmark, array( |
| 680 | + 'name' => 'oldid', |
| 681 | + 'id' => "mw-oldid-$id" ) ) ); |
| 682 | + $checkmark = array(); |
| 683 | + } |
| 684 | + $second = Xml::element( 'input', |
| 685 | + array_merge( $radio, $checkmark, array( |
| 686 | + 'name' => 'diff', |
| 687 | + 'id' => "mw-diff-$id" ) ) ); |
| 688 | + return $first . $second; |
| 689 | + } else { |
| 690 | + return ''; |
| 691 | + } |
| 692 | + } |
| 693 | +} |
| 694 | + |
| 695 | +/** |
| 696 | + * Backwards-compatibility aliases |
| 697 | + */ |
| 698 | +class PageHistory extends HistoryPage {} |
| 699 | +class PageHistoryPager extends HistoryPager {} |
| 700 | + |
Property changes on: trunk/phase3/includes/HistoryPage.php |
___________________________________________________________________ |
Name: svn:mergeinfo |
1 | 701 | + /branches/REL1_15/phase3/includes/PageHistory.php:51646 |
Name: svn:eol-style |
2 | 702 | + native |
Name: svn:keywords |
3 | 703 | + Author Date Id Revision |
Index: trunk/phase3/includes/AutoLoader.php |
— | — | @@ -95,6 +95,8 @@ |
96 | 96 | 'HistoryBlobCurStub' => 'includes/HistoryBlob.php', |
97 | 97 | 'HistoryBlob' => 'includes/HistoryBlob.php', |
98 | 98 | 'HistoryBlobStub' => 'includes/HistoryBlob.php', |
| 99 | + 'HistoryPage' => 'includes/HistoryPage.php', |
| 100 | + 'HistoryPager' => 'includes/HistoryPage.php', |
99 | 101 | 'Html' => 'includes/Html.php', |
100 | 102 | 'HTMLCacheUpdate' => 'includes/HTMLCacheUpdate.php', |
101 | 103 | 'HTMLCacheUpdateJob' => 'includes/HTMLCacheUpdate.php', |
— | — | @@ -157,9 +159,9 @@ |
158 | 160 | 'Namespace' => 'includes/NamespaceCompat.php', // Compat |
159 | 161 | 'OldChangesList' => 'includes/ChangesList.php', |
160 | 162 | 'OutputPage' => 'includes/OutputPage.php', |
161 | | - 'PageHistory' => 'includes/PageHistory.php', |
162 | | - 'PageHistoryPager' => 'includes/PageHistory.php', |
163 | 163 | 'PageQueryPage' => 'includes/PageQueryPage.php', |
| 164 | + 'PageHistory' => 'includes/HistoryPage.php', |
| 165 | + 'PageHistoryPager' => 'includes/HistoryPage.php', |
164 | 166 | 'Pager' => 'includes/Pager.php', |
165 | 167 | 'PasswordError' => 'includes/User.php', |
166 | 168 | 'PatrolLog' => 'includes/PatrolLog.php', |
Index: trunk/phase3/includes/Wiki.php |
— | — | @@ -532,7 +532,7 @@ |
533 | 533 | if( $request->getFullRequestURL() == $title->getInternalURL( 'action=history' ) ) { |
534 | 534 | $output->setSquidMaxage( $this->getVal( 'SquidMaxage' ) ); |
535 | 535 | } |
536 | | - $history = new PageHistory( $article ); |
| 536 | + $history = new HistoryPage( $article ); |
537 | 537 | $history->history(); |
538 | 538 | break; |
539 | 539 | default: |
Index: trunk/phase3/includes/Pager.php |
— | — | @@ -50,7 +50,7 @@ |
51 | 51 | * last page depending on the dir parameter. |
52 | 52 | * |
53 | 53 | * Subclassing the pager to implement concrete functionality should be fairly |
54 | | - * simple, please see the examples in PageHistory.php and |
| 54 | + * simple, please see the examples in HistoryPage.php and |
55 | 55 | * SpecialIpblocklist.php. You just need to override formatRow(), |
56 | 56 | * getQueryInfo() and getIndexField(). Don't forget to call the parent |
57 | 57 | * constructor if you override it. |
— | — | @@ -87,6 +87,9 @@ |
88 | 88 | public $mDefaultDirection; |
89 | 89 | public $mIsBackwards; |
90 | 90 | |
| 91 | + /** True if the current result set is the first one */ |
| 92 | + public $mIsFirst; |
| 93 | + |
91 | 94 | /** |
92 | 95 | * Result object for the query. Warning: seek before use. |
93 | 96 | */ |