r64916 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r64915‎ | r64916 | r64917 >
Date:23:47, 10 April 2010
Author:aaron
Status:ok
Tags:
Comment:
* Fixed type error in updateStableVersion() call.
* Made argument types stricter. Also helps IDEs and compilers.
Modified paths:
  • /trunk/extensions/FlaggedRevs/FlaggedRevision.php (modified) (history)
  • /trunk/extensions/FlaggedRevs/FlaggedRevs.class.php (modified) (history)

Diff [purge]

Index: trunk/extensions/FlaggedRevs/FlaggedRevs.class.php
@@ -259,7 +259,7 @@
260260 * @param array $config
261261 * @returns string
262262 */
263 - public static function getProtectionLevel( $config ) {
 263+ public static function getProtectionLevel( array $config ) {
264264 if( !self::useProtectionLevels() ) {
265265 throw new MWException('getProtectionLevel() called with $wgFlaggedRevsProtection off');
266266 }
@@ -472,11 +472,11 @@
473473 /**
474474 * Get minimum tags that are closest to $oldFlags
475475 * given the site, page, and user rights limitations.
476 - * @param Array $oldFlags previous stable rev flags
477 - * @param Array $config
 476+ * @param array $oldFlags previous stable rev flags
 477+ * @param array $config
478478 * @return mixed array or null
479479 */
480 - public static function getAutoReviewTags( $oldFlags, $config = array() ) {
 480+ public static function getAutoReviewTags( $oldFlags, array $config = array() ) {
481481 if ( !FlaggedRevs::autoReviewEdits() ) {
482482 return null; // shouldn't happen
483483 }
@@ -506,7 +506,7 @@
507507 * @return array( string, array, array, array, int )
508508 * All included pages/arguments are expanded out
509509 */
510 - public static function expandText( $text = '', $title, $id ) {
 510+ public static function expandText( $text = '', Title $title, $id ) {
511511 global $wgParser;
512512 # Make our hooks trigger (force unstub so setting doesn't get lost)
513513 $wgParser->firstCallInit();
@@ -530,7 +530,7 @@
531531 * @param int $id
532532 * @return ParserOutput
533533 */
534 - public static function parseStableText( $article, $text = '', $id ) {
 534+ public static function parseStableText( Article $article, $text, $id ) {
535535 global $wgParser;
536536 $title = $article->getTitle(); // avoid pass-by-reference error
537537 # Make our hooks trigger (force unstub so setting doesn't get lost)
@@ -550,7 +550,7 @@
551551 * @param User $user (optional)
552552 * @returns ParserOptions
553553 */
554 - public static function makeParserOptions( $user = null ) {
 554+ public static function makeParserOptions( User $user = null ) {
555555 global $wgUser;
556556 $user = $user ? $user : $wgUser; // assume current
557557 $options = ParserOptions::newFromUser( $user );
@@ -567,7 +567,7 @@
568568 * @return ParserOutput
569569 * Get the page cache for the top stable revision of an article
570570 */
571 - public static function getPageCache( $article, $user ) {
 571+ public static function getPageCache( Article $article, User $user ) {
572572 global $parserMemc, $wgCacheEpoch;
573573 wfProfileIn( __METHOD__ );
574574 # Make sure it is valid
@@ -615,7 +615,7 @@
616616 /**
617617 * Like ParserCache::getKey() with stable-pcache instead of pcache
618618 */
619 - public static function getCacheKey( $parserCache, $article, $user ) {
 619+ public static function getCacheKey( $parserCache, Article $article, User $user ) {
620620 $key = $parserCache->getKey( $article, $user );
621621 $key = str_replace( ':pcache:', ':stable-pcache:', $key );
622622 return $key;
@@ -627,7 +627,9 @@
628628 * @param parserOutput $parserOut
629629 * Updates the stable cache of a page with the given $parserOut
630630 */
631 - public static function updatePageCache( $article, $user, $parserOut = null ) {
 631+ public static function updatePageCache(
 632+ Article $article, User $user, ParserOutput $parserOut = null
 633+ ) {
632634 global $parserMemc, $wgParserCacheExpireTime, $wgEnableParserCache;
633635 # Make sure it is valid and $wgEnableParserCache is enabled
634636 if ( !$wgEnableParserCache || is_null( $parserOut ) )
@@ -659,7 +661,7 @@
660662 * @param array $imgParams (like ParserOutput image time->sha1 pairs)
661663 * Set the template/image versioning cache for parser
662664 */
663 - public static function setIncludeVersionCache( $revId, $tmpParams, $imgParams ) {
 665+ public static function setIncludeVersionCache( $revId, array $tmpParams, array $imgParams ) {
664666 self::load();
665667 self::$includeVersionCache[$revId] = array();
666668 self::$includeVersionCache[$revId]['templates'] = $tmpParams;
@@ -741,7 +743,10 @@
742744 * This function is pretty expensive...
743745 */
744746 public static function stableVersionIsSynced(
745 - $srev, $article, $stableOutput = null, $currentOutput = null
 747+ FlaggedRevision $srev,
 748+ Article $article,
 749+ ParserOutput $stableOutput = null,
 750+ ParserOutput $currentOutput = null
746751 ) {
747752 global $wgMemc, $wgEnableParserCache, $wgUser;
748753 # Must be the same revision as the current
@@ -825,7 +830,7 @@
826831
827832 /**
828833 * @param string $val
829 - * @return obj array
 834+ * @return Object (val,time) tuple
830835 * Get a memcache storage object
831836 */
832837 public static function makeMemcObj( $val ) {
@@ -836,12 +841,12 @@
837842 }
838843
839844 /**
840 - * @param mixed $data Memc data returned
 845+ * @param mixed $data makeMemcObj() tuple (false/Object)
841846 * @param Article $article
842847 * @return mixed
843848 * Return memc value if not expired
844849 */
845 - public static function getMemcValue( $data, $article ) {
 850+ public static function getMemcValue( $data, Article $article ) {
846851 if ( is_object( $data ) && $data->time >= $article->getTouched() ) {
847852 return $data->value;
848853 }
@@ -855,7 +860,7 @@
856861 * @return int
857862 * Get number of revs since the stable revision
858863 */
859 - public static function getRevCountSince( $article, $revId, $forUpdate = false ) {
 864+ public static function getRevCountSince( Article $article, $revId, $forUpdate = false ) {
860865 global $wgMemc, $wgParserCacheExpireTime;
861866 # Try the cache
862867 $count = null;
@@ -884,7 +889,7 @@
885890 * @param mixed $latest, the latest rev ID (optional)
886891 * Updates the tracking tables and pending edit count cache. Called on edit.
887892 */
888 - public static function updateStableVersion( $article, $rev, $latest = null ) {
 893+ public static function updateStableVersion( Article $article, Revision $rev, $latest = null ) {
889894 if ( !$article->getId() )
890895 return true; // no bogus entries
891896 # Get the latest revision ID if not set
@@ -939,7 +944,7 @@
940945 * @param mixed $latest, the latest rev ID (optional)
941946 * Updates the flaggedpage_pending table
942947 */
943 - public static function updatePendingList( $article, $latest = null ) {
 948+ public static function updatePendingList( Article $article, $latest = null ) {
944949 $data = array();
945950 $level = self::pristineVersions() ? FR_PRISTINE : FR_QUALITY;
946951 if ( !self::qualityVersions() )
@@ -1006,7 +1011,7 @@
10071012 /**
10081013 * Resets links for a page when changed (other than edits)
10091014 */
1010 - public static function articleLinksUpdate( $article ) {
 1015+ public static function articleLinksUpdate( Article $article ) {
10111016 global $wgUser, $wgParser;
10121017 # Update the links tables as the stable version may now be the default page...
10131018 $parserCache = ParserCache::singleton();
@@ -1027,7 +1032,7 @@
10281033 /**
10291034 * Resets links for a page when changed (other than edits)
10301035 */
1031 - public static function titleLinksUpdate( $title ) {
 1036+ public static function titleLinksUpdate( Title $title ) {
10321037 return self::articleLinksUpdate( new Article( $title ) );
10331038 }
10341039
@@ -1039,7 +1044,7 @@
10401045 * @param int $rev_id
10411046 * @return Array
10421047 */
1043 - public static function getRevisionTags( $title, $rev_id ) {
 1048+ public static function getRevisionTags( Title $title, $rev_id ) {
10441049 $dbr = wfGetDB( DB_SLAVE );
10451050 $tags = $dbr->selectField( 'flaggedrevs', 'fr_tags',
10461051 array( 'fr_rev_id' => $rev_id,
@@ -1074,7 +1079,7 @@
10751080 * @returns bool
10761081 * Useful for quickly pinging to see if a revision is flagged
10771082 */
1078 - public static function revIsFlagged( $title, $rev_id, $flags = 0 ) {
 1083+ public static function revIsFlagged( Title $title, $rev_id, $flags = 0 ) {
10791084 $quality = self::getRevQuality( $title->getArticleId(), $rev_id, $flags );
10801085 return ( $quality !== false );
10811086 }
@@ -1085,7 +1090,7 @@
10861091 * @returns mixed (integer/false)
10871092 * Will not return a revision if deleted
10881093 */
1089 - public static function getPrimeFlaggedRevId( $article ) {
 1094+ public static function getPrimeFlaggedRevId( Article $article ) {
10901095 $dbr = wfGetDB( DB_SLAVE );
10911096 # Get the highest quality revision (not necessarily this one).
10921097 $oldid = $dbr->selectField( array( 'flaggedrevs', 'revision' ),
@@ -1109,7 +1114,7 @@
11101115 * @param Revision $rev
11111116 * @returns bool DB write query used
11121117 */
1113 - public static function markRevisionPatrolled( $rev ) {
 1118+ public static function markRevisionPatrolled( Revision $rev ) {
11141119 $rcid = $rev->isUnpatrolled();
11151120 # Make sure it is now marked patrolled...
11161121 if ( $rcid ) {
@@ -1130,9 +1135,9 @@
11311136 * Get visibility settings/restrictions for a page
11321137 * @param Title $title, page title
11331138 * @param int $flags, FR_MASTER
1134 - * @returns Array (associative) (select,override,autoreview,expiry)
 1139+ * @returns array (associative) (select,override,autoreview,expiry)
11351140 */
1136 - public static function getPageVisibilitySettings( $title, $flags = 0 ) {
 1141+ public static function getPageVisibilitySettings( Title $title, $flags = 0 ) {
11371142 $db = ($flags & FR_MASTER) ?
11381143 wfGetDB( DB_MASTER ) : wfGetDB( DB_SLAVE );
11391144 $row = $db->selectRow( 'flaggedpage_config',
@@ -1266,7 +1271,7 @@
12671272 $srev = FlaggedRevision::newFromStable( $title, FR_MASTER, $config );
12681273 if ( $srev ) {
12691274 $article = new Article( $title );
1270 - self::updateStableVersion( $article, $srev, $title->getArticleID() );
 1275+ self::updateStableVersion( $article, $srev->getRevision(), $title->getArticleID() );
12711276 } else {
12721277 self::clearTrackingRows( $pageId ); // no stable version
12731278 }
@@ -1276,45 +1281,48 @@
12771282 # ################ Other utility functions #################
12781283
12791284 /**
1280 - * @param Array $flags
 1285+ * @param array $flags
12811286 * @return bool, is this revision at basic review condition?
12821287 */
1283 - public static function isSighted( $flags ) {
 1288+ public static function isSighted( array $flags ) {
12841289 return self::tagsAtLevel( $flags, self::$minSL );
12851290 }
12861291
12871292 /**
1288 - * @param Array $flags
 1293+ * @param array $flags
12891294 * @return bool, is this revision at quality review condition?
12901295 */
1291 - public static function isQuality( $flags ) {
 1296+ public static function isQuality( array $flags ) {
12921297 return self::tagsAtLevel( $flags, self::$minQL );
12931298 }
12941299
12951300 /**
1296 - * @param Array $flags
 1301+ * @param array $flags
12971302 * @return bool, is this revision at pristine review condition?
12981303 */
1299 - public static function isPristine( $flags ) {
 1304+ public static function isPristine( array $flags ) {
13001305 return self::tagsAtLevel( $flags, self::$minPL );
13011306 }
13021307
13031308 // Checks if $flags meets $reqFlagLevels
1304 - protected static function tagsAtLevel( $flags, $reqFlagLevels ) {
1305 - if ( empty( $flags ) ) return false;
 1309+ protected static function tagsAtLevel( array $flags, $reqFlagLevels ) {
 1310+ if ( empty( $flags ) ) {
 1311+ return false;
 1312+ }
13061313 foreach ( self::$dimensions as $f => $x ) {
1307 - if ( !isset( $flags[$f] ) || $reqFlagLevels[$f] > $flags[$f] )
 1314+ if ( !isset( $flags[$f] ) || $reqFlagLevels[$f] > $flags[$f] ) {
13081315 return false;
 1316+ }
13091317 }
13101318 return true;
13111319 }
13121320
13131321 /**
13141322 * Get the quality tier of review flags
1315 - * @param Array $flags
 1323+ * @param array $flags
13161324 * @return int, flagging tier (-1 for non-sighted)
13171325 */
1318 - public static function getLevelTier( $flags ) {
 1326+ public static function getLevelTier( array $flags ) {
13191327 if ( self::isPristine( $flags ) )
13201328 return FR_PRISTINE; // 2
13211329 elseif ( self::isQuality( $flags ) )
@@ -1350,7 +1358,7 @@
13511359 * @param Title, $title
13521360 * @return bool
13531361 */
1354 - public static function inReviewNamespace( $title ) {
 1362+ public static function inReviewNamespace( Title $title ) {
13551363 global $wgFlaggedRevsWhitelist;
13561364 $namespaces = self::getReviewNamespaces();
13571365 $ns = ( $title->getNamespace() == NS_MEDIA ) ?
@@ -1367,7 +1375,7 @@
13681376 * @param Title, $title
13691377 * @return bool
13701378 */
1371 - public static function inPatrolNamespace( $title ) {
 1379+ public static function inPatrolNamespace( Title $title ) {
13721380 $namespaces = self::getPatrolNamespaces();
13731381 $ns = ( $title->getNamespace() == NS_MEDIA ) ?
13741382 NS_FILE : $title->getNamespace(); // Treat NS_MEDIA as NS_FILE
@@ -1389,7 +1397,7 @@
13901398 * Get params for a user
13911399 * @param int $uid
13921400 * @param string $DBName, optional wiki name
1393 - * @returns Array $params
 1401+ * @returns array $params
13941402 */
13951403 public static function getUserParams( $uid, $DBName = false ) {
13961404 $dbw = wfGetDB( DB_MASTER, array(), $DBName );
@@ -1425,11 +1433,11 @@
14261434 /**
14271435 * Save params for a user
14281436 * @param int $uid
1429 - * @param Array $params
 1437+ * @param array $params
14301438 * @param string $DBName, optional wiki name
14311439 * @returns bool success
14321440 */
1433 - public static function saveUserParams( $uid, $params, $DBName = false ) {
 1441+ public static function saveUserParams( $uid, array $params, $DBName = false ) {
14341442 $flatParams = '';
14351443 foreach ( $params as $key => $value ) {
14361444 $flatParams .= "{$key}={$value}\n";
@@ -1459,7 +1467,7 @@
14601468 * If no appropriate tags can be found, then the review will abort.
14611469 */
14621470 public static function autoReviewEdit(
1463 - $article, $user, $text, $rev, $flags = null, $auto = true
 1471+ Article $article, User $user, $text, Revision $rev, array $flags = null, $auto = true
14641472 ) {
14651473 wfProfileIn( __METHOD__ );
14661474 $title = $article->getTitle();
@@ -1602,7 +1610,9 @@
16031611 * @param array $imageSHA1Keys (from ParserOutput/OutputPage->fr_ImageSHA1Keys)
16041612 * @returns array( templateParams, imageParams, fileVersion )
16051613 */
1606 - public static function getIncludeParams( $article, $templateIDs, $imageSHA1Keys ) {
 1614+ public static function getIncludeParams(
 1615+ Article $article, array $templateIDs, array $imageSHA1Keys
 1616+ ) {
16071617 $templateParams = $imageParams = $fileVersion = '';
16081618 # NS -> title -> rev ID mapping
16091619 foreach ( $templateIDs as $namespace => $t ) {
Index: trunk/extensions/FlaggedRevs/FlaggedRevision.php
@@ -217,7 +217,7 @@
218218 * @param bool $auto autopatrolled
219219 * @return bool success
220220 */
221 - public function insertOn( $tmpRows, $fileRows, $auto = false ) {
 221+ public function insertOn( array $tmpRows, array $fileRows, $auto = false ) {
222222 $textFlags = 'dynamic';
223223 if ( $auto ) $textFlags .= ',auto';
224224 $this->mFlags = explode( ',', $textFlags );
@@ -257,7 +257,7 @@
258258 }
259259
260260 /**
261 - * @returns Array basic select fields (not including text/text flags)
 261+ * @returns array basic select fields (not including text/text flags)
262262 */
263263 public static function selectFields() {
264264 return array(
@@ -346,7 +346,7 @@
347347 }
348348
349349 /**
350 - * @returns Array tag metadata
 350+ * @returns array tag metadata
351351 */
352352 public function getTags() {
353353 return $this->mTags;
@@ -385,22 +385,22 @@
386386
387387 /**
388388 * Set template versions array
389 - * @param Array template versions (ns -> dbKey -> rev id)
 389+ * @param array template versions (ns -> dbKey -> rev id)
390390 */
391 - public function setTemplateVersions( $templateVersions ) {
 391+ public function setTemplateVersions( array $templateVersions ) {
392392 $this->mTemplates = $templateVersions;
393393 }
394394
395395 /**
396396 * Set file versions array
397 - * @param Array file versions (dbKey -> sha1)
 397+ * @param array file versions (dbKey -> sha1)
398398 */
399 - public function setFileVersions( $fileVersions ) {
 399+ public function setFileVersions( array $fileVersions ) {
400400 $this->mFiles = $fileVersions;
401401 }
402402
403403 /**
404 - * @returns Array template versions (ns -> dbKey -> rev id)
 404+ * @returns array template versions (ns -> dbKey -> rev id)
405405 */
406406 public function getTemplateVersions() {
407407 if ( $this->mTemplates == null ) {
@@ -421,7 +421,7 @@
422422 }
423423
424424 /**
425 - * @returns Array file versions (dbKey -> sha1)
 425+ * @returns array file versions (dbKey -> sha1)
426426 */
427427 public function getFileVersions() {
428428 if ( $this->mFiles == null ) {
@@ -480,10 +480,10 @@
481481
482482 /**
483483 * Get flags for a revision
484 - * @param Array $tags
 484+ * @param array $tags
485485 * @return string
486486 */
487 - public static function flattenRevisionTags( $tags ) {
 487+ public static function flattenRevisionTags( array $tags ) {
488488 $flags = '';
489489 foreach ( $tags as $tag => $value ) {
490490 # Add only currently recognized ones

Follow-up revisions

RevisionCommit summaryAuthorDate
r65418MFT r64916-HEADaaron01:35, 22 April 2010

Status & tagging log