r89932 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r89931‎ | r89932 | r89933 >
Date:18:46, 12 June 2011
Author:ialex
Status:ok (Comments)
Tags:
Comment:
Moved action=deletetrackback and action=markpatrolled to Action class.
Also fixed order in DefaultSettings.php
Modified paths:
  • /trunk/phase3/includes/Article.php (modified) (history)
  • /trunk/phase3/includes/AutoLoader.php (modified) (history)
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/includes/Wiki.php (modified) (history)
  • /trunk/phase3/includes/actions/DeletetrackbackAction.php (added) (history)
  • /trunk/phase3/includes/actions/MarkpatrolledAction.php (added) (history)

Diff [purge]

Index: trunk/phase3/includes/Article.php
@@ -1706,29 +1706,10 @@
17071707
17081708 /**
17091709 * Removes trackback record for current article from trackbacks table
 1710+ * @deprecated since 1.19
17101711 */
17111712 public function deletetrackback() {
1712 - global $wgRequest, $wgOut;
1713 -
1714 - if ( !$wgOut->getUser()->matchEditToken( $wgRequest->getVal( 'token' ) ) ) {
1715 - $wgOut->addWikiMsg( 'sessionfailure' );
1716 -
1717 - return;
1718 - }
1719 -
1720 - $permission_errors = $this->mTitle->getUserPermissionsErrors( 'delete', $wgOut->getUser() );
1721 -
1722 - if ( count( $permission_errors ) ) {
1723 - $wgOut->showPermissionsErrorPage( $permission_errors );
1724 -
1725 - return;
1726 - }
1727 -
1728 - $db = wfGetDB( DB_MASTER );
1729 - $db->delete( 'trackbacks', array( 'tb_id' => $wgRequest->getInt( 'tbid' ) ) );
1730 -
1731 - $wgOut->addWikiMsg( 'trackbackdeleteok' );
1732 - $this->mTitle->invalidateCache();
 1713+ return Action::factory( 'deletetrackback', $this )->show();
17331714 }
17341715
17351716 /**
@@ -1786,62 +1767,10 @@
17871768
17881769 /**
17891770 * Mark this particular edit/page as patrolled
 1771+ * @deprecated since 1.19
17901772 */
17911773 public function markpatrolled() {
1792 - global $wgOut, $wgRequest;
1793 -
1794 - $wgOut->setRobotPolicy( 'noindex,nofollow' );
1795 -
1796 - # If we haven't been given an rc_id value, we can't do anything
1797 - $rcid = (int) $wgRequest->getVal( 'rcid' );
1798 -
1799 - if ( !$wgOut->getUser()->matchEditToken( $wgRequest->getVal( 'token' ), $rcid ) ) {
1800 - $wgOut->showErrorPage( 'sessionfailure-title', 'sessionfailure' );
1801 - return;
1802 - }
1803 -
1804 - $rc = RecentChange::newFromId( $rcid );
1805 -
1806 - if ( is_null( $rc ) ) {
1807 - $wgOut->showErrorPage( 'markedaspatrollederror', 'markedaspatrollederrortext' );
1808 - return;
1809 - }
1810 -
1811 - # It would be nice to see where the user had actually come from, but for now just guess
1812 - $returnto = $rc->getAttribute( 'rc_type' ) == RC_NEW ? 'Newpages' : 'Recentchanges';
1813 - $return = SpecialPage::getTitleFor( $returnto );
1814 -
1815 - $errors = $rc->doMarkPatrolled();
1816 -
1817 - if ( in_array( array( 'rcpatroldisabled' ), $errors ) ) {
1818 - $wgOut->showErrorPage( 'rcpatroldisabled', 'rcpatroldisabledtext' );
1819 -
1820 - return;
1821 - }
1822 -
1823 - if ( in_array( array( 'hookaborted' ), $errors ) ) {
1824 - // The hook itself has handled any output
1825 - return;
1826 - }
1827 -
1828 - if ( in_array( array( 'markedaspatrollederror-noautopatrol' ), $errors ) ) {
1829 - $wgOut->setPageTitle( wfMsg( 'markedaspatrollederror' ) );
1830 - $wgOut->addWikiMsg( 'markedaspatrollederror-noautopatrol' );
1831 - $wgOut->returnToMain( null, $return );
1832 -
1833 - return;
1834 - }
1835 -
1836 - if ( !empty( $errors ) ) {
1837 - $wgOut->showPermissionsErrorPage( $errors );
1838 -
1839 - return;
1840 - }
1841 -
1842 - # Inform the user
1843 - $wgOut->setPageTitle( wfMsg( 'markedaspatrolled' ) );
1844 - $wgOut->addWikiMsg( 'markedaspatrolledtext', $rc->getTitle()->getPrefixedText() );
1845 - $wgOut->returnToMain( null, $return );
 1774+ Action::factory( 'markpatrolled', $this )->show();
18461775 }
18471776
18481777 /**
Index: trunk/phase3/includes/actions/MarkpatrolledAction.php
@@ -0,0 +1,86 @@
 2+<?php
 3+/**
 4+ * Mark a revision as patrolled on a page
 5+ *
 6+ * Copyright © 2011 Alexandre Emsenhuber
 7+ *
 8+ * This program is free software; you can redistribute it and/or modify
 9+ * it under the terms of the GNU General Public License as published by
 10+ * the Free Software Foundation; either version 2 of the License, or
 11+ * (at your option) any later version.
 12+ *
 13+ * This program is distributed in the hope that it will be useful,
 14+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
 15+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 16+ * GNU General Public License for more details.
 17+ *
 18+ * You should have received a copy of the GNU General Public License
 19+ * along with this program; if not, write to the Free Software
 20+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
 21+ *
 22+ * @file
 23+ * @ingroup Actions
 24+ */
 25+
 26+class MarkpatrolledAction extends FormlessAction {
 27+
 28+ public function getName() {
 29+ return 'markpatrolled';
 30+ }
 31+
 32+ public function getRestriction() {
 33+ return 'read';
 34+ }
 35+
 36+ protected function getDescription() {
 37+ return '';
 38+ }
 39+
 40+ protected function checkCanExecute( User $user ) {
 41+ if ( !$user->matchEditToken( $this->getRequest()->getVal( 'token' ), $this->getRequest()->getInt( 'rcid' ) ) ) {
 42+ throw new ErrorPageError( 'sessionfailure-title', 'sessionfailure' );
 43+ }
 44+
 45+ return parent::checkCanExecute( $user );
 46+ }
 47+
 48+ public function onView() {
 49+ $rc = RecentChange::newFromId( $this->getRequest()->getInt( 'rcid' ) );
 50+
 51+ if ( is_null( $rc ) ) {
 52+ throw new ErrorPageError( 'markedaspatrollederror', 'markedaspatrollederrortext' );
 53+ }
 54+
 55+ # It would be nice to see where the user had actually come from, but for now just guess
 56+ $returnto = $rc->getAttribute( 'rc_type' ) == RC_NEW ? 'Newpages' : 'Recentchanges';
 57+ $return = SpecialPage::getTitleFor( $returnto );
 58+
 59+ $errors = $rc->doMarkPatrolled();
 60+
 61+ if ( in_array( array( 'rcpatroldisabled' ), $errors ) ) {
 62+ throw new ErrorPageError( 'rcpatroldisabled', 'rcpatroldisabledtext' );
 63+ }
 64+
 65+ if ( in_array( array( 'hookaborted' ), $errors ) ) {
 66+ // The hook itself has handled any output
 67+ return;
 68+ }
 69+
 70+ if ( in_array( array( 'markedaspatrollederror-noautopatrol' ), $errors ) ) {
 71+ $this->getOutput()->setPageTitle( wfMsg( 'markedaspatrollederror' ) );
 72+ $this->getOutput()->addWikiMsg( 'markedaspatrollederror-noautopatrol' );
 73+ $this->getOutput()->returnToMain( null, $return );
 74+ return;
 75+ }
 76+
 77+ if ( !empty( $errors ) ) {
 78+ $this->getOutput()->showPermissionsErrorPage( $errors );
 79+ return;
 80+ }
 81+
 82+ # Inform the user
 83+ $this->getOutput()->setPageTitle( wfMsg( 'markedaspatrolled' ) );
 84+ $this->getOutput()->addWikiMsg( 'markedaspatrolledtext', $rc->getTitle()->getPrefixedText() );
 85+ $this->getOutput()->returnToMain( null, $return );
 86+ }
 87+}
Property changes on: trunk/phase3/includes/actions/MarkpatrolledAction.php
___________________________________________________________________
Added: svn:eol-style
188 + native
Index: trunk/phase3/includes/actions/DeletetrackbackAction.php
@@ -0,0 +1,54 @@
 2+<?php
 3+/**
 4+ * Delete a trackback on a page
 5+ *
 6+ * Copyright © 2011 Alexandre Emsenhuber
 7+ *
 8+ * This program is free software; you can redistribute it and/or modify
 9+ * it under the terms of the GNU General Public License as published by
 10+ * the Free Software Foundation; either version 2 of the License, or
 11+ * (at your option) any later version.
 12+ *
 13+ * This program is distributed in the hope that it will be useful,
 14+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
 15+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 16+ * GNU General Public License for more details.
 17+ *
 18+ * You should have received a copy of the GNU General Public License
 19+ * along with this program; if not, write to the Free Software
 20+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
 21+ *
 22+ * @file
 23+ * @ingroup Actions
 24+ */
 25+
 26+class DeletetrackbackAction extends FormlessAction {
 27+
 28+ public function getName() {
 29+ return 'deletetrackback';
 30+ }
 31+
 32+ public function getRestriction() {
 33+ return 'delete';
 34+ }
 35+
 36+ protected function getDescription() {
 37+ return '';
 38+ }
 39+
 40+ protected function checkCanExecute( User $user ) {
 41+ if ( !$user->matchEditToken( $this->getRequest()->getVal( 'token' ) ) ) {
 42+ throw new ErrorPageError( 'sessionfailure-title', 'sessionfailure' );
 43+ }
 44+
 45+ return parent::checkCanExecute( $user );
 46+ }
 47+
 48+ public function onView() {
 49+ $db = wfGetDB( DB_MASTER );
 50+ $db->delete( 'trackbacks', array( 'tb_id' => $this->getRequest()->getInt( 'tbid' ) ) );
 51+
 52+ $this->getOutput()->addWikiMsg( 'trackbackdeleteok' );
 53+ $this->getTitle()->invalidateCache();
 54+ }
 55+}
Property changes on: trunk/phase3/includes/actions/DeletetrackbackAction.php
___________________________________________________________________
Added: svn:eol-style
156 + native
Index: trunk/phase3/includes/AutoLoader.php
@@ -249,6 +249,8 @@
250250
251251 # includes/actions
252252 'CreditsAction' => 'includes/actions/CreditsAction.php',
 253+ 'DeletetrackbackAction' => 'includes/actions/DeletetrackbackAction.php',
 254+ 'MarkpatrolledAction' => 'includes/actions/MarkpatrolledAction.php',
253255 'PurgeAction' => 'includes/actions/PurgeAction.php',
254256 'RevisiondeleteAction' => 'includes/actions/RevisiondeleteAction.php',
255257 'UnwatchAction' => 'includes/actions/WatchAction.php',
Index: trunk/phase3/includes/Wiki.php
@@ -430,9 +430,7 @@
431431 case 'protect':
432432 case 'unprotect':
433433 case 'info':
434 - case 'markpatrolled':
435434 case 'render':
436 - case 'deletetrackback':
437435 $article->$act();
438436 break;
439437 case 'submit':
Index: trunk/phase3/includes/DefaultSettings.php
@@ -5026,8 +5026,10 @@
50275027 */
50285028 $wgActions = array(
50295029 'credits' => true,
 5030+ 'deletetrackback' => true,
 5031+ 'markpatrolled' => true,
 5032+ 'purge' => true,
50305033 'revisiondelete' => true,
5031 - 'purge' => true,
50325034 'unwatch' => true,
50335035 'watch' => true,
50345036 );

Comments

#Comment by Nikerabbit (talk | contribs)   19:45, 12 June 2011

What was the point of this new Action class if it doesn't separate backend logic from frontend stuff?

#Comment by Krinkle (talk | contribs)   19:50, 12 June 2011

What about the API ?

#Comment by Krinkle (talk | contribs)   19:51, 12 June 2011

Nevermind, ApiPatrol uses it's own methods.

Status & tagging log