const BAD_TITLE = 5; // $this is not a valid Article
const ALREADY_ROLLED = 6; // Someone else already rolled this back. $from and $summary will be set
const ONLY_AUTHOR = 7; // User is the only author of the page
+ const RATE_LIMITED = 8;
/**
* Constructor and clear the article
$this->mRevIdFetched = 0;
$this->mRedirectUrl = false;
$this->mLatest = false;
+ $this->mPreparedEdit = false;
}
/**
# If we have been passed an &rcid= parameter, we want to give the user a
# chance to mark this new article as patrolled.
- if (!is_null( $rcid ) && $rcid != 0 && $wgUser->isAllowed( 'patrol' ) ) {
+ if( !is_null( $rcid ) && $rcid != 0 && $wgUser->isAllowed( 'patrol' ) && $this->mTitle->exists() ) {
$wgOut->addHTML(
"<div class='patrollink'>" .
wfMsgHtml( 'markaspatrolledlink',
if ($flags & EDIT_AUTOSUMMARY && $summary == '')
$summary = $this->getAutosummary( $oldtext, $text, $flags );
- $text = $this->preSaveTransform( $text );
+ $editInfo = $this->prepareTextForEdit( $text );
+ $text = $editInfo->pst;
$newsize = strlen( $text );
$dbw = wfGetDB( DB_MASTER );
return;
}
- if ( $rc->mAttribs['rc_type'] == RC_NEW && !$wgUseNPPatrol ) {
- $wgOut->errorpage( 'nppatroldisabled', 'nppatroldisabledtext' );
- return;
- }
-
if ( !$wgUseRCPatrol && $rc->mAttribs['rc_type'] != RC_NEW) {
+ // Only new pages can be patrolled if the general patrolling is off....???
+ // @fixme -- is this necessary? Shouldn't we only bother controlling the
+ // front end here?
$wgOut->errorPage( 'rcpatroldisabled', 'rcpatroldisabledtext' );
return;
}
global $wgUser, $wgRestrictionTypes, $wgContLang;
$id = $this->mTitle->getArticleID();
- if( !$wgUser->isAllowed( 'protect' ) || wfReadOnly() || $id == 0 ) {
+ if( array() != $this->mTitle->getUserPermissionsErrors( 'protect', $wgUser ) || wfReadOnly() || $id == 0 ) {
return false;
}
/**
* Auto-generates a deletion reason
- * @param bool &$hashistory Whether the page has a history
+ * @param bool &$hasHistory Whether the page has a history
*/
- public function generateReason(&$hashistory)
+ public function generateReason(&$hasHistory)
{
global $wgContLang;
$dbw = wfGetDB(DB_MASTER);
*/
function delete() {
global $wgUser, $wgOut, $wgRequest;
+
$confirm = $wgRequest->wasPosted() &&
- $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) );
- $reason = $wgRequest->getText( 'wpReason' );
+ $wgUser->matchEditToken( $wgRequest->getVal( 'wpEditToken' ) );
+
+ $this->DeleteReasonList = $wgRequest->getText( 'wpDeleteReasonList', 'other' );
+ $this->DeleteReason = $wgRequest->getText( 'wpReason' );
+
+ $reason = $this->DeleteReasonList;
+
+ if ( $reason != 'other' && $this->DeleteReason != '') {
+ // Entry from drop down menu + additional comment
+ $reason .= ': ' . $this->DeleteReason;
+ } elseif ( $reason == 'other' ) {
+ $reason = $this->DeleteReason;
+ }
# This code desperately needs to be totally rewritten
// Generate deletion reason
$hasHistory = false;
- $reason = $this->generateReason($hasHistory);
+ if ( !$reason ) $reason = $this->generateReason($hasHistory);
// If the page has a history, insert a warning
if( $hasHistory && !$confirm ) {
$formaction = $this->mTitle->escapeLocalURL( 'action=delete' . $par );
$confirm = htmlspecialchars( wfMsg( 'deletepage' ) );
- $delcom = htmlspecialchars( wfMsg( 'deletecomment' ) );
+ $delcom = Xml::label( wfMsg( 'deletecomment' ), 'wpDeleteReasonList' );
$token = htmlspecialchars( $wgUser->editToken() );
$watch = Xml::checkLabel( wfMsg( 'watchthis' ), 'wpWatch', 'wpWatch', $wgUser->getBoolOption( 'watchdeletion' ) || $this->mTitle->userIsWatching(), array( 'tabindex' => '2' ) );
-
+
+ $mDeletereasonother = Xml::label( wfMsg( 'deleteotherreason' ), 'wpReason' );
+ $mDeletereasonotherlist = wfMsgHtml( 'deletereasonotherlist' );
+ $scDeleteReasonList = wfMsgForContent( 'deletereason-dropdown' );
+
+ $deleteReasonList = '';
+ if ( $scDeleteReasonList != '' && $scDeleteReasonList != '-' ) {
+ $deleteReasonList = "<option value=\"other\">$mDeletereasonotherlist</option>";
+ $optgroup = "";
+ foreach ( explode( "\n", $scDeleteReasonList ) as $option) {
+ $value = trim( htmlspecialchars($option) );
+ if ( $value == '' ) {
+ continue;
+ } elseif ( substr( $value, 0, 1) == '*' && substr( $value, 1, 1) != '*' ) {
+ // A new group is starting ...
+ $value = trim( substr( $value, 1 ) );
+ $deleteReasonList .= "$optgroup<optgroup label=\"$value\">";
+ $optgroup = "</optgroup>";
+ } elseif ( substr( $value, 0, 2) == '**' ) {
+ // groupmember
+ $selected = "";
+ $value = trim( substr( $value, 2 ) );
+ if ( $this->DeleteReasonList === $value)
+ $selected = ' selected="selected"';
+ $deleteReasonList .= "<option value=\"$value\"$selected>$value</option>";
+ } else {
+ // groupless delete reason
+ $selected = "";
+ if ( $this->DeleteReasonList === $value)
+ $selected = ' selected="selected"';
+ $deleteReasonList .= "$optgroup<option value=\"$value\"$selected>$value</option>";
+ $optgroup = "";
+ }
+ }
+ $deleteReasonList .= $optgroup;
+ }
$wgOut->addHTML( "
<form id='deleteconfirm' method='post' action=\"{$formaction}\">
<table border='0'>
- <tr>
+ <tr id=\"wpDeleteReasonListRow\" name=\"wpDeleteReasonListRow\">
<td align='right'>
- <label for='wpReason'>{$delcom}:</label>
+ $delcom:
</td>
<td align='left'>
- <input type='text' maxlength='255' size='60' name='wpReason' id='wpReason' value=\"" . htmlspecialchars( $reason ) . "\" tabindex=\"1\" />
+ <select tabindex='1' id='wpDeleteReasonList' name=\"wpDeleteReasonList\">
+ $deleteReasonList
+ </select>
+ </td>
+ </tr>
+ <tr id=\"wpDeleteReasonRow\" name=\"wpDeleteReasonRow\">
+ <td>
+ $mDeletereasonother
+ </td>
+ <td align='left'>
+ <input type='text' maxlength='255' size='60' name='wpReason' id='wpReason' value=\"" . htmlspecialchars( $reason ) . "\" tabindex=\"2\" />
</td>
</tr>
<tr>
if( !$wgUser->matchEditToken( $token, array( $this->mTitle->getPrefixedText(), $fromP ) ) )
return self::BAD_TOKEN;
+ if ( $wgUser->pingLimiter('rollback') || $wgUser->pingLimiter() ) {
+ return self::RATE_LIMITED;
+ }
+
$dbw = wfGetDB( DB_MASTER );
# Get the last editor
}
$set = array();
- if ( $bot ) {
+ if ( $bot && $wgUser->isAllowed('markbotedits') ) {
# Mark all reverted edits as bot
$set['rc_bot'] = 1;
}
$summary = wfMsgForContent( 'revertpage', $target->getUserText(), $from );
# Save
- $flags = EDIT_UPDATE | EDIT_MINOR;
+ $flags = EDIT_UPDATE;
+
+ if ($wgUser->isAllowed('minoredit'))
+ $flags |= EDIT_MINOR;
+
if( $bot )
$flags |= EDIT_FORCE_BOT;
$this->doEdit( $target->getText(), $summary, $flags );
$wgOut->setPageTitle( wfMsg( 'rollbackfailed' ) );
$wgOut->addHtml( wfMsg( 'cantrollback' ) );
break;
+ case self::RATE_LIMITED:
+ $wgOut->rateLimited();
+ break;
case self::SUCCESS:
$current = $details['current'];
$target = $details['target'];
$wgUser->clearNotification( $this->mTitle );
}
+ /**
+ * Prepare text which is about to be saved.
+ * Returns a stdclass with source, pst and output members
+ */
+ function prepareTextForEdit( $text, $revid=null ) {
+ if ( $this->mPreparedEdit && $this->mPreparedEdit->newText == $text && $this->mPreparedEdit->revid == $revid) {
+ // Already prepared
+ return $this->mPreparedEdit;
+ }
+ global $wgParser;
+ $edit = (object)array();
+ $edit->revid = $revid;
+ $edit->newText = $text;
+ $edit->pst = $this->preSaveTransform( $text );
+ $options = new ParserOptions;
+ $options->setTidy( true );
+ $options->enableLimitReport();
+ $edit->output = $wgParser->parse( $edit->pst, $this->mTitle, $options, true, true, $revid );
+ $edit->oldText = $this->getContent();
+ $this->mPreparedEdit = $edit;
+ return $edit;
+ }
+
/**
* Do standard deferred updates after page edit.
* Update links tables, site stats, search index and message cache.
wfProfileIn( __METHOD__ );
# Parse the text
- $options = new ParserOptions;
- $options->setTidy(true);
- $poutput = $wgParser->parse( $text, $this->mTitle, $options, true, true, $newid );
+ # Be careful not to double-PST: $text is usually already PST-ed once
+ if ( !$this->mPreparedEdit || $this->mPreparedEdit->output->getFlag( 'vary-revision' ) ) {
+ wfDebug( __METHOD__ . ": No prepared edit or vary-revision is set...\n" );
+ $editInfo = $this->prepareTextForEdit( $text, $newid );
+ } else {
+ wfDebug( __METHOD__ . ": No vary-revision, using prepared edit...\n" );
+ $editInfo = $this->mPreparedEdit;
+ }
# Save it to the parser cache
$parserCache =& ParserCache::singleton();
- $parserCache->save( $poutput, $this, $wgUser );
+ $parserCache->save( $editInfo->output, $this, $wgUser );
# Update the links tables
- $u = new LinksUpdate( $this->mTitle, $poutput );
+ $u = new LinksUpdate( $this->mTitle, $editInfo->output );
$u->doUpdate();
if( wfRunHooks( 'ArticleEditUpdatesDeleteFromRecentchanges', array( &$this ) ) ) {
$title->touchLinks();
$title->purgeSquid();
+ $title->deleteTitleProtection();
}
static function onArticleDelete( $title ) {
$popts = $wgOut->parserOptions();
$popts->setTidy(true);
+ $popts->enableLimitReport();
$parserOutput = $wgParser->parse( $text, $this->mTitle,
$popts, true, true, $this->getRevIdFetched() );
$popts->setTidy(false);
+ $popts->enableLimitReport( false );
if ( $cache && $this && $parserOutput->getCacheTime() != -1 ) {
$parserCache =& ParserCache::singleton();
$parserCache->save( $parserOutput, $this, $wgUser );