Ran stylize.php, manually fixed documentation, etc.

Change-Id: I8e684d00bf5142eff70d45d64e4c29cfc380749d
This commit is contained in:
Jack Phoenix 2014-09-21 20:00:51 +03:00
parent 89abe6bffb
commit 7678ee7c4b
4 changed files with 78 additions and 69 deletions

View file

@ -24,7 +24,7 @@ class SpecialTopRatings extends IncludableSpecialPage {
/** /**
* Show the special page * 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 ) { public function execute( $par ) {
// Set the page title, robot policies, etc. // Set the page title, robot policies, etc.
@ -164,7 +164,7 @@ class SpecialTopRatings extends IncludableSpecialPage {
$data = $wgMemc->get( $key ); $data = $wgMemc->get( $key );
$voteAvg = 0; $voteAvg = 0;
if( $data ) { if ( $data ) {
wfDebug( "Loading vote avg for page {$pageId} from cache (TopRatings)\n" ); wfDebug( "Loading vote avg for page {$pageId} from cache (TopRatings)\n" );
$voteAvg = $data; $voteAvg = $data;
} else { } else {

View file

@ -14,7 +14,7 @@ class Vote {
/** /**
* Constructor * Constructor
* *
* @param $pageID Integer: article ID number * @param int $pageID Article ID number
*/ */
public function __construct( $pageID ) { public function __construct( $pageID ) {
global $wgUser; global $wgUser;
@ -28,7 +28,7 @@ class Vote {
* Counts all votes, fetching the data from memcached if available * Counts all votes, fetching the data from memcached if available
* or from the database if memcached isn't available * or from the database if memcached isn't available
* *
* @return Integer: amount of votes * @return int Amount of votes
*/ */
function count() { function count() {
global $wgMemc; global $wgMemc;
@ -37,7 +37,7 @@ class Vote {
$data = $wgMemc->get( $key ); $data = $wgMemc->get( $key );
// Try cache // Try cache
if( $data ) { if ( $data ) {
wfDebug( "Loading vote count for page {$this->PageID} from cache\n" ); wfDebug( "Loading vote count for page {$this->PageID} from cache\n" );
$vote_count = $data; $vote_count = $data;
} else { } else {
@ -50,7 +50,7 @@ class Vote {
__METHOD__ __METHOD__
); );
$row = $dbr->fetchObject( $res ); $row = $dbr->fetchObject( $res );
if( $row ) { if ( $row ) {
$vote_count = $row->votecount; $vote_count = $row->votecount;
} }
$wgMemc->set( $key, $vote_count ); $wgMemc->set( $key, $vote_count );
@ -61,7 +61,8 @@ class Vote {
/** /**
* Gets the average score of all votes * 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() { function getAverageVote() {
global $wgMemc; global $wgMemc;
@ -69,7 +70,7 @@ class Vote {
$data = $wgMemc->get( $key ); $data = $wgMemc->get( $key );
$voteAvg = 0; $voteAvg = 0;
if( $data ) { if ( $data ) {
wfDebug( "Loading vote avg for page {$this->PageID} from cache\n" ); wfDebug( "Loading vote avg for page {$this->PageID} from cache\n" );
$voteAvg = $data; $voteAvg = $data;
} else { } else {
@ -81,7 +82,7 @@ class Vote {
__METHOD__ __METHOD__
); );
$row = $dbr->fetchObject( $res ); $row = $dbr->fetchObject( $res );
if( $row ) { if ( $row ) {
$voteAvg = $row->voteavg; $voteAvg = $row->voteavg;
} }
$wgMemc->set( $key, $voteAvg ); $wgMemc->set( $key, $voteAvg );
@ -102,7 +103,7 @@ class Vote {
// Purge squid // Purge squid
$pageTitle = Title::newFromID( $this->PageID ); $pageTitle = Title::newFromID( $this->PageID );
if( is_object( $pageTitle ) ) { if ( is_object( $pageTitle ) ) {
$pageTitle->invalidateCache(); $pageTitle->invalidateCache();
$pageTitle->purgeSquid(); $pageTitle->purgeSquid();
@ -134,7 +135,7 @@ class Vote {
$this->clearCache(); $this->clearCache();
// Update social statistics if SocialProfile extension is enabled // Update social statistics if SocialProfile extension is enabled
if( class_exists( 'UserStatsTrack' ) ) { if ( class_exists( 'UserStatsTrack' ) ) {
$stats = new UserStatsTrack( $this->Userid, $this->Username ); $stats = new UserStatsTrack( $this->Userid, $this->Username );
$stats->decStatField( 'vote' ); $stats->decStatField( 'vote' );
} }
@ -142,7 +143,8 @@ class Vote {
/** /**
* Inserts a new vote into the Vote database table * Inserts a new vote into the Vote database table
* @param $voteValue *
* @param int $voteValue
*/ */
function insert( $voteValue ) { function insert( $voteValue ) {
global $wgRequest; global $wgRequest;
@ -150,7 +152,7 @@ class Vote {
wfSuppressWarnings(); // E_STRICT whining wfSuppressWarnings(); // E_STRICT whining
$voteDate = date( 'Y-m-d H:i:s' ); $voteDate = date( 'Y-m-d H:i:s' );
wfRestoreWarnings(); wfRestoreWarnings();
if( $this->UserAlreadyVoted() == false ) { if ( $this->UserAlreadyVoted() == false ) {
$dbw->begin(); $dbw->begin();
$dbw->insert( $dbw->insert(
'Vote', 'Vote',
@ -169,7 +171,7 @@ class Vote {
$this->clearCache(); $this->clearCache();
// Update social statistics if SocialProfile extension is enabled // Update social statistics if SocialProfile extension is enabled
if( class_exists( 'UserStatsTrack' ) ) { if ( class_exists( 'UserStatsTrack' ) ) {
$stats = new UserStatsTrack( $this->Userid, $this->Username ); $stats = new UserStatsTrack( $this->Userid, $this->Username );
$stats->incStatField( 'vote' ); $stats->incStatField( 'vote' );
} }
@ -179,8 +181,8 @@ class Vote {
/** /**
* Checks if a user has already voted * Checks if a user has already voted
* *
* @return Boolean|Integer: false if s/he hasn't, otherwise returns the * @return bool|int False if s/he hasn't, otherwise returns the
* value of 'vote_value' column from Vote DB table * value of 'vote_value' column from Vote DB table
*/ */
function UserAlreadyVoted() { function UserAlreadyVoted() {
$dbr = wfGetDB( DB_SLAVE ); $dbr = wfGetDB( DB_SLAVE );
@ -193,7 +195,7 @@ class Vote {
), ),
__METHOD__ __METHOD__
); );
if( $s === false ) { if ( $s === false ) {
return false; return false;
} else { } else {
return $s->vote_value; return $s->vote_value;
@ -202,7 +204,8 @@ class Vote {
/** /**
* Displays the green voting box * Displays the green voting box
* @return Mixed: HTML output *
* @return string HTML output
*/ */
function display() { function display() {
global $wgUser; global $wgUser;
@ -210,7 +213,7 @@ class Vote {
$voted = $this->UserAlreadyVoted(); $voted = $this->UserAlreadyVoted();
$make_vote_box_clickable = ''; $make_vote_box_clickable = '';
if( $voted == false ) { if ( $voted == false ) {
$make_vote_box_clickable = ' vote-clickable'; $make_vote_box_clickable = ' vote-clickable';
} }
@ -228,8 +231,8 @@ class Vote {
htmlspecialchars( $login->getFullURL() ) . '" rel="nofollow">' . htmlspecialchars( $login->getFullURL() ) . '" rel="nofollow">' .
wfMessage( 'voteny-link' )->plain() . '</a>'; wfMessage( 'voteny-link' )->plain() . '</a>';
} else { } else {
if( !wfReadOnly() ) { if ( !wfReadOnly() ) {
if( $voted == false ) { if ( $voted == false ) {
$output .= '<a href="javascript:void(0);" class="vote-vote-link">' . $output .= '<a href="javascript:void(0);" class="vote-vote-link">' .
wfMessage( 'voteny-link' )->plain() . '</a>'; wfMessage( 'voteny-link' )->plain() . '</a>';
} else { } else {
@ -254,15 +257,15 @@ class VoteStars extends Vote {
/** /**
* Displays voting stars * Displays voting stars
* *
* @param $voted Boolean: has the user already voted? False by default * @param bool $voted Has the user already voted? False by default
* @return Mixed: HTML output * @return string HTML output
*/ */
function display( $voted = false ) { function display( $voted = false ) {
global $wgUser; global $wgUser;
$overall_rating = $this->getAverageVote(); $overall_rating = $this->getAverageVote();
if( $voted ) { if ( $voted ) {
$display_stars_rating = $voted; $display_stars_rating = $voted;
} else { } else {
$display_stars_rating = $this->getAverageVote(); $display_stars_rating = $this->getAverageVote();
@ -279,12 +282,12 @@ class VoteStars extends Vote {
$output .= '<div class="rating-section">'; $output .= '<div class="rating-section">';
$output .= $this->displayStars( $id, $display_stars_rating, $voted ); $output .= $this->displayStars( $id, $display_stars_rating, $voted );
$count = $this->count(); $count = $this->count();
if( isset( $count ) ) { if ( isset( $count ) ) {
$output .= ' <span class="rating-total">(' . $output .= ' <span class="rating-total">(' .
wfMessage( 'voteny-votes', $count )->parse() . ')</span>'; wfMessage( 'voteny-votes', $count )->parse() . ')</span>';
} }
$already_voted = $this->UserAlreadyVoted(); $already_voted = $this->UserAlreadyVoted();
if( $already_voted && $wgUser->isLoggedIn() ) { if ( $already_voted && $wgUser->isLoggedIn() ) {
$output .= '<div class="rating-voted">' . $output .= '<div class="rating-voted">' .
wfMessage( 'voteny-gave-this', $already_voted )->parse() . wfMessage( 'voteny-gave-this', $already_voted )->parse() .
" </div> " </div>
@ -302,24 +305,25 @@ class VoteStars extends Vote {
/** /**
* Displays the actual star images, depending on the state of the user's mouse * 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 int $id ID of the rating (div) element
* @param $voted Integer * @param int $rating Average rating
* @return Mixed: generated <img> tag * @param int $voted
* @return string Generated <img> tag
*/ */
function displayStars( $id, $rating, $voted ) { function displayStars( $id, $rating, $voted ) {
global $wgExtensionAssetsPath; global $wgExtensionAssetsPath;
if( !$rating ) { if ( !$rating ) {
$rating = 0; $rating = 0;
} }
if( !$voted ) { if ( !$voted ) {
$voted = 0; $voted = 0;
} }
$output = ''; $output = '';
for( $x = 1; $x <= $this->maxRating; $x++ ) { for ( $x = 1; $x <= $this->maxRating; $x++ ) {
if( !$id ) { if ( !$id ) {
$action = 3; $action = 3;
} else { } else {
$action = 5; $action = 5;
@ -328,18 +332,18 @@ class VoteStars extends Vote {
" data-vote-id=\"{$id}\" data-vote-action=\"{$action}\" data-vote-rating=\"{$rating}\"" . " data-vote-id=\"{$id}\" data-vote-action=\"{$action}\" data-vote-rating=\"{$rating}\"" .
" data-vote-voted=\"{$voted}\" id=\"rating_{$id}_{$x}\"" . " data-vote-voted=\"{$voted}\" id=\"rating_{$id}_{$x}\"" .
" src=\"{$wgExtensionAssetsPath}/VoteNY/images/star_"; " src=\"{$wgExtensionAssetsPath}/VoteNY/images/star_";
switch( true ) { switch ( true ) {
case $rating >= $x: case $rating >= $x:
if( $voted ) { if ( $voted ) {
$output .= 'voted'; $output .= 'voted';
} else { } else {
$output .= 'on'; $output .= 'on';
} }
break; break;
case( $rating > 0 && $rating < $x && $rating > ( $x - 1 ) ): case ( $rating > 0 && $rating < $x && $rating > ( $x - 1 ) ):
$output .= 'half'; $output .= 'half';
break; break;
case( $rating < $x ): case ( $rating < $x ):
$output .= 'off'; $output .= 'off';
break; break;
} }
@ -353,6 +357,8 @@ class VoteStars extends Vote {
/** /**
* Displays the average score for the current page * Displays the average score for the current page
* and the total amount of votes. * and the total amount of votes.
*
* @return string
*/ */
function displayScore() { function displayScore() {
$count = $this->count(); $count = $this->count();

View file

@ -10,8 +10,8 @@ class VoteHooks {
/** /**
* Set up the <vote> parser hook. * Set up the <vote> parser hook.
* *
* @param $parser Parser: instance of Parser * @param Parser $parser
* @return Boolean: true * @return bool
*/ */
public static function registerParserHook( &$parser ) { public static function registerParserHook( &$parser ) {
$parser->setHook( 'vote', array( 'VoteHooks', 'renderVote' ) ); $parser->setHook( 'vote', array( 'VoteHooks', 'renderVote' ) );
@ -21,10 +21,10 @@ class VoteHooks {
/** /**
* Callback function for registerParserHook. * Callback function for registerParserHook.
* *
* @param $input String: user-supplied input, unused * @param string $input User-supplied input, unused
* @param $args Array: user-supplied arguments, unused * @param array $args User-supplied arguments
* @param $parser Parser: instance of Parser, unused * @param Parser $parser Instance of Parser, unused
* @return String: HTML * @return string HTML
*/ */
public static function renderVote( $input, $args, $parser ) { public static function renderVote( $input, $args, $parser ) {
global $wgOut; global $wgOut;
@ -45,16 +45,15 @@ class VoteHooks {
$type = 0; $type = 0;
// Determine what kind of a voting gadget the user wants: a box or pretty stars? // 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] ); $type = htmlspecialchars( $matches[1] );
} elseif( !empty( $args['type'] ) ) { } elseif ( !empty( $args['type'] ) ) {
$type = intval( $args['type'] ); $type = intval( $args['type'] );
} }
$output = null; $output = null;
$title = $wgOut->getTitle(); $title = $wgOut->getTitle();
if( $title ) { if ( $title ) {
$articleID = $title->getArticleID(); $articleID = $title->getArticleID();
switch( $type ) { switch( $type ) {
case 0: case 0:
@ -78,8 +77,8 @@ class VoteHooks {
/** /**
* For the Renameuser extension. * For the Renameuser extension.
* *
* @param $renameUserSQL * @param RenameuserSQL $renameUserSQL
* @return Boolean: true * @return bool
*/ */
public static function onUserRename( $renameUserSQL ) { public static function onUserRename( $renameUserSQL ) {
$renameUserSQL->tables['Vote'] = array( 'username', 'vote_user_id' ); $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 * 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. * fails, we fetch it directly from the database and cache it for 24 hours.
* *
* @param $parser Parser * @param Parser $parser
* @param $cache * @param $cache
* @param $magicWordId String: magic word ID * @param string $magicWordId Magic word ID
* @param $ret Integer: return value (number of votes) * @param int $ret Return value (number of votes)
* @return Boolean: true * @return bool
*/ */
public static function assignValueToMagicWord( &$parser, &$cache, &$magicWordId, &$ret ) { public static function assignValueToMagicWord( &$parser, &$cache, &$magicWordId, &$ret ) {
global $wgMemc; global $wgMemc;
@ -135,11 +134,13 @@ class VoteHooks {
/** /**
* Main function to get the number of votes for a specific page * 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 ) { public static function getNumberOfVotesPage( Title $title ) {
global $wgMemc; global $wgMemc;
$id = $title->getArticleID(); $id = $title->getArticleID();
$key = wfMemcKey( 'vote', 'magic-word-page', $id ); $key = wfMemcKey( 'vote', 'magic-word-page', $id );
@ -165,9 +166,10 @@ class VoteHooks {
/** /**
* Hook for parser function {{NUMBEROFVOTESPAGE:<page>}} * Hook for parser function {{NUMBEROFVOTESPAGE:<page>}}
*
* @param Parser $parser * @param Parser $parser
* @param string $pagename * @param string $pagename Page name
* @return integer * @return int Amount of votes for the given page
*/ */
static function getNumberOfVotesPageParser( $parser, $pagename ) { static function getNumberOfVotesPageParser( $parser, $pagename ) {
$title = Title::newFromText( $pagename ); $title = Title::newFromText( $pagename );
@ -182,8 +184,8 @@ class VoteHooks {
/** /**
* Register the magic word ID for {{NUMBEROFVOTES}} and {{NUMBEROFVOTESPAGE}} * Register the magic word ID for {{NUMBEROFVOTES}} and {{NUMBEROFVOTESPAGE}}
* *
* @param $variableIds Array: array of pre-existing variable IDs * @param array $variableIds Array of pre-existing variable IDs
* @return Boolean: true * @return bool
*/ */
public static function registerVariableId( &$variableIds ) { public static function registerVariableId( &$variableIds ) {
$variableIds[] = 'NUMBEROFVOTES'; $variableIds[] = 'NUMBEROFVOTES';
@ -193,8 +195,9 @@ class VoteHooks {
/** /**
* Hook to setup parser function {{NUMBEROFVOTESPAGE:<page>}} * Hook to setup parser function {{NUMBEROFVOTESPAGE:<page>}}
*
* @param Parser $parser * @param Parser $parser
* @return boolean * @return bool
*/ */
static function setupNumberOfVotesPageParser( &$parser ) { static function setupNumberOfVotesPageParser( &$parser ) {
$parser->setFunctionHook( 'NUMBEROFVOTESPAGE', 'VoteHooks::getNumberOfVotesPageParser', SFH_NO_HASH ); $parser->setFunctionHook( 'NUMBEROFVOTESPAGE', 'VoteHooks::getNumberOfVotesPageParser', SFH_NO_HASH );
@ -205,16 +208,16 @@ class VoteHooks {
* Creates the necessary database table when the user runs * Creates the necessary database table when the user runs
* maintenance/update.php. * maintenance/update.php.
* *
* @param $updater DatabaseUpdater * @param DatabaseUpdater $updater
* @return Boolean: true * @return bool
*/ */
public static function addTable( $updater ) { public static function addTable( $updater ) {
$dbt = $updater->getDB()->getType(); $dbt = $updater->getDB()->getType();
$file = dirname( __FILE__ ) . "/vote.$dbt"; $file = __DIR__ . "/vote.$dbt";
if ( file_exists( $file ) ) { if ( file_exists( $file ) ) {
$updater->addExtensionUpdate( array( 'addTable', 'Vote', $file, true ) ); $updater->addExtensionUpdate( array( 'addTable', 'Vote', $file, true ) );
} else { } else {
throw new MWException("VoteNY does not support $dbt."); throw new MWException( "VoteNY does not support $dbt." );
} }
return true; return true;
} }

View file

@ -11,7 +11,7 @@ function wfVoteClick( $voteValue, $pageId ) {
return ''; return '';
} }
if( is_numeric( $pageId ) && ( is_numeric( $voteValue ) ) ) { if ( is_numeric( $pageId ) && ( is_numeric( $voteValue ) ) ) {
$vote = new Vote( $pageId ); $vote = new Vote( $pageId );
$vote->insert( $voteValue ); $vote->insert( $voteValue );
@ -29,7 +29,7 @@ function wfVoteDelete( $pageId ) {
return ''; return '';
} }
if( is_numeric( $pageId ) ) { if ( is_numeric( $pageId ) ) {
$vote = new Vote( $pageId ); $vote = new Vote( $pageId );
$vote->delete(); $vote->delete();
@ -48,7 +48,7 @@ function wfVoteStars( $voteValue, $pageId ) {
} }
$vote = new VoteStars( $pageId ); $vote = new VoteStars( $pageId );
if( $vote->UserAlreadyVoted() ) { if ( $vote->UserAlreadyVoted() ) {
$vote->delete(); $vote->delete();
} }
$vote->insert( $voteValue ); $vote->insert( $voteValue );
@ -65,7 +65,7 @@ function wfVoteStarsMulti( $voteValue, $pageId ) {
} }
$vote = new VoteStars( $pageId ); $vote = new VoteStars( $pageId );
if( $vote->UserAlreadyVoted() ) { if ( $vote->UserAlreadyVoted() ) {
$vote->delete(); $vote->delete();
} }
$vote->insert( $voteValue ); $vote->insert( $voteValue );