r36692 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r36691‎ | r36692 | r36693 >
Date:06:24, 27 June 2008
Author:werdna
Status:old
Tags:
Comment:
Core changes for AbuseFilter extension.
In particular:
Xml.php
* Add textarea method to Xml class.
* Make submit button optional for Xml::buildForm
* Right-align labels in buildForm.

Article.php:
* Make ArticleDelete hook display a real error

EditPage.php:
* Split off getBaseRevision()

Title.php:
* Allow errors to be ignored to be sent to getUserPermissionsErrors.
* Allow AbortMove hook to display a real error.

Block.php:
* Add 'mAngryAutoblock' option, for blocks by software, which does retroactive autoblocks on the last 5 IPs used in the last 7 days.
Modified paths:
  • /trunk/phase3/includes/Article.php (modified) (history)
  • /trunk/phase3/includes/Block.php (modified) (history)
  • /trunk/phase3/includes/EditPage.php (modified) (history)
  • /trunk/phase3/includes/Title.php (modified) (history)
  • /trunk/phase3/includes/Xml.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Xml.php
@@ -472,6 +472,25 @@
473473
474474 return $s;
475475 }
 476+
 477+ /**
 478+ * Shortcut for creating textareas.
 479+ *
 480+ * @param $name The 'name' for the textarea
 481+ * @param $content Content for the textarea
 482+ * @param $cols The number of columns for the textarea
 483+ * @param $rows The number of rows for the textarea
 484+ * @param $attribs Any other attributes for the textarea
 485+ */
 486+ public static function textarea( $name, $content, $cols = 40, $rows = 5, $attribs = array() ) {
 487+ return self::element( 'textarea',
 488+ array( 'name' => $name,
 489+ 'id' => $name,
 490+ 'cols' => $cols,
 491+ 'rows' => $rows
 492+ ) + $attribs,
 493+ $content );
 494+ }
476495
477496 /**
478497 * Returns an escaped string suitable for inclusion in a string literal
@@ -606,30 +625,30 @@
607626
608627 /**
609628 * Generate a form (without the opening form element).
610 - * Output DOES include a submit button.
 629+ * Output optionally includes a submit button.
611630 * @param $fields Associative array, key is message corresponding to a description for the field (colon is in the message), value is appropriate input.
612631 * @param $submitLabel A message containing a label for the submit button.
613632 * @return string HTML form.
614633 */
615 - public static function buildForm( $fields, $submitLabel ) {
 634+ public static function buildForm( $fields, $submitLabel = null ) {
616635 $form = '';
617636 $form .= "<table><tbody>";
618637
619638 foreach( $fields as $labelmsg => $input ) {
620639 $id = "mw-$labelmsg";
 640+
621641 $form .= Xml::openElement( 'tr', array( 'id' => $id ) );
622 -
623 - $form .= Xml::element( 'td', array('valign' => 'top'), wfMsg( $labelmsg ) );
624 -
 642+ $form .= Xml::tags( 'td', array('valign'=>'top','align' => 'right'), wfMsgExt( $labelmsg, array('parseinline') ) );
625643 $form .= Xml::openElement( 'td' ) . $input . Xml::closeElement( 'td' );
626 -
627644 $form .= Xml::closeElement( 'tr' );
628645 }
629646
630647 $form .= "</tbody></table>";
 648+
 649+ if ($submitLabel) {
 650+ $form .= Xml::submitButton( wfMsg($submitLabel) );
 651+ }
631652
632 - $form .= Xml::submitButton( wfMsg($submitLabel) );
633 -
634653 return $form;
635654 }
636655 }
Index: trunk/phase3/includes/Article.php
@@ -2250,8 +2250,10 @@
22512251 wfDebug( __METHOD__."\n" );
22522252
22532253 $id = $this->getId();
 2254+
 2255+ $error = '';
22542256
2255 - if (wfRunHooks('ArticleDelete', array(&$this, &$wgUser, &$reason))) {
 2257+ if (wfRunHooks('ArticleDelete', array(&$this, &$wgUser, &$reason, &$error))) {
22562258 if ( $this->doDeleteArticle( $reason, $suppress ) ) {
22572259 $deleted = $this->mTitle->getPrefixedText();
22582260
@@ -2264,7 +2266,10 @@
22652267 $wgOut->returnToMain( false );
22662268 wfRunHooks('ArticleDeleteComplete', array(&$this, &$wgUser, $reason, $id));
22672269 } else {
2268 - $wgOut->showFatalError( wfMsg( 'cannotdelete' ) );
 2270+ if ($error = '')
 2271+ $wgOut->showFatalError( wfMsg( 'cannotdelete' ) );
 2272+ else
 2273+ $wgOut->showFatalError( $error );
22692274 }
22702275 }
22712276 }
Index: trunk/phase3/includes/EditPage.php
@@ -62,6 +62,7 @@
6363 var $autoSumm = '';
6464 var $hookError = '';
6565 var $mPreviewTemplates;
 66+ var $mBaseRevision = false;
6667
6768 # Form values
6869 var $save = false, $preview = false, $diff = false;
@@ -1722,8 +1723,7 @@
17231724 $db = wfGetDB( DB_MASTER );
17241725
17251726 // This is the revision the editor started from
1726 - $baseRevision = Revision::loadFromTimestamp(
1727 - $db, $this->mTitle, $this->edittime );
 1727+ $baseRevision = $this->getBaseRevision();
17281728 if( is_null( $baseRevision ) ) {
17291729 wfProfileOut( $fname );
17301730 return false;
@@ -2321,4 +2321,15 @@
23222322 return false;
23232323 }
23242324 }
 2325+
 2326+ function getBaseRevision() {
 2327+ if ($this->mBaseRevision == false) {
 2328+ $db = wfGetDB( DB_MASTER );
 2329+ $baseRevision = Revision::loadFromTimestamp(
 2330+ $db, $editor->mTitle, $editor->edittime );
 2331+ return $this->mBaseRevision = $baseRevision;
 2332+ } else {
 2333+ return $this->mBaseRevision;
 2334+ }
 2335+ }
23252336 }
Index: trunk/phase3/includes/Title.php
@@ -1049,9 +1049,10 @@
10501050 * @param string $action action that permission needs to be checked for
10511051 * @param User $user user to check
10521052 * @param bool $doExpensiveQueries Set this to false to avoid doing unnecessary queries.
 1053+ * @param array $ignoreErrors Set this to a list of message keys whose corresponding errors may be ignored.
10531054 * @return array Array of arrays of the arguments to wfMsg to explain permissions problems.
10541055 */
1055 - public function getUserPermissionsErrors( $action, $user, $doExpensiveQueries = true ) {
 1056+ public function getUserPermissionsErrors( $action, $user, $doExpensiveQueries = true, $ignoreErrors = array() ) {
10561057 if( !StubObject::isRealObject( $user ) ) {
10571058 //Since StubObject is always used on globals, we can unstub $wgUser here and set $user = $wgUser
10581059 global $wgUser;
@@ -1116,6 +1117,16 @@
11171118 $errors[] = array( ($block->mAuto ? 'autoblockedtext' : 'blockedtext'), $link, $reason, $ip, $name,
11181119 $blockid, $blockExpiry, $intended, $blockTimestamp );
11191120 }
 1121+
 1122+ // Remove the errors being ignored.
 1123+
 1124+ foreach( $errors as $index => $error ) {
 1125+ $error_key = is_array($error) ? $error[0] : $error;
 1126+
 1127+ if (in_array( $error_key, $ignoreErrors )) {
 1128+ unset($errors[$index]);
 1129+ }
 1130+ }
11201131
11211132 return $errors;
11221133 }
Index: trunk/phase3/includes/Block.php
@@ -17,7 +17,7 @@
1818 {
1919 /* public*/ var $mAddress, $mUser, $mBy, $mReason, $mTimestamp, $mAuto, $mId, $mExpiry,
2020 $mRangeStart, $mRangeEnd, $mAnonOnly, $mEnableAutoblock, $mHideName,
21 - $mBlockEmail, $mByName;
 21+ $mBlockEmail, $mByName, $mAngryAutoblock;
2222 /* private */ var $mNetworkBits, $mIntegerAddr, $mForUpdate, $mFromMaster;
2323
2424 const EB_KEEP_EXPIRED = 1;
@@ -46,6 +46,7 @@
4747 $this->mForUpdate = false;
4848 $this->mFromMaster = false;
4949 $this->mByName = false;
 50+ $this->mAngryAutoblock = false;
5051 $this->initialiseRange();
5152 }
5253
@@ -430,17 +431,30 @@
431432
432433 if ($this->mEnableAutoblock && $this->mUser) {
433434 wfDebug("Doing retroactive autoblocks for " . $this->mAddress . "\n");
 435+
 436+ $options = array( 'ORDER BY' => 'rc_timestamp DESC' );
 437+ $conds = array( 'rc_user_text' => $this->mAddress );
 438+
 439+ if ($this->mAngryAutoblock) {
 440+ // Block any IP used in the last 7 days. Up to five IPs.
 441+ $conds[] = 'rc_timestamp < ' . $dbr->addQuotes( $dbr->timestamp( time() - (7*86400) ) );
 442+ $options['LIMIT'] = 5;
 443+ } else {
 444+ // Just the last IP used.
 445+ $options['LIMIT'] = 1;
 446+ }
434447
435 - $row = $dbr->selectRow( 'recentchanges', array( 'rc_ip' ), array( 'rc_user_text' => $this->mAddress ),
436 - __METHOD__ , array( 'ORDER BY' => 'rc_timestamp DESC' ) );
 448+ $res = $dbr->select( 'recentchanges', array( 'rc_ip' ), $conds,
 449+ __METHOD__ , $options);
437450
438 - if ( !$row || !$row->rc_ip ) {
 451+ if ( !$dbr->numRows( $res ) ) {
439452 #No results, don't autoblock anything
440453 wfDebug("No IP found to retroactively autoblock\n");
441454 } else {
442 - #Limit is 1, so no loop needed.
443 - $retroblockip = $row->rc_ip;
444 - return $this->doAutoblock( $retroblockip, true );
 455+ while ( $row = $dbr->fetchObject( $res ) ) {
 456+ if ( $row->rc_ip )
 457+ $this->doAutoblock( $row->rc_ip );
 458+ }
445459 }
446460 }
447461 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r36745Update RELEASE-NOTES and hooks.txt for r36692. Contrary to the commit messag...simetrical13:37, 27 June 2008
r36885* Partial revert of r36692. Has been spewing fatal errors for few days alreadynikerabbit07:36, 2 July 2008

Status & tagging log