Skip to content

Commit

Permalink
Use PHP CodeSniffer to auto-fix style issues (#89)
Browse files Browse the repository at this point in the history
* phpcbf auto-fixes round 1

* Manual fixes to phpcbf auto-fixes

* More auto-fixes

* Manual fix to get phpcbf to stop breaking

* Major reduction in phpcs errors

* WatchAnalyticsTablePager::reallyDoQuery() must match IndexPager::reallyDoQuery()

* Fix type hinting
  • Loading branch information
jamesmontalvo3 authored and krisfield committed Nov 28, 2018
1 parent 3ae1e8d commit a181f46
Show file tree
Hide file tree
Showing 26 changed files with 823 additions and 1,562 deletions.
90 changes: 40 additions & 50 deletions Hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,16 @@ class WatchAnalyticsHooks {
/**
* Handler for PersonalUrls hook. Replace the "watchlist" item on the user
* toolbar ('personal URLs') with a link to Special:PendingReviews.
*
* @see http://www.mediawiki.org/wiki/Manual:Hooks/PersonalUrls
*
* @param &$personal_urls Array of URLs to append to.
* @param &$title Title of page being visited.
*
* @return bool true in all cases
* @param array &$personal_urls Array of URLs to append to.
* @return bool
*/
static public function onPersonalUrls ( &$personal_urls /*, &$title ,$sk*/ ) {

public static function onPersonalUrls( array &$personal_urls ) {
global $wgUser, $wgOut;
$user = $wgUser;

if ( !$user->isAllowed('pendingreviewslink') ) {
if ( !$user->isAllowed( 'pendingreviewslink' ) ) {
return true;
}

Expand All @@ -32,18 +28,17 @@ static public function onPersonalUrls ( &$personal_urls /*, &$title ,$sk*/ ) {
$maxPendingDays = $watchStats['max_pending_days'];

// Determine CSS class of Watchlist/PendingReviews link
$personal_urls['watchlist']['class'] = array( 'mw-watchanalytics-watchlist-badge' );
$personal_urls['watchlist']['class'] = [ 'mw-watchanalytics-watchlist-badge' ];
if ( $numPending != 0 ) {
$personal_urls['watchlist']['class'] = array( 'mw-watchanalytics-watchlist-pending' );
$personal_urls['watchlist']['class'] = [ 'mw-watchanalytics-watchlist-pending' ];
}

// Determine text of Watchlist/PendingReviews link
global $egPendingReviewsEmphasizeDays;
if ( $maxPendingDays > $egPendingReviewsEmphasizeDays ) {
$personal_urls['watchlist']['class'][] = 'mw-watchanalytics-watchlist-pending-old';
$text = wfMessage( 'watchanalytics-personal-url-old' )->params( $numPending, $maxPendingDays )->text();
}
else {
} else {
// when $sk (third arg) available, replace wfMessage with $sk->msg()
$text = wfMessage( 'watchanalytics-personal-url' )->params( $numPending )->text();
}
Expand All @@ -70,11 +65,10 @@ static public function onPersonalUrls ( &$personal_urls /*, &$title ,$sk*/ ) {
*
* @return bool true in all cases
*/
static public function onBeforePageDisplay ( $out /*, $skin*/ ) {
public static function onBeforePageDisplay( $out /*, $skin*/ ) {
$user = $out->getUser();
$title = $out->getTitle();


#
# 1) Is user's oldest pending review is old enough to require emphasis
#
Expand All @@ -86,14 +80,13 @@ static public function onBeforePageDisplay ( $out /*, $skin*/ ) {

global $egPendingReviewsEmphasizeDays;
if ( $user->watchStats['max_pending_days'] > $egPendingReviewsEmphasizeDays ) {
$out->addModules( array( 'ext.watchanalytics.shakependingreviews' ) );
$out->addModules( [ 'ext.watchanalytics.shakependingreviews' ] );
}


#
# 2) Insert page scores
#
if ( in_array( $title->getNamespace() , $GLOBALS['egWatchAnalyticsPageScoreNamespaces'] )
if ( in_array( $title->getNamespace(), $GLOBALS['egWatchAnalyticsPageScoreNamespaces'] )
&& $user->isAllowed( 'viewpagescore' )
&& PageScore::pageScoreIsEnabled() ) {

Expand All @@ -103,23 +96,22 @@ static public function onBeforePageDisplay ( $out /*, $skin*/ ) {
$out->addModuleStyles( 'ext.watchanalytics.pagescores.styles' );
}


// REMOVED FOR MW 1.27
// #
// # 3) If user has reviewed page on this page load show "unreview" option
// #
// $reviewHandler = ReviewHandler::pageHasBeenReviewed();
// if ( $reviewHandler ) {

// // display "unreview" button
// $out->addScript( $reviewHandler->getTemplate() );
// $wgOut->addModules( [
// 'ext.watchanalytics.reviewhandler.scripts',
// 'ext.watchanalytics.reviewhandler.styles'
// ] );
// // display "unreview" button
// $out->addScript( $reviewHandler->getTemplate() );
// $wgOut->addModules( [
// 'ext.watchanalytics.reviewhandler.scripts',
// 'ext.watchanalytics.reviewhandler.styles'
// ] );

// // record change in user/page stats
// WatchStateRecorder::recordReview( $user, $title );
// // record change in user/page stats
// WatchStateRecorder::recordReview( $user, $title );

// }

Expand Down Expand Up @@ -149,9 +141,8 @@ static public function onBeforePageDisplay ( $out /*, $skin*/ ) {
*
* @return bool true in all cases
*/
static public function onTitleMoveComplete ( Title &$originalTitle, Title &$newTitle,
public static function onTitleMoveComplete( Title &$originalTitle, Title &$newTitle,
User &$user, $oldid, $newid, $reason = null ) {

#
# Record move in watch stats
#
Expand All @@ -172,19 +163,19 @@ static public function onTitleMoveComplete ( Title &$originalTitle, Title &$newT

$dbw = wfGetDB( DB_MASTER );
$results = $dbw->select( 'watchlist',
array( 'wl_user', 'wl_notificationtimestamp' ),
array( 'wl_namespace' => $oldNS, 'wl_title' => $oldDBkey ),
[ 'wl_user', 'wl_notificationtimestamp' ],
[ 'wl_namespace' => $oldNS, 'wl_title' => $oldDBkey ],
__METHOD__
);
# Construct array to replace into the watchlist
$values = array();
$values = [];
foreach ( $results as $oldRow ) {
$values[] = array(
$values[] = [
'wl_user' => $oldRow->wl_user,
'wl_namespace' => $newNS,
'wl_title' => $newDBkey,
'wl_notificationtimestamp' => $oldRow->wl_notificationtimestamp,
);
];
}

if ( empty( $values ) ) {
Expand All @@ -197,7 +188,7 @@ static public function onTitleMoveComplete ( Title &$originalTitle, Title &$newT
# some other DBMSes, mostly due to poor simulation by us
$dbw->replace(
'watchlist',
array( array( 'wl_user', 'wl_namespace', 'wl_title' ) ),
[ [ 'wl_user', 'wl_namespace', 'wl_title' ] ],
$values,
__METHOD__
);
Expand All @@ -208,13 +199,13 @@ static public function onTitleMoveComplete ( Title &$originalTitle, Title &$newT
/**
* Register magic-word variable ID to hide page score from select pages.
*
* @see FIXME (include link to hook documentation)
* @see FIXME (include link to hook documentation)
*
* @param Array $magicWordVariableIDs array of names of magic words
* @param Array &$magicWordVariableIDs array of names of magic words
*
* @return bool
*/
static public function addMagicWordVariableIDs( &$magicWordVariableIDs ) {
public static function addMagicWordVariableIDs( &$magicWordVariableIDs ) {
$magicWordVariableIDs[] = 'MAG_NOPAGESCORE';
return true;
}
Expand All @@ -223,14 +214,14 @@ static public function addMagicWordVariableIDs( &$magicWordVariableIDs ) {
* Set values in the page_props table based on the presence of the
* 'NOPAGESCORE' magic word in a page
*
* @see FIXME (include link to hook documentation)
* @see FIXME (include link to hook documentation)
*
* @param Parser $parser reference to MediaWiki parser.
* @param string $text FIXME html/wikitext? of output page before complete
* @param Parser &$parser reference to MediaWiki parser.
* @param string &$text FIXME html/wikitext? of output page before complete
*
* @return bool
*/
static public function handleMagicWords( &$parser, &$text ) {
public static function handleMagicWords( &$parser, &$text ) {
$magicWord = MagicWord::get( 'MAG_NOPAGESCORE' );
if ( $magicWord->matchAndRemove( $text ) ) {
// $parser->mOutput->setProperty( 'approvedrevs', 'y' );
Expand All @@ -251,8 +242,7 @@ static public function handleMagicWords( &$parser, &$text ) {
*
* @return bool
*/
static public function onPageViewUpdates ( WikiPage $wikiPage, User $user ) {

public static function onPageViewUpdates( WikiPage $wikiPage, User $user ) {
$title = $wikiPage->getTitle();
$reviewHandler = ReviewHandler::setup( $user, $title );

Expand Down Expand Up @@ -285,21 +275,21 @@ static public function onPageViewUpdates ( WikiPage $wikiPage, User $user ) {
*
* @see https://www.mediawiki.org/wiki/Manual:Hooks/PageContentSaveComplete
*
* @param WikiPage $article
* @param WikiPage $wikipage
*
* @return boolean
* @return bool
*/
static public function onPageContentSaveComplete ( $article ) {
WatchStateRecorder::recordPageChange( $article );
public static function onPageContentSaveComplete( WikiPage $wikipage ) {
WatchStateRecorder::recordPageChange( $wikipage );
return true;
}

public static function onLanguageGetMagic( &$magicWords, $langCode ) {
switch ( $langCode ) {
default:
$magicWords['underwatched_categories'] = array( 0, 'underwatched_categories' );
$magicWords['watchers_needed'] = array( 0, 'watchers_needed' );
$magicWords['MAG_NOPAGESCORE'] = array( 0, '__NOPAGESCORE__' );
$magicWords['underwatched_categories'] = [ 0, 'underwatched_categories' ];
$magicWords['watchers_needed'] = [ 0, 'watchers_needed' ];
$magicWords['MAG_NOPAGESCORE'] = [ 0, '__NOPAGESCORE__' ];
}
return true;
}
Expand Down
22 changes: 11 additions & 11 deletions WatchAnalytics.i18n.magic.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php

$magicWords['en'] = array(
'underwatched_categories' => array(
0, // zero means case-insensitive, 1 means case sensitive
'underwatched_categories'
),
'watchers_needed' => array(
0, // zero means case-insensitive, 1 means case sensitive
'watchers_needed'
),
'MAG_NOPAGESCORE' => array( 0, '__NOPAGESCORE__' ),
);
$magicWords['en'] = [
'underwatched_categories' => [
0, // zero means case-insensitive, 1 means case sensitive
'underwatched_categories'
],
'watchers_needed' => [
0, // zero means case-insensitive, 1 means case sensitive
'watchers_needed'
],
'MAG_NOPAGESCORE' => [ 0, '__NOPAGESCORE__' ],
];
71 changes: 9 additions & 62 deletions WatchAnalyticsUser.php
Original file line number Diff line number Diff line change
@@ -1,93 +1,40 @@
<?php
/**
* MediaWiki Extension: WatchAnalytics
* http://www.mediawiki.org/wiki/Extension:WatchAnalytics
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* This program is distributed WITHOUT ANY WARRANTY.
*/

/**
*
* @file
* @ingroup Extensions
* @author James Montalvo
* @licence MIT License
*/

# Alert the user that this is not a valid entry point to MediaWiki if they try to access the special pages file directly.
if ( !defined( 'MEDIAWIKI' ) ) {
echo <<<EOT
To install this extension, put the following line in LocalSettings.php:
require_once( "$IP/extensions/WatchAnalytics/WatchAnalytics.php" );
EOT;
exit( 1 );
}

class WatchAnalyticsUser {

protected $user;
protected $pendingWatches;

public function __construct ( User $user ) {
public function __construct( User $user ) {
$this->user = $user;
}


/*
SELECT watchlist.wl_title, user.user_name
FROM watchlist
LEFT JOIN user ON
user.user_id = watchlist.wl_user
WHERE
wl_notificationtimestamp IS NOT NULL
AND user.user_name = 'Cmavridi';
*/
// SELECT
// watchlist.wl_title AS title,
// watchlist.wl_namespace AS namespace,
// watchlist.wl_notificationtimestamp AS notification,
// user.user_name AS user_name,
// user.user_real_name AS real_name
// FROM watchlist
// LEFT JOIN user ON user.user_id = watchlist.wl_user
public function getPendingWatches () {

$dbr = wfGetDB( DB_SLAVE );
public function getPendingWatches() {
$dbr = wfGetDB( DB_REPLICA );

$res = $dbr->select(
array( 'w' => 'watchlist' ),
array(
[ 'w' => 'watchlist' ],
[
'w.wl_namespace AS namespace_id',
'w.wl_title AS title_text',
'w.wl_notificationtimestamp AS notification_timestamp',
),
],
'w.wl_notificationtimestamp IS NOT NULL AND w.wl_user=' . $this->user->getId(),
__METHOD__,
array(
[
// "DISTINCT",
// "GROUP BY" => "w.hit_year, w.hit_month, w.hit_day",
// "ORDER BY" => "w.hit_year DESC, w.hit_month DESC, w.hit_day DESC",
"LIMIT" => "100000",
),
],
null // array( 'u' => array( 'LEFT JOIN', 'u.user-id=w.wl_user' ) )
);
$this->pendingWatches = array();
$this->pendingWatches = [];
while ( $row = $dbr->fetchRow( $res ) ) {

// $title = Title::newFromText( $row['title_text'], $row['notification_timestamp'] );
$this->pendingWatches[] = $row;


}

return $this;
Expand Down
Loading

0 comments on commit a181f46

Please sign in to comment.