r34844 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r34843‎ | r34844 | r34845 >
Date:03:13, 15 May 2008
Author:aaron
Status:old
Tags:
Comment:
* More sanity checks
* Remove uneeded code
* Add userCanSetFlags() accessor
* Remove ugly skipReviewDiff field
Modified paths:
  • /trunk/extensions/FlaggedRevs/FlaggedArticle.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevision.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/FlaggedRevs.php
@@ -1868,14 +1868,35 @@
18691869 }
18701870
18711871 /**
 1872+ * Was this request an edit to said title?
 1873+ * @param Title $title
 1874+ * @param Revision $rev
 1875+ */
 1876+ public static function revSubmitted( $title, $rev ) {
 1877+ global $wgRequest, $wgUser;
 1878+ if( !$wgRequest->wasPosted() || !$wgRequest->getVal('wpSave') || $wgRequest->getVal('title') !== $title->getPrefixedDBkey() ) {
 1879+ return false;
 1880+ }
 1881+ # Must be by this user
 1882+ if( $wgUser->getId() ) {
 1883+ if( $rev->getUser() != $wgUser->getId() ) {
 1884+ return false;
 1885+ }
 1886+ # Must be by this IP
 1887+ } else {
 1888+ if( $rev->getRawUserText() != $wgUser->getName() ) {
 1889+ return false;
 1890+ }
 1891+ }
 1892+ return true;
 1893+ }
 1894+
 1895+ /**
18721896 * When an edit is made by a reviewer, if the current revision is the stable
18731897 * version, try to automatically review it.
18741898 */
18751899 public static function maybeMakeEditReviewed( $rev ) {
1876 - global $wgFlaggedRevsAutoReview, $wgFlaggedArticle, $wgRequest;
1877 - # For edits from form submits only
1878 - if( !$wgRequest->getVal('wpSave') || !$wgRequest->wasPosted() )
1879 - return true;
 1900+ global $wgFlaggedRevsAutoReview, $wgFlaggedArticle, $wgRequest, $wgUser;
18801901 # Get the user
18811902 $user = User::newFromId( $rev->getUser() );
18821903 if( !$wgFlaggedRevsAutoReview || !$user->isAllowed('autoreview') )
@@ -1887,41 +1908,39 @@
18881909 if( !$title || !self::isPageReviewable( $title ) ) {
18891910 return true;
18901911 }
 1912+ # For edits from normal form submits only!
 1913+ if( !self::revSubmitted( $title, $rev ) ) {
 1914+ return true;
 1915+ }
18911916 $article = new Article( $title );
1892 - # Revision will be null for null edits
1893 - if( $rev ) {
1894 - $frev = null;
1895 - $reviewableNewPage = false;
1896 - # Get the revision the incoming one was based off
1897 - $baseRevID = $wgRequest->getVal('baseRevId');
1898 - if( $baseRevID ) {
1899 - $frev = self::getFlaggedRev( $article->getTitle(), $baseRevID );
1900 - } else {
1901 - $prevRevID = $article->getTitle()->getPreviousRevisionId( $rev->getId() );
1902 - $prevRev = $prevRevID ? Revision::newFromID( $prevRevID ) : null;
1903 - # Check for null edits
1904 - if( $prevRev && $prevRev->getTextId() == $rev->getTextId() ) {
1905 - $frev = self::getFlaggedRev( $title, $prevRev->getId() );
1906 - # Check for new pages
1907 - } else if( !$prevRev ) {
1908 - global $wgFlaggedRevsAutoReviewNew;
1909 - $reviewableNewPage = $wgFlaggedRevsAutoReviewNew;
1910 - }
 1917+ $frev = null;
 1918+ $reviewableNewPage = false;
 1919+ # Get the revision the incoming one was based off
 1920+ $baseRevID = $wgRequest->getVal('baseRevId');
 1921+ if( $baseRevID ) {
 1922+ $frev = self::getFlaggedRev( $article->getTitle(), $baseRevID );
 1923+ } else {
 1924+ $prevRevID = $article->getTitle()->getPreviousRevisionId( $rev->getId() );
 1925+ $prevRev = $prevRevID ? Revision::newFromID( $prevRevID ) : null;
 1926+ # Check for null edits
 1927+ if( $prevRev && $prevRev->getTextId() == $rev->getTextId() ) {
 1928+ $frev = self::getFlaggedRev( $title, $prevRev->getId() );
 1929+ # Check for new pages
 1930+ } else if( !$prevRev ) {
 1931+ global $wgFlaggedRevsAutoReviewNew;
 1932+ $reviewableNewPage = $wgFlaggedRevsAutoReviewNew;
19111933 }
1912 - # Is this an edit directly to the stable version?
1913 - if( $reviewableNewPage || !is_null($frev) ) {
1914 - # Assume basic flagging level
1915 - $flags = array();
1916 - foreach( self::$dimensions as $tag => $minQL ) {
1917 - $flags[$tag] = 1;
1918 - }
1919 - # Review this revision of the page. Let articlesavecomplete hook do rc_patrolled bit...
1920 - self::autoReviewEdit( $article, $user, $rev->getText(), $rev, $flags, false );
 1934+ }
 1935+ # Is this an edit directly to the stable version?
 1936+ if( $reviewableNewPage || !is_null($frev) ) {
 1937+ # Assume basic flagging level
 1938+ $flags = array();
 1939+ foreach( self::$dimensions as $tag => $minQL ) {
 1940+ $flags[$tag] = 1;
19211941 }
 1942+ # Review this revision of the page. Let articlesavecomplete hook do rc_patrolled bit...
 1943+ self::autoReviewEdit( $article, $user, $rev->getText(), $rev, $flags, false );
19221944 }
1923 - if( $wgFlaggedArticle ) {
1924 - $wgFlaggedArticle->skipReviewDiff = true; // Don't jump to diff...
1925 - }
19261945 return true;
19271946 }
19281947
@@ -1949,9 +1968,6 @@
19501969 self::articleLinksUpdate( $article ); // lame...
19511970 }
19521971 }
1953 - if( $wgFlaggedArticle ) {
1954 - $wgFlaggedArticle->skipReviewDiff = true; // Don't jump to diff...
1955 - }
19561972 return true;
19571973 }
19581974
Index: trunk/extensions/FlaggedRevs/FlaggedArticle.php
@@ -2,7 +2,6 @@
33
44 class FlaggedArticle extends Article {
55 public $isDiffFromStable = false;
6 - public $skipReviewDiff = false;
76 public $stableRev = null;
87 public $pageconfig = null;
98 public $flags = null;
@@ -849,17 +848,15 @@
850849 # Don't show this for the talk page
851850 if( !$this->isReviewable() || $article->getTitle()->isTalkPage() )
852851 return true;
853 - # Get the stable version and flags
854 - $frev = $this->getStableRev();
855 - $flags = $frev ? $frev->getTags() : array();
 852+ # Get the stable version, from master
 853+ $frev = $this->getStableRev( false, true );
 854+ if( !$frev )
 855+ return true;
 856+ $latest = $article->getTitle()->getLatestRevID(GAID_FOR_UPDATE);
856857 // If we are supposed to review after edit, and it was not autoreviewed,
857858 // and the user can actually make new stable version, take us to the diff...
858 - if( $wgReviewChangesAfterEdit && !$this->skipReviewDiff && $frev && RevisionReview::userCanSetFlags($flags) ) {
859 - $flags = $frev->getTags();
860 - # If the user can update the stable version, jump to it...
861 - if( RevisionReview::userCanSetFlags( $flags ) ) {
862 - $extraq .= "oldid={$frev->getRevId()}&diff=cur";
863 - }
 859+ if( $wgReviewChangesAfterEdit && $frev && $latest > $frev->getRevId() && $frev->userCanSetFlags() ) {
 860+ $extraq .= "oldid={$frev->getRevId()}&diff=cur";
864861 // ...otherwise, go to the current revision after completing an edit.
865862 } else {
866863 if( $frev ){
@@ -869,7 +866,6 @@
870867 }
871868 }
872869 }
873 -
874870 return true;
875871 }
876872
Index: trunk/extensions/FlaggedRevs/FlaggedRevision.php
@@ -61,7 +61,7 @@
6262 * @returns String revision timestamp in MW format
6363 */
6464 public function getTimestamp() {
65 - return wfTimestamp(TS_MW, $this->mTimestamp);
 65+ return wfTimestamp( TS_MW, $this->mTimestamp );
6666 }
6767
6868 /**
@@ -116,6 +116,13 @@
117117 public function getTags() {
118118 return $this->mTags;
119119 }
 120+
 121+ /**
 122+ * @returns bool
 123+ */
 124+ public function userCanSetFlags() {
 125+ return RevisionReview::userCanSetFlags( $this->mTags );
 126+ }
120127
121128 /**
122129 * @returns mixed (string/false) expanded text

Status & tagging log