r77679 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r77678‎ | r77679 | r77680 >
Date:20:30, 3 December 2010
Author:reedy
Status:ok
Tags:
Comment:
Fixup 1 more autoloader from r77677

Add Abstract classes explicitally to the autoloader

Move abstract classes from RevisionDelete.php to RevisionDeleteAbstracts.php (svn copy and remove of redundant classes)
Modified paths:
  • /trunk/phase3/includes/AutoLoader.php (modified) (history)
  • /trunk/phase3/includes/revisiondelete/RevisionDelete.php (modified) (history)
  • /trunk/phase3/includes/revisiondelete/RevisionDeleteAbstracts.php (added) (history)

Diff [purge]

Index: trunk/phase3/includes/revisiondelete/RevisionDelete.php
@@ -270,459 +270,6 @@
271271 }
272272
273273 /**
274 - * Abstract base class for a list of deletable items
275 - */
276 -abstract class RevDel_List {
277 - var $special, $title, $ids, $res, $current;
278 - var $type = null; // override this
279 - var $idField = null; // override this
280 - var $dateField = false; // override this
281 - var $authorIdField = false; // override this
282 - var $authorNameField = false; // override this
283 -
284 - /**
285 - * @param $special The parent SpecialPage
286 - * @param $title The target title
287 - * @param $ids Array of IDs
288 - */
289 - public function __construct( $special, $title, $ids ) {
290 - $this->special = $special;
291 - $this->title = $title;
292 - $this->ids = $ids;
293 - }
294 -
295 - /**
296 - * Get the internal type name of this list. Equal to the table name.
297 - */
298 - public function getType() {
299 - return $this->type;
300 - }
301 -
302 - /**
303 - * Get the DB field name associated with the ID list
304 - */
305 - public function getIdField() {
306 - return $this->idField;
307 - }
308 -
309 - /**
310 - * Get the DB field name storing timestamps
311 - */
312 - public function getTimestampField() {
313 - return $this->dateField;
314 - }
315 -
316 - /**
317 - * Get the DB field name storing user ids
318 - */
319 - public function getAuthorIdField() {
320 - return $this->authorIdField;
321 - }
322 -
323 - /**
324 - * Get the DB field name storing user names
325 - */
326 - public function getAuthorNameField() {
327 - return $this->authorNameField;
328 - }
329 - /**
330 - * Set the visibility for the revisions in this list. Logging and
331 - * transactions are done here.
332 - *
333 - * @param $params Associative array of parameters. Members are:
334 - * value: The integer value to set the visibility to
335 - * comment: The log comment.
336 - * @return Status
337 - */
338 - public function setVisibility( $params ) {
339 - $bitPars = $params['value'];
340 - $comment = $params['comment'];
341 -
342 - $this->res = false;
343 - $dbw = wfGetDB( DB_MASTER );
344 - $this->doQuery( $dbw );
345 - $dbw->begin();
346 - $status = Status::newGood();
347 - $missing = array_flip( $this->ids );
348 - $this->clearFileOps();
349 - $idsForLog = array();
350 - $authorIds = $authorIPs = array();
351 -
352 - for ( $this->reset(); $this->current(); $this->next() ) {
353 - $item = $this->current();
354 - unset( $missing[ $item->getId() ] );
355 -
356 - $oldBits = $item->getBits();
357 - // Build the actual new rev_deleted bitfield
358 - $newBits = SpecialRevisionDelete::extractBitfield( $bitPars, $oldBits );
359 -
360 - if ( $oldBits == $newBits ) {
361 - $status->warning( 'revdelete-no-change', $item->formatDate(), $item->formatTime() );
362 - $status->failCount++;
363 - continue;
364 - } elseif ( $oldBits == 0 && $newBits != 0 ) {
365 - $opType = 'hide';
366 - } elseif ( $oldBits != 0 && $newBits == 0 ) {
367 - $opType = 'show';
368 - } else {
369 - $opType = 'modify';
370 - }
371 -
372 - if ( $item->isHideCurrentOp( $newBits ) ) {
373 - // Cannot hide current version text
374 - $status->error( 'revdelete-hide-current', $item->formatDate(), $item->formatTime() );
375 - $status->failCount++;
376 - continue;
377 - }
378 - if ( !$item->canView() ) {
379 - // Cannot access this revision
380 - $msg = ($opType == 'show') ?
381 - 'revdelete-show-no-access' : 'revdelete-modify-no-access';
382 - $status->error( $msg, $item->formatDate(), $item->formatTime() );
383 - $status->failCount++;
384 - continue;
385 - }
386 - // Cannot just "hide from Sysops" without hiding any fields
387 - if( $newBits == Revision::DELETED_RESTRICTED ) {
388 - $status->warning( 'revdelete-only-restricted', $item->formatDate(), $item->formatTime() );
389 - $status->failCount++;
390 - continue;
391 - }
392 -
393 - // Update the revision
394 - $ok = $item->setBits( $newBits );
395 -
396 - if ( $ok ) {
397 - $idsForLog[] = $item->getId();
398 - $status->successCount++;
399 - if( $item->getAuthorId() > 0 ) {
400 - $authorIds[] = $item->getAuthorId();
401 - } else if( IP::isIPAddress( $item->getAuthorName() ) ) {
402 - $authorIPs[] = $item->getAuthorName();
403 - }
404 - } else {
405 - $status->error( 'revdelete-concurrent-change', $item->formatDate(), $item->formatTime() );
406 - $status->failCount++;
407 - }
408 - }
409 -
410 - // Handle missing revisions
411 - foreach ( $missing as $id => $unused ) {
412 - $status->error( 'revdelete-modify-missing', $id );
413 - $status->failCount++;
414 - }
415 -
416 - if ( $status->successCount == 0 ) {
417 - $status->ok = false;
418 - $dbw->rollback();
419 - return $status;
420 - }
421 -
422 - // Save success count
423 - $successCount = $status->successCount;
424 -
425 - // Move files, if there are any
426 - $status->merge( $this->doPreCommitUpdates() );
427 - if ( !$status->isOK() ) {
428 - // Fatal error, such as no configured archive directory
429 - $dbw->rollback();
430 - return $status;
431 - }
432 -
433 - // Log it
434 - $this->updateLog( array(
435 - 'title' => $this->title,
436 - 'count' => $successCount,
437 - 'newBits' => $newBits,
438 - 'oldBits' => $oldBits,
439 - 'comment' => $comment,
440 - 'ids' => $idsForLog,
441 - 'authorIds' => $authorIds,
442 - 'authorIPs' => $authorIPs
443 - ) );
444 - $dbw->commit();
445 -
446 - // Clear caches
447 - $status->merge( $this->doPostCommitUpdates() );
448 - return $status;
449 - }
450 -
451 - /**
452 - * Reload the list data from the master DB. This can be done after setVisibility()
453 - * to allow $item->getHTML() to show the new data.
454 - */
455 - function reloadFromMaster() {
456 - $dbw = wfGetDB( DB_MASTER );
457 - $this->res = $this->doQuery( $dbw );
458 - }
459 -
460 - /**
461 - * Record a log entry on the action
462 - * @param $params Associative array of parameters:
463 - * newBits: The new value of the *_deleted bitfield
464 - * oldBits: The old value of the *_deleted bitfield.
465 - * title: The target title
466 - * ids: The ID list
467 - * comment: The log comment
468 - * authorsIds: The array of the user IDs of the offenders
469 - * authorsIPs: The array of the IP/anon user offenders
470 - */
471 - protected function updateLog( $params ) {
472 - // Get the URL param's corresponding DB field
473 - $field = RevisionDeleter::getRelationType( $this->getType() );
474 - if( !$field ) {
475 - throw new MWException( "Bad log URL param type!" );
476 - }
477 - // Put things hidden from sysops in the oversight log
478 - if ( ( $params['newBits'] | $params['oldBits'] ) & $this->getSuppressBit() ) {
479 - $logType = 'suppress';
480 - } else {
481 - $logType = 'delete';
482 - }
483 - // Add params for effected page and ids
484 - $logParams = $this->getLogParams( $params );
485 - // Actually add the deletion log entry
486 - $log = new LogPage( $logType );
487 - $logid = $log->addEntry( $this->getLogAction(), $params['title'],
488 - $params['comment'], $logParams );
489 - // Allow for easy searching of deletion log items for revision/log items
490 - $log->addRelations( $field, $params['ids'], $logid );
491 - $log->addRelations( 'target_author_id', $params['authorIds'], $logid );
492 - $log->addRelations( 'target_author_ip', $params['authorIPs'], $logid );
493 - }
494 -
495 - /**
496 - * Get the log action for this list type
497 - */
498 - public function getLogAction() {
499 - return 'revision';
500 - }
501 -
502 - /**
503 - * Get log parameter array.
504 - * @param $params Associative array of log parameters, same as updateLog()
505 - * @return array
506 - */
507 - public function getLogParams( $params ) {
508 - return array(
509 - $this->getType(),
510 - implode( ',', $params['ids'] ),
511 - "ofield={$params['oldBits']}",
512 - "nfield={$params['newBits']}"
513 - );
514 - }
515 -
516 - /**
517 - * Initialise the current iteration pointer
518 - */
519 - protected function initCurrent() {
520 - $row = $this->res->current();
521 - if ( $row ) {
522 - $this->current = $this->newItem( $row );
523 - } else {
524 - $this->current = false;
525 - }
526 - }
527 -
528 - /**
529 - * Start iteration. This must be called before current() or next().
530 - * @return First list item
531 - */
532 - public function reset() {
533 - if ( !$this->res ) {
534 - $this->res = $this->doQuery( wfGetDB( DB_SLAVE ) );
535 - } else {
536 - $this->res->rewind();
537 - }
538 - $this->initCurrent();
539 - return $this->current;
540 - }
541 -
542 - /**
543 - * Get the current list item, or false if we are at the end
544 - */
545 - public function current() {
546 - return $this->current;
547 - }
548 -
549 - /**
550 - * Move the iteration pointer to the next list item, and return it.
551 - */
552 - public function next() {
553 - $this->res->next();
554 - $this->initCurrent();
555 - return $this->current;
556 - }
557 -
558 - /**
559 - * Get the number of items in the list.
560 - */
561 - public function length() {
562 - if( !$this->res ) {
563 - return 0;
564 - } else {
565 - return $this->res->numRows();
566 - }
567 - }
568 -
569 - /**
570 - * Clear any data structures needed for doPreCommitUpdates() and doPostCommitUpdates()
571 - * STUB
572 - */
573 - public function clearFileOps() {
574 - }
575 -
576 - /**
577 - * A hook for setVisibility(): do batch updates pre-commit.
578 - * STUB
579 - * @return Status
580 - */
581 - public function doPreCommitUpdates() {
582 - return Status::newGood();
583 - }
584 -
585 - /**
586 - * A hook for setVisibility(): do any necessary updates post-commit.
587 - * STUB
588 - * @return Status
589 - */
590 - public function doPostCommitUpdates() {
591 - return Status::newGood();
592 - }
593 -
594 - /**
595 - * Create an item object from a DB result row
596 - * @param $row stdclass
597 - */
598 - abstract public function newItem( $row );
599 -
600 - /**
601 - * Do the DB query to iterate through the objects.
602 - * @param $db Database object to use for the query
603 - */
604 - abstract public function doQuery( $db );
605 -
606 - /**
607 - * Get the integer value of the flag used for suppression
608 - */
609 - abstract public function getSuppressBit();
610 -}
611 -
612 -/**
613 - * Abstract base class for deletable items
614 - */
615 -abstract class RevDel_Item {
616 - /** The parent SpecialPage */
617 - var $special;
618 -
619 - /** The parent RevDel_List */
620 - var $list;
621 -
622 - /** The DB result row */
623 - var $row;
624 -
625 - /**
626 - * @param $list RevDel_List
627 - * @param $row DB result row
628 - */
629 - public function __construct( $list, $row ) {
630 - $this->special = $list->special;
631 - $this->list = $list;
632 - $this->row = $row;
633 - }
634 -
635 - /**
636 - * Get the ID, as it would appear in the ids URL parameter
637 - */
638 - public function getId() {
639 - $field = $this->list->getIdField();
640 - return $this->row->$field;
641 - }
642 -
643 - /**
644 - * Get the date, formatted with $wgLang
645 - */
646 - public function formatDate() {
647 - global $wgLang;
648 - return $wgLang->date( $this->getTimestamp() );
649 - }
650 -
651 - /**
652 - * Get the time, formatted with $wgLang
653 - */
654 - public function formatTime() {
655 - global $wgLang;
656 - return $wgLang->time( $this->getTimestamp() );
657 - }
658 -
659 - /**
660 - * Get the timestamp in MW 14-char form
661 - */
662 - public function getTimestamp() {
663 - $field = $this->list->getTimestampField();
664 - return wfTimestamp( TS_MW, $this->row->$field );
665 - }
666 -
667 - /**
668 - * Get the author user ID
669 - */
670 - public function getAuthorId() {
671 - $field = $this->list->getAuthorIdField();
672 - return intval( $this->row->$field );
673 - }
674 -
675 - /**
676 - * Get the author user name
677 - */
678 - public function getAuthorName() {
679 - $field = $this->list->getAuthorNameField();
680 - return strval( $this->row->$field );
681 - }
682 -
683 - /**
684 - * Returns true if the item is "current", and the operation to set the given
685 - * bits can't be executed for that reason
686 - * STUB
687 - */
688 - public function isHideCurrentOp( $newBits ) {
689 - return false;
690 - }
691 -
692 - /**
693 - * Returns true if the current user can view the item
694 - */
695 - abstract public function canView();
696 -
697 - /**
698 - * Returns true if the current user can view the item text/file
699 - */
700 - abstract public function canViewContent();
701 -
702 - /**
703 - * Get the current deletion bitfield value
704 - */
705 - abstract public function getBits();
706 -
707 - /**
708 - * Get the HTML of the list item. Should be include <li></li> tags.
709 - * This is used to show the list in HTML form, by the special page.
710 - */
711 - abstract public function getHTML();
712 -
713 - /**
714 - * Set the visibility of the item. This should do any necessary DB queries.
715 - *
716 - * The DB update query should have a condition which forces it to only update
717 - * if the value in the DB matches the value fetched earlier with the SELECT.
718 - * If the update fails because it did not match, the function should return
719 - * false. This prevents concurrency problems.
720 - *
721 - * @return boolean success
722 - */
723 - abstract public function setBits( $newBits );
724 -}
725 -
726 -/**
727274 * List for revision table items
728275 */
729276 class RevDel_RevisionList extends RevDel_List {
Index: trunk/phase3/includes/revisiondelete/RevisionDeleteAbstracts.php
@@ -0,0 +1,454 @@
 2+<?php
 3+
 4+/**
 5+ * Abstract base class for a list of deletable items
 6+ */
 7+abstract class RevDel_List {
 8+ var $special, $title, $ids, $res, $current;
 9+ var $type = null; // override this
 10+ var $idField = null; // override this
 11+ var $dateField = false; // override this
 12+ var $authorIdField = false; // override this
 13+ var $authorNameField = false; // override this
 14+
 15+ /**
 16+ * @param $special The parent SpecialPage
 17+ * @param $title The target title
 18+ * @param $ids Array of IDs
 19+ */
 20+ public function __construct( $special, $title, $ids ) {
 21+ $this->special = $special;
 22+ $this->title = $title;
 23+ $this->ids = $ids;
 24+ }
 25+
 26+ /**
 27+ * Get the internal type name of this list. Equal to the table name.
 28+ */
 29+ public function getType() {
 30+ return $this->type;
 31+ }
 32+
 33+ /**
 34+ * Get the DB field name associated with the ID list
 35+ */
 36+ public function getIdField() {
 37+ return $this->idField;
 38+ }
 39+
 40+ /**
 41+ * Get the DB field name storing timestamps
 42+ */
 43+ public function getTimestampField() {
 44+ return $this->dateField;
 45+ }
 46+
 47+ /**
 48+ * Get the DB field name storing user ids
 49+ */
 50+ public function getAuthorIdField() {
 51+ return $this->authorIdField;
 52+ }
 53+
 54+ /**
 55+ * Get the DB field name storing user names
 56+ */
 57+ public function getAuthorNameField() {
 58+ return $this->authorNameField;
 59+ }
 60+ /**
 61+ * Set the visibility for the revisions in this list. Logging and
 62+ * transactions are done here.
 63+ *
 64+ * @param $params Associative array of parameters. Members are:
 65+ * value: The integer value to set the visibility to
 66+ * comment: The log comment.
 67+ * @return Status
 68+ */
 69+ public function setVisibility( $params ) {
 70+ $bitPars = $params['value'];
 71+ $comment = $params['comment'];
 72+
 73+ $this->res = false;
 74+ $dbw = wfGetDB( DB_MASTER );
 75+ $this->doQuery( $dbw );
 76+ $dbw->begin();
 77+ $status = Status::newGood();
 78+ $missing = array_flip( $this->ids );
 79+ $this->clearFileOps();
 80+ $idsForLog = array();
 81+ $authorIds = $authorIPs = array();
 82+
 83+ for ( $this->reset(); $this->current(); $this->next() ) {
 84+ $item = $this->current();
 85+ unset( $missing[ $item->getId() ] );
 86+
 87+ $oldBits = $item->getBits();
 88+ // Build the actual new rev_deleted bitfield
 89+ $newBits = SpecialRevisionDelete::extractBitfield( $bitPars, $oldBits );
 90+
 91+ if ( $oldBits == $newBits ) {
 92+ $status->warning( 'revdelete-no-change', $item->formatDate(), $item->formatTime() );
 93+ $status->failCount++;
 94+ continue;
 95+ } elseif ( $oldBits == 0 && $newBits != 0 ) {
 96+ $opType = 'hide';
 97+ } elseif ( $oldBits != 0 && $newBits == 0 ) {
 98+ $opType = 'show';
 99+ } else {
 100+ $opType = 'modify';
 101+ }
 102+
 103+ if ( $item->isHideCurrentOp( $newBits ) ) {
 104+ // Cannot hide current version text
 105+ $status->error( 'revdelete-hide-current', $item->formatDate(), $item->formatTime() );
 106+ $status->failCount++;
 107+ continue;
 108+ }
 109+ if ( !$item->canView() ) {
 110+ // Cannot access this revision
 111+ $msg = ($opType == 'show') ?
 112+ 'revdelete-show-no-access' : 'revdelete-modify-no-access';
 113+ $status->error( $msg, $item->formatDate(), $item->formatTime() );
 114+ $status->failCount++;
 115+ continue;
 116+ }
 117+ // Cannot just "hide from Sysops" without hiding any fields
 118+ if( $newBits == Revision::DELETED_RESTRICTED ) {
 119+ $status->warning( 'revdelete-only-restricted', $item->formatDate(), $item->formatTime() );
 120+ $status->failCount++;
 121+ continue;
 122+ }
 123+
 124+ // Update the revision
 125+ $ok = $item->setBits( $newBits );
 126+
 127+ if ( $ok ) {
 128+ $idsForLog[] = $item->getId();
 129+ $status->successCount++;
 130+ if( $item->getAuthorId() > 0 ) {
 131+ $authorIds[] = $item->getAuthorId();
 132+ } else if( IP::isIPAddress( $item->getAuthorName() ) ) {
 133+ $authorIPs[] = $item->getAuthorName();
 134+ }
 135+ } else {
 136+ $status->error( 'revdelete-concurrent-change', $item->formatDate(), $item->formatTime() );
 137+ $status->failCount++;
 138+ }
 139+ }
 140+
 141+ // Handle missing revisions
 142+ foreach ( $missing as $id => $unused ) {
 143+ $status->error( 'revdelete-modify-missing', $id );
 144+ $status->failCount++;
 145+ }
 146+
 147+ if ( $status->successCount == 0 ) {
 148+ $status->ok = false;
 149+ $dbw->rollback();
 150+ return $status;
 151+ }
 152+
 153+ // Save success count
 154+ $successCount = $status->successCount;
 155+
 156+ // Move files, if there are any
 157+ $status->merge( $this->doPreCommitUpdates() );
 158+ if ( !$status->isOK() ) {
 159+ // Fatal error, such as no configured archive directory
 160+ $dbw->rollback();
 161+ return $status;
 162+ }
 163+
 164+ // Log it
 165+ $this->updateLog( array(
 166+ 'title' => $this->title,
 167+ 'count' => $successCount,
 168+ 'newBits' => $newBits,
 169+ 'oldBits' => $oldBits,
 170+ 'comment' => $comment,
 171+ 'ids' => $idsForLog,
 172+ 'authorIds' => $authorIds,
 173+ 'authorIPs' => $authorIPs
 174+ ) );
 175+ $dbw->commit();
 176+
 177+ // Clear caches
 178+ $status->merge( $this->doPostCommitUpdates() );
 179+ return $status;
 180+ }
 181+
 182+ /**
 183+ * Reload the list data from the master DB. This can be done after setVisibility()
 184+ * to allow $item->getHTML() to show the new data.
 185+ */
 186+ function reloadFromMaster() {
 187+ $dbw = wfGetDB( DB_MASTER );
 188+ $this->res = $this->doQuery( $dbw );
 189+ }
 190+
 191+ /**
 192+ * Record a log entry on the action
 193+ * @param $params Associative array of parameters:
 194+ * newBits: The new value of the *_deleted bitfield
 195+ * oldBits: The old value of the *_deleted bitfield.
 196+ * title: The target title
 197+ * ids: The ID list
 198+ * comment: The log comment
 199+ * authorsIds: The array of the user IDs of the offenders
 200+ * authorsIPs: The array of the IP/anon user offenders
 201+ */
 202+ protected function updateLog( $params ) {
 203+ // Get the URL param's corresponding DB field
 204+ $field = RevisionDeleter::getRelationType( $this->getType() );
 205+ if( !$field ) {
 206+ throw new MWException( "Bad log URL param type!" );
 207+ }
 208+ // Put things hidden from sysops in the oversight log
 209+ if ( ( $params['newBits'] | $params['oldBits'] ) & $this->getSuppressBit() ) {
 210+ $logType = 'suppress';
 211+ } else {
 212+ $logType = 'delete';
 213+ }
 214+ // Add params for effected page and ids
 215+ $logParams = $this->getLogParams( $params );
 216+ // Actually add the deletion log entry
 217+ $log = new LogPage( $logType );
 218+ $logid = $log->addEntry( $this->getLogAction(), $params['title'],
 219+ $params['comment'], $logParams );
 220+ // Allow for easy searching of deletion log items for revision/log items
 221+ $log->addRelations( $field, $params['ids'], $logid );
 222+ $log->addRelations( 'target_author_id', $params['authorIds'], $logid );
 223+ $log->addRelations( 'target_author_ip', $params['authorIPs'], $logid );
 224+ }
 225+
 226+ /**
 227+ * Get the log action for this list type
 228+ */
 229+ public function getLogAction() {
 230+ return 'revision';
 231+ }
 232+
 233+ /**
 234+ * Get log parameter array.
 235+ * @param $params Associative array of log parameters, same as updateLog()
 236+ * @return array
 237+ */
 238+ public function getLogParams( $params ) {
 239+ return array(
 240+ $this->getType(),
 241+ implode( ',', $params['ids'] ),
 242+ "ofield={$params['oldBits']}",
 243+ "nfield={$params['newBits']}"
 244+ );
 245+ }
 246+
 247+ /**
 248+ * Initialise the current iteration pointer
 249+ */
 250+ protected function initCurrent() {
 251+ $row = $this->res->current();
 252+ if ( $row ) {
 253+ $this->current = $this->newItem( $row );
 254+ } else {
 255+ $this->current = false;
 256+ }
 257+ }
 258+
 259+ /**
 260+ * Start iteration. This must be called before current() or next().
 261+ * @return First list item
 262+ */
 263+ public function reset() {
 264+ if ( !$this->res ) {
 265+ $this->res = $this->doQuery( wfGetDB( DB_SLAVE ) );
 266+ } else {
 267+ $this->res->rewind();
 268+ }
 269+ $this->initCurrent();
 270+ return $this->current;
 271+ }
 272+
 273+ /**
 274+ * Get the current list item, or false if we are at the end
 275+ */
 276+ public function current() {
 277+ return $this->current;
 278+ }
 279+
 280+ /**
 281+ * Move the iteration pointer to the next list item, and return it.
 282+ */
 283+ public function next() {
 284+ $this->res->next();
 285+ $this->initCurrent();
 286+ return $this->current;
 287+ }
 288+
 289+ /**
 290+ * Get the number of items in the list.
 291+ */
 292+ public function length() {
 293+ if( !$this->res ) {
 294+ return 0;
 295+ } else {
 296+ return $this->res->numRows();
 297+ }
 298+ }
 299+
 300+ /**
 301+ * Clear any data structures needed for doPreCommitUpdates() and doPostCommitUpdates()
 302+ * STUB
 303+ */
 304+ public function clearFileOps() {
 305+ }
 306+
 307+ /**
 308+ * A hook for setVisibility(): do batch updates pre-commit.
 309+ * STUB
 310+ * @return Status
 311+ */
 312+ public function doPreCommitUpdates() {
 313+ return Status::newGood();
 314+ }
 315+
 316+ /**
 317+ * A hook for setVisibility(): do any necessary updates post-commit.
 318+ * STUB
 319+ * @return Status
 320+ */
 321+ public function doPostCommitUpdates() {
 322+ return Status::newGood();
 323+ }
 324+
 325+ /**
 326+ * Create an item object from a DB result row
 327+ * @param $row stdclass
 328+ */
 329+ abstract public function newItem( $row );
 330+
 331+ /**
 332+ * Do the DB query to iterate through the objects.
 333+ * @param $db Database object to use for the query
 334+ */
 335+ abstract public function doQuery( $db );
 336+
 337+ /**
 338+ * Get the integer value of the flag used for suppression
 339+ */
 340+ abstract public function getSuppressBit();
 341+}
 342+
 343+/**
 344+ * Abstract base class for deletable items
 345+ */
 346+abstract class RevDel_Item {
 347+ /** The parent SpecialPage */
 348+ var $special;
 349+
 350+ /** The parent RevDel_List */
 351+ var $list;
 352+
 353+ /** The DB result row */
 354+ var $row;
 355+
 356+ /**
 357+ * @param $list RevDel_List
 358+ * @param $row DB result row
 359+ */
 360+ public function __construct( $list, $row ) {
 361+ $this->special = $list->special;
 362+ $this->list = $list;
 363+ $this->row = $row;
 364+ }
 365+
 366+ /**
 367+ * Get the ID, as it would appear in the ids URL parameter
 368+ */
 369+ public function getId() {
 370+ $field = $this->list->getIdField();
 371+ return $this->row->$field;
 372+ }
 373+
 374+ /**
 375+ * Get the date, formatted with $wgLang
 376+ */
 377+ public function formatDate() {
 378+ global $wgLang;
 379+ return $wgLang->date( $this->getTimestamp() );
 380+ }
 381+
 382+ /**
 383+ * Get the time, formatted with $wgLang
 384+ */
 385+ public function formatTime() {
 386+ global $wgLang;
 387+ return $wgLang->time( $this->getTimestamp() );
 388+ }
 389+
 390+ /**
 391+ * Get the timestamp in MW 14-char form
 392+ */
 393+ public function getTimestamp() {
 394+ $field = $this->list->getTimestampField();
 395+ return wfTimestamp( TS_MW, $this->row->$field );
 396+ }
 397+
 398+ /**
 399+ * Get the author user ID
 400+ */
 401+ public function getAuthorId() {
 402+ $field = $this->list->getAuthorIdField();
 403+ return intval( $this->row->$field );
 404+ }
 405+
 406+ /**
 407+ * Get the author user name
 408+ */
 409+ public function getAuthorName() {
 410+ $field = $this->list->getAuthorNameField();
 411+ return strval( $this->row->$field );
 412+ }
 413+
 414+ /**
 415+ * Returns true if the item is "current", and the operation to set the given
 416+ * bits can't be executed for that reason
 417+ * STUB
 418+ */
 419+ public function isHideCurrentOp( $newBits ) {
 420+ return false;
 421+ }
 422+
 423+ /**
 424+ * Returns true if the current user can view the item
 425+ */
 426+ abstract public function canView();
 427+
 428+ /**
 429+ * Returns true if the current user can view the item text/file
 430+ */
 431+ abstract public function canViewContent();
 432+
 433+ /**
 434+ * Get the current deletion bitfield value
 435+ */
 436+ abstract public function getBits();
 437+
 438+ /**
 439+ * Get the HTML of the list item. Should be include <li></li> tags.
 440+ * This is used to show the list in HTML form, by the special page.
 441+ */
 442+ abstract public function getHTML();
 443+
 444+ /**
 445+ * Set the visibility of the item. This should do any necessary DB queries.
 446+ *
 447+ * The DB update query should have a condition which forces it to only update
 448+ * if the value in the DB matches the value fetched earlier with the SELECT.
 449+ * If the update fails because it did not match, the function should return
 450+ * false. This prevents concurrency problems.
 451+ *
 452+ * @return boolean success
 453+ */
 454+ abstract public function setBits( $newBits );
 455+}
Property changes on: trunk/phase3/includes/revisiondelete/RevisionDeleteAbstracts.php
___________________________________________________________________
Added: svn:eol-style
1456 + native
Added: svn:keywords
2457 + Author Date Id Revision
Index: trunk/phase3/includes/AutoLoader.php
@@ -605,7 +605,9 @@
606606 'PreferencesForm' => 'includes/Preferences.php',
607607 'RandomPage' => 'includes/specials/SpecialRandompage.php',
608608 'SpecialRevisionDelete' => 'includes/specials/SpecialRevisiondelete.php',
609 - 'RevisionDeleter' => 'includes/RevisionDelete.php',
 609+ 'RevisionDeleter' => 'includes/revisiondelete/RevisionDelete.php',
 610+ 'RevDel_List' => 'includes/revisiondelete/RevisionDeleteAbstracts.php',
 611+ 'RevDel_Item' => 'includes/revisiondelete/RevisionDeleteAbstracts.php',
610612 'RevDel_RevisionList' => 'includes/revisiondelete/RevisionDelete.php',
611613 'RevDel_RevisionItem' => 'includes/revisiondelete/RevisionDelete.php',
612614 'RevDel_ArchiveList' => 'includes/revisiondelete/RevisionDelete.php',

Follow-up revisions

RevisionCommit summaryAuthorDate
r77695Followup r77679, 1 more for bug 23332reedy00:13, 4 December 2010

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r77677Move includes/RevisionDelete.php to includes/revisiondelete/RevisionDelete.phpreedy19:56, 3 December 2010

Status & tagging log