r107508 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107507‎ | r107508 | r107509 >
Date:18:41, 28 December 2011
Author:ialex
Status:ok
Tags:
Comment:
* Use Linker::getRevDeleteLink() where possible to remove code duplication
* Pass the User object to Revision::userCan() in Linker::getRevDeleteLink()
* Return the result Linker::revDeleteLinkDisabled() in Linker::getRevDeleteLink() instead of storing it in a variable that will not be used
Modified paths:
  • /trunk/phase3/includes/Article.php (modified) (history)
  • /trunk/phase3/includes/Linker.php (modified) (history)
  • /trunk/phase3/includes/diff/DifferenceEngine.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialContributions.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/diff/DifferenceEngine.php
@@ -462,24 +462,8 @@
463463 * @return String
464464 */
465465 protected function revisionDeleteLink( $rev ) {
466 - $link = '';
467 - $user = $this->getUser();
468 - $canHide = $user->isAllowed( 'deleterevision' );
469 - // Show del/undel link if:
470 - // (a) the user can delete revisions, or
471 - // (b) the user can view deleted revision *and* this one is deleted
472 - if ( $canHide || ( $rev->getVisibility() && $user->isAllowed( 'deletedhistory' ) ) ) {
473 - if ( !$rev->userCan( Revision::DELETED_RESTRICTED, $user ) ) {
474 - $link = Linker::revDeleteLinkDisabled( $canHide ); // revision was hidden from sysops
475 - } else {
476 - $query = array(
477 - 'type' => 'revision',
478 - 'target' => $rev->getTitle()->getPrefixedDBkey(),
479 - 'ids' => $rev->getId()
480 - );
481 - $link = Linker::revDeleteLink( $query,
482 - $rev->isDeleted( Revision::DELETED_RESTRICTED ), $canHide );
483 - }
 466+ $link = Linker::getRevDeleteLink( $this->getUser(), $rev, $rev->getTitle() );
 467+ if ( $link !== '' ) {
484468 $link = '   ' . $link . ' ';
485469 }
486470 return $link;
Index: trunk/phase3/includes/Article.php
@@ -1147,21 +1147,8 @@
11481148 array( 'known', 'noclasses' )
11491149 );
11501150
1151 - $cdel = '';
1152 -
1153 - // User can delete revisions or view deleted revisions...
1154 - $canHide = $wgUser->isAllowed( 'deleterevision' );
1155 - if ( $canHide || ( $revision->getVisibility() && $wgUser->isAllowed( 'deletedhistory' ) ) ) {
1156 - if ( !$revision->userCan( Revision::DELETED_RESTRICTED ) ) {
1157 - $cdel = Linker::revDeleteLinkDisabled( $canHide ); // rev was hidden from Sysops
1158 - } else {
1159 - $query = array(
1160 - 'type' => 'revision',
1161 - 'target' => $this->getTitle()->getPrefixedDbkey(),
1162 - 'ids' => $oldid
1163 - );
1164 - $cdel = Linker::revDeleteLink( $query, $revision->isDeleted( File::DELETED_RESTRICTED ), $canHide );
1165 - }
 1151+ $cdel = Linker::getRevDeleteLink( $wgUser, $revision, $this->getTitle() );
 1152+ if ( $cdel !== '' ) {
11661153 $cdel .= ' ';
11671154 }
11681155
Index: trunk/phase3/includes/Linker.php
@@ -1803,32 +1803,33 @@
18041804 */
18051805 public static function getRevDeleteLink( User $user, Revision $rev, Title $title ) {
18061806 $canHide = $user->isAllowed( 'deleterevision' );
1807 - if ( $canHide || ( $rev->getVisibility() && $user->isAllowed( 'deletedhistory' ) ) ) {
1808 - if( !$rev->userCan( Revision::DELETED_RESTRICTED ) ) {
1809 - $revdlink = Linker::revDeleteLinkDisabled( $canHide ); // revision was hidden from sysops
 1807+ if ( !$canHide && !( $rev->getVisibility() && $user->isAllowed( 'deletedhistory' ) ) ) {
 1808+ return '';
 1809+ }
 1810+
 1811+ if ( !$rev->userCan( Revision::DELETED_RESTRICTED, $user ) ) {
 1812+ return Linker::revDeleteLinkDisabled( $canHide ); // revision was hidden from sysops
 1813+ } else {
 1814+ if ( $rev->getId() ) {
 1815+ // RevDelete links using revision ID are stable across
 1816+ // page deletion and undeletion; use when possible.
 1817+ $query = array(
 1818+ 'type' => 'revision',
 1819+ 'target' => $title->getPrefixedDBkey(),
 1820+ 'ids' => $rev->getId()
 1821+ );
18101822 } else {
1811 - if ( $rev->getId() ) {
1812 - // RevDelete links using revision ID are stable across
1813 - // page deletion and undeletion; use when possible.
1814 - $query = array(
1815 - 'type' => 'revision',
1816 - 'target' => $title->getPrefixedDBkey(),
1817 - 'ids' => $rev->getId()
1818 - );
1819 - } else {
1820 - // Older deleted entries didn't save a revision ID.
1821 - // We have to refer to these by timestamp, ick!
1822 - $query = array(
1823 - 'type' => 'archive',
1824 - 'target' => $title->getPrefixedDBkey(),
1825 - 'ids' => $rev->getTimestamp()
1826 - );
1827 - }
1828 - return Linker::revDeleteLink( $query,
1829 - $rev->isDeleted( File::DELETED_RESTRICTED ), $canHide );
 1823+ // Older deleted entries didn't save a revision ID.
 1824+ // We have to refer to these by timestamp, ick!
 1825+ $query = array(
 1826+ 'type' => 'archive',
 1827+ 'target' => $title->getPrefixedDBkey(),
 1828+ 'ids' => $rev->getTimestamp()
 1829+ );
18301830 }
 1831+ return Linker::revDeleteLink( $query,
 1832+ $rev->isDeleted( Revision::DELETED_RESTRICTED ), $canHide );
18311833 }
1832 - return '';
18331834 }
18341835
18351836 /**
Index: trunk/phase3/includes/specials/SpecialContributions.php
@@ -833,23 +833,9 @@
834834 $mflag = '';
835835 }
836836
837 - // Don't show useless link to people who cannot hide revisions
838 - $canHide = $user->isAllowed( 'deleterevision' );
839 - if ( $canHide || ( $rev->getVisibility() && $user->isAllowed( 'deletedhistory' ) ) ) {
840 - if ( !$rev->userCan( Revision::DELETED_RESTRICTED, $user ) ) {
841 - $del = Linker::revDeleteLinkDisabled( $canHide ); // revision was hidden from sysops
842 - } else {
843 - $query = array(
844 - 'type' => 'revision',
845 - 'target' => $page->getPrefixedDbkey(),
846 - 'ids' => $rev->getId()
847 - );
848 - $del = Linker::revDeleteLink( $query,
849 - $rev->isDeleted( Revision::DELETED_RESTRICTED ), $canHide );
850 - }
 837+ $del = Linker::getRevDeleteLink( $user, $rev, $page );
 838+ if ( $del !== '' ) {
851839 $del .= ' ';
852 - } else {
853 - $del = '';
854840 }
855841
856842 $diffHistLinks = '(' . $difftext . $this->messages['pipe-separator'] . $histlink . ')';

Sign-offs

UserFlagDate
Nikerabbitinspected06:12, 29 December 2011

Status & tagging log