Index: trunk/extensions/FlaggedRevs/FlaggedRevs.php |
— | — | @@ -347,6 +347,8 @@ |
348 | 348 | $wgAPIListModules['oldreviewedpages'] = 'ApiQueryOldreviewedpages'; |
349 | 349 | $wgAutoloadClasses['ApiQueryFlagged'] = $dir . 'api/ApiQueryFlagged.php'; |
350 | 350 | $wgAPIPropModules['flagged'] = 'ApiQueryFlagged'; |
| 351 | +$wgAutoloadClasses['ApiReview'] = $dir.'api/ApiReview.php'; |
| 352 | +$wgAPIModules['review'] = 'ApiReview'; |
351 | 353 | |
352 | 354 | ######### Hook attachments ######### |
353 | 355 | # Remove stand-alone patrolling |
Index: trunk/extensions/FlaggedRevs/api/ApiReview.php |
— | — | @@ -0,0 +1,166 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/* |
| 5 | + * Created on Dec 20, 2008 |
| 6 | + * |
| 7 | + * API module for MediaWiki's FlaggedRevs extension |
| 8 | + * |
| 9 | + * This program is free software; you can redistribute it and/or modify |
| 10 | + * it under the terms of the GNU General Public License as published by |
| 11 | + * the Free Software Foundation; either version 2 of the License, or |
| 12 | + * (at your option) any later version. |
| 13 | + * |
| 14 | + * This program is distributed in the hope that it will be useful, |
| 15 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | + * GNU General Public License for more details. |
| 18 | + * |
| 19 | + * You should have received a copy of the GNU General Public License along |
| 20 | + * with this program; if not, write to the Free Software Foundation, Inc., |
| 21 | + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 22 | + * http://www.gnu.org/copyleft/gpl.html |
| 23 | + */ |
| 24 | + |
| 25 | +/** |
| 26 | + * API module to review revisions |
| 27 | + * |
| 28 | + * @ingroup FlaggedRevs |
| 29 | + */ |
| 30 | +class ApiReview extends ApiBase { |
| 31 | + |
| 32 | + /** |
| 33 | + * This function does essentially the same as RevisionReview::AjaxReview, |
| 34 | + * except that it generates the template and image parameters itself. |
| 35 | + */ |
| 36 | + public function execute() { |
| 37 | + global $wgUser; |
| 38 | + $this->getMain()->requestWriteMode(); |
| 39 | + $params = $this->extractRequestParams(); |
| 40 | + |
| 41 | + // Check permissions |
| 42 | + if( !$wgUser->isAllowed( 'review' ) ) |
| 43 | + $this->dieUsageMsg( array( 'badaccess-group0' ) ); |
| 44 | + if( $wgUser->isBlocked() ) |
| 45 | + $this->dieUsageMsg( array( 'blockedtext' ) ); |
| 46 | + if( !$wgUser->matchEditToken( $params['token'] ) ) |
| 47 | + $this->dieUsageMsg( array( 'sessionfailure' ) ); |
| 48 | + |
| 49 | + // Construct submit form |
| 50 | + $form = new RevisionReview(); |
| 51 | + $revid = intval( $params['revid'] ); |
| 52 | + $rev = Revision::newFromId( $revid ); |
| 53 | + if( !$rev ) |
| 54 | + $this->dieUsage( "Cannot find a revision with the specified ID.", 'notarget' ); |
| 55 | + $form->oldid = $revid; |
| 56 | + $title = $rev->getTitle(); |
| 57 | + $form->page = $title; |
| 58 | + if( !FlaggedRevs::isPageReviewable( $title ) ) |
| 59 | + $this->dieUsage( "Provided revision or page can not be reviewed.", 'notreviewable' ); |
| 60 | + |
| 61 | + if( isset( $params['unapprove'] ) ) |
| 62 | + $form->approve = !$params['unapprove']; |
| 63 | + if( isset( $params['comment'] ) ) |
| 64 | + $form->comment = $params['comment']; |
| 65 | + if( isset( $params['notes'] ) ) |
| 66 | + $form->notes = $wgUser->isAllowed( 'validate' ) ? $params['notes'] : ''; |
| 67 | + |
| 68 | + // The flagging parameters have the form 'flag_$name'. |
| 69 | + // Extract them and put the values into $form->dims |
| 70 | + $flags = FlaggedRevs::getDimensions(); |
| 71 | + foreach( $flags as $name => $levels ) { |
| 72 | + if( !( $form->dims[$name] = intval( $params['flag_' . $name] ) ) ) |
| 73 | + $form->unapprovedTags++; |
| 74 | + } |
| 75 | + |
| 76 | + // Check if this is a valid approval/unapproval of the revision |
| 77 | + if( $form->unapprovedTags && $form->unapprovedTags < count( $flags ) ) |
| 78 | + $this->dieUsage( "Either all or none of the flags have to be set to zero.", 'mixedapproval' ); |
| 79 | + |
| 80 | + // Check if user is even allowed to set the flags |
| 81 | + $form->oflags = FlaggedRevs::getRevisionTags( $title, $form->oldid ); |
| 82 | + if( !$title->quickUserCan('edit') || !$form->userCanSetFlags( $form->dims, $form->oflags ) ) |
| 83 | + $this->dieUsage( "You don't have the necessary rights to set the specified flags.", 'permissiondenied' ); |
| 84 | + |
| 85 | + // Now get the template and image parameters needed |
| 86 | + // If it is the current revision, try the parser cache first |
| 87 | + $article = new Article( $title, $revid ); |
| 88 | + if( $rev->isCurrent() ) { |
| 89 | + $parserCache = ParserCache::singleton(); |
| 90 | + $parserOutput = $parserCache->get( $article, $wgUser ); |
| 91 | + } |
| 92 | + if( empty( $parserOutput ) ) { |
| 93 | + // Miss, we have to reparse the page |
| 94 | + global $wgParser; |
| 95 | + $text = $article->getContent(); |
| 96 | + $options = FlaggedRevs::makeParserOptions(); |
| 97 | + $parserOutput = $wgParser->parse( $text, $title, $options ); |
| 98 | + } |
| 99 | + |
| 100 | + list( $form->templateParams, $form->imageParams, $form->fileVersion ) = |
| 101 | + FlaggedRevs::getIncludeParams( $article, $parserOutput->mTemplateIds, $parserOutput->fr_ImageSHA1Keys ); |
| 102 | + |
| 103 | + // Do the actual review |
| 104 | + list( $approved, $status ) = $form->submit(); |
| 105 | + if( $status === true ) { |
| 106 | + $this->getResult()->addValue( null, $this->getModuleName(), array( 'result' => 'Success' ) ); |
| 107 | + } else if( $approved && is_array( $status ) ) { |
| 108 | + $this->dieUsage( "A sync failure has occured while reviewing. Please try again.", 'syncfailure' ); |
| 109 | + } else if( $approved ) { |
| 110 | + $this->dieUsage( "Cannot find a revision with the specified ID.", 'notarget' ); |
| 111 | + } else { |
| 112 | + $this->dieUsageMsg( array( 'unknownerror' ) ); |
| 113 | + } |
| 114 | + } |
| 115 | + |
| 116 | + public function mustBePosted() { |
| 117 | + return true; |
| 118 | + } |
| 119 | + |
| 120 | + public function getAllowedParams() { |
| 121 | + $pars = array( |
| 122 | + 'revid' => null, |
| 123 | + 'token' => null, |
| 124 | + 'comment' => null, |
| 125 | + ); |
| 126 | + if( FlaggedRevs::allowComments() ) |
| 127 | + $pars['notes'] = null; |
| 128 | + if( FlaggedRevs::dimensionsEmpty() ) { |
| 129 | + $pars['unapprove'] = false; |
| 130 | + } else { |
| 131 | + foreach( FlaggedRevs::getDimensions() as $flagname => $levels ) { |
| 132 | + $pars['flag_' . $flagname] = array( |
| 133 | + ApiBase::PARAM_DFLT => 1, // default |
| 134 | + ApiBase::PARAM_TYPE => array_keys( $levels ) // array of allowed values |
| 135 | + ); |
| 136 | + } |
| 137 | + } |
| 138 | + return $pars; |
| 139 | + } |
| 140 | + |
| 141 | + public function getParamDescription() { |
| 142 | + $desc = array( |
| 143 | + 'revid' => 'The revision ID for which to set the flags', |
| 144 | + 'token' => 'An edit token retrieved through prop=info', |
| 145 | + 'comment' => 'Comment for the review (optional)', |
| 146 | + //Only if FlaggedRevs::allowComments() is true: |
| 147 | + 'notes' => "Additional notes for the review. The ``validate'' right is needed to set this parameter.", |
| 148 | + //Will only show if FlaggedRevs::dimensionsEmpty() is true: |
| 149 | + 'unapprove' => "If set, revision will be unapproved" |
| 150 | + ); |
| 151 | + foreach( FlaggedRevs::getDimensions() as $flagname => $levels ) |
| 152 | + $desc['flag_' . $flagname] = "Set the flag ''{$flagname}'' to the specified value"; |
| 153 | + return $desc; |
| 154 | + } |
| 155 | + |
| 156 | + public function getDescription() { |
| 157 | + return 'Review a revision via FlaggedRevs.'; |
| 158 | + } |
| 159 | + |
| 160 | + protected function getExamples() { |
| 161 | + return 'api.php?action=review&revid=12345&token=123AB&flag_accuracy=1&comment=Ok'; |
| 162 | + } |
| 163 | + |
| 164 | + public function getVersion() { |
| 165 | + return __CLASS__ . ': $Id$'; |
| 166 | + } |
| 167 | +} |
Property changes on: trunk/extensions/FlaggedRevs/api/ApiReview.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 168 | + native |