diff options
Diffstat (limited to 'includes/revisiondelete')
-rw-r--r-- | includes/revisiondelete/RevisionDelete.php | 152 | ||||
-rw-r--r-- | includes/revisiondelete/RevisionDeleteAbstracts.php | 38 | ||||
-rw-r--r-- | includes/revisiondelete/RevisionDeleteUser.php | 22 | ||||
-rw-r--r-- | includes/revisiondelete/RevisionDeleter.php | 84 |
4 files changed, 157 insertions, 139 deletions
diff --git a/includes/revisiondelete/RevisionDelete.php b/includes/revisiondelete/RevisionDelete.php index 6cee6246..6ceadff4 100644 --- a/includes/revisiondelete/RevisionDelete.php +++ b/includes/revisiondelete/RevisionDelete.php @@ -1,5 +1,27 @@ <?php /** + * Base implementations for deletable items. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/gpl.html + * + * @file + * @ingroup RevisionDelete + */ + +/** * List for revision table items * * This will check both the 'revision' table for live revisions and the @@ -191,13 +213,16 @@ class RevDel_RevisionItem extends RevDel_Item { /** * Get the HTML link to the revision text. * Overridden by RevDel_ArchiveItem. + * @return string */ protected function getRevisionLink() { - $date = $this->list->getLanguage()->timeanddate( $this->revision->getTimestamp(), true ); + $date = htmlspecialchars( $this->list->getLanguage()->userTimeAndDate( + $this->revision->getTimestamp(), $this->list->getUser() ) ); + if ( $this->isDeleted() && !$this->canViewContent() ) { return $date; } - return Linker::link( + return Linker::linkKnown( $this->list->title, $date, array(), @@ -211,38 +236,36 @@ class RevDel_RevisionItem extends RevDel_Item { /** * Get the HTML link to the diff. * Overridden by RevDel_ArchiveItem + * @return string */ protected function getDiffLink() { if ( $this->isDeleted() && !$this->canViewContent() ) { - return wfMsgHtml('diff'); + return $this->list->msg( 'diff' )->escaped(); } else { return - Linker::link( + Linker::linkKnown( $this->list->title, - wfMsgHtml('diff'), + $this->list->msg( 'diff' )->escaped(), array(), array( 'diff' => $this->revision->getId(), 'oldid' => 'prev', 'unhide' => 1 - ), - array( - 'known', - 'noclasses' ) ); } } public function getHTML() { - $difflink = $this->getDiffLink(); + $difflink = $this->list->msg( 'parentheses' ) + ->rawParams( $this->getDiffLink() )->escaped(); $revlink = $this->getRevisionLink(); $userlink = Linker::revUserLink( $this->revision ); $comment = Linker::revComment( $this->revision ); if ( $this->isDeleted() ) { $revlink = "<span class=\"history-deleted\">$revlink</span>"; } - return "<li>($difflink) $revlink $userlink $comment</li>"; + return "<li>$difflink $revlink $userlink $comment</li>"; } } @@ -298,7 +321,7 @@ class RevDel_ArchiveItem extends RevDel_RevisionItem { public function __construct( $list, $row ) { RevDel_Item::__construct( $list, $row ); $this->revision = Revision::newFromArchiveRow( $row, - array( 'page' => $this->list->title->getArticleId() ) ); + array( 'page' => $this->list->title->getArticleID() ) ); } public function getIdField() { @@ -339,29 +362,39 @@ class RevDel_ArchiveItem extends RevDel_RevisionItem { } protected function getRevisionLink() { - $undelete = SpecialPage::getTitleFor( 'Undelete' ); - $date = $this->list->getLanguage()->timeanddate( $this->revision->getTimestamp(), true ); + $date = htmlspecialchars( $this->list->getLanguage()->userTimeAndDate( + $this->revision->getTimestamp(), $this->list->getUser() ) ); + if ( $this->isDeleted() && !$this->canViewContent() ) { return $date; } - return Linker::link( $undelete, $date, array(), + + return Linker::link( + SpecialPage::getTitleFor( 'Undelete' ), + $date, + array(), array( 'target' => $this->list->title->getPrefixedText(), 'timestamp' => $this->revision->getTimestamp() - ) ); + ) + ); } protected function getDiffLink() { if ( $this->isDeleted() && !$this->canViewContent() ) { - return wfMsgHtml( 'diff' ); + return $this->list->msg( 'diff' )->escaped(); } - $undelete = SpecialPage::getTitleFor( 'Undelete' ); - return Linker::link( $undelete, wfMsgHtml('diff'), array(), + + return Linker::link( + SpecialPage::getTitleFor( 'Undelete' ), + $this->list->msg( 'diff' )->escaped(), + array(), array( 'target' => $this->list->title->getPrefixedText(), 'diff' => 'prev', 'timestamp' => $this->revision->getTimestamp() - ) ); + ) + ); } } @@ -375,7 +408,7 @@ class RevDel_ArchivedRevisionItem extends RevDel_ArchiveItem { RevDel_Item::__construct( $list, $row ); $this->revision = Revision::newFromArchiveRow( $row, - array( 'page' => $this->list->title->getArticleId() ) ); + array( 'page' => $this->list->title->getArticleID() ) ); } public function getIdField() { @@ -569,31 +602,34 @@ class RevDel_FileItem extends RevDel_Item { /** * Get the link to the file. * Overridden by RevDel_ArchivedFileItem. + * @return string */ protected function getLink() { - $date = $this->list->getLanguage()->timeanddate( $this->file->getTimestamp(), true ); - if ( $this->isDeleted() ) { - # Hidden files... - if ( !$this->canViewContent() ) { - $link = $date; - } else { - $revdelete = SpecialPage::getTitleFor( 'Revisiondelete' ); - $link = Linker::link( - $revdelete, - $date, array(), - array( - 'target' => $this->list->title->getPrefixedText(), - 'file' => $this->file->getArchiveName(), - 'token' => $this->list->getUser()->getEditToken( - $this->file->getArchiveName() ) - ) - ); - } - return '<span class="history-deleted">' . $link . '</span>'; - } else { + $date = htmlspecialchars( $this->list->getLanguage()->userTimeAndDate( + $this->file->getTimestamp(), $this->list->getUser() ) ); + + if ( !$this->isDeleted() ) { # Regular files... - return Xml::element( 'a', array( 'href' => $this->file->getUrl() ), $date ); + return Html::rawElement( 'a', array( 'href' => $this->file->getUrl() ), $date ); } + + # Hidden files... + if ( !$this->canViewContent() ) { + $link = $date; + } else { + $link = Linker::link( + SpecialPage::getTitleFor( 'Revisiondelete' ), + $date, + array(), + array( + 'target' => $this->list->title->getPrefixedText(), + 'file' => $this->file->getArchiveName(), + 'token' => $this->list->getUser()->getEditToken( + $this->file->getArchiveName() ) + ) + ); + } + return '<span class="history-deleted">' . $link . '</span>'; } /** * Generate a user tool link cluster if the current user is allowed to view it @@ -604,7 +640,7 @@ class RevDel_FileItem extends RevDel_Item { $link = Linker::userLink( $this->file->user, $this->file->user_text ) . Linker::userToolLinks( $this->file->user, $this->file->user_text ); } else { - $link = wfMsgHtml( 'rev-deleted-user' ); + $link = $this->list->msg( 'rev-deleted-user' )->escaped(); } if( $this->file->isDeleted( Revision::DELETED_USER ) ) { return '<span class="history-deleted">' . $link . '</span>'; @@ -622,7 +658,7 @@ class RevDel_FileItem extends RevDel_Item { if( $this->file->userCan( File::DELETED_COMMENT, $this->list->getUser() ) ) { $block = Linker::commentBlock( $this->file->description ); } else { - $block = ' ' . wfMsgHtml( 'rev-deleted-comment' ); + $block = ' ' . $this->list->msg( 'rev-deleted-comment' )->escaped(); } if( $this->file->isDeleted( File::DELETED_COMMENT ) ) { return "<span class=\"history-deleted\">$block</span>"; @@ -632,14 +668,9 @@ class RevDel_FileItem extends RevDel_Item { public function getHTML() { $data = - wfMsg( - 'widthheight', - $this->list->getLanguage()->formatNum( $this->file->getWidth() ), - $this->list->getLanguage()->formatNum( $this->file->getHeight() ) - ) . - ' (' . - wfMsgExt( 'nbytes', 'parsemag', $this->list->getLanguage()->formatNum( $this->file->getSize() ) ) . - ')'; + $this->list->msg( 'widthheight' )->numParams( + $this->file->getWidth(), $this->file->getHeight() )->text() . + ' (' . $this->list->msg( 'nbytes' )->numParams( $this->file->getSize() )->text() . ')'; return '<li>' . $this->getLink() . ' ' . $this->getUserTools() . ' ' . $data . ' ' . $this->getComment(). '</li>'; @@ -722,13 +753,15 @@ class RevDel_ArchivedFileItem extends RevDel_FileItem { } protected function getLink() { - $date = $this->list->getLanguage()->timeanddate( $this->file->getTimestamp(), true ); - $undelete = SpecialPage::getTitleFor( 'Undelete' ); - $key = $this->file->getKey(); + $date = htmlspecialchars( $this->list->getLanguage()->userTimeAndDate( + $this->file->getTimestamp(), $this->list->getUser() ) ); + # Hidden files... if( !$this->canViewContent() ) { $link = $date; } else { + $undelete = SpecialPage::getTitleFor( 'Undelete' ); + $key = $this->file->getKey(); $link = Linker::link( $undelete, $date, array(), array( 'target' => $this->list->title->getPrefixedText(), @@ -847,18 +880,21 @@ class RevDel_LogItem extends RevDel_Item { } public function getHTML() { - $date = htmlspecialchars( $this->list->getLanguage()->timeanddate( $this->row->log_timestamp ) ); + $date = htmlspecialchars( $this->list->getLanguage()->userTimeAndDate( + $this->row->log_timestamp, $this->list->getUser() ) ); $title = Title::makeTitle( $this->row->log_namespace, $this->row->log_title ); $formatter = LogFormatter::newFromRow( $this->row ); + $formatter->setContext( $this->list->getContext() ); $formatter->setAudience( LogFormatter::FOR_THIS_USER ); // Log link for this page $loglink = Linker::link( SpecialPage::getTitleFor( 'Log' ), - wfMsgHtml( 'log' ), + $this->list->msg( 'log' )->escaped(), array(), array( 'page' => $title->getPrefixedText() ) ); + $loglink = $this->list->msg( 'parentheses' )->rawParams( $loglink )->escaped(); // User links and action text $action = $formatter->getActionText(); // Comment @@ -867,6 +903,6 @@ class RevDel_LogItem extends RevDel_Item { $comment = '<span class="history-deleted">' . $comment . '</span>'; } - return "<li>($loglink) $date $action $comment</li>"; + return "<li>$loglink $date $action $comment</li>"; } } diff --git a/includes/revisiondelete/RevisionDeleteAbstracts.php b/includes/revisiondelete/RevisionDeleteAbstracts.php index dc7af194..4f58099f 100644 --- a/includes/revisiondelete/RevisionDeleteAbstracts.php +++ b/includes/revisiondelete/RevisionDeleteAbstracts.php @@ -1,4 +1,25 @@ <?php +/** + * Interface definition for deletable items. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/gpl.html + * + * @file + * @ingroup RevisionDelete + */ /** * Abstract base class for a list of deletable items. The list class @@ -16,6 +37,7 @@ abstract class RevDel_List extends RevisionListBase { * Get the DB field name associated with the ID list. * This used to populate the log_search table for finding log entries. * Override this function. + * @return null */ public static function getRelationType() { return null; @@ -25,7 +47,7 @@ abstract class RevDel_List extends RevisionListBase { * Set the visibility for the revisions in this list. Logging and * transactions are done here. * - * @param $params Associative array of parameters. Members are: + * @param $params array Associative array of parameters. Members are: * value: The integer value to set the visibility to * comment: The log comment. * @return Status @@ -37,7 +59,7 @@ abstract class RevDel_List extends RevisionListBase { $this->res = false; $dbw = wfGetDB( DB_MASTER ); $this->doQuery( $dbw ); - $dbw->begin(); + $dbw->begin( __METHOD__ ); $status = Status::newGood(); $missing = array_flip( $this->ids ); $this->clearFileOps(); @@ -110,7 +132,7 @@ abstract class RevDel_List extends RevisionListBase { if ( $status->successCount == 0 ) { $status->ok = false; - $dbw->rollback(); + $dbw->rollback( __METHOD__ ); return $status; } @@ -121,7 +143,7 @@ abstract class RevDel_List extends RevisionListBase { $status->merge( $this->doPreCommitUpdates() ); if ( !$status->isOK() ) { // Fatal error, such as no configured archive directory - $dbw->rollback(); + $dbw->rollback( __METHOD__ ); return $status; } @@ -136,7 +158,7 @@ abstract class RevDel_List extends RevisionListBase { 'authorIds' => $authorIds, 'authorIPs' => $authorIPs ) ); - $dbw->commit(); + $dbw->commit( __METHOD__ ); // Clear caches $status->merge( $this->doPostCommitUpdates() ); @@ -154,7 +176,7 @@ abstract class RevDel_List extends RevisionListBase { /** * Record a log entry on the action - * @param $params Associative array of parameters: + * @param $params array Associative array of parameters: * newBits: The new value of the *_deleted bitfield * oldBits: The old value of the *_deleted bitfield. * title: The target title @@ -189,6 +211,7 @@ abstract class RevDel_List extends RevisionListBase { /** * Get the log action for this list type + * @return string */ public function getLogAction() { return 'revision'; @@ -196,7 +219,7 @@ abstract class RevDel_List extends RevisionListBase { /** * Get log parameter array. - * @param $params Associative array of log parameters, same as updateLog() + * @param $params array Associative array of log parameters, same as updateLog() * @return array */ public function getLogParams( $params ) { @@ -247,6 +270,7 @@ abstract class RevDel_Item extends RevisionItemBase { * Returns true if the item is "current", and the operation to set the given * bits can't be executed for that reason * STUB + * @return bool */ public function isHideCurrentOp( $newBits ) { return false; diff --git a/includes/revisiondelete/RevisionDeleteUser.php b/includes/revisiondelete/RevisionDeleteUser.php index c88b4d91..c02e9c76 100644 --- a/includes/revisiondelete/RevisionDeleteUser.php +++ b/includes/revisiondelete/RevisionDeleteUser.php @@ -1,9 +1,6 @@ <?php /** - * Backend functions for suppressing and unsuppressing all references to a given user, - * used when blocking with HideUser enabled. This was spun out of SpecialBlockip.php - * in 1.18; at some point it needs to be rewritten to either use RevisionDelete abstraction, - * or at least schema abstraction. + * Backend functions for suppressing and unsuppressing all references to a given user. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,6 +20,15 @@ * @file * @ingroup RevisionDelete */ + +/** + * Backend functions for suppressing and unsuppressing all references to a given user, + * used when blocking with HideUser enabled. This was spun out of SpecialBlockip.php + * in 1.18; at some point it needs to be rewritten to either use RevisionDelete abstraction, + * or at least schema abstraction. + * + * @ingroup RevisionDelete + */ class RevisionDeleteUser { /** @@ -30,14 +36,14 @@ class RevisionDeleteUser { * @param $name String username * @param $userId Int user id * @param $op String operator '|' or '&' - * @param $dbw null|Database, if you happen to have one lying around + * @param $dbw null|DatabaseBase, if you happen to have one lying around * @return bool */ private static function setUsernameBitfields( $name, $userId, $op, $dbw ) { - if( $op !== '|' && $op !== '&' ){ + if ( !$userId || ( $op !== '|' && $op !== '&' ) ) { return false; // sanity check } - if( !$dbw instanceof DatabaseBase ){ + if ( !$dbw instanceof DatabaseBase ) { $dbw = wfGetDB( DB_MASTER ); } @@ -127,4 +133,4 @@ class RevisionDeleteUser { public static function unsuppressUserName( $name, $userId, $dbw = null ) { return self::setUsernameBitfields( $name, $userId, '&', $dbw ); } -}
\ No newline at end of file +} diff --git a/includes/revisiondelete/RevisionDeleter.php b/includes/revisiondelete/RevisionDeleter.php index 59a9fa82..c59edc2a 100644 --- a/includes/revisiondelete/RevisionDeleter.php +++ b/includes/revisiondelete/RevisionDeleter.php @@ -2,12 +2,29 @@ /** * Revision/log/file deletion backend * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/gpl.html + * * @file + * @ingroup RevisionDelete */ /** * Temporary b/c interface, collection of static functions. * @ingroup SpecialPage + * @ingroup RevisionDelete */ class RevisionDeleter { /** @@ -42,7 +59,7 @@ class RevisionDeleter { * * @param $n Integer: the new bitfield. * @param $o Integer: the old bitfield. - * @return An array as described above. + * @return array An array as described above. * @since 1.19 public */ public static function getChanges( $n, $o ) { @@ -107,69 +124,4 @@ class RevisionDeleter { return $timestamp; } - - /** - * Creates utility links for log entries. - * - * @param $title Title - * @param $paramArray Array - * @param $messages - * @return String - */ - public static function getLogLinks( $title, $paramArray, $messages ) { - global $wgLang; - - if ( count( $paramArray ) >= 2 ) { - // Different revision types use different URL params... - $key = $paramArray[0]; - // $paramArray[1] is a CSV of the IDs - $Ids = explode( ',', $paramArray[1] ); - - $revert = array(); - - // Diff link for single rev deletions - if ( count( $Ids ) == 1 ) { - // Live revision diffs... - if ( in_array( $key, array( 'oldid', 'revision' ) ) ) { - $revert[] = Linker::linkKnown( - $title, - $messages['diff'], - array(), - array( - 'diff' => intval( $Ids[0] ), - 'unhide' => 1 - ) - ); - // Deleted revision diffs... - } elseif ( in_array( $key, array( 'artimestamp','archive' ) ) ) { - $revert[] = Linker::linkKnown( - SpecialPage::getTitleFor( 'Undelete' ), - $messages['diff'], - array(), - array( - 'target' => $title->getPrefixedDBKey(), - 'diff' => 'prev', - 'timestamp' => $Ids[0] - ) - ); - } - } - - // View/modify link... - $revert[] = Linker::linkKnown( - SpecialPage::getTitleFor( 'Revisiondelete' ), - $messages['revdel-restore'], - array(), - array( - 'target' => $title->getPrefixedText(), - 'type' => $key, - 'ids' => implode(',', $Ids), - ) - ); - - // Pipe links - return wfMsg( 'parentheses', $wgLang->pipeList( $revert ) ); - } - return ''; - } } |