From 7678ee7c4b8ffa50a378d6b1ee5873d2e80bb246 Mon Sep 17 00:00:00 2001 From: Jack Phoenix Date: Sun, 21 Sep 2014 20:00:51 +0300 Subject: [PATCH] Ran stylize.php, manually fixed documentation, etc. Change-Id: I8e684d00bf5142eff70d45d64e4c29cfc380749d --- SpecialTopRatings.php | 4 +-- VoteClass.php | 78 +++++++++++++++++++++++------------------- VoteHooks.php | 57 +++++++++++++++--------------- Vote_AjaxFunctions.php | 8 ++--- 4 files changed, 78 insertions(+), 69 deletions(-) diff --git a/SpecialTopRatings.php b/SpecialTopRatings.php index 467c482..86e1850 100644 --- a/SpecialTopRatings.php +++ b/SpecialTopRatings.php @@ -24,7 +24,7 @@ class SpecialTopRatings extends IncludableSpecialPage { /** * Show the special page * - * @param $par Mixed: parameter passed to the special page or null + * @param mixed|null $par Parameter passed to the special page or null */ public function execute( $par ) { // Set the page title, robot policies, etc. @@ -164,7 +164,7 @@ class SpecialTopRatings extends IncludableSpecialPage { $data = $wgMemc->get( $key ); $voteAvg = 0; - if( $data ) { + if ( $data ) { wfDebug( "Loading vote avg for page {$pageId} from cache (TopRatings)\n" ); $voteAvg = $data; } else { diff --git a/VoteClass.php b/VoteClass.php index 35b8587..dd45593 100644 --- a/VoteClass.php +++ b/VoteClass.php @@ -14,7 +14,7 @@ class Vote { /** * Constructor * - * @param $pageID Integer: article ID number + * @param int $pageID Article ID number */ public function __construct( $pageID ) { global $wgUser; @@ -28,7 +28,7 @@ class Vote { * Counts all votes, fetching the data from memcached if available * or from the database if memcached isn't available * - * @return Integer: amount of votes + * @return int Amount of votes */ function count() { global $wgMemc; @@ -37,7 +37,7 @@ class Vote { $data = $wgMemc->get( $key ); // Try cache - if( $data ) { + if ( $data ) { wfDebug( "Loading vote count for page {$this->PageID} from cache\n" ); $vote_count = $data; } else { @@ -50,7 +50,7 @@ class Vote { __METHOD__ ); $row = $dbr->fetchObject( $res ); - if( $row ) { + if ( $row ) { $vote_count = $row->votecount; } $wgMemc->set( $key, $vote_count ); @@ -61,7 +61,8 @@ class Vote { /** * Gets the average score of all votes - * @return Integer: formatted average number of votes (something like 3.50) + * + * @return int Formatted average number of votes (something like 3.50) */ function getAverageVote() { global $wgMemc; @@ -69,7 +70,7 @@ class Vote { $data = $wgMemc->get( $key ); $voteAvg = 0; - if( $data ) { + if ( $data ) { wfDebug( "Loading vote avg for page {$this->PageID} from cache\n" ); $voteAvg = $data; } else { @@ -81,7 +82,7 @@ class Vote { __METHOD__ ); $row = $dbr->fetchObject( $res ); - if( $row ) { + if ( $row ) { $voteAvg = $row->voteavg; } $wgMemc->set( $key, $voteAvg ); @@ -102,7 +103,7 @@ class Vote { // Purge squid $pageTitle = Title::newFromID( $this->PageID ); - if( is_object( $pageTitle ) ) { + if ( is_object( $pageTitle ) ) { $pageTitle->invalidateCache(); $pageTitle->purgeSquid(); @@ -134,7 +135,7 @@ class Vote { $this->clearCache(); // Update social statistics if SocialProfile extension is enabled - if( class_exists( 'UserStatsTrack' ) ) { + if ( class_exists( 'UserStatsTrack' ) ) { $stats = new UserStatsTrack( $this->Userid, $this->Username ); $stats->decStatField( 'vote' ); } @@ -142,7 +143,8 @@ class Vote { /** * Inserts a new vote into the Vote database table - * @param $voteValue + * + * @param int $voteValue */ function insert( $voteValue ) { global $wgRequest; @@ -150,7 +152,7 @@ class Vote { wfSuppressWarnings(); // E_STRICT whining $voteDate = date( 'Y-m-d H:i:s' ); wfRestoreWarnings(); - if( $this->UserAlreadyVoted() == false ) { + if ( $this->UserAlreadyVoted() == false ) { $dbw->begin(); $dbw->insert( 'Vote', @@ -169,7 +171,7 @@ class Vote { $this->clearCache(); // Update social statistics if SocialProfile extension is enabled - if( class_exists( 'UserStatsTrack' ) ) { + if ( class_exists( 'UserStatsTrack' ) ) { $stats = new UserStatsTrack( $this->Userid, $this->Username ); $stats->incStatField( 'vote' ); } @@ -179,8 +181,8 @@ class Vote { /** * Checks if a user has already voted * - * @return Boolean|Integer: false if s/he hasn't, otherwise returns the - * value of 'vote_value' column from Vote DB table + * @return bool|int False if s/he hasn't, otherwise returns the + * value of 'vote_value' column from Vote DB table */ function UserAlreadyVoted() { $dbr = wfGetDB( DB_SLAVE ); @@ -193,7 +195,7 @@ class Vote { ), __METHOD__ ); - if( $s === false ) { + if ( $s === false ) { return false; } else { return $s->vote_value; @@ -202,7 +204,8 @@ class Vote { /** * Displays the green voting box - * @return Mixed: HTML output + * + * @return string HTML output */ function display() { global $wgUser; @@ -210,7 +213,7 @@ class Vote { $voted = $this->UserAlreadyVoted(); $make_vote_box_clickable = ''; - if( $voted == false ) { + if ( $voted == false ) { $make_vote_box_clickable = ' vote-clickable'; } @@ -228,8 +231,8 @@ class Vote { htmlspecialchars( $login->getFullURL() ) . '" rel="nofollow">' . wfMessage( 'voteny-link' )->plain() . ''; } else { - if( !wfReadOnly() ) { - if( $voted == false ) { + if ( !wfReadOnly() ) { + if ( $voted == false ) { $output .= '' . wfMessage( 'voteny-link' )->plain() . ''; } else { @@ -254,15 +257,15 @@ class VoteStars extends Vote { /** * Displays voting stars * - * @param $voted Boolean: has the user already voted? False by default - * @return Mixed: HTML output + * @param bool $voted Has the user already voted? False by default + * @return string HTML output */ function display( $voted = false ) { global $wgUser; $overall_rating = $this->getAverageVote(); - if( $voted ) { + if ( $voted ) { $display_stars_rating = $voted; } else { $display_stars_rating = $this->getAverageVote(); @@ -279,12 +282,12 @@ class VoteStars extends Vote { $output .= '
'; $output .= $this->displayStars( $id, $display_stars_rating, $voted ); $count = $this->count(); - if( isset( $count ) ) { + if ( isset( $count ) ) { $output .= ' (' . wfMessage( 'voteny-votes', $count )->parse() . ')'; } $already_voted = $this->UserAlreadyVoted(); - if( $already_voted && $wgUser->isLoggedIn() ) { + if ( $already_voted && $wgUser->isLoggedIn() ) { $output .= '
' . wfMessage( 'voteny-gave-this', $already_voted )->parse() . "
@@ -302,24 +305,25 @@ class VoteStars extends Vote { /** * Displays the actual star images, depending on the state of the user's mouse - * @param $id Integer: ID of the rating (div) element - * @param $rating Integer: average rating - * @param $voted Integer - * @return Mixed: generated tag + * + * @param int $id ID of the rating (div) element + * @param int $rating Average rating + * @param int $voted + * @return string Generated tag */ function displayStars( $id, $rating, $voted ) { global $wgExtensionAssetsPath; - if( !$rating ) { + if ( !$rating ) { $rating = 0; } - if( !$voted ) { + if ( !$voted ) { $voted = 0; } $output = ''; - for( $x = 1; $x <= $this->maxRating; $x++ ) { - if( !$id ) { + for ( $x = 1; $x <= $this->maxRating; $x++ ) { + if ( !$id ) { $action = 3; } else { $action = 5; @@ -328,18 +332,18 @@ class VoteStars extends Vote { " data-vote-id=\"{$id}\" data-vote-action=\"{$action}\" data-vote-rating=\"{$rating}\"" . " data-vote-voted=\"{$voted}\" id=\"rating_{$id}_{$x}\"" . " src=\"{$wgExtensionAssetsPath}/VoteNY/images/star_"; - switch( true ) { + switch ( true ) { case $rating >= $x: - if( $voted ) { + if ( $voted ) { $output .= 'voted'; } else { $output .= 'on'; } break; - case( $rating > 0 && $rating < $x && $rating > ( $x - 1 ) ): + case ( $rating > 0 && $rating < $x && $rating > ( $x - 1 ) ): $output .= 'half'; break; - case( $rating < $x ): + case ( $rating < $x ): $output .= 'off'; break; } @@ -353,6 +357,8 @@ class VoteStars extends Vote { /** * Displays the average score for the current page * and the total amount of votes. + * + * @return string */ function displayScore() { $count = $this->count(); diff --git a/VoteHooks.php b/VoteHooks.php index 2d7c35e..3c47be1 100644 --- a/VoteHooks.php +++ b/VoteHooks.php @@ -10,8 +10,8 @@ class VoteHooks { /** * Set up the parser hook. * - * @param $parser Parser: instance of Parser - * @return Boolean: true + * @param Parser $parser + * @return bool */ public static function registerParserHook( &$parser ) { $parser->setHook( 'vote', array( 'VoteHooks', 'renderVote' ) ); @@ -21,10 +21,10 @@ class VoteHooks { /** * Callback function for registerParserHook. * - * @param $input String: user-supplied input, unused - * @param $args Array: user-supplied arguments, unused - * @param $parser Parser: instance of Parser, unused - * @return String: HTML + * @param string $input User-supplied input, unused + * @param array $args User-supplied arguments + * @param Parser $parser Instance of Parser, unused + * @return string HTML */ public static function renderVote( $input, $args, $parser ) { global $wgOut; @@ -45,16 +45,15 @@ class VoteHooks { $type = 0; // Determine what kind of a voting gadget the user wants: a box or pretty stars? - if( preg_match( "/^\s*type\s*=\s*(.*)/mi", $input, $matches ) ) { + if ( preg_match( "/^\s*type\s*=\s*(.*)/mi", $input, $matches ) ) { $type = htmlspecialchars( $matches[1] ); - } elseif( !empty( $args['type'] ) ) { + } elseif ( !empty( $args['type'] ) ) { $type = intval( $args['type'] ); } $output = null; $title = $wgOut->getTitle(); - if( $title ) { - + if ( $title ) { $articleID = $title->getArticleID(); switch( $type ) { case 0: @@ -78,8 +77,8 @@ class VoteHooks { /** * For the Renameuser extension. * - * @param $renameUserSQL - * @return Boolean: true + * @param RenameuserSQL $renameUserSQL + * @return bool */ public static function onUserRename( $renameUserSQL ) { $renameUserSQL->tables['Vote'] = array( 'username', 'vote_user_id' ); @@ -90,11 +89,11 @@ class VoteHooks { * Assign a value to {{NUMBEROFVOTES}}. First we try memcached and if that * fails, we fetch it directly from the database and cache it for 24 hours. * - * @param $parser Parser + * @param Parser $parser * @param $cache - * @param $magicWordId String: magic word ID - * @param $ret Integer: return value (number of votes) - * @return Boolean: true + * @param string $magicWordId Magic word ID + * @param int $ret Return value (number of votes) + * @return bool */ public static function assignValueToMagicWord( &$parser, &$cache, &$magicWordId, &$ret ) { global $wgMemc; @@ -135,11 +134,13 @@ class VoteHooks { /** * Main function to get the number of votes for a specific page - * @param Title $title: page to get votes for - * @return integer: number of votes for the given page + * + * @param Title $title Page to get votes for + * @return int Number of votes for the given page */ public static function getNumberOfVotesPage( Title $title ) { global $wgMemc; + $id = $title->getArticleID(); $key = wfMemcKey( 'vote', 'magic-word-page', $id ); @@ -165,9 +166,10 @@ class VoteHooks { /** * Hook for parser function {{NUMBEROFVOTESPAGE:}} + * * @param Parser $parser - * @param string $pagename - * @return integer + * @param string $pagename Page name + * @return int Amount of votes for the given page */ static function getNumberOfVotesPageParser( $parser, $pagename ) { $title = Title::newFromText( $pagename ); @@ -182,8 +184,8 @@ class VoteHooks { /** * Register the magic word ID for {{NUMBEROFVOTES}} and {{NUMBEROFVOTESPAGE}} * - * @param $variableIds Array: array of pre-existing variable IDs - * @return Boolean: true + * @param array $variableIds Array of pre-existing variable IDs + * @return bool */ public static function registerVariableId( &$variableIds ) { $variableIds[] = 'NUMBEROFVOTES'; @@ -193,8 +195,9 @@ class VoteHooks { /** * Hook to setup parser function {{NUMBEROFVOTESPAGE:}} + * * @param Parser $parser - * @return boolean + * @return bool */ static function setupNumberOfVotesPageParser( &$parser ) { $parser->setFunctionHook( 'NUMBEROFVOTESPAGE', 'VoteHooks::getNumberOfVotesPageParser', SFH_NO_HASH ); @@ -205,16 +208,16 @@ class VoteHooks { * Creates the necessary database table when the user runs * maintenance/update.php. * - * @param $updater DatabaseUpdater - * @return Boolean: true + * @param DatabaseUpdater $updater + * @return bool */ public static function addTable( $updater ) { $dbt = $updater->getDB()->getType(); - $file = dirname( __FILE__ ) . "/vote.$dbt"; + $file = __DIR__ . "/vote.$dbt"; if ( file_exists( $file ) ) { $updater->addExtensionUpdate( array( 'addTable', 'Vote', $file, true ) ); } else { - throw new MWException("VoteNY does not support $dbt."); + throw new MWException( "VoteNY does not support $dbt." ); } return true; } diff --git a/Vote_AjaxFunctions.php b/Vote_AjaxFunctions.php index 311f6f5..f838b18 100644 --- a/Vote_AjaxFunctions.php +++ b/Vote_AjaxFunctions.php @@ -11,7 +11,7 @@ function wfVoteClick( $voteValue, $pageId ) { return ''; } - if( is_numeric( $pageId ) && ( is_numeric( $voteValue ) ) ) { + if ( is_numeric( $pageId ) && ( is_numeric( $voteValue ) ) ) { $vote = new Vote( $pageId ); $vote->insert( $voteValue ); @@ -29,7 +29,7 @@ function wfVoteDelete( $pageId ) { return ''; } - if( is_numeric( $pageId ) ) { + if ( is_numeric( $pageId ) ) { $vote = new Vote( $pageId ); $vote->delete(); @@ -48,7 +48,7 @@ function wfVoteStars( $voteValue, $pageId ) { } $vote = new VoteStars( $pageId ); - if( $vote->UserAlreadyVoted() ) { + if ( $vote->UserAlreadyVoted() ) { $vote->delete(); } $vote->insert( $voteValue ); @@ -65,7 +65,7 @@ function wfVoteStarsMulti( $voteValue, $pageId ) { } $vote = new VoteStars( $pageId ); - if( $vote->UserAlreadyVoted() ) { + if ( $vote->UserAlreadyVoted() ) { $vote->delete(); } $vote->insert( $voteValue );