diff --git a/Hooks.php b/Hooks.php index 9fe5193..66453d8 100644 --- a/Hooks.php +++ b/Hooks.php @@ -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; } @@ -32,9 +28,9 @@ 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 @@ -42,8 +38,7 @@ static public function onPersonalUrls ( &$personal_urls /*, &$title ,$sk*/ ) { 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(); } @@ -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 # @@ -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() ) { @@ -103,7 +96,6 @@ 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 @@ -111,15 +103,15 @@ static public function onBeforePageDisplay ( $out /*, $skin*/ ) { // $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 ); // } @@ -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 # @@ -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 ) ) { @@ -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__ ); @@ -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; } @@ -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' ); @@ -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 ); @@ -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; } diff --git a/WatchAnalytics.i18n.magic.php b/WatchAnalytics.i18n.magic.php index 13d1d5c..cb922a7 100644 --- a/WatchAnalytics.i18n.magic.php +++ b/WatchAnalytics.i18n.magic.php @@ -1,13 +1,13 @@ 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__' ), -); \ No newline at end of file +$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__' ], +]; diff --git a/WatchAnalyticsUser.php b/WatchAnalyticsUser.php index 43eb1c8..f4d44d9 100644 --- a/WatchAnalyticsUser.php +++ b/WatchAnalyticsUser.php @@ -1,93 +1,40 @@ 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; diff --git a/includes/PageScore.php b/includes/PageScore.php index 63eca90..59503eb 100644 --- a/includes/PageScore.php +++ b/includes/PageScore.php @@ -1,37 +1,4 @@ mTitle = $title; - $this->cssColorClasses = array( + $this->cssColorClasses = [ 'excellent', // 'good', 'okay', // 'warning', 'danger', - ); + ]; } - static public function noPageScore () { + public static function noPageScore() { self::$displayPageScore = false; } - static public function pageScoreIsEnabled () { + public static function pageScoreIsEnabled() { return self::$displayPageScore; } @@ -76,60 +42,53 @@ static public function pageScoreIsEnabled () { * * @return string */ - public function getWatchQuality () { + public function getWatchQuality() { $pwq = new PageWatchesQuery(); return round( $pwq->getPageWatchQuality( $this->mTitle ), 1 ); } - public function getReviewStatus () { + public function getReviewStatus() { return $this->getNumReviews(); } - public function getNumReviews () { - - $dbr = wfGetDB( DB_SLAVE ); - + public function getNumReviews() { + $dbr = wfGetDB( DB_REPLICA ); $pageData = $dbr->selectRow( 'watchlist', 'COUNT(*) AS num_reviews', - array( + [ 'wl_notificationtimestamp IS NULL', 'wl_namespace' => $this->mTitle->getNamespace(), 'wl_title' => $this->mTitle->getDBkey() - ), + ], __METHOD__ ); return $pageData->num_reviews; - } - public function getScoreColor ( $score, $configVariable ) { - + public function getScoreColor( $score, $configVariable ) { $scoreArr = $GLOBALS[ $configVariable ]; $scoreArrCount = count( $scoreArr ); - for ( $i = 0; $i < $scoreArrCount; $i++ ) { // ) as $index => $upperBound + for ( $i = 0; $i < $scoreArrCount; $i++ ) { // ) as $index => $upperBound if ( $score > $scoreArr[ $i ] ) { return $this->cssColorClasses[ $i ]; } } return $this->cssColorClasses[ count( $scoreArr ) ]; - } - - public function getPageScoreTemplate () { - + public function getPageScoreTemplate() { // simple explanation of what PageScores are $pageScoresTooltip = wfMessage( 'watch-analytics-page-score-tooltip' )->text(); // @FIXME: Replace with special page showing page stats // $pageScoresHelpPageLink = Title::makeTitle( NS_HELP, "Page Scores" )->getInternalURL(); - $pageScoresHelpPageLink = SpecialPage::getTitleFor( 'PageStatistics' )->getInternalURL( array( + $pageScoresHelpPageLink = SpecialPage::getTitleFor( 'PageStatistics' )->getInternalURL( [ 'page' => $this->mTitle->getPrefixedText() - ) ); + ] ); // when MW 1.25 is released (very soon) replace this with a mustache template $template = @@ -139,23 +98,19 @@ public function getPageScoreTemplate () { . ""; return ""; - } - public function getBadge ( $label, $score, $color, $showLabel = false ) { - + public function getBadge( $label, $score, $color, $showLabel = false ) { // @todo FIXME: make the javascript apply a class to handle this, so this can just apply a class if ( $showLabel ) { $leftStyle = " style='display:inherit; border-radius: 4px 0 0 4px;'"; $rightStyle = " style='border-radius: 0 4px 4px 0;'"; - } - else { + } else { $leftStyle = ""; $rightStyle = ""; } - return - "
";
- $table .= "".wfMessage( 'clearpendingreviews-pages-cleared' ).""; + $table .= "" . wfMessage( 'clearpendingreviews-pages-cleared' ) . ""; $table .= "
| ";
$table .= "";
- $table .= "".wfMessage( 'clearpendingreviews-people-impacted' ).""; + $table .= "" . wfMessage( 'clearpendingreviews-people-impacted' ) . ""; $table .= "
\"$requestedPage\" is either not a page or is not watchable " ); - } - else { + } else { $wgOut->addHTML( "No page requested " ); } - } public function getPageHeader() { global $wgOut; - $wgOut->addModuleStyles( array( 'ext.watchanalytics.pagescores.styles' ) ); - + $wgOut->addModuleStyles( [ 'ext.watchanalytics.pagescores.styles' ] ); $pageScore = new PageScore( $this->mTitle ); // $out->addScript( $pageScore->getPageScoreTemplate() ); @@ -105,28 +93,25 @@ public function getPageHeader() { | The number of people who have reviewed this page. |
" . + // Newer self: Why not? + return "
" . wfMessage( 'watchanalytics-unreview-complete' )->parse() . "
' . wfMessage( 'watchanalytics-all-wiki-stats-recorded' )->text() . '
' ); } - $filters = array( + $filters = [ 'groupfilter' => $wgRequest->getVal( 'groupfilter', '' ), 'categoryfilter' => $wgRequest->getVal( 'categoryfilter', '' ), - ); + ]; foreach ( $filters as &$filter ) { if ( $filter === '' ) { $filter = false; @@ -50,50 +49,46 @@ public function execute ( $parser = null ) { $wgOut->addHTML( $this->getPageHeader() ); if ( $this->mMode == 'users' ) { $this->usersList( $filters ); - } - else if ( $this->mMode == 'wikihistory' ) { + } elseif ( $this->mMode == 'wikihistory' ) { $this->wikiHistory(); - } - else if ( $this->mMode == 'forcegraph' ) { + } elseif ( $this->mMode == 'forcegraph' ) { $this->forceGraph(); - } - else { + } else { $this->pagesList( $filters ); } } public function getPageHeader() { - // show the names of the four lists of pages, with the one // corresponding to the current "mode" not being linked // SELECT - // COUNT(*) AS watches, - // SUM( IF(watchlist.wl_notificationtimestamp IS NULL, 0, 1) ) AS num_pending, - // SUM( IF(watchlist.wl_notificationtimestamp IS NULL, 0, 1) ) * 100 / COUNT(*) AS percent_pending + // COUNT(*) AS watches, + // SUM( IF(watchlist.wl_notificationtimestamp IS NULL, 0, 1) ) AS num_pending, + // SUM( IF(watchlist.wl_notificationtimestamp IS NULL, 0, 1) ) * 100 / COUNT(*) AS percent_pending // FROM watchlist // INNER JOIN page ON page.page_namespace = watchlist.wl_namespace AND page.page_title = watchlist.wl_title; $dbr = wfGetDB( DB_SLAVE ); - $dbr = wfGetDB( DB_SLAVE ); + $dbr = wfGetDB( DB_REPLICA ); // $res = $dbr->select( - // array( - // 'w' => 'watchlist', - // 'p' => 'page', - // ), - // array( - // "COUNT(*) AS watches", - // "SUM( IF(watchlist.wl_notificationtimestamp IS NULL, 0, 1) ) AS num_pending", - // "SUM( IF(watchlist.wl_notificationtimestamp IS NULL, 0, 1) ) * 100 / COUNT(*) AS percent_pending", - // ), - // null, // conditions - // __METHOD__, - // array(), // options - // array( - // 'page' => array( - // 'INNER JOIN', 'p.page_namespace=w.wl_namespace AND p.page_title=w.wl_title' - // ) - // ) + // array( + // 'w' => 'watchlist', + // 'p' => 'page', + // ), + // array( + // "COUNT(*) AS watches", + // "SUM( IF(watchlist.wl_notificationtimestamp IS NULL, 0, 1) ) AS num_pending", + // "SUM( IF(watchlist.wl_notificationtimestamp IS NULL, 0, 1) ) * 100 / COUNT(*) AS percent_pending", + // ), + // null, // conditions + // __METHOD__, + // array(), // options + // array( + // 'page' => array( + // 'INNER JOIN', 'p.page_namespace=w.wl_namespace AND p.page_title=w.wl_title' + // ) + // ) // ); $res = $dbr->query( ' @@ -107,11 +102,11 @@ public function getPageHeader() { $allWikiData = $dbr->fetchRow( $res ); - list( $watches, $pending, $percent ) = array( + list( $watches, $pending, $percent ) = [ $allWikiData['num_watches'], $allWikiData['num_pending'], $allWikiData['percent_pending'] - ); + ]; $percent = round( $percent, 1 ); $stateOf = "The state of the Wiki: $watches watches of which $percent% ($pending) are pending"; @@ -124,12 +119,10 @@ public function getPageHeader() { $header = '' . wfMessage( 'watchanalytics-view' )->text() . ''; $header .= Xml::tags( 'ul', null, $navLinks ) . "\n"; - return $stateOf . Xml::tags( 'div', array( 'class' => 'special-watchanalytics-header' ), $header ); - + return $stateOf . Xml::tags( 'div', [ 'class' => 'special-watchanalytics-header' ], $header ); } public function createHeaderLink( $msg, $query_param ) { - $WatchAnalyticsTitle = SpecialPage::getTitleFor( $this->getName() ); if ( $this->mMode == $query_param ) { @@ -138,38 +131,37 @@ public function createHeaderLink( $msg, $query_param ) { wfMessage( $msg )->text() ); } else { - $show = ( $query_param == '' ) ? array() : array( 'show' => $query_param ); + $show = ( $query_param == '' ) ? [] : [ 'show' => $query_param ]; return Xml::element( 'a', - array( 'href' => $WatchAnalyticsTitle->getLocalURL( $show ) ), + [ 'href' => $WatchAnalyticsTitle->getLocalURL( $show ) ], wfMessage( $msg )->text() ); } - } - public function pagesList ( $filters ) { + public function pagesList( $filters ) { return $this->createTablePager( 'watchanalytics-special-pages-pagetitle', - new WatchAnalyticsPageTablePager( $this, array(), $filters ) + new WatchAnalyticsPageTablePager( $this, [], $filters ) ); } - public function usersList ( $filters ) { + public function usersList( $filters ) { return $this->createTablePager( 'watchanalytics-special-users-pagetitle', - new WatchAnalyticsUserTablePager( $this, array(), $filters ) + new WatchAnalyticsUserTablePager( $this, [], $filters ) ); } - public function wikiHistory () { + public function wikiHistory() { return $this->createTablePager( 'watchanalytics-special-wikihistory-pagetitle', - new WatchAnalyticsWikiTablePager( $this, array() ) + new WatchAnalyticsWikiTablePager( $this, [] ) ); } - public function createTablePager ( $titleMsg, WatchAnalyticsTablePager $tablePager ) { - global $wgOut, $wgRequest; + public function createTablePager( $titleMsg, WatchAnalyticsTablePager $tablePager ) { + global $wgOut; $wgOut->setPageTitle( wfMessage( $titleMsg )->text() ); @@ -181,71 +173,56 @@ public function createTablePager ( $titleMsg, WatchAnalyticsTablePager $tablePag $html .= $tablePager->getNavigationBar(); $html .= $body; $html .= $tablePager->getNavigationBar(); - } - else { + } else { $html .= '' . wfMsgHTML( 'listusers-noresult' ) . '
'; } $wgOut->addHTML( $html ); return true; } - public function forceGraph () { - + public function forceGraph() { global $wgOut; $wgOut->setPageTitle( 'Watch Analytics: User/Page Watch Relationships' ); - $dbr = wfGetDB( DB_SLAVE ); + $dbr = wfGetDB( DB_REPLICA ); // Load the module for the D3.js force directed graph $wgOut->addModules( 'ext.watchanalytics.forcegraph.scripts' ); // Load the styles for the D3.js force directed graph $wgOut->addModuleStyles( 'ext.watchanalytics.forcegraph.styles' ); - // SELECT - // watchlist.wl_title AS title, - // 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 - // WHERE - // wl_namespace = 0 - // AND user.user_name IN (\'Lwelsh\',\'Swray\',\'Balpert\',\'Ejmontal\',\'Cmavridi\', \'Sgeffert\', \'Smulhern\', \'Kgjohns1\', \'Bscheib\', \'Ssjohns5\') - // LIMIT 20000 - $res = $dbr->select( - array( + [ 'w' => 'watchlist', 'u' => 'user', 'p' => 'page', - ), - array( + ], + [ 'w.wl_title AS title', 'w.wl_notificationtimestamp as notification', 'u.user_name as user_name', 'u.user_real_name AS real_name', - ), + ], 'w.wl_namespace = 0 AND p.page_is_redirect = 0', __METHOD__, - array( + [ "LIMIT" => "100000", - ), - array( - 'u' => array( + ], + [ + 'u' => [ 'LEFT JOIN', 'u.user_id = w.wl_user' - ), - 'p' => array( + ], + 'p' => [ 'RIGHT JOIN', 'w.wl_title = p.page_title AND w.wl_namespace = p.page_namespace' - ), - ) + ], + ] ); - - $nodes = array(); - $pages = array(); - $users = array(); - $links = array(); + $nodes = []; + $pages = []; + $users = []; + $links = []; while ( $row = $res->fetchRow() ) { // if the page isn't in $pages, then it's also not in $nodes @@ -256,11 +233,11 @@ public function forceGraph () { $pages[ $row['title'] ] = $nextNode; // $nodes[ $nextNode ] = $row['title']; - $nodes[ $nextNode ] = array( + $nodes[ $nextNode ] = [ "name" => $row['title'], "label" => $row['title'], "group" => 1 - ); + ]; } // same for users...add to $users and $nodes accordingly @@ -270,44 +247,41 @@ public function forceGraph () { $users[ $row['user_name'] ] = $nextNode; $nodes[ $nextNode ] = $row['user_name']; - if ( $row['real_name'] !== NULL && trim( $row['real_name'] ) !== '' ) { + if ( $row['real_name'] !== null && trim( $row['real_name'] ) !== '' ) { $displayName = $row['real_name']; - } - else { + } else { $displayName = $row['user_name']; } - $nodes[ $nextNode ] = array( + $nodes[ $nextNode ] = [ "name" => $displayName, "label" => $displayName, "group" => 2, "weight" => 1 - ); + ]; - } - else { + } else { $userNodeIndex = $users[ $row['user_name'] ]; $nodes[ $userNodeIndex ]['weight']++; } - if ( $row['notification'] == NULL ) { + if ( $row['notification'] == null ) { $linkClass = "link"; - } - else { + } else { $linkClass = "unreviewed"; } // if ( $linkClass !== "unreviewed" ) { - $links[] = array( + $links[] = [ "source" => $users[ $row['user_name'] ], "target" => $pages[ $row['title'] ], "value" => 1, "linkclass" => $linkClass - ); + ]; // } } - $json = array( "nodes" => $nodes, "links" => $links ); + $json = [ "nodes" => $nodes, "links" => $links ]; $json = json_encode( $json ); // , JSON_PRETTY_PRINT ); $html = '$json"; // easy testing $html .= ""; $wgOut->addHTML( $html ); - } } -