Index: trunk/phase3/includes/specials/SpecialRevisiondelete.php |
— | — | @@ -11,18 +11,15 @@ |
12 | 12 | |
13 | 13 | public function __construct() { |
14 | 14 | parent::__construct( 'Revisiondelete', 'deleterevision' ); |
15 | | - $this->includable( false ); |
| 15 | + $this->includable( false ); // paranoia |
16 | 16 | } |
17 | 17 | |
18 | 18 | public function execute( $par ) { |
19 | 19 | global $wgOut, $wgUser, $wgRequest; |
20 | | - if( wfReadOnly() ) { |
21 | | - $wgOut->readOnlyPage(); |
22 | | - return; |
23 | | - } |
24 | 20 | if( !$wgUser->isAllowed( 'deleterevision' ) ) { |
25 | | - $wgOut->permissionRequired( 'deleterevision' ); |
26 | | - return; |
| 21 | + return $wgOut->permissionRequired( 'deleterevision' ); |
| 22 | + } else if( wfReadOnly() ) { |
| 23 | + return $wgOut->readOnlyPage(); |
27 | 24 | } |
28 | 25 | $this->skin =& $wgUser->getSkin(); |
29 | 26 | $this->setHeaders(); |
— | — | @@ -40,15 +37,14 @@ |
41 | 38 | # For reviewing deleted files... |
42 | 39 | $this->file = $wgRequest->getVal( 'file' ); |
43 | 40 | # Only one target set at a time please! |
44 | | - $i = (bool)$this->file + (bool)$this->oldids + (bool)$this->logids |
| 41 | + $types = (bool)$this->file + (bool)$this->oldids + (bool)$this->logids |
45 | 42 | + (bool)$this->artimestamps + (bool)$this->fileids + (bool)$this->oldimgs; |
46 | 43 | # No targets? |
47 | | - if( $i == 0 ) { |
48 | | - $wgOut->showErrorPage( 'notargettitle', 'notargettext' ); |
| 44 | + if( $types == 0 ) { |
| 45 | + $wgOut->showErrorPage( 'revdelete-nooldid-title', 'revdelete-nooldid-text' ); |
49 | 46 | return; |
50 | | - } |
51 | 47 | # Too many targets? |
52 | | - if( $i !== 1 ) { |
| 48 | + } else if( $types > 1 ) { |
53 | 49 | $wgOut->showErrorPage( 'revdelete-toomanytargets-title', 'revdelete-toomanytargets-text' ); |
54 | 50 | return; |
55 | 51 | } |
— | — | @@ -62,45 +58,18 @@ |
63 | 59 | } |
64 | 60 | # We need a target page! |
65 | 61 | if( is_null($this->page) ) { |
66 | | - $wgOut->addWikiMsg( 'undelete-header' ); |
67 | | - return; |
| 62 | + return $wgOut->addWikiMsg( 'undelete-header' ); |
68 | 63 | } |
69 | | - # Logs must have a type given |
70 | | - if( $this->logids && !strpos($this->page->getDBKey(),'/') ) { |
71 | | - $wgOut->showErrorPage( 'revdelete-nologtype-title', 'revdelete-nologtype-text' ); |
72 | | - return; |
73 | | - } |
74 | 64 | # For reviewing deleted files...show it now if allowed |
75 | 65 | if( $this->file ) { |
76 | | - $oimage = RepoGroup::singleton()->getLocalRepo()->newFromArchiveName( $this->page, $this->file ); |
77 | | - $oimage->load(); |
78 | | - // Check if user is allowed to see this file |
79 | | - if( !$oimage->userCan(File::DELETED_FILE) ) { |
80 | | - $wgOut->permissionRequired( 'suppressrevision' ); |
81 | | - } else { |
82 | | - $this->showFile( $this->file ); |
83 | | - } |
84 | | - return; |
| 66 | + return $this->tryShowFile( $this->file ); |
85 | 67 | } |
86 | | - # Give a link to the logs/hist for this page |
87 | | - if( !is_null($this->page) && $this->page->getNamespace() > -1 ) { |
88 | | - $links = array(); |
89 | | - |
90 | | - $logtitle = SpecialPage::getTitleFor( 'Log' ); |
91 | | - $links[] = $this->skin->makeKnownLinkObj( $logtitle, wfMsgHtml( 'viewpagelogs' ), |
92 | | - wfArrayToCGI( array( 'page' => $this->page->getPrefixedUrl() ) ) ); |
93 | | - # Give a link to the page history |
94 | | - $links[] = $this->skin->makeKnownLinkObj( $this->page, wfMsgHtml( 'pagehist' ), |
95 | | - wfArrayToCGI( array( 'action' => 'history' ) ) ); |
96 | | - # Link to deleted edits |
97 | | - if( $wgUser->isAllowed('undelete') ) { |
98 | | - $undelete = SpecialPage::getTitleFor( 'Undelete' ); |
99 | | - $links[] = $this->skin->makeKnownLinkObj( $undelete, wfMsgHtml( 'deletedhist' ), |
100 | | - wfArrayToCGI( array( 'target' => $this->page->getPrefixedDBkey() ) ) ); |
101 | | - } |
102 | | - # Logs themselves don't have histories or archived revisions |
103 | | - $wgOut->setSubtitle( '<p>'.implode($links,' / ').'</p>' ); |
| 68 | + # Logs must have a type given |
| 69 | + if( $this->logids && !strpos($this->page->getDBKey(),'/') ) { |
| 70 | + return $wgOut->showErrorPage( 'revdelete-nologtype-title', 'revdelete-nologtype-text' ); |
104 | 71 | } |
| 72 | + # Give a link to the logs/hist for this page |
| 73 | + $this->showConvenienceLinks(); |
105 | 74 | # Lock the operation and the form context |
106 | 75 | $this->secureOperation(); |
107 | 76 | # Either submit or create our form |
— | — | @@ -124,6 +93,28 @@ |
125 | 94 | } |
126 | 95 | } |
127 | 96 | |
| 97 | + private function showConvenienceLinks() { |
| 98 | + global $wgOut, $wgUser; |
| 99 | + # Give a link to the logs/hist for this page |
| 100 | + if( !is_null($this->page) && $this->page->getNamespace() > -1 ) { |
| 101 | + $links = array(); |
| 102 | + $logtitle = SpecialPage::getTitleFor( 'Log' ); |
| 103 | + $links[] = $this->skin->makeKnownLinkObj( $logtitle, wfMsgHtml( 'viewpagelogs' ), |
| 104 | + wfArrayToCGI( array( 'page' => $this->page->getPrefixedUrl() ) ) ); |
| 105 | + # Give a link to the page history |
| 106 | + $links[] = $this->skin->makeKnownLinkObj( $this->page, wfMsgHtml( 'pagehist' ), |
| 107 | + wfArrayToCGI( array( 'action' => 'history' ) ) ); |
| 108 | + # Link to deleted edits |
| 109 | + if( $wgUser->isAllowed('undelete') ) { |
| 110 | + $undelete = SpecialPage::getTitleFor( 'Undelete' ); |
| 111 | + $links[] = $this->skin->makeKnownLinkObj( $undelete, wfMsgHtml( 'deletedhist' ), |
| 112 | + wfArrayToCGI( array( 'target' => $this->page->getPrefixedDBkey() ) ) ); |
| 113 | + } |
| 114 | + # Logs themselves don't have histories or archived revisions |
| 115 | + $wgOut->setSubtitle( '<p>'.implode($links,' / ').'</p>' ); |
| 116 | + } |
| 117 | + } |
| 118 | + |
128 | 119 | private function getLogQueryCond() { |
129 | 120 | $ids = $safeIds = array(); |
130 | 121 | $action = 'revision'; |
— | — | @@ -203,20 +194,26 @@ |
204 | 195 | /** |
205 | 196 | * Show a deleted file version requested by the visitor. |
206 | 197 | */ |
207 | | - private function showFile( $key ) { |
| 198 | + private function tryShowFile( $key ) { |
208 | 199 | global $wgOut, $wgRequest; |
209 | | - $wgOut->disable(); |
210 | | - |
211 | | - # We mustn't allow the output to be Squid cached, otherwise |
212 | | - # if an admin previews a deleted image, and it's cached, then |
213 | | - # a user without appropriate permissions can toddle off and |
214 | | - # nab the image, and Squid will serve it |
215 | | - $wgRequest->response()->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' ); |
216 | | - $wgRequest->response()->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' ); |
217 | | - $wgRequest->response()->header( 'Pragma: no-cache' ); |
218 | | - |
219 | | - $store = FileStore::get( 'deleted' ); |
220 | | - $store->stream( $key ); |
| 200 | + $oimage = RepoGroup::singleton()->getLocalRepo()->newFromArchiveName( $this->page, $key ); |
| 201 | + $oimage->load(); |
| 202 | + // Check if user is allowed to see this file |
| 203 | + if( !$oimage->userCan(File::DELETED_FILE) ) { |
| 204 | + $wgOut->permissionRequired( 'suppressrevision' ); |
| 205 | + } else { |
| 206 | + $wgOut->disable(); |
| 207 | + # We mustn't allow the output to be Squid cached, otherwise |
| 208 | + # if an admin previews a deleted image, and it's cached, then |
| 209 | + # a user without appropriate permissions can toddle off and |
| 210 | + # nab the image, and Squid will serve it |
| 211 | + $wgRequest->response()->header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' ); |
| 212 | + $wgRequest->response()->header( 'Cache-Control: no-cache, no-store, max-age=0, must-revalidate' ); |
| 213 | + $wgRequest->response()->header( 'Pragma: no-cache' ); |
| 214 | + # Stream the file to the client |
| 215 | + $store = FileStore::get( 'deleted' ); |
| 216 | + $store->stream( $key ); |
| 217 | + } |
221 | 218 | } |
222 | 219 | |
223 | 220 | /** |
— | — | @@ -226,7 +223,7 @@ |
227 | 224 | global $wgOut, $wgUser; |
228 | 225 | $UserAllowed = true; |
229 | 226 | |
230 | | - $count = ($this->deleteKey=='oldid') ? |
| 227 | + $count = ($this->deleteKey == 'oldid') ? |
231 | 228 | count($this->revisions) : count($this->archrevs); |
232 | 229 | $wgOut->addWikiMsg( 'revdelete-selected', $this->page->getPrefixedText(), $count ); |
233 | 230 | |
— | — | @@ -238,7 +235,7 @@ |
239 | 236 | |
240 | 237 | $revisions = 0; |
241 | 238 | // Live revisions... |
242 | | - if( $this->deleteKey=='oldid' ) { |
| 239 | + if( $this->deleteKey == 'oldid' ) { |
243 | 240 | // Run through and pull all our data in one query |
244 | 241 | foreach( $this->revisions as $revid ) { |
245 | 242 | $where[] = intval($revid); |
— | — | @@ -332,7 +329,7 @@ |
333 | 330 | Xml::hidden( 'target', $this->page->getPrefixedText() ), |
334 | 331 | Xml::hidden( 'type', $this->deleteKey ) |
335 | 332 | ); |
336 | | - if( $this->deleteKey=='oldid' ) { |
| 333 | + if( $this->deleteKey == 'oldid' ) { |
337 | 334 | $hidden[] = Xml::hidden( 'oldid', implode(',',$this->oldids) ); |
338 | 335 | } else { |
339 | 336 | $hidden[] = Xml::hidden( 'artimestamp', implode(',',$this->artimestamps) ); |
— | — | @@ -366,7 +363,7 @@ |
367 | 364 | global $wgOut, $wgUser, $wgLang; |
368 | 365 | $UserAllowed = true; |
369 | 366 | |
370 | | - $count = ($this->deleteKey=='oldimage') ? count($this->ofiles) : count($this->afiles); |
| 367 | + $count = ($this->deleteKey == 'oldimage') ? count($this->ofiles) : count($this->afiles); |
371 | 368 | $wgOut->addWikiMsg( 'revdelete-selected', $this->page->getPrefixedText(), |
372 | 369 | $wgLang->formatNum($count) ); |
373 | 370 | |
— | — | @@ -377,7 +374,7 @@ |
378 | 375 | $dbr = wfGetDB( DB_MASTER ); |
379 | 376 | // Live old revisions... |
380 | 377 | $revisions = 0; |
381 | | - if( $this->deleteKey=='oldimage' ) { |
| 378 | + if( $this->deleteKey == 'oldimage' ) { |
382 | 379 | // Run through and pull all our data in one query |
383 | 380 | foreach( $this->ofiles as $timestamp ) { |
384 | 381 | $where[] = $timestamp.'!'.$this->page->getDBKey(); |
— | — | @@ -462,7 +459,7 @@ |
463 | 460 | Xml::hidden( 'target', $this->page->getPrefixedText() ), |
464 | 461 | Xml::hidden( 'type', $this->deleteKey ) |
465 | 462 | ); |
466 | | - if( $this->deleteKey=='oldimage' ) { |
| 463 | + if( $this->deleteKey == 'oldimage' ) { |
467 | 464 | $hidden[] = Xml::hidden( 'oldimage', implode(',',$this->oldimgs) ); |
468 | 465 | } else { |
469 | 466 | $hidden[] = Xml::hidden( 'fileid', implode(',',$this->fileids) ); |
— | — | @@ -612,7 +609,7 @@ |
613 | 610 | $date = $wgLang->timeanddate( $rev->getTimestamp() ); |
614 | 611 | $difflink = $del = ''; |
615 | 612 | // Live revisions |
616 | | - if( $this->deleteKey=='oldid' ) { |
| 613 | + if( $this->deleteKey == 'oldid' ) { |
617 | 614 | $tokenParams = '&unhide=1&token='.urlencode( $wgUser->editToken( $rev->getId() ) ); |
618 | 615 | $revlink = $this->skin->makeLinkObj( $this->page, $date, 'oldid='.$rev->getId() . $tokenParams ); |
619 | 616 | $difflink = '(' . $this->skin->makeKnownLinkObj( $this->page, wfMsgHtml('diff'), |
— | — | @@ -674,7 +671,8 @@ |
675 | 672 | ' (' . wfMsgExt( 'nbytes', 'parsemag', $wgLang->formatNum( $file->getSize() ) ) . ')'; |
676 | 673 | $data = htmlspecialchars( $data ); |
677 | 674 | |
678 | | - return "<li>$pageLink ".$this->fileUserTools( $file )." $data ".$this->fileComment( $file )."$del</li>"; |
| 675 | + return "<li>$pageLink ".$this->fileUserTools( $file )." $data ". |
| 676 | + $this->fileComment( $file )."$del</li>"; |
679 | 677 | } |
680 | 678 | |
681 | 679 | /** |
— | — | @@ -688,7 +686,8 @@ |
689 | 687 | $date = $wgLang->timeanddate( $file->getTimestamp(), true ); |
690 | 688 | |
691 | 689 | $undelete = SpecialPage::getTitleFor( 'Undelete' ); |
692 | | - $pageLink = $this->skin->makeKnownLinkObj( $undelete, $date, "target=$target&file={$file->getKey()}" ); |
| 690 | + $pageLink = $this->skin->makeKnownLinkObj( $undelete, $date, |
| 691 | + "target=$target&file={$file->getKey()}" ); |
693 | 692 | |
694 | 693 | $del = ''; |
695 | 694 | if( $file->isDeleted(File::DELETED_FILE) ) { |
— | — | @@ -701,7 +700,8 @@ |
702 | 701 | ' (' . wfMsgExt( 'nbytes', 'parsemag', $wgLang->formatNum( $file->getSize() ) ) . ')'; |
703 | 702 | $data = htmlspecialchars( $data ); |
704 | 703 | |
705 | | - return "<li> $pageLink ".$this->fileUserTools( $file )." $data ".$this->fileComment( $file )."$del</li>"; |
| 704 | + return "<li>$pageLink ".$this->fileUserTools( $file )." $data ". |
| 705 | + $this->fileComment( $file )."$del</li>"; |
706 | 706 | } |
707 | 707 | |
708 | 708 | /** |
— | — | @@ -814,16 +814,16 @@ |
815 | 815 | |
816 | 816 | $wrap = '<span class="success">$1</span>'; |
817 | 817 | |
818 | | - if( $this->deleteKey=='logid' ) { |
| 818 | + if( $this->deleteKey == 'logid' ) { |
819 | 819 | $wgOut->wrapWikiMsg( $wrap, 'logdelete-success' ); |
820 | 820 | $this->showLogItems(); |
821 | | - } else if( $this->deleteKey=='oldid' || $this->deleteKey=='artimestamp' ) { |
| 821 | + } else if( $this->deleteKey == 'oldid' || $this->deleteKey == 'artimestamp' ) { |
822 | 822 | $wgOut->wrapWikiMsg( $wrap, 'revdelete-success' ); |
823 | 823 | $this->showRevs(); |
824 | | - } else if( $this->deleteKey=='fileid' ) { |
| 824 | + } else if( $this->deleteKey == 'fileid' ) { |
825 | 825 | $wgOut->wrapWikiMsg( $wrap, 'revdelete-success' ); |
826 | 826 | $this->showImages(); |
827 | | - } else if( $this->deleteKey=='oldimage' ) { |
| 827 | + } else if( $this->deleteKey == 'oldimage' ) { |
828 | 828 | $wgOut->wrapWikiMsg( $wrap, 'revdelete-success' ); |
829 | 829 | $this->showImages(); |
830 | 830 | } |
— | — | @@ -1440,9 +1440,9 @@ |
1441 | 1441 | * @param int $diff The xor of the old and new bitfields. |
1442 | 1442 | * @param array $arr The array to update. |
1443 | 1443 | */ |
1444 | | - function checkItem ( $desc, $field, $diff, $new, &$arr ) { |
1445 | | - if ( $diff & $field ) { |
1446 | | - $arr [ ( $new & $field ) ? 0 : 1 ][] = $desc; |
| 1444 | + function checkItem( $desc, $field, $diff, $new, &$arr ) { |
| 1445 | + if( $diff & $field ) { |
| 1446 | + $arr[ ( $new & $field ) ? 0 : 1 ][] = $desc; |
1447 | 1447 | } |
1448 | 1448 | } |
1449 | 1449 | |
— | — | @@ -1458,25 +1458,23 @@ |
1459 | 1459 | * @param int $o The old bitfield. |
1460 | 1460 | * @return An array as described above. |
1461 | 1461 | */ |
1462 | | - function getChanges ( $n, $o ) { |
| 1462 | + function getChanges( $n, $o ) { |
1463 | 1463 | $diff = $n ^ $o; |
1464 | | - $ret = array ( 0 => array(), 1 => array(), 2 => array() ); |
1465 | | - |
1466 | | - $this->checkItem ( wfMsgForContent ( 'revdelete-content' ), |
1467 | | - Revision::DELETED_TEXT, $diff, $n, $ret ); |
1468 | | - $this->checkItem ( wfMsgForContent ( 'revdelete-summary' ), |
1469 | | - Revision::DELETED_COMMENT, $diff, $n, $ret ); |
1470 | | - $this->checkItem ( wfMsgForContent ( 'revdelete-uname' ), |
1471 | | - Revision::DELETED_USER, $diff, $n, $ret ); |
1472 | | - |
| 1464 | + $ret = array( 0 => array(), 1 => array(), 2 => array() ); |
| 1465 | + // Build bitfield changes in language |
| 1466 | + $this->checkItem( wfMsgForContent( 'revdelete-content' ), |
| 1467 | + Revision::DELETED_TEXT, $diff, $n, $ret ); |
| 1468 | + $this->checkItem( wfMsgForContent( 'revdelete-summary' ), |
| 1469 | + Revision::DELETED_COMMENT, $diff, $n, $ret ); |
| 1470 | + $this->checkItem( wfMsgForContent( 'revdelete-uname' ), |
| 1471 | + Revision::DELETED_USER, $diff, $n, $ret ); |
1473 | 1472 | // Restriction application to sysops |
1474 | | - if ( $diff & Revision::DELETED_RESTRICTED ) { |
1475 | | - if ( $n & Revision::DELETED_RESTRICTED ) |
1476 | | - $ret[2][] = wfMsgForContent ( 'revdelete-restricted' ); |
| 1473 | + if( $diff & Revision::DELETED_RESTRICTED ) { |
| 1474 | + if( $n & Revision::DELETED_RESTRICTED ) |
| 1475 | + $ret[2][] = wfMsgForContent( 'revdelete-restricted' ); |
1477 | 1476 | else |
1478 | | - $ret[2][] = wfMsgForContent ( 'revdelete-unrestricted' ); |
| 1477 | + $ret[2][] = wfMsgForContent( 'revdelete-unrestricted' ); |
1479 | 1478 | } |
1480 | | - |
1481 | 1479 | return $ret; |
1482 | 1480 | } |
1483 | 1481 | |
— | — | @@ -1491,35 +1489,28 @@ |
1492 | 1490 | * @param string $comment The comment associated with the change. |
1493 | 1491 | * @param bool $isForLog |
1494 | 1492 | */ |
1495 | | - function getLogMessage ( $count, $nbitfield, $obitfield, $comment, $isForLog = false ) { |
| 1493 | + function getLogMessage( $count, $nbitfield, $obitfield, $comment, $isForLog = false ) { |
1496 | 1494 | global $wgContLang; |
1497 | 1495 | |
1498 | 1496 | $s = ''; |
1499 | 1497 | $changes = $this->getChanges( $nbitfield, $obitfield ); |
1500 | 1498 | |
1501 | | - if ( count ( $changes[0] ) ) { |
| 1499 | + if( count( $changes[0] ) ) { |
1502 | 1500 | $s .= wfMsgForContent ( 'revdelete-hid', implode ( ', ', $changes[0] ) ); |
1503 | 1501 | } |
1504 | | - |
1505 | | - if ( count ( $changes[1] ) ) { |
| 1502 | + if( count( $changes[1] ) ) { |
1506 | 1503 | if ($s) $s .= '; '; |
1507 | | - |
1508 | 1504 | $s .= wfMsgForContent ( 'revdelete-unhid', implode ( ', ', $changes[1] ) ); |
1509 | 1505 | } |
1510 | | - |
1511 | | - if ( count ( $changes[2] )) { |
1512 | | - if ($s) |
1513 | | - $s .= ' (' . $changes[2][0] . ')'; |
1514 | | - else |
1515 | | - $s = $changes[2][0]; |
| 1506 | + if( count( $changes[2] ) ) { |
| 1507 | + $s .= $s ? ' (' . $changes[2][0] . ')' : $changes[2][0]; |
1516 | 1508 | } |
1517 | 1509 | |
1518 | 1510 | $msg = $isForLog ? 'logdelete-log-message' : 'revdelete-log-message'; |
1519 | 1511 | $ret = wfMsgExt ( $msg, array( 'parsemag', 'content' ), |
1520 | 1512 | $s, $wgContLang->formatNum( $count ) ); |
1521 | 1513 | |
1522 | | - if ( $comment ) |
1523 | | - $ret .= ": $comment"; |
| 1514 | + if( $comment ) $ret .= ": $comment"; |
1524 | 1515 | |
1525 | 1516 | return $ret; |
1526 | 1517 | |
— | — | @@ -1536,11 +1527,12 @@ |
1537 | 1528 | * @param string $param, URL param |
1538 | 1529 | * @param Array $items |
1539 | 1530 | */ |
1540 | | - function updateLog( $title, $count, $nbitfield, $obitfield, $comment, |
1541 | | - $target, $param, $items = array() ) |
| 1531 | + function updateLog( $title, $count, $nbitfield, $obitfield, $comment, $target, |
| 1532 | + $param, $items = array() ) |
1542 | 1533 | { |
1543 | 1534 | // Put things hidden from sysops in the oversight log |
1544 | | - $logtype = ( ($nbitfield | $obitfield) & Revision::DELETED_RESTRICTED ) ? 'suppress' : 'delete'; |
| 1535 | + $logtype = ( ($nbitfield | $obitfield) & Revision::DELETED_RESTRICTED ) ? |
| 1536 | + 'suppress' : 'delete'; |
1545 | 1537 | $log = new LogPage( $logtype ); |
1546 | 1538 | |
1547 | 1539 | $reason = $this->getLogMessage( $count, $nbitfield, $obitfield, $comment, $param == 'logid' ); |