summaryrefslogtreecommitdiff
path: root/includes/changetags
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2015-06-04 07:31:04 +0200
committerPierre Schmitz <pierre@archlinux.de>2015-06-04 07:58:39 +0200
commitf6d65e533c62f6deb21342d4901ece24497b433e (patch)
treef28adf0362d14bcd448f7b65a7aaf38650f923aa /includes/changetags
parentc27b2e832fe25651ef2410fae85b41072aae7519 (diff)
Update to MediaWiki 1.25.1
Diffstat (limited to 'includes/changetags')
-rw-r--r--includes/changetags/ChangeTagsList.php77
-rw-r--r--includes/changetags/ChangeTagsLogItem.php100
-rw-r--r--includes/changetags/ChangeTagsLogList.php89
-rw-r--r--includes/changetags/ChangeTagsRevisionItem.php58
-rw-r--r--includes/changetags/ChangeTagsRevisionList.php99
5 files changed, 423 insertions, 0 deletions
diff --git a/includes/changetags/ChangeTagsList.php b/includes/changetags/ChangeTagsList.php
new file mode 100644
index 00000000..dd8bab98
--- /dev/null
+++ b/includes/changetags/ChangeTagsList.php
@@ -0,0 +1,77 @@
+<?php
+/**
+ * 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 Change tagging
+ */
+
+/**
+ * Generic list for change tagging.
+ */
+abstract class ChangeTagsList extends RevisionListBase {
+ function __construct( IContextSource $context, Title $title, array $ids ) {
+ parent::__construct( $context, $title );
+ $this->ids = $ids;
+ }
+
+ /**
+ * Creates a ChangeTags*List of the requested type.
+ *
+ * @param string $typeName 'revision' or 'logentry'
+ * @param IContextSource $context
+ * @param Title $title
+ * @param array $ids
+ * @return ChangeTagsList An instance of the requested subclass
+ * @throws Exception If you give an unknown $typeName
+ */
+ public static function factory( $typeName, IContextSource $context,
+ Title $title, array $ids ) {
+
+ switch ( $typeName ) {
+ case 'revision':
+ $className = 'ChangeTagsRevisionList';
+ break;
+ case 'logentry':
+ $className = 'ChangeTagsLogList';
+ break;
+ default:
+ throw new Exception( "Class $className requested, but does not exist" );
+ }
+ return new $className( $context, $title, $ids );
+ }
+
+ /**
+ * Reload the list data from the master DB.
+ */
+ function reloadFromMaster() {
+ $dbw = wfGetDB( DB_MASTER );
+ $this->res = $this->doQuery( $dbw );
+ }
+
+ /**
+ * Add/remove change tags from all the items in the list.
+ *
+ * @param array $tagsToAdd
+ * @param array $tagsToRemove
+ * @param array $params
+ * @param string $reason
+ * @param User $user
+ * @return Status
+ */
+ abstract function updateChangeTagsOnAll( $tagsToAdd, $tagsToRemove, $params,
+ $reason, $user );
+}
diff --git a/includes/changetags/ChangeTagsLogItem.php b/includes/changetags/ChangeTagsLogItem.php
new file mode 100644
index 00000000..565d159a
--- /dev/null
+++ b/includes/changetags/ChangeTagsLogItem.php
@@ -0,0 +1,100 @@
+<?php
+/**
+ * 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 Change tagging
+ */
+
+/**
+ * Item class for a logging table row with its associated change tags.
+ * @todo Abstract out a base class for this and RevDelLogItem, similar to the
+ * RevisionItem class but specifically for log items.
+ * @since 1.25
+ */
+class ChangeTagsLogItem extends RevisionItemBase {
+ public function getIdField() {
+ return 'log_id';
+ }
+
+ public function getTimestampField() {
+ return 'log_timestamp';
+ }
+
+ public function getAuthorIdField() {
+ return 'log_user';
+ }
+
+ public function getAuthorNameField() {
+ return 'log_user_text';
+ }
+
+ public function canView() {
+ return LogEventsList::userCan( $this->row, Revision::DELETED_RESTRICTED, $this->list->getUser() );
+ }
+
+ public function canViewContent() {
+ return true; // none
+ }
+
+ /**
+ * @return string Comma-separated list of tags
+ */
+ public function getTags() {
+ return $this->row->ts_tags;
+ }
+
+ /**
+ * @return string A HTML <li> element representing this revision, showing
+ * change tags and everything
+ */
+ public function getHTML() {
+ $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' ),
+ $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
+ $comment = $this->list->getLanguage()->getDirMark() .
+ $formatter->getComment();
+
+ if ( LogEventsList::isDeleted( $this->row, LogPage::DELETED_COMMENT ) ) {
+ $comment = '<span class="history-deleted">' . $comment . '</span>';
+ }
+
+ $content = "$loglink $date $action $comment";
+ $attribs = array();
+ $tags = $this->getTags();
+ if ( $tags ) {
+ list( $tagSummary, $classes ) = ChangeTags::formatSummaryRow( $tags, 'edittags' );
+ $content .= " $tagSummary";
+ $attribs['class'] = implode( ' ', $classes );
+ }
+ return Xml::tags( 'li', $attribs, $content );
+ }
+}
diff --git a/includes/changetags/ChangeTagsLogList.php b/includes/changetags/ChangeTagsLogList.php
new file mode 100644
index 00000000..fe80695f
--- /dev/null
+++ b/includes/changetags/ChangeTagsLogList.php
@@ -0,0 +1,89 @@
+<?php
+/**
+ * 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 Change tagging
+ */
+
+/**
+ * Stores a list of taggable log entries.
+ * @since 1.25
+ */
+class ChangeTagsLogList extends ChangeTagsList {
+ public function getType() {
+ return 'logentry';
+ }
+
+ /**
+ * @param DatabaseBase $db
+ * @return mixed
+ */
+ public function doQuery( $db ) {
+ $ids = array_map( 'intval', $this->ids );
+ $queryInfo = DatabaseLogEntry::getSelectQueryData();
+ $queryInfo['conds'] += array( 'log_id' => $ids );
+ $queryInfo['options'] += array( 'ORDER BY' => 'log_id DESC' );
+ ChangeTags::modifyDisplayQuery(
+ $queryInfo['tables'],
+ $queryInfo['fields'],
+ $queryInfo['conds'],
+ $queryInfo['join_conds'],
+ $queryInfo['options']
+ );
+ return $db->select(
+ $queryInfo['tables'],
+ $queryInfo['fields'],
+ $queryInfo['conds'],
+ __METHOD__,
+ $queryInfo['options'],
+ $queryInfo['join_conds']
+ );
+ }
+
+ public function newItem( $row ) {
+ return new ChangeTagsLogItem( $this, $row );
+ }
+
+ /**
+ * Add/remove change tags from all the log entries in the list.
+ *
+ * @param array $tagsToAdd
+ * @param array $tagsToRemove
+ * @param array $params
+ * @param string $reason
+ * @param User $user
+ * @return Status
+ */
+ public function updateChangeTagsOnAll( $tagsToAdd, $tagsToRemove, $params,
+ $reason, $user ) {
+
+ // @codingStandardsIgnoreStart Generic.CodeAnalysis.ForLoopWithTestFunctionCall.NotAllowed
+ for ( $this->reset(); $this->current(); $this->next() ) {
+ // @codingStandardsIgnoreEnd
+ $item = $this->current();
+ $status = ChangeTags::updateTagsWithChecks( $tagsToAdd, $tagsToRemove,
+ null, null, $item->getId(), $params, $reason, $user );
+ // Should only fail on second and subsequent times if the user trips
+ // the rate limiter
+ if ( !$status->isOK() ) {
+ break;
+ }
+ }
+
+ return $status;
+ }
+}
diff --git a/includes/changetags/ChangeTagsRevisionItem.php b/includes/changetags/ChangeTagsRevisionItem.php
new file mode 100644
index 00000000..e90a1b4f
--- /dev/null
+++ b/includes/changetags/ChangeTagsRevisionItem.php
@@ -0,0 +1,58 @@
+<?php
+/**
+ * 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 Change tagging
+ */
+
+/**
+ * Item class for a live revision table row with its associated change tags.
+ * @since 1.25
+ */
+class ChangeTagsRevisionItem extends RevisionItem {
+ /**
+ * @return string Comma-separated list of tags
+ */
+ public function getTags() {
+ return $this->row->ts_tags;
+ }
+
+ /**
+ * @return string A HTML <li> element representing this revision, showing
+ * change tags and everything
+ */
+ public function getHTML() {
+ $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>";
+ }
+
+ $content = "$difflink $revlink $userlink $comment";
+ $attribs = array();
+ $tags = $this->getTags();
+ if ( $tags ) {
+ list( $tagSummary, $classes ) = ChangeTags::formatSummaryRow( $tags, 'edittags' );
+ $content .= " $tagSummary";
+ $attribs['class'] = implode( ' ', $classes );
+ }
+ return Xml::tags( 'li', $attribs, $content );
+ }
+}
diff --git a/includes/changetags/ChangeTagsRevisionList.php b/includes/changetags/ChangeTagsRevisionList.php
new file mode 100644
index 00000000..842d3272
--- /dev/null
+++ b/includes/changetags/ChangeTagsRevisionList.php
@@ -0,0 +1,99 @@
+<?php
+/**
+ * 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 Change tagging
+ */
+
+/**
+ * Stores a list of taggable revisions.
+ * @since 1.25
+ */
+class ChangeTagsRevisionList extends ChangeTagsList {
+ public function getType() {
+ return 'revision';
+ }
+
+ /**
+ * @param DatabaseBase $db
+ * @return mixed
+ */
+ public function doQuery( $db ) {
+ $ids = array_map( 'intval', $this->ids );
+ $queryInfo = array(
+ 'tables' => array( 'revision', 'user' ),
+ 'fields' => array_merge( Revision::selectFields(), Revision::selectUserFields() ),
+ 'conds' => array(
+ 'rev_page' => $this->title->getArticleID(),
+ 'rev_id' => $ids,
+ ),
+ 'options' => array( 'ORDER BY' => 'rev_id DESC' ),
+ 'join_conds' => array(
+ 'page' => Revision::pageJoinCond(),
+ 'user' => Revision::userJoinCond(),
+ ),
+ );
+ ChangeTags::modifyDisplayQuery(
+ $queryInfo['tables'],
+ $queryInfo['fields'],
+ $queryInfo['conds'],
+ $queryInfo['join_conds'],
+ $queryInfo['options']
+ );
+ return $db->select(
+ $queryInfo['tables'],
+ $queryInfo['fields'],
+ $queryInfo['conds'],
+ __METHOD__,
+ $queryInfo['options'],
+ $queryInfo['join_conds']
+ );
+ }
+
+ public function newItem( $row ) {
+ return new ChangeTagsRevisionItem( $this, $row );
+ }
+
+ /**
+ * Add/remove change tags from all the revisions in the list.
+ *
+ * @param array $tagsToAdd
+ * @param array $tagsToRemove
+ * @param array $params
+ * @param string $reason
+ * @param User $user
+ * @return Status
+ */
+ public function updateChangeTagsOnAll( $tagsToAdd, $tagsToRemove, $params,
+ $reason, $user ) {
+
+ // @codingStandardsIgnoreStart Generic.CodeAnalysis.ForLoopWithTestFunctionCall.NotAllowed
+ for ( $this->reset(); $this->current(); $this->next() ) {
+ // @codingStandardsIgnoreEnd
+ $item = $this->current();
+ $status = ChangeTags::updateTagsWithChecks( $tagsToAdd, $tagsToRemove,
+ null, $item->getId(), null, $params, $reason, $user );
+ // Should only fail on second and subsequent times if the user trips
+ // the rate limiter
+ if ( !$status->isOK() ) {
+ break;
+ }
+ }
+
+ return $status;
+ }
+}