Index: trunk/extensions/CodeReview/backend/CodeRevision.php |
— | — | @@ -3,6 +3,12 @@ |
4 | 4 | class CodeRevision { |
5 | 5 | public $mRepoId, $mRepo, $mId, $mAuthor, $mTimestamp, $mMessage, $mPaths, $mStatus, $mOldStatus, $mCommonPath; |
6 | 6 | |
| 7 | + /** |
| 8 | + * @static |
| 9 | + * @param CodeRepository $repo |
| 10 | + * @param $data |
| 11 | + * @return CodeRevision |
| 12 | + */ |
7 | 13 | public static function newFromSvn( CodeRepository $repo, $data ) { |
8 | 14 | $rev = new CodeRevision(); |
9 | 15 | $rev->mRepoId = $repo->getId(); |
— | — | @@ -62,6 +68,13 @@ |
63 | 69 | return $rev; |
64 | 70 | } |
65 | 71 | |
| 72 | + /** |
| 73 | + * @static |
| 74 | + * @throws MWException |
| 75 | + * @param CodeRepository $repo |
| 76 | + * @param $row |
| 77 | + * @return CodeRevision |
| 78 | + */ |
66 | 79 | public static function newFromRow( CodeRepository $repo, $row ) { |
67 | 80 | $rev = new CodeRevision(); |
68 | 81 | $rev->mRepoId = intval( $row->cr_repo_id ); |
— | — | @@ -79,6 +92,9 @@ |
80 | 93 | return $rev; |
81 | 94 | } |
82 | 95 | |
| 96 | + /** |
| 97 | + * @return int |
| 98 | + */ |
83 | 99 | public function getId() { |
84 | 100 | return intval( $this->mId ); |
85 | 101 | } |
— | — | @@ -86,6 +102,7 @@ |
87 | 103 | /** |
88 | 104 | * Like getId(), but returns the result as a string, including prefix, |
89 | 105 | * i.e. "r123" instead of 123. |
| 106 | + * @param $id |
90 | 107 | */ |
91 | 108 | public function getIdString( $id = null ) { |
92 | 109 | if ( $id === null ) { |
— | — | @@ -101,6 +118,9 @@ |
102 | 119 | * This ensures you get a unique reference, as the revision ID alone can be |
103 | 120 | * confusing (e.g. in e-mails, page titles etc.). If only one repository is |
104 | 121 | * defined then this returns the same as getIdString() as there is no ambiguity. |
| 122 | + * |
| 123 | + * @param null $id |
| 124 | + * @return |
105 | 125 | */ |
106 | 126 | public function getIdStringUnique( $id = null ) { |
107 | 127 | if ( $id === null ) { |
— | — | @@ -109,30 +129,51 @@ |
110 | 130 | return $this->mRepo->getRevIdStringUnique( $id ); |
111 | 131 | } |
112 | 132 | |
| 133 | + /** |
| 134 | + * @return int |
| 135 | + */ |
113 | 136 | public function getRepoId() { |
114 | 137 | return intval( $this->mRepoId ); |
115 | 138 | } |
116 | 139 | |
| 140 | + /** |
| 141 | + * @return |
| 142 | + */ |
117 | 143 | public function getAuthor() { |
118 | 144 | return $this->mAuthor; |
119 | 145 | } |
120 | 146 | |
| 147 | + /** |
| 148 | + * @return |
| 149 | + */ |
121 | 150 | public function getWikiUser() { |
122 | 151 | return $this->mRepo->authorWikiUser( $this->getAuthor() ); |
123 | 152 | } |
124 | 153 | |
| 154 | + /** |
| 155 | + * @return |
| 156 | + */ |
125 | 157 | public function getTimestamp() { |
126 | 158 | return $this->mTimestamp; |
127 | 159 | } |
128 | 160 | |
| 161 | + /** |
| 162 | + * @return |
| 163 | + */ |
129 | 164 | public function getMessage() { |
130 | 165 | return $this->mMessage; |
131 | 166 | } |
132 | 167 | |
| 168 | + /** |
| 169 | + * @return |
| 170 | + */ |
133 | 171 | public function getStatus() { |
134 | 172 | return $this->mStatus; |
135 | 173 | } |
136 | 174 | |
| 175 | + /** |
| 176 | + * @return |
| 177 | + */ |
137 | 178 | public function getCommonPath() { |
138 | 179 | return $this->mCommonPath; |
139 | 180 | } |
— | — | @@ -234,6 +275,9 @@ |
235 | 276 | } |
236 | 277 | } |
237 | 278 | |
| 279 | + /** |
| 280 | + * @return void |
| 281 | + */ |
238 | 282 | public function save() { |
239 | 283 | $dbw = wfGetDB( DB_MASTER ); |
240 | 284 | $dbw->begin(); |
— | — | @@ -420,6 +464,9 @@ |
421 | 465 | return $affectedRevs; |
422 | 466 | } |
423 | 467 | |
| 468 | + /** |
| 469 | + * @return |
| 470 | + */ |
424 | 471 | public function getModifiedPaths() { |
425 | 472 | $dbr = wfGetDB( DB_SLAVE ); |
426 | 473 | return $dbr->select( |
— | — | @@ -430,6 +477,9 @@ |
431 | 478 | ); |
432 | 479 | } |
433 | 480 | |
| 481 | + /** |
| 482 | + * @return bool |
| 483 | + */ |
434 | 484 | public function isDiffable() { |
435 | 485 | $paths = $this->getModifiedPaths(); |
436 | 486 | if ( !$paths->numRows() || $paths->numRows() > 20 ) { |
— | — | @@ -438,12 +488,24 @@ |
439 | 489 | return true; |
440 | 490 | } |
441 | 491 | |
| 492 | + /** |
| 493 | + * @param $text |
| 494 | + * @param $review |
| 495 | + * @param null $parent |
| 496 | + * @return CodeComment |
| 497 | + */ |
442 | 498 | public function previewComment( $text, $review, $parent = null ) { |
443 | 499 | $data = $this->commentData( $text, $review, $parent ); |
444 | 500 | $data['cc_id'] = null; |
445 | 501 | return CodeComment::newFromData( $this, $data ); |
446 | 502 | } |
447 | 503 | |
| 504 | + /** |
| 505 | + * @param $text |
| 506 | + * @param $review |
| 507 | + * @param null $parent |
| 508 | + * @return int |
| 509 | + */ |
448 | 510 | public function saveComment( $text, $review, $parent = null ) { |
449 | 511 | $text = trim( $text ); |
450 | 512 | if ( !strlen( $text ) ) { |
— | — | @@ -511,6 +573,12 @@ |
512 | 574 | } |
513 | 575 | } |
514 | 576 | |
| 577 | + /** |
| 578 | + * @param $text |
| 579 | + * @param $review |
| 580 | + * @param null $parent |
| 581 | + * @return array |
| 582 | + */ |
515 | 583 | protected function commentData( $text, $review, $parent = null ) { |
516 | 584 | global $wgUser; |
517 | 585 | $dbw = wfGetDB( DB_MASTER ); |
— | — | @@ -528,6 +596,12 @@ |
529 | 597 | 'cc_sortkey' => $sortkey ); |
530 | 598 | } |
531 | 599 | |
| 600 | + /** |
| 601 | + * @throws MWException |
| 602 | + * @param $parent |
| 603 | + * @param $ts |
| 604 | + * @return string |
| 605 | + */ |
532 | 606 | protected function threadedSortKey( $parent, $ts ) { |
533 | 607 | if ( $parent ) { |
534 | 608 | // We construct a threaded sort key by concatenating the timestamps |
— | — | @@ -548,6 +622,9 @@ |
549 | 623 | } |
550 | 624 | } |
551 | 625 | |
| 626 | + /** |
| 627 | + * @return array |
| 628 | + */ |
552 | 629 | public function getComments() { |
553 | 630 | $dbr = wfGetDB( DB_SLAVE ); |
554 | 631 | $result = $dbr->select( 'code_comment', |
— | — | @@ -593,6 +670,9 @@ |
594 | 671 | } |
595 | 672 | } |
596 | 673 | |
| 674 | + /** |
| 675 | + * @return array |
| 676 | + */ |
597 | 677 | public function getPropChanges() { |
598 | 678 | $dbr = wfGetDB( DB_SLAVE ); |
599 | 679 | $result = $dbr->select( array( 'code_prop_changes', 'user' ), |
— | — | @@ -619,6 +699,9 @@ |
620 | 700 | return $changes; |
621 | 701 | } |
622 | 702 | |
| 703 | + /** |
| 704 | + * @return array |
| 705 | + */ |
623 | 706 | public function getPropChangeUsers() { |
624 | 707 | $dbr = wfGetDB( DB_SLAVE ); |
625 | 708 | $result = $dbr->select( 'code_prop_changes', |
— | — | @@ -643,6 +726,9 @@ |
644 | 727 | return array_merge( $this->getCommentingUsers(), $this->getPropChangeUsers() ); |
645 | 728 | } |
646 | 729 | |
| 730 | + /** |
| 731 | + * @return array |
| 732 | + */ |
647 | 733 | protected function getCommentingUsers() { |
648 | 734 | $dbr = wfGetDB( DB_SLAVE ); |
649 | 735 | $res = $dbr->select( 'code_comment', |
— | — | @@ -712,6 +798,10 @@ |
713 | 799 | $this->addReferences( $data ); |
714 | 800 | } |
715 | 801 | |
| 802 | + /** |
| 803 | + * @param $data |
| 804 | + * @return void |
| 805 | + */ |
716 | 806 | private function addReferences( $data ) { |
717 | 807 | $dbw = wfGetDB( DB_MASTER ); |
718 | 808 | $dbw->insert( 'code_relations', $data, __METHOD__, array( 'IGNORE' ) ); |
— | — | @@ -814,6 +904,10 @@ |
815 | 905 | } |
816 | 906 | } |
817 | 907 | |
| 908 | + /** |
| 909 | + * @param int $from |
| 910 | + * @return array |
| 911 | + */ |
818 | 912 | public function getTags( $from = DB_SLAVE ) { |
819 | 913 | $db = wfGetDB( $from ); |
820 | 914 | $result = $db->select( 'code_tags', |
— | — | @@ -830,6 +924,12 @@ |
831 | 925 | return $tags; |
832 | 926 | } |
833 | 927 | |
| 928 | + /** |
| 929 | + * @param $addTags |
| 930 | + * @param $removeTags |
| 931 | + * @param null $user |
| 932 | + * @return void |
| 933 | + */ |
834 | 934 | public function changeTags( $addTags, $removeTags, $user = null ) { |
835 | 935 | // Get the current tags and see what changes |
836 | 936 | $tagsNow = $this->getTags( DB_MASTER ); |
— | — | @@ -874,6 +974,10 @@ |
875 | 975 | } |
876 | 976 | } |
877 | 977 | |
| 978 | + /** |
| 979 | + * @param $tags |
| 980 | + * @return array |
| 981 | + */ |
878 | 982 | protected function normalizeTags( $tags ) { |
879 | 983 | $out = array(); |
880 | 984 | foreach ( $tags as $tag ) { |
— | — | @@ -882,6 +986,10 @@ |
883 | 987 | return $out; |
884 | 988 | } |
885 | 989 | |
| 990 | + /** |
| 991 | + * @param $tags |
| 992 | + * @return array |
| 993 | + */ |
886 | 994 | protected function tagData( $tags ) { |
887 | 995 | $data = array(); |
888 | 996 | foreach ( $tags as $tag ) { |
— | — | @@ -894,6 +1002,10 @@ |
895 | 1003 | return $data; |
896 | 1004 | } |
897 | 1005 | |
| 1006 | + /** |
| 1007 | + * @param $tag |
| 1008 | + * @return bool |
| 1009 | + */ |
898 | 1010 | public function normalizeTag( $tag ) { |
899 | 1011 | global $wgContLang; |
900 | 1012 | $lower = $wgContLang->lc( $tag ); |
— | — | @@ -906,10 +1018,18 @@ |
907 | 1019 | } |
908 | 1020 | } |
909 | 1021 | |
| 1022 | + /** |
| 1023 | + * @param $tag |
| 1024 | + * @return bool |
| 1025 | + */ |
910 | 1026 | public function isValidTag( $tag ) { |
911 | 1027 | return ( $this->normalizeTag( $tag ) !== false ); |
912 | 1028 | } |
913 | 1029 | |
| 1030 | + /** |
| 1031 | + * @param string $path |
| 1032 | + * @return bool|int |
| 1033 | + */ |
914 | 1034 | public function getPrevious( $path = '' ) { |
915 | 1035 | $dbr = wfGetDB( DB_SLAVE ); |
916 | 1036 | $encId = $dbr->addQuotes( $this->mId ); |
— | — | @@ -935,6 +1055,10 @@ |
936 | 1056 | } |
937 | 1057 | } |
938 | 1058 | |
| 1059 | + /** |
| 1060 | + * @param string $path |
| 1061 | + * @return bool|int |
| 1062 | + */ |
939 | 1063 | public function getNext( $path = '' ) { |
940 | 1064 | $dbr = wfGetDB( DB_SLAVE ); |
941 | 1065 | $encId = $dbr->addQuotes( $this->mId ); |
— | — | @@ -960,6 +1084,10 @@ |
961 | 1085 | } |
962 | 1086 | } |
963 | 1087 | |
| 1088 | + /** |
| 1089 | + * @param $path |
| 1090 | + * @return array |
| 1091 | + */ |
964 | 1092 | protected function getPathConds( $path ) { |
965 | 1093 | $dbr = wfGetDB( DB_SLAVE ); |
966 | 1094 | return array( |
— | — | @@ -973,6 +1101,10 @@ |
974 | 1102 | ); |
975 | 1103 | } |
976 | 1104 | |
| 1105 | + /** |
| 1106 | + * @param string $path |
| 1107 | + * @return bool|int |
| 1108 | + */ |
977 | 1109 | public function getNextUnresolved( $path = '' ) { |
978 | 1110 | $dbr = wfGetDB( DB_SLAVE ); |
979 | 1111 | $encId = $dbr->addQuotes( $this->mId ); |
— | — | @@ -999,6 +1131,10 @@ |
1000 | 1132 | } |
1001 | 1133 | } |
1002 | 1134 | |
| 1135 | + /** |
| 1136 | + * @param string $commentId |
| 1137 | + * @return \type |
| 1138 | + */ |
1003 | 1139 | public function getFullUrl( $commentId = '' ) { |
1004 | 1140 | $title = SpecialPage::getTitleFor( 'Code', $this->mRepo->getName() . '/' . $this->mId ); |
1005 | 1141 | |
— | — | @@ -1009,6 +1145,12 @@ |
1010 | 1146 | return $title->getFullUrl(); |
1011 | 1147 | } |
1012 | 1148 | |
| 1149 | + /** |
| 1150 | + * @param $commentId |
| 1151 | + * @param $text |
| 1152 | + * @param null $url |
| 1153 | + * @return void |
| 1154 | + */ |
1013 | 1155 | protected function sendCommentToUDP( $commentId, $text, $url = null ) { |
1014 | 1156 | global $wgCodeReviewUDPAddress, $wgCodeReviewUDPPort, $wgCodeReviewUDPPrefix, $wgLang, $wgUser; |
1015 | 1157 | |
— | — | @@ -1025,6 +1167,11 @@ |
1026 | 1168 | } |
1027 | 1169 | } |
1028 | 1170 | |
| 1171 | + /** |
| 1172 | + * @param $status |
| 1173 | + * @param $oldStatus |
| 1174 | + * @return void |
| 1175 | + */ |
1029 | 1176 | protected function sendStatusToUDP( $status, $oldStatus ) { |
1030 | 1177 | global $wgCodeReviewUDPAddress, $wgCodeReviewUDPPort, $wgCodeReviewUDPPrefix, $wgUser; |
1031 | 1178 | |