r103588 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r103587‎ | r103588 | r103589 >
Date:14:28, 18 November 2011
Author:jeroendedauw
Status:reverted
Tags:
Comment:
made db object class use lsb since this extension can require php 5.3 and fixed some c/p errors
Modified paths:
  • /trunk/extensions/Reviews/Reviews.php (modified) (history)
  • /trunk/extensions/Reviews/Reviews.settings.php (modified) (history)
  • /trunk/extensions/Reviews/includes/ReviewsDBObject.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Reviews/includes/ReviewsDBObject.php
@@ -451,19 +451,13 @@
452452 return new static( $data, $loadDefaults );
453453 }
454454
455 - //
456 - //
457 - // All below methods ought to be static, but can't be since this would require LSB introduced in PHP 5.3.
458 - //
459 - //
460 -
461455 /**
462456 * Get the database type used for read operations.
463457 *
464458 * @since 0.2
465459 * @return integer DB_ enum
466460 */
467 - public function getReadDb() {
 461+ public static function getReadDb() {
468462 return self::$readDb;
469463 }
470464
@@ -474,7 +468,7 @@
475469 *
476470 * @since 0.2
477471 */
478 - public function setReadDb( $db ) {
 472+ public static function setReadDb( $db ) {
479473 self::$readDb = $db;
480474 }
481475
@@ -487,8 +481,8 @@
488482 *
489483 * @return boolean
490484 */
491 - public function canHasField( $name ) {
492 - return array_key_exists( $name, $this->getFieldTypes() );
 485+ public static function canHasField( $name ) {
 486+ return array_key_exists( $name, static::getFieldTypes() );
493487 }
494488
495489 /**
@@ -501,11 +495,11 @@
502496 *
503497 * @return array
504498 */
505 - public function getPrefixedFields( $fields ) {
 499+ public static function getPrefixedFields( $fields ) {
506500 $fields = (array)$fields;
507501
508502 foreach ( $fields as &$field ) {
509 - $field = $this->getFieldPrefix() . $field;
 503+ $field = static::getFieldPrefix() . $field;
510504 }
511505
512506 return $fields;
@@ -520,8 +514,8 @@
521515 *
522516 * @return string
523517 */
524 - public function getPrefixedField( $field ) {
525 - return $this->getFieldPrefix() . $field;
 518+ public static function getPrefixedField( $field ) {
 519+ return static::getFieldPrefix() . $field;
526520 }
527521
528522 /**
@@ -535,11 +529,11 @@
536530 *
537531 * @return array
538532 */
539 - public function getPrefixedValues( array $values ) {
 533+ public static function getPrefixedValues( array $values ) {
540534 $prefixedValues = array();
541535
542536 foreach ( $values as $field => $value ) {
543 - $prefixedValues[$this->getFieldPrefix() . $field] = $value;
 537+ $prefixedValues[static::getFieldPrefix() . $field] = $value;
544538 }
545539
546540 return $prefixedValues;
@@ -556,10 +550,10 @@
557551 *
558552 * @return array
559553 */
560 - protected function getFieldsFromDBResult( $result ) {
 554+ protected static function getFieldsFromDBResult( $result ) {
561555 $result = (array)$result;
562556 $data = array();
563 - $idFieldLength = strlen( $this->getFieldPrefix() );
 557+ $idFieldLength = strlen( static::getFieldPrefix() );
564558
565559 foreach ( $result as $name => $value ) {
566560 $data[substr( $name, $idFieldLength )] = $value;
@@ -577,8 +571,8 @@
578572 *
579573 * @return ReviewDBObject
580574 */
581 - public function newFromDBResult( $result ) {
582 - return $this->newFromArray( $this->getFieldsFromDBResult( $result ) );
 575+ public static function newFromDBResult( $result ) {
 576+ return static::newFromArray( static::getFieldsFromDBResult( $result ) );
583577 }
584578
585579 /**
@@ -590,10 +584,10 @@
591585 *
592586 * @return boolean Success indicator
593587 */
594 - public function delete( array $conditions ) {
 588+ public static function delete( array $conditions ) {
595589 return wfGetDB( DB_MASTER )->delete(
596 - $this->getDBTable(),
597 - $this->getPrefixedValues( $conditions )
 590+ static::getDBTable(),
 591+ static::getPrefixedValues( $conditions )
598592 );
599593 }
600594
@@ -607,12 +601,12 @@
608602 *
609603 * @return boolean Success indicator
610604 */
611 - public function addToField( $field, $amount ) {
 605+ public static function addToField( $field, $amount ) {
612606 if ( $amount == 0 ) {
613607 return true;
614608 }
615609
616 - if ( !$this->hasIdField() ) {
 610+ if ( !static::hasIdField() ) {
617611 return false;
618612 }
619613
@@ -621,17 +615,17 @@
622616
623617 $dbw = wfGetDB( DB_MASTER );
624618
625 - $fullField = $this->getPrefixedField( $field );
 619+ $fullField = static::getPrefixedField( $field );
626620
627621 $success = $dbw->update(
628 - $this->getDBTable(),
 622+ static::getDBTable(),
629623 array( "$fullField=$fullField" . ( $isNegative ? '-' : '+' ) . $absoluteAmount ),
630 - array( $this->getPrefixedField( 'id' ) => $this->getId() ),
 624+ array( static::getPrefixedField( 'id' ) => static::getId() ),
631625 __METHOD__
632626 );
633627
634 - if ( $success && $this->hasField( $field ) ) {
635 - $this->setField( $field, $this->getField( $field ) + $amount );
 628+ if ( $success && static::hasField( $field ) ) {
 629+ static::setField( $field, static::getField( $field ) + $amount );
636630 }
637631
638632 return $success;
@@ -649,21 +643,21 @@
650644 *
651645 * @return array of self
652646 */
653 - public function select( $fields = null, array $conditions = array(), array $options = array() ) {
 647+ public static function select( $fields = null, array $conditions = array(), array $options = array() ) {
654648 if ( is_null( $fields ) ) {
655 - $fields = array_keys( $this->getFieldTypes() );
 649+ $fields = array_keys( static::getFieldTypes() );
656650 }
657651
658 - $result = $this->rawSelect(
659 - $this->getPrefixedFields( $fields ),
660 - $this->getPrefixedValues( $conditions ),
 652+ $result = static::rawSelect(
 653+ static::getPrefixedFields( $fields ),
 654+ static::getPrefixedValues( $conditions ),
661655 $options
662656 );
663657
664658 $objects = array();
665659
666660 foreach ( $result as $record ) {
667 - $objects[] = $this->newFromDBResult( $record );
 661+ $objects[] = static::newFromDBResult( $record );
668662 }
669663
670664 return $objects;
@@ -681,10 +675,10 @@
682676 *
683677 * @return self|false
684678 */
685 - public function selectRow( $fields = null, array $conditions = array(), array $options = array() ) {
 679+ public static function selectRow( $fields = null, array $conditions = array(), array $options = array() ) {
686680 $options['LIMIT'] = 1;
687681
688 - $objects = $this->select( $fields, $conditions, $options );
 682+ $objects = static::select( $fields, $conditions, $options );
689683
690684 return count( $objects ) > 0 ? $objects[0] : false;
691685 }
@@ -699,8 +693,8 @@
700694 *
701695 * @return boolean
702696 */
703 - public function has( array $conditions = array() ) {
704 - return $this->selectRow( array( 'id' ), $conditions ) !== false;
 697+ public static function has( array $conditions = array() ) {
 698+ return static::selectRow( array( 'id' ), $conditions ) !== false;
705699 }
706700
707701 /**
@@ -714,10 +708,10 @@
715709 *
716710 * @return integer
717711 */
718 - public function count( array $conditions = array(), array $options = array() ) {
719 - $res = $this->rawSelect(
 712+ public static function count( array $conditions = array(), array $options = array() ) {
 713+ $res = static::rawSelect(
720714 array( 'COUNT(*) AS rowcount' ),
721 - $this->getPrefixedValues( $conditions ),
 715+ static::getPrefixedValues( $conditions ),
722716 $options
723717 )->fetchObject();
724718
@@ -736,11 +730,11 @@
737731 *
738732 * @return ResultWrapper
739733 */
740 - public function rawSelect( $fields = null, array $conditions = array(), array $options = array() ) {
741 - $dbr = wfGetDB( $this->getReadDb() );
 734+ public static function rawSelect( $fields = null, array $conditions = array(), array $options = array() ) {
 735+ $dbr = wfGetDB( static::getReadDb() );
742736
743737 return $dbr->select(
744 - $this->getDBTable(),
 738+ static::getDBTable(),
745739 $fields,
746740 count( $conditions ) == 0 ? '' : $conditions,
747741 __METHOD__,
@@ -760,13 +754,13 @@
761755 *
762756 * @return boolean Success indicator
763757 */
764 - public function update( array $values, array $conditions = array() ) {
 758+ public static function update( array $values, array $conditions = array() ) {
765759 $dbw = wfGetDB( DB_MASTER );
766760
767761 return $dbw->update(
768 - $this->getDBTable(),
769 - $this->getPrefixedValues( $values ),
770 - $this->getPrefixedValues( $conditions ),
 762+ static::getDBTable(),
 763+ static::getPrefixedValues( $values ),
 764+ static::getPrefixedValues( $conditions ),
771765 __METHOD__
772766 );
773767 }
@@ -778,8 +772,8 @@
779773 *
780774 * @return array
781775 */
782 - public function getFieldNames() {
783 - return array_keys( $this->getFieldTypes() );
 776+ public static function getFieldNames() {
 777+ return array_keys( static::getFieldTypes() );
784778 }
785779
786780 /**
@@ -791,7 +785,7 @@
792786 *
793787 * @return array
794788 */
795 - public function getFieldDescriptions() {
 789+ public static function getFieldDescriptions() {
796790 return array();
797791 }
798792
@@ -805,7 +799,7 @@
806800 *
807801 * @return array
808802 */
809 - public function getAPIParams( $requireParams = false, $setDefaults = false ) {
 803+ public static function getAPIParams( $requireParams = false, $setDefaults = false ) {
810804 $typeMap = array(
811805 'id' => 'integer',
812806 'int' => 'integer',
@@ -816,9 +810,9 @@
817811 );
818812
819813 $params = array();
820 - $defaults = $this->getDefaults();
 814+ $defaults = static::getDefaults();
821815
822 - foreach ( $this->getFieldTypes() as $field => $type ) {
 816+ foreach ( static::getFieldTypes() as $field => $type ) {
823817 if ( $field == 'id' ) {
824818 continue;
825819 }
Index: trunk/extensions/Reviews/Reviews.settings.php
@@ -28,6 +28,7 @@
2929 */
3030 protected static function getDefaultSettings() {
3131 return array(
 32+ 'enableTopLink' => true,
3233 );
3334 }
3435
Index: trunk/extensions/Reviews/Reviews.php
@@ -28,7 +28,7 @@
2929 die( '<b>Error:</b> Reviews requires MediaWiki 1.18 or above.' );
3030 }
3131
32 -define( 'REVIEWS_VERSION', '0.2 alpha' );
 32+define( 'REVIEWS_VERSION', '0.1 alpha' );
3333
3434 $wgExtensionCredits['other'][] = array(
3535 'path' => __FILE__,
@@ -95,3 +95,6 @@
9696 unset( $moduleTemplate );
9797
9898 $egReviewsSettings = array();
 99+
 100+# The default value for the user preference to display a top link to the my reviews special page.
 101+$wgDefaultUserOptions['reviews_showtoplink'] = false;

Status & tagging log