summaryrefslogtreecommitdiff
path: root/includes/actions
diff options
context:
space:
mode:
Diffstat (limited to 'includes/actions')
-rw-r--r--includes/actions/CreditsAction.php235
-rw-r--r--includes/actions/DeletetrackbackAction.php54
-rw-r--r--includes/actions/InfoAction.php151
-rw-r--r--includes/actions/MarkpatrolledAction.php86
-rw-r--r--includes/actions/PurgeAction.php100
-rw-r--r--includes/actions/RevertAction.php140
-rw-r--r--includes/actions/RevisiondeleteAction.php53
-rw-r--r--includes/actions/RollbackAction.php122
-rw-r--r--includes/actions/WatchAction.php183
9 files changed, 1124 insertions, 0 deletions
diff --git a/includes/actions/CreditsAction.php b/includes/actions/CreditsAction.php
new file mode 100644
index 00000000..1040085b
--- /dev/null
+++ b/includes/actions/CreditsAction.php
@@ -0,0 +1,235 @@
+<?php
+/**
+ * Formats credits for articles
+ *
+ * Copyright 2004, Evan Prodromou <evan@wikitravel.org>.
+ *
+ * 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
+ *
+ * @file
+ * @ingroup Actions
+ * @author <evan@wikitravel.org>
+ */
+
+class CreditsAction extends FormlessAction {
+
+ public function getName() {
+ return 'credits';
+ }
+
+ public function getRestriction() {
+ return null;
+ }
+
+ protected function getDescription() {
+ return wfMsg( 'creditspage' );
+ }
+
+ /**
+ * This is largely cadged from PageHistory::history
+ *
+ * @return String HTML
+ */
+ public function onView() {
+ wfProfileIn( __METHOD__ );
+
+ if ( $this->page->getID() == 0 ) {
+ $s = wfMsg( 'nocredits' );
+ } else {
+ $s = $this->getCredits( -1 );
+ }
+
+ wfProfileOut( __METHOD__ );
+
+ return Html::rawElement( 'div', array( 'id' => 'mw-credits' ), $s );
+ }
+
+ /**
+ * Get a list of contributors
+ *
+ * @param $cnt Int: maximum list of contributors to show
+ * @param $showIfMax Bool: whether to contributors if there more than $cnt
+ * @return String: html
+ */
+ public function getCredits( $cnt, $showIfMax = true ) {
+ wfProfileIn( __METHOD__ );
+ $s = '';
+
+ if ( isset( $cnt ) && $cnt != 0 ) {
+ $s = self::getAuthor( $this->page );
+ if ( $cnt > 1 || $cnt < 0 ) {
+ $s .= ' ' . $this->getContributors( $cnt - 1, $showIfMax );
+ }
+ }
+
+ wfProfileOut( __METHOD__ );
+ return $s;
+ }
+
+ /**
+ * Get the last author with the last modification time
+ * @param $article Article object
+ * @return String HTML
+ */
+ protected static function getAuthor( Page $article ) {
+ global $wgLang;
+
+ $user = User::newFromId( $article->getUser() );
+
+ $timestamp = $article->getTimestamp();
+ if ( $timestamp ) {
+ $d = $wgLang->date( $article->getTimestamp(), true );
+ $t = $wgLang->time( $article->getTimestamp(), true );
+ } else {
+ $d = '';
+ $t = '';
+ }
+ return wfMessage( 'lastmodifiedatby', $d, $t )->rawParams( self::userLink( $user ) )->params( $user->getName() )->escaped();
+ }
+
+ /**
+ * Get a list of contributors of $article
+ * @param $cnt Int: maximum list of contributors to show
+ * @param $showIfMax Bool: whether to contributors if there more than $cnt
+ * @return String: html
+ */
+ protected function getContributors( $cnt, $showIfMax ) {
+ global $wgLang, $wgHiddenPrefs;
+
+ $contributors = $this->page->getContributors();
+
+ $others_link = false;
+
+ # Hmm... too many to fit!
+ if ( $cnt > 0 && $contributors->count() > $cnt ) {
+ $others_link = $this->othersLink();
+ if ( !$showIfMax )
+ return wfMessage( 'othercontribs' )->rawParams( $others_link )->params( $contributors->count() )->escaped();
+ }
+
+ $real_names = array();
+ $user_names = array();
+ $anon_ips = array();
+
+ # Sift for real versus user names
+ foreach ( $contributors as $user ) {
+ $cnt--;
+ if ( $user->isLoggedIn() ) {
+ $link = self::link( $user );
+ if ( !in_array( 'realname', $wgHiddenPrefs ) && $user->getRealName() ) {
+ $real_names[] = $link;
+ } else {
+ $user_names[] = $link;
+ }
+ } else {
+ $anon_ips[] = self::link( $user );
+ }
+
+ if ( $cnt == 0 ) {
+ break;
+ }
+ }
+
+ if ( count( $real_names ) ) {
+ $real = $wgLang->listToText( $real_names );
+ } else {
+ $real = false;
+ }
+
+ # "ThisSite user(s) A, B and C"
+ if ( count( $user_names ) ) {
+ $user = wfMessage( 'siteusers' )->rawParams( $wgLang->listToText( $user_names ) )->params(
+ count( $user_names ) )->escaped();
+ } else {
+ $user = false;
+ }
+
+ if ( count( $anon_ips ) ) {
+ $anon = wfMessage( 'anonusers' )->rawParams( $wgLang->listToText( $anon_ips ) )->params(
+ count( $anon_ips ) )->escaped();
+ } else {
+ $anon = false;
+ }
+
+ # This is the big list, all mooshed together. We sift for blank strings
+ $fulllist = array();
+ foreach ( array( $real, $user, $anon, $others_link ) as $s ) {
+ if ( $s !== false ) {
+ array_push( $fulllist, $s );
+ }
+ }
+
+ $count = count( $fulllist );
+ # "Based on work by ..."
+ return $count
+ ? wfMessage( 'othercontribs' )->rawParams(
+ $wgLang->listToText( $fulllist ) )->params( $count )->escaped()
+ : '';
+ }
+
+ /**
+ * Get a link to $user's user page
+ * @param $user User object
+ * @return String: html
+ */
+ protected static function link( User $user ) {
+ global $wgHiddenPrefs;
+ if ( !in_array( 'realname', $wgHiddenPrefs ) && !$user->isAnon() ) {
+ $real = $user->getRealName();
+ } else {
+ $real = false;
+ }
+
+ $page = $user->isAnon()
+ ? SpecialPage::getTitleFor( 'Contributions', $user->getName() )
+ : $user->getUserPage();
+
+ return Linker::link( $page, htmlspecialchars( $real ? $real : $user->getName() ) );
+ }
+
+ /**
+ * Get a link to $user's user page
+ * @param $user User object
+ * @return String: html
+ */
+ protected static function userLink( User $user ) {
+ $link = self::link( $user );
+ if ( $user->isAnon() ) {
+ return wfMsgExt( 'anonuser', array( 'parseinline', 'replaceafter' ), $link );
+ } else {
+ global $wgHiddenPrefs;
+ if ( !in_array( 'realname', $wgHiddenPrefs ) && $user->getRealName() ) {
+ return $link;
+ } else {
+ return wfMessage( 'siteuser' )->rawParams( $link )->params( $user->getName() )->escaped();
+ }
+ }
+ }
+
+ /**
+ * Get a link to action=credits of $article page
+ * @param $article Article object
+ * @return String: html
+ */
+ protected function othersLink() {
+ return Linker::link(
+ $this->getTitle(),
+ wfMsgHtml( 'others' ),
+ array(),
+ array( 'action' => 'credits' ),
+ array( 'known' )
+ );
+ }
+}
diff --git a/includes/actions/DeletetrackbackAction.php b/includes/actions/DeletetrackbackAction.php
new file mode 100644
index 00000000..0efebdf5
--- /dev/null
+++ b/includes/actions/DeletetrackbackAction.php
@@ -0,0 +1,54 @@
+<?php
+/**
+ * Delete a trackback on a page
+ *
+ * Copyright © 2011 Alexandre Emsenhuber
+ *
+ * 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
+ *
+ * @file
+ * @ingroup Actions
+ */
+
+class DeletetrackbackAction extends FormlessAction {
+
+ public function getName() {
+ return 'deletetrackback';
+ }
+
+ public function getRestriction() {
+ return 'delete';
+ }
+
+ protected function getDescription() {
+ return '';
+ }
+
+ protected function checkCanExecute( User $user ) {
+ if ( !$user->matchEditToken( $this->getRequest()->getVal( 'token' ) ) ) {
+ throw new ErrorPageError( 'sessionfailure-title', 'sessionfailure' );
+ }
+
+ return parent::checkCanExecute( $user );
+ }
+
+ public function onView() {
+ $db = wfGetDB( DB_MASTER );
+ $db->delete( 'trackbacks', array( 'tb_id' => $this->getRequest()->getInt( 'tbid' ) ) );
+
+ $this->getOutput()->addWikiMsg( 'trackbackdeleteok' );
+ $this->getTitle()->invalidateCache();
+ }
+}
diff --git a/includes/actions/InfoAction.php b/includes/actions/InfoAction.php
new file mode 100644
index 00000000..b0b5f259
--- /dev/null
+++ b/includes/actions/InfoAction.php
@@ -0,0 +1,151 @@
+<?php
+/**
+ * Display informations about a page.
+ * Very inefficient for the moment.
+ *
+ * Copyright © 2011 Alexandre Emsenhuber
+ *
+ * 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
+ *
+ * @file
+ * @ingroup Actions
+ */
+
+class InfoAction extends FormlessAction {
+
+ public function getName() {
+ return 'info';
+ }
+
+ public function getRestriction() {
+ return 'read';
+ }
+
+ protected function getDescription() {
+ return '';
+ }
+
+ public function requiresWrite() {
+ return false;
+ }
+
+ public function requiresUnblock() {
+ return false;
+ }
+
+ protected function getPageTitle() {
+ return wfMsg( 'pageinfo-title', $this->getTitle()->getSubjectPage()->getPrefixedText() );
+ }
+
+ public function onView() {
+ global $wgDisableCounters;
+
+ $title = $this->getTitle()->getSubjectPage();
+
+ $pageInfo = self::pageCountInfo( $title );
+ $talkInfo = self::pageCountInfo( $title->getTalkPage() );
+
+ return Html::rawElement( 'table', array( 'class' => 'wikitable mw-page-info' ),
+ Html::rawElement( 'tr', array(),
+ Html::element( 'th', array(), '' ) .
+ Html::element( 'th', array(), wfMsg( 'pageinfo-subjectpage' ) ) .
+ Html::element( 'th', array(), wfMsg( 'pageinfo-talkpage' ) )
+ ) .
+ Html::rawElement( 'tr', array(),
+ Html::element( 'th', array( 'colspan' => 3 ), wfMsg( 'pageinfo-header-edits' ) )
+ ) .
+ Html::rawElement( 'tr', array(),
+ Html::element( 'td', array(), wfMsg( 'pageinfo-edits' ) ) .
+ Html::element( 'td', array(), $this->getLang()->formatNum( $pageInfo['edits'] ) ) .
+ Html::element( 'td', array(), $this->getLang()->formatNum( $talkInfo['edits'] ) )
+ ) .
+ Html::rawElement( 'tr', array(),
+ Html::element( 'td', array(), wfMsg( 'pageinfo-authors' ) ) .
+ Html::element( 'td', array(), $this->getLang()->formatNum( $pageInfo['authors'] ) ) .
+ Html::element( 'td', array(), $this->getLang()->formatNum( $talkInfo['authors'] ) )
+ ) .
+ ( !$this->getUser()->isAllowed( 'unwatchedpages' ) ? '' :
+ Html::rawElement( 'tr', array(),
+ Html::element( 'th', array( 'colspan' => 3 ), wfMsg( 'pageinfo-header-watchlist' ) )
+ ) .
+ Html::rawElement( 'tr', array(),
+ Html::element( 'td', array(), wfMsg( 'pageinfo-watchers' ) ) .
+ Html::element( 'td', array( 'colspan' => 2 ), $this->getLang()->formatNum( $pageInfo['watchers'] ) )
+ )
+ ).
+ ( $wgDisableCounters ? '' :
+ Html::rawElement( 'tr', array(),
+ Html::element( 'th', array( 'colspan' => 3 ), wfMsg( 'pageinfo-header-views' ) )
+ ) .
+ Html::rawElement( 'tr', array(),
+ Html::element( 'td', array(), wfMsg( 'pageinfo-views' ) ) .
+ Html::element( 'td', array(), $this->getLang()->formatNum( $pageInfo['views'] ) ) .
+ Html::element( 'td', array(), $this->getLang()->formatNum( $talkInfo['views'] ) )
+ ) .
+ Html::rawElement( 'tr', array(),
+ Html::element( 'td', array(), wfMsg( 'pageinfo-viewsperedit' ) ) .
+ Html::element( 'td', array(), $this->getLang()->formatNum( sprintf( '%.2f', $pageInfo['edits'] ? $pageInfo['views'] / $pageInfo['edits'] : 0 ) ) ) .
+ Html::element( 'td', array(), $this->getLang()->formatNum( sprintf( '%.2f', $talkInfo['edits'] ? $talkInfo['views'] / $talkInfo['edits'] : 0 ) ) )
+ )
+ )
+ );
+ }
+
+ /**
+ * Return the total number of edits and number of unique editors
+ * on a given page. If page does not exist, returns false.
+ *
+ * @param $title Title object
+ * @return mixed array or boolean false
+ */
+ public static function pageCountInfo( $title ) {
+ $id = $title->getArticleId();
+ $dbr = wfGetDB( DB_SLAVE );
+
+ $watchers = (int)$dbr->selectField(
+ 'watchlist',
+ 'COUNT(*)',
+ array(
+ 'wl_title' => $title->getDBkey(),
+ 'wl_namespace' => $title->getNamespace()
+ ),
+ __METHOD__
+ );
+
+ $edits = (int)$dbr->selectField(
+ 'revision',
+ 'COUNT(rev_page)',
+ array( 'rev_page' => $id ),
+ __METHOD__
+ );
+
+ $authors = (int)$dbr->selectField(
+ 'revision',
+ 'COUNT(DISTINCT rev_user_text)',
+ array( 'rev_page' => $id ),
+ __METHOD__
+ );
+
+ $views = (int)$dbr->selectField(
+ 'page',
+ 'page_counter',
+ array( 'page_id' => $id ),
+ __METHOD__
+ );
+
+ return array( 'watchers' => $watchers, 'edits' => $edits,
+ 'authors' => $authors, 'views' => $views );
+ }
+}
diff --git a/includes/actions/MarkpatrolledAction.php b/includes/actions/MarkpatrolledAction.php
new file mode 100644
index 00000000..a5d76627
--- /dev/null
+++ b/includes/actions/MarkpatrolledAction.php
@@ -0,0 +1,86 @@
+<?php
+/**
+ * Mark a revision as patrolled on a page
+ *
+ * Copyright © 2011 Alexandre Emsenhuber
+ *
+ * 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
+ *
+ * @file
+ * @ingroup Actions
+ */
+
+class MarkpatrolledAction extends FormlessAction {
+
+ public function getName() {
+ return 'markpatrolled';
+ }
+
+ public function getRestriction() {
+ return 'read';
+ }
+
+ protected function getDescription() {
+ return '';
+ }
+
+ protected function checkCanExecute( User $user ) {
+ if ( !$user->matchEditToken( $this->getRequest()->getVal( 'token' ), $this->getRequest()->getInt( 'rcid' ) ) ) {
+ throw new ErrorPageError( 'sessionfailure-title', 'sessionfailure' );
+ }
+
+ return parent::checkCanExecute( $user );
+ }
+
+ public function onView() {
+ $rc = RecentChange::newFromId( $this->getRequest()->getInt( 'rcid' ) );
+
+ if ( is_null( $rc ) ) {
+ throw new ErrorPageError( 'markedaspatrollederror', 'markedaspatrollederrortext' );
+ }
+
+ $errors = $rc->doMarkPatrolled( $this->getUser() );
+
+ if ( in_array( array( 'rcpatroldisabled' ), $errors ) ) {
+ throw new ErrorPageError( 'rcpatroldisabled', 'rcpatroldisabledtext' );
+ }
+
+ if ( in_array( array( 'hookaborted' ), $errors ) ) {
+ // The hook itself has handled any output
+ return;
+ }
+
+ # It would be nice to see where the user had actually come from, but for now just guess
+ $returnto = $rc->getAttribute( 'rc_type' ) == RC_NEW ? 'Newpages' : 'Recentchanges';
+ $return = SpecialPage::getTitleFor( $returnto );
+
+ if ( in_array( array( 'markedaspatrollederror-noautopatrol' ), $errors ) ) {
+ $this->getOutput()->setPageTitle( wfMsg( 'markedaspatrollederror' ) );
+ $this->getOutput()->addWikiMsg( 'markedaspatrollederror-noautopatrol' );
+ $this->getOutput()->returnToMain( null, $return );
+ return;
+ }
+
+ if ( !empty( $errors ) ) {
+ $this->getOutput()->showPermissionsErrorPage( $errors );
+ return;
+ }
+
+ # Inform the user
+ $this->getOutput()->setPageTitle( wfMsg( 'markedaspatrolled' ) );
+ $this->getOutput()->addWikiMsg( 'markedaspatrolledtext', $rc->getTitle()->getPrefixedText() );
+ $this->getOutput()->returnToMain( null, $return );
+ }
+}
diff --git a/includes/actions/PurgeAction.php b/includes/actions/PurgeAction.php
new file mode 100644
index 00000000..29cbf3ae
--- /dev/null
+++ b/includes/actions/PurgeAction.php
@@ -0,0 +1,100 @@
+<?php
+/**
+ * Formats credits for articles
+ *
+ * Copyright 2004, Evan Prodromou <evan@wikitravel.org>.
+ *
+ * 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
+ *
+ * @file
+ * @ingroup Actions
+ * @author <evan@wikitravel.org>
+ */
+
+class PurgeAction extends FormAction {
+
+ private $redirectParams;
+
+ public function getName() {
+ return 'purge';
+ }
+
+ public function getRestriction() {
+ return null;
+ }
+
+ public function requiresUnblock() {
+ return false;
+ }
+
+ public function getDescription() {
+ return '';
+ }
+
+ /**
+ * Just get an empty form with a single submit button
+ * @return array
+ */
+ protected function getFormFields() {
+ return array();
+ }
+
+ public function onSubmit( $data ) {
+ $this->page->doPurge();
+ return true;
+ }
+
+ /**
+ * purge is slightly weird because it can be either formed or formless depending
+ * on user permissions
+ */
+ public function show() {
+ $this->setHeaders();
+
+ // This will throw exceptions if there's a problem
+ $this->checkCanExecute( $this->getUser() );
+
+ if ( $this->getUser()->isAllowed( 'purge' ) ) {
+ $this->redirectParams = wfArrayToCGI( array_diff_key(
+ $this->getRequest()->getQueryValues(),
+ array( 'title' => null, 'action' => null )
+ ) );
+ $this->onSubmit( array() );
+ $this->onSuccess();
+ } else {
+ $this->redirectParams = $this->getRequest()->getVal( 'redirectparams', '' );
+ $form = $this->getForm();
+ if ( $form->show() ) {
+ $this->onSuccess();
+ }
+ }
+ }
+
+ protected function alterForm( HTMLForm $form ) {
+ $form->setSubmitText( wfMsg( 'confirm_purge_button' ) );
+ }
+
+ protected function preText() {
+ return wfMessage( 'confirm-purge-top' )->parse();
+ }
+
+ protected function postText() {
+ return wfMessage( 'confirm-purge-bottom' )->parse();
+ }
+
+ public function onSuccess() {
+ $this->getOutput()->redirect( $this->getTitle()->getFullUrl( $this->redirectParams ) );
+ }
+}
diff --git a/includes/actions/RevertAction.php b/includes/actions/RevertAction.php
new file mode 100644
index 00000000..bcb8cd8b
--- /dev/null
+++ b/includes/actions/RevertAction.php
@@ -0,0 +1,140 @@
+<?php
+/**
+ * File reversion user interface
+ *
+ * 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
+ *
+ * @file
+ * @ingroup Action
+ * @ingroup Media
+ * @author Alexandre Emsenhuber
+ * @author Rob Church <robchur@gmail.com>
+ */
+
+/**
+ * Dummy class for pages not in NS_FILE
+ *
+ * @ingroup Action
+ */
+class RevertAction extends Action {
+
+ public function getName() {
+ return 'revert';
+ }
+
+ public function getRestriction() {
+ return 'read';
+ }
+
+ public function show() {
+ $this->getOutput()->showErrorPage( 'nosuchaction', 'nosuchactiontext' );
+ }
+
+ public function execute() {}
+}
+
+/**
+ * Class for pages in NS_FILE
+ *
+ * @ingroup Action
+ */
+class RevertFileAction extends FormAction {
+ protected $oldFile;
+
+ public function getName() {
+ return 'revert';
+ }
+
+ public function getRestriction() {
+ return 'upload';
+ }
+
+ protected function checkCanExecute( User $user ) {
+ parent::checkCanExecute( $user );
+
+ $oldimage = $this->getRequest()->getText( 'oldimage' );
+ if ( strlen( $oldimage ) < 16
+ || strpos( $oldimage, '/' ) !== false
+ || strpos( $oldimage, '\\' ) !== false )
+ {
+ throw new ErrorPageError( 'internalerror', 'unexpected', array( 'oldimage', $oldimage ) );
+ }
+
+ $this->oldFile = RepoGroup::singleton()->getLocalRepo()->newFromArchiveName( $this->getTitle(), $oldimage );
+ if ( !$this->oldFile->exists() ) {
+ throw new ErrorPageError( '', 'filerevert-badversion' );
+ }
+ }
+
+ protected function alterForm( HTMLForm $form ) {
+ $form->setWrapperLegend( wfMsgHtml( 'filerevert-legend' ) );
+ $form->setSubmitText( wfMsg( 'filerevert-submit' ) );
+ $form->addHiddenField( 'oldimage', $this->getRequest()->getText( 'oldimage' ) );
+ }
+
+ protected function getFormFields() {
+ global $wgContLang;
+
+ $timestamp = $this->oldFile->getTimestamp();
+
+ return array(
+ 'intro' => array(
+ 'type' => 'info',
+ 'vertical-label' => true,
+ 'raw' => true,
+ 'default' => wfMsgExt( 'filerevert-intro', 'parse', $this->getTitle()->getText(),
+ $this->getLang()->date( $timestamp, true ), $this->getLang()->time( $timestamp, true ),
+ wfExpandUrl( $this->page->getFile()->getArchiveUrl( $this->getRequest()->getText( 'oldimage' ) ),
+ PROTO_CURRENT
+ ) )
+ ),
+ 'comment' => array(
+ 'type' => 'text',
+ 'label-message' => 'filerevert-comment',
+ 'default' => wfMsgForContent( 'filerevert-defaultcomment',
+ $wgContLang->date( $timestamp, false, false ), $wgContLang->time( $timestamp, false, false ) ),
+ )
+ );
+ }
+
+ public function onSubmit( $data ) {
+ $source = $this->page->getFile()->getArchiveVirtualUrl( $this->getRequest()->getText( 'oldimage' ) );
+ $comment = $data['comment'];
+ // TODO: Preserve file properties from database instead of reloading from file
+ return $this->page->getFile()->upload( $source, $comment, $comment );
+ }
+
+ public function onSuccess() {
+ $timestamp = $this->oldFile->getTimestamp();
+ $this->getOutput()->addHTML( wfMsgExt( 'filerevert-success', 'parse', $this->getTitle()->getText(),
+ $this->getLang()->date( $timestamp, true ),
+ $this->getLang()->time( $timestamp, true ),
+ wfExpandUrl( $this->page->getFile()->getArchiveUrl( $this->getRequest()->getText( 'oldimage' ) ),
+ PROTO_CURRENT
+ ) ) );
+ $this->getOutput()->returnToMain( false, $this->getTitle() );
+ }
+
+ protected function getPageTitle() {
+ return wfMsg( 'filerevert', $this->getTitle()->getText() );
+ }
+
+ protected function getDescription() {
+ return wfMsg(
+ 'filerevert-backlink',
+ Linker::linkKnown( $this->getTitle() )
+ );
+ }
+}
diff --git a/includes/actions/RevisiondeleteAction.php b/includes/actions/RevisiondeleteAction.php
new file mode 100644
index 00000000..2ac03d18
--- /dev/null
+++ b/includes/actions/RevisiondeleteAction.php
@@ -0,0 +1,53 @@
+<?php
+/**
+ * An action that just pass the request to Special:RevisionDelete
+ *
+ * Copyright © 2011 Alexandre Emsenhuber
+ *
+ * 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
+ *
+ * @file
+ * @ingroup Actions
+ * @author Alexandre Emsenhuber
+ */
+
+class RevisiondeleteAction extends FormlessAction {
+
+ public function getName() {
+ return 'revisiondelete';
+ }
+
+ public function getRestriction() {
+ return null;
+ }
+
+ public function requiresUnblock() {
+ return false;
+ }
+
+ public function getDescription() {
+ return '';
+ }
+
+ public function onView() {
+ return '';
+ }
+
+ public function show() {
+ $special = SpecialPageFactory::getPage( 'Revisiondelete' );
+ $special->setContext( $this->getContext() );
+ $special->execute( '' );
+ }
+}
diff --git a/includes/actions/RollbackAction.php b/includes/actions/RollbackAction.php
new file mode 100644
index 00000000..9036ebf5
--- /dev/null
+++ b/includes/actions/RollbackAction.php
@@ -0,0 +1,122 @@
+<?php
+/**
+ * Edit rollback user interface
+ *
+ * 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
+ *
+ * @file
+ * @ingroup Action
+ */
+
+/**
+ * User interface for the rollback action
+ *
+ * @ingroup Action
+ */
+class RollbackAction extends FormlessAction {
+
+ public function getName() {
+ return 'rollback';
+ }
+
+ public function getRestriction() {
+ return 'rollback';
+ }
+
+ public function onView() {
+ $details = null;
+
+ $request = $this->getRequest();
+
+ $result = $this->page->doRollback(
+ $request->getVal( 'from' ),
+ $request->getText( 'summary' ),
+ $request->getVal( 'token' ),
+ $request->getBool( 'bot' ),
+ $details,
+ $this->getUser()
+ );
+
+ if ( in_array( array( 'actionthrottledtext' ), $result ) ) {
+ throw new ThrottledError;
+ }
+
+ if ( isset( $result[0][0] ) && ( $result[0][0] == 'alreadyrolled' || $result[0][0] == 'cantrollback' ) ) {
+ $this->getOutput()->setPageTitle( wfMsg( 'rollbackfailed' ) );
+ $errArray = $result[0];
+ $errMsg = array_shift( $errArray );
+ $this->getOutput()->addWikiMsgArray( $errMsg, $errArray );
+
+ if ( isset( $details['current'] ) ) {
+ $current = $details['current'];
+
+ if ( $current->getComment() != '' ) {
+ $this->getOutput()->addHTML( wfMessage( 'editcomment' )->rawParams(
+ Linker::formatComment( $current->getComment() ) )->parse() );
+ }
+ }
+
+ return;
+ }
+
+ # Display permissions errors before read-only message -- there's no
+ # point in misleading the user into thinking the inability to rollback
+ # is only temporary.
+ if ( !empty( $result ) && $result !== array( array( 'readonlytext' ) ) ) {
+ # array_diff is completely broken for arrays of arrays, sigh.
+ # Remove any 'readonlytext' error manually.
+ $out = array();
+ foreach ( $result as $error ) {
+ if ( $error != array( 'readonlytext' ) ) {
+ $out [] = $error;
+ }
+ }
+ $this->getOutput()->showPermissionsErrorPage( $out );
+
+ return;
+ }
+
+ if ( $result == array( array( 'readonlytext' ) ) ) {
+ throw new ReadOnlyError;
+ }
+
+ $current = $details['current'];
+ $target = $details['target'];
+ $newId = $details['newid'];
+ $this->getOutput()->setPageTitle( wfMsg( 'actioncomplete' ) );
+ $this->getOutput()->setRobotPolicy( 'noindex,nofollow' );
+
+ if ( $current->getUserText() === '' ) {
+ $old = wfMsg( 'rev-deleted-user' );
+ } else {
+ $old = Linker::userLink( $current->getUser(), $current->getUserText() )
+ . Linker::userToolLinks( $current->getUser(), $current->getUserText() );
+ }
+
+ $new = Linker::userLink( $target->getUser(), $target->getUserText() )
+ . Linker::userToolLinks( $target->getUser(), $target->getUserText() );
+ $this->getOutput()->addHTML( wfMsgExt( 'rollback-success', array( 'parse', 'replaceafter' ), $old, $new ) );
+ $this->getOutput()->returnToMain( false, $this->getTitle() );
+
+ if ( !$request->getBool( 'hidediff', false ) && !$this->getUser()->getBoolOption( 'norollbackdiff', false ) ) {
+ $de = new DifferenceEngine( $this->getTitle(), $current->getId(), $newId, false, true );
+ $de->showDiff( '', '' );
+ }
+ }
+
+ protected function getDescription() {
+ return '';
+ }
+}
diff --git a/includes/actions/WatchAction.php b/includes/actions/WatchAction.php
new file mode 100644
index 00000000..52e66754
--- /dev/null
+++ b/includes/actions/WatchAction.php
@@ -0,0 +1,183 @@
+<?php
+/**
+ * Performs the watch and unwatch actions on a page
+ *
+ * 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
+ *
+ * @file
+ * @ingroup Actions
+ */
+
+class WatchAction extends FormAction {
+
+ public function getName() {
+ return 'watch';
+ }
+
+ public function getRestriction() {
+ return 'read';
+ }
+
+ public function requiresUnblock() {
+ return false;
+ }
+
+ protected function getDescription() {
+ return wfMsg( 'addwatch' );
+ }
+
+ /**
+ * Just get an empty form with a single submit button
+ * @return array
+ */
+ protected function getFormFields() {
+ return array();
+ }
+
+ public function onSubmit( $data ) {
+ wfProfileIn( __METHOD__ );
+ self::doWatch( $this->getTitle(), $this->getUser() );
+ wfProfileOut( __METHOD__ );
+ return true;
+ }
+
+ /**
+ * This can be either formed or formless depending on the session token given
+ */
+ public function show() {
+ $this->setHeaders();
+
+ $user = $this->getUser();
+ // This will throw exceptions if there's a problem
+ $this->checkCanExecute( $user );
+
+ // Must have valid token for this action/title
+ $salt = array( $this->getName(), $this->getTitle()->getDBkey() );
+
+ if ( $user->matchEditToken( $this->getRequest()->getVal( 'token' ), $salt ) ) {
+ $this->onSubmit( array() );
+ $this->onSuccess();
+ } else {
+ $form = $this->getForm();
+ if ( $form->show() ) {
+ $this->onSuccess();
+ }
+ }
+ }
+
+ protected function checkCanExecute( User $user ) {
+ // Must be logged in
+ if ( $user->isAnon() ) {
+ throw new ErrorPageError( 'watchnologin', 'watchnologintext' );
+ }
+
+ return parent::checkCanExecute( $user );
+ }
+
+ public static function doWatch( Title $title, User $user ) {
+ $page = new Article( $title, 0 );
+
+ if ( wfRunHooks( 'WatchArticle', array( &$user, &$page ) ) ) {
+ $user->addWatch( $title );
+ wfRunHooks( 'WatchArticleComplete', array( &$user, &$page ) );
+ }
+ return true;
+ }
+
+ public static function doUnwatch( Title $title, User $user ) {
+ $page = new Article( $title, 0 );
+
+ if ( wfRunHooks( 'UnwatchArticle', array( &$user, &$page ) ) ) {
+ $user->removeWatch( $title );
+ wfRunHooks( 'UnwatchArticleComplete', array( &$user, &$page ) );
+ }
+ return true;
+ }
+
+ /**
+ * Get token to watch (or unwatch) a page for a user
+ *
+ * @param Title $title Title object of page to watch
+ * @param User $title User for whom the action is going to be performed
+ * @param string $action Optionally override the action to 'unwatch'
+ * @return string Token
+ * @since 1.18
+ */
+ public static function getWatchToken( Title $title, User $user, $action = 'watch' ) {
+ if ( $action != 'unwatch' ) {
+ $action = 'watch';
+ }
+ $salt = array( $action, $title->getDBkey() );
+
+ // This token stronger salted and not compatible with ApiWatch
+ // It's title/action specific because index.php is GET and API is POST
+ return $user->editToken( $salt );
+ }
+
+ /**
+ * Get token to unwatch (or watch) a page for a user
+ *
+ * @param Title $title Title object of page to unwatch
+ * @param User $title User for whom the action is going to be performed
+ * @param string $action Optionally override the action to 'watch'
+ * @return string Token
+ * @since 1.18
+ */
+ public static function getUnwatchToken( Title $title, User $user, $action = 'unwatch' ) {
+ return self::getWatchToken( $title, $user, $action );
+ }
+
+ protected function alterForm( HTMLForm $form ) {
+ $form->setSubmitText( wfMsg( 'confirm-watch-button' ) );
+ }
+
+ protected function preText() {
+ return wfMessage( 'confirm-watch-top' )->parse();
+ }
+
+ public function onSuccess() {
+ $this->getOutput()->addWikiMsg( 'addedwatchtext', $this->getTitle()->getPrefixedText() );
+ }
+}
+
+class UnwatchAction extends WatchAction {
+
+ public function getName() {
+ return 'unwatch';
+ }
+
+ protected function getDescription() {
+ return wfMsg( 'removewatch' );
+ }
+
+ public function onSubmit( $data ) {
+ wfProfileIn( __METHOD__ );
+ self::doUnwatch( $this->getTitle(), $this->getUser() );
+ wfProfileOut( __METHOD__ );
+ return true;
+ }
+
+ protected function alterForm( HTMLForm $form ) {
+ $form->setSubmitText( wfMsg( 'confirm-unwatch-button' ) );
+ }
+
+ protected function preText() {
+ return wfMessage( 'confirm-unwatch-top' )->parse();
+ }
+
+ public function onSuccess() {
+ $this->getOutput()->addWikiMsg( 'removedwatchtext', $this->getTitle()->getPrefixedText() );
+ }
+}