00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 if ( !defined( 'MEDIAWIKI' ) ) {
00026
00027 require_once ( "ApiBase.php" );
00028 }
00029
00033 class ApiUndelete extends ApiBase {
00034
00035 public function __construct( $main, $action ) {
00036 parent :: __construct( $main, $action );
00037 }
00038
00039 public function execute() {
00040 global $wgUser;
00041 $params = $this->extractRequestParams();
00042
00043 $titleObj = null;
00044 if ( !isset( $params['title'] ) )
00045 $this->dieUsageMsg( array( 'missingparam', 'title' ) );
00046
00047 if ( !$wgUser->isAllowed( 'undelete' ) )
00048 $this->dieUsageMsg( array( 'permdenied-undelete' ) );
00049
00050 if ( $wgUser->isBlocked() )
00051 $this->dieUsageMsg( array( 'blockedtext' ) );
00052
00053 $titleObj = Title::newFromText( $params['title'] );
00054 if ( !$titleObj )
00055 $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) );
00056
00057
00058 if ( !isset( $params['timestamps'] ) )
00059 $params['timestamps'] = array();
00060 if ( !is_array( $params['timestamps'] ) )
00061 $params['timestamps'] = array( $params['timestamps'] );
00062 foreach ( $params['timestamps'] as $i => $ts )
00063 $params['timestamps'][$i] = wfTimestamp( TS_MW, $ts );
00064
00065 $pa = new PageArchive( $titleObj );
00066 $dbw = wfGetDB( DB_MASTER );
00067 $dbw->begin();
00068 $retval = $pa->undelete( ( isset( $params['timestamps'] ) ? $params['timestamps'] : array() ), $params['reason'] );
00069 if ( !is_array( $retval ) )
00070 $this->dieUsageMsg( array( 'cannotundelete' ) );
00071
00072 if ( $retval[1] )
00073 wfRunHooks( 'FileUndeleteComplete',
00074 array( $titleObj, array(), $wgUser, $params['reason'] ) );
00075
00076 $info['title'] = $titleObj->getPrefixedText();
00077 $info['revisions'] = intval( $retval[0] );
00078 $info['fileversions'] = intval( $retval[1] );
00079 $info['reason'] = intval( $retval[2] );
00080 $this->getResult()->addValue( null, $this->getModuleName(), $info );
00081 }
00082
00083 public function mustBePosted() {
00084 return true;
00085 }
00086
00087 public function isWriteMode() {
00088 return true;
00089 }
00090
00091 public function getAllowedParams() {
00092 return array (
00093 'title' => null,
00094 'token' => null,
00095 'reason' => "",
00096 'timestamps' => array(
00097 ApiBase :: PARAM_ISMULTI => true
00098 )
00099 );
00100 }
00101
00102 public function getParamDescription() {
00103 return array (
00104 'title' => 'Title of the page you want to restore.',
00105 'token' => 'An undelete token previously retrieved through list=deletedrevs',
00106 'reason' => 'Reason for restoring (optional)',
00107 'timestamps' => 'Timestamps of the revisions to restore. If not set, all revisions will be restored.'
00108 );
00109 }
00110
00111 public function getDescription() {
00112 return array(
00113 'Restore certain revisions of a deleted page. A list of deleted revisions (including timestamps) can be',
00114 'retrieved through list=deletedrevs'
00115 );
00116 }
00117
00118 public function getPossibleErrors() {
00119 return array_merge( parent::getPossibleErrors(), array(
00120 array( 'missingparam', 'title' ),
00121 array( 'permdenied-undelete' ),
00122 array( 'blockedtext' ),
00123 array( 'invalidtitle', 'title' ),
00124 array( 'cannotundelete' ),
00125 ) );
00126 }
00127
00128 public function needsToken() {
00129 return true;
00130 }
00131
00132 public function getTokenSalt() {
00133 return '';
00134 }
00135
00136 protected function getExamples() {
00137 return array (
00138 'api.php?action=undelete&title=Main%20Page&token=123ABC&reason=Restoring%20main%20page',
00139 'api.php?action=undelete&title=Main%20Page&token=123ABC×tamps=20070703220045|20070702194856'
00140 );
00141 }
00142
00143 public function getVersion() {
00144 return __CLASS__ . ': $Id: ApiUndelete.php 74217 2010-10-03 15:53:07Z reedy $';
00145 }
00146 }