wfDebug( __METHOD__."\n" );
$id = $this->getId();
+
+ $error = '';
- if (wfRunHooks('ArticleDelete', array(&$this, &$wgUser, &$reason))) {
+ if (wfRunHooks('ArticleDelete', array(&$this, &$wgUser, &$reason, &$error))) {
if ( $this->doDeleteArticle( $reason, $suppress ) ) {
$deleted = $this->mTitle->getPrefixedText();
$wgOut->returnToMain( false );
wfRunHooks('ArticleDeleteComplete', array(&$this, &$wgUser, $reason, $id));
} else {
- $wgOut->showFatalError( wfMsg( 'cannotdelete' ) );
+ if ($error = '')
+ $wgOut->showFatalError( wfMsg( 'cannotdelete' ) );
+ else
+ $wgOut->showFatalError( $error );
}
}
}
{
/* public*/ var $mAddress, $mUser, $mBy, $mReason, $mTimestamp, $mAuto, $mId, $mExpiry,
$mRangeStart, $mRangeEnd, $mAnonOnly, $mEnableAutoblock, $mHideName,
- $mBlockEmail, $mByName;
+ $mBlockEmail, $mByName, $mAngryAutoblock;
/* private */ var $mNetworkBits, $mIntegerAddr, $mForUpdate, $mFromMaster;
const EB_KEEP_EXPIRED = 1;
$this->mForUpdate = false;
$this->mFromMaster = false;
$this->mByName = false;
+ $this->mAngryAutoblock = false;
$this->initialiseRange();
}
if ($this->mEnableAutoblock && $this->mUser) {
wfDebug("Doing retroactive autoblocks for " . $this->mAddress . "\n");
+
+ $options = array( 'ORDER BY' => 'rc_timestamp DESC' );
+ $conds = array( 'rc_user_text' => $this->mAddress );
+
+ if ($this->mAngryAutoblock) {
+ // Block any IP used in the last 7 days. Up to five IPs.
+ $conds[] = 'rc_timestamp < ' . $dbr->addQuotes( $dbr->timestamp( time() - (7*86400) ) );
+ $options['LIMIT'] = 5;
+ } else {
+ // Just the last IP used.
+ $options['LIMIT'] = 1;
+ }
- $row = $dbr->selectRow( 'recentchanges', array( 'rc_ip' ), array( 'rc_user_text' => $this->mAddress ),
- __METHOD__ , array( 'ORDER BY' => 'rc_timestamp DESC' ) );
+ $res = $dbr->select( 'recentchanges', array( 'rc_ip' ), $conds,
+ __METHOD__ , $options);
- if ( !$row || !$row->rc_ip ) {
+ if ( !$dbr->numRows( $res ) ) {
#No results, don't autoblock anything
wfDebug("No IP found to retroactively autoblock\n");
} else {
- #Limit is 1, so no loop needed.
- $retroblockip = $row->rc_ip;
- return $this->doAutoblock( $retroblockip, true );
+ while ( $row = $dbr->fetchObject( $res ) ) {
+ if ( $row->rc_ip )
+ $this->doAutoblock( $row->rc_ip );
+ }
}
}
}
var $autoSumm = '';
var $hookError = '';
var $mPreviewTemplates;
+ var $mBaseRevision = false;
# Form values
var $save = false, $preview = false, $diff = false;
$db = wfGetDB( DB_MASTER );
// This is the revision the editor started from
- $baseRevision = Revision::loadFromTimestamp(
- $db, $this->mTitle, $this->edittime );
+ $baseRevision = $this->getBaseRevision();
if( is_null( $baseRevision ) ) {
wfProfileOut( $fname );
return false;
return false;
}
}
+
+ function getBaseRevision() {
+ if ($this->mBaseRevision == false) {
+ $db = wfGetDB( DB_MASTER );
+ $baseRevision = Revision::loadFromTimestamp(
+ $db, $editor->mTitle, $editor->edittime );
+ return $this->mBaseRevision = $baseRevision;
+ } else {
+ return $this->mBaseRevision;
+ }
+ }
}
* @param string $action action that permission needs to be checked for
* @param User $user user to check
* @param bool $doExpensiveQueries Set this to false to avoid doing unnecessary queries.
+ * @param array $ignoreErrors Set this to a list of message keys whose corresponding errors may be ignored.
* @return array Array of arrays of the arguments to wfMsg to explain permissions problems.
*/
- public function getUserPermissionsErrors( $action, $user, $doExpensiveQueries = true ) {
+ public function getUserPermissionsErrors( $action, $user, $doExpensiveQueries = true, $ignoreErrors = array() ) {
if( !StubObject::isRealObject( $user ) ) {
//Since StubObject is always used on globals, we can unstub $wgUser here and set $user = $wgUser
global $wgUser;
$errors[] = array( ($block->mAuto ? 'autoblockedtext' : 'blockedtext'), $link, $reason, $ip, $name,
$blockid, $blockExpiry, $intended, $blockTimestamp );
}
+
+ // Remove the errors being ignored.
+
+ foreach( $errors as $index => $error ) {
+ $error_key = is_array($error) ? $error[0] : $error;
+
+ if (in_array( $error_key, $ignoreErrors )) {
+ unset($errors[$index]);
+ }
+ }
return $errors;
}
return $s;
}
+
+ /**
+ * Shortcut for creating textareas.
+ *
+ * @param $name The 'name' for the textarea
+ * @param $content Content for the textarea
+ * @param $cols The number of columns for the textarea
+ * @param $rows The number of rows for the textarea
+ * @param $attribs Any other attributes for the textarea
+ */
+ public static function textarea( $name, $content, $cols = 40, $rows = 5, $attribs = array() ) {
+ return self::element( 'textarea',
+ array( 'name' => $name,
+ 'id' => $name,
+ 'cols' => $cols,
+ 'rows' => $rows
+ ) + $attribs,
+ $content );
+ }
/**
* Returns an escaped string suitable for inclusion in a string literal
/**
* Generate a form (without the opening form element).
- * Output DOES include a submit button.
+ * Output optionally includes a submit button.
* @param $fields Associative array, key is message corresponding to a description for the field (colon is in the message), value is appropriate input.
* @param $submitLabel A message containing a label for the submit button.
* @return string HTML form.
*/
- public static function buildForm( $fields, $submitLabel ) {
+ public static function buildForm( $fields, $submitLabel = null ) {
$form = '';
$form .= "<table><tbody>";
foreach( $fields as $labelmsg => $input ) {
$id = "mw-$labelmsg";
+
$form .= Xml::openElement( 'tr', array( 'id' => $id ) );
-
- $form .= Xml::element( 'td', array('valign' => 'top'), wfMsg( $labelmsg ) );
-
+ $form .= Xml::tags( 'td', array('valign'=>'top','align' => 'right'), wfMsgExt( $labelmsg, array('parseinline') ) );
$form .= Xml::openElement( 'td' ) . $input . Xml::closeElement( 'td' );
-
$form .= Xml::closeElement( 'tr' );
}
$form .= "</tbody></table>";
-
- $form .= Xml::submitButton( wfMsg($submitLabel) );
+
+ if ($submitLabel) {
+ $form .= Xml::submitButton( wfMsg($submitLabel) );
+ }
return $form;
}