Lokal Profil has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/377921 )
Change subject: Include tools directory in php linting
......................................................................
Include tools directory in php linting
Includes the tools directory (with the exception of the browser
sub-directory) in the php linting.
Also fixes any violations of the linting rules.
Change-Id: I758dd5a83beea050c4ee9d1ea2f1547770b7cf6c
---
M phpcs.xml
M tools/export_as_text.php
M tools/id_checker.php
M tools/rankings.php
M tools/stress-test.php
M tools/wlm-latest.php
M tools/wlm/gallery-all.php
M tools/wlmlast.php
8 files changed, 397 insertions(+), 399 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/labs/tools/heritage
refs/changes/21/377921/1
diff --git a/phpcs.xml b/phpcs.xml
index 1c220f6..e23f03e 100644
--- a/phpcs.xml
+++ b/phpcs.xml
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<ruleset>
- <rule ref="vendor/mediawiki/mediawiki-codesniffer/MediaWiki">
+ <rule ref="vendor/mediawiki/mediawiki-codesniffer/MediaWiki">
<exclude
name="Generic.CodeAnalysis.ForLoopWithTestFunctionCall.NotAllowed"/>
<exclude name="Generic.Files.LineLength"/>
<exclude name="Generic.PHP.NoSilencedErrors.Discouraged"/>
@@ -11,14 +11,14 @@
<exclude name="PSR2.Classes.PropertyDeclaration.Underscore"/>
<exclude name="PSR2.Classes.PropertyDeclaration.VarUsed"/>
</rule>
- <file>.</file>
- <arg name="extensions" value="php,php5,inc"/>
- <arg name="encoding" value="utf8"/>
- <exclude-pattern>node_modules</exclude-pattern>
- <exclude-pattern>vendor</exclude-pattern>
- <exclude-pattern>api/tripplanner</exclude-pattern>
- <exclude-pattern>common</exclude-pattern>
- <exclude-pattern>map</exclude-pattern>
- <exclude-pattern>prox_search/cls</exclude-pattern>
- <exclude-pattern>tools</exclude-pattern>
+ <file>.</file>
+ <arg name="extensions" value="php,php5,inc"/>
+ <arg name="encoding" value="utf8"/>
+ <exclude-pattern>node_modules</exclude-pattern>
+ <exclude-pattern>vendor</exclude-pattern>
+ <exclude-pattern>api/tripplanner</exclude-pattern>
+ <exclude-pattern>common</exclude-pattern>
+ <exclude-pattern>map</exclude-pattern>
+ <exclude-pattern>prox_search/cls</exclude-pattern>
+ <exclude-pattern>tools/browser</exclude-pattern>
</ruleset>
diff --git a/tools/export_as_text.php b/tools/export_as_text.php
index 579bd10..3b75b0f 100644
--- a/tools/export_as_text.php
+++ b/tools/export_as_text.php
@@ -1,5 +1,5 @@
<?php
-if ( php_sapi_name() != 'cli' ) {
+if ( PHP_SAPI != 'cli' ) {
die( 'This is a command-line script' );
}
@@ -9,8 +9,8 @@
ini_set( 'memory_limit', '200M' );
$t0 = microtime( true );
-require_once( dirname( dirname( __FILE__ ) ) . '/api/includes/Defaults.php' );
-require_once( dirname( dirname( dirname( __FILE__ ) ) ) . '/database.inc' );
+require_once ( dirname( __DIR__ ) . '/api/includes/Defaults.php' );
+require_once ( dirname( dirname( __DIR__ ) ) . '/database.inc' );
// make the db connection, check for errors
$db = new mysqli( $dbServer, $dbUser, $dbPassword, $dbDatabase );
@@ -30,7 +30,7 @@
handleDbError( $query );
while ( $row = $res->fetch_assoc() ) {
$columns = 0;
- foreach( $row as $value ) {
+ foreach ( $row as $value ) {
if ( $columns++ ) {
echo "\t";
}
@@ -41,7 +41,6 @@
}
mysqli_close( $db );
-
/**
* Helper function for handling MySQL errors
diff --git a/tools/id_checker.php b/tools/id_checker.php
index 964ab11..07c27b4 100644
--- a/tools/id_checker.php
+++ b/tools/id_checker.php
@@ -6,7 +6,6 @@
require_once dirname( __DIR__ ) . '/api/common.php';
require_once ( '/api/includes/CommonFunctions.php' );
-
$db = Database::getDb();
print '<html>';
print '<head>
diff --git a/tools/rankings.php b/tools/rankings.php
index 85ad92a..73479e8 100644
--- a/tools/rankings.php
+++ b/tools/rankings.php
@@ -3,288 +3,288 @@
* By default from
http://commons.wikimedia.org/wiki/Category:Images_from_Wiki_Loves_Monuments_2011
* if country if given, one of the subcategories.
*/
-header("Cache-Control: no-cache, must-revalidate");
-header("Expires: Thu, 01 Jan 1970 00:00:00 GMT");
-header('Content-type: text/html;; charset=utf-8');
+header( "Cache-Control: no-cache, must-revalidate" );
+header( "Expires: Thu, 01 Jan 1970 00:00:00 GMT" );
+header( 'Content-type: text/html;; charset=utf-8' );
?><!DOCTYPE html>
<html><head>
- <title></title>
- <style>
- * {
- margin:0;
- padding:0;
- }
- #photos-wlm {
- margin: 0;
- padding: 0;
- }
+ <title></title>
+ <style>
+ * {
+ margin:0;
+ padding:0;
+ }
+ #photos-wlm {
+ margin: 0;
+ padding: 0;
+ }
- #photos-wlm li {
- list-style-type: none;
- }
+ #photos-wlm li {
+ list-style-type: none;
+ }
- #photos-wlm a {
- float: left;
- width: <?php echo $size; ?>px;
- height: <?php echo $size; ?>px;
- margin: 9px;
- background-repeat: no-repeat;
- background-position: center center;
- }
+ #photos-wlm a {
+ float: left;
+ width: <?php echo $size; ?>px;
+ height: <?php echo $size; ?>px;
+ margin: 9px;
+ background-repeat: no-repeat;
+ background-position: center center;
+ }
<?php
- if (isset($_GET['width'])) {
- echo 'table { width: '.$_GET['width']."; }\n\n";
- }
+ if ( isset( $_GET['width'] ) ) {
+ echo 'table { width: '.$_GET['width']."; }\n\n";
+ }
?>
- td {
- text-align: right;
- }
- td.lbl {
- text-align: left;
- }
- </style>
- <link media="all" type="text/css"
href="/~ntavares/patrimonio/api/jscss/style.css" rel="stylesheet">
- <script src="/~ntavares/patrimonio/api/jscss/custom.js"
type="text/javascript"></script>
+ td {
+ text-align: right;
+ }
+ td.lbl {
+ text-align: left;
+ }
+ </style>
+ <link media="all" type="text/css"
href="/~ntavares/patrimonio/api/jscss/style.css" rel="stylesheet">
+ <script src="/~ntavares/patrimonio/api/jscss/custom.js"
type="text/javascript"></script>
<body>
<?
$i18n = array(
- 'pt' => array(
- 'Participant' => 'Participante',
- 'Participating in' => 'Participa em',
- 'Submissions' => 'Fotografias',
- 'Accepted' => 'Validadas',
- 'Images' => 'Lista de imagens',
- 'Country' => 'País',
- 'Different Users' => 'Participantes distintos',
- 'User Ratio' => 'Rácio por utilizador',
- ),
+ 'pt' => array(
+ 'Participant' => 'Participante',
+ 'Participating in' => 'Participa em',
+ 'Submissions' => 'Fotografias',
+ 'Accepted' => 'Validadas',
+ 'Images' => 'Lista de imagens',
+ 'Country' => 'País',
+ 'Different Users' => 'Participantes distintos',
+ 'User Ratio' => 'Rácio por utilizador',
+ ),
);
function _T($lbl) {
- global $i18n, $lang;
- if (isset($i18n[$lang][$lbl])) {
- return $i18n[$lang][$lbl];
- }
- return $lbl;
+ global $i18n, $lang;
+ if (isset($i18n[$lang][$lbl])) {
+ return $i18n[$lang][$lbl];
+ }
+ return $lbl;
}
function getUserRankings($limit, $country, $showopts){
- //print "showopts: ".implode('|',$showopts)."\n";
- $ts_pw = posix_getpwuid(posix_getuid());
- $ts_mycnf = parse_ini_file($ts_pw['dir'] . "/.my.cnf");
-// $db = new mysqli('commonswiki-p.rrdb.toolserver.org',
- $db = new mysqli('sql-s2-rr.toolserver.org',
- $ts_mycnf['user'],
- $ts_mycnf['password'],
- 'commonswiki_p');
- $db->set_charset('utf-8');
- unset($ts_mycnf);
- unset($ts_pw);
+ //print "showopts: ".implode('|',$showopts)."\n";
+ $ts_pw = posix_getpwuid(posix_getuid());
+ $ts_mycnf = parse_ini_file($ts_pw['dir'] . "/.my.cnf");
+// $db = new mysqli('commonswiki-p.rrdb.toolserver.org',
+ $db = new mysqli('sql-s2-rr.toolserver.org',
+ $ts_mycnf['user'],
+ $ts_mycnf['password'],
+ 'commonswiki_p');
+ $db->set_charset('utf-8');
+ unset($ts_mycnf);
+ unset($ts_pw);
- $limit = intval($limit);
- if($country) {
- $category = 'Images_from_Wiki_Loves_Monuments_2011_in_' .
$db->real_escape_string($country);
- $categoryr = 'Reviewed_images_from_Wiki_Loves_Monuments_2011_in_' .
$db->real_escape_string($country);
- $sql = 'SELECT u.user_name
- , COUNT(1) AS total
- , SUM(IF(cl2.cl_to IS NULL, 0, 1)) AS reviewed
- , GROUP_CONCAT(DISTINCT p.page_title SEPARATOR "[,]") AS images
- , INSTR(GROUP_CONCAT(DISTINCT ug.ug_group), "bot") AS found_bot
- FROM categorylinks cl
- LEFT JOIN categorylinks cl2 ON cl2.cl_from = cl.cl_from
- AND cl2.cl_to = "'.$categoryr.'"
- JOIN page p ON cl.cl_from = p.page_id
- AND p.page_namespace = 6
- AND p.page_is_redirect = 0
- JOIN image i ON i.img_name = p.page_title
- JOIN user u ON u.user_id = i.img_user
- LEFT JOIN user_groups ug ON ug.ug_user = u.user_id
- WHERE cl.cl_to = "'.$category.'"
- GROUP BY u.user_name
- HAVING found_bot <= 0 OR found_bot IS NULL
- ORDER BY total DESC
- LIMIT '.$limit;
- } else {
- $category = 'Images_from_Wiki_Loves_Monuments_2011';
- $categoryr = 'Reviewed_images_from_Wiki_Loves_Monuments_2011';
+ $limit = intval($limit);
+ if($country) {
+ $category = 'Images_from_Wiki_Loves_Monuments_2011_in_' .
$db->real_escape_string($country);
+ $categoryr =
'Reviewed_images_from_Wiki_Loves_Monuments_2011_in_' .
$db->real_escape_string($country);
+ $sql = 'SELECT u.user_name
+ , COUNT(1) AS total
+ , SUM(IF(cl2.cl_to IS NULL, 0, 1)) AS reviewed
+ , GROUP_CONCAT(DISTINCT p.page_title SEPARATOR
"[,]") AS images
+ , INSTR(GROUP_CONCAT(DISTINCT ug.ug_group),
"bot") AS found_bot
+ FROM categorylinks cl
+ LEFT JOIN categorylinks cl2 ON cl2.cl_from = cl.cl_from
+ AND cl2.cl_to = "'.$categoryr.'"
+ JOIN page p ON cl.cl_from = p.page_id
+ AND p.page_namespace = 6
+ AND p.page_is_redirect = 0
+ JOIN image i ON i.img_name = p.page_title
+ JOIN user u ON u.user_id = i.img_user
+ LEFT JOIN user_groups ug ON ug.ug_user = u.user_id
+ WHERE cl.cl_to = "'.$category.'"
+ GROUP BY u.user_name
+ HAVING found_bot <= 0 OR found_bot IS NULL
+ ORDER BY total DESC
+ LIMIT '.$limit;
+ } else {
+ $category = 'Images_from_Wiki_Loves_Monuments_2011';
+ $categoryr = 'Reviewed_images_from_Wiki_Loves_Monuments_2011';
- // I don't want to go to recentchanges to get the initial upload
- // (Rotatebot will reupload a version of the image and be marked as
the user_text)
- // So I just exclude the bots from the queries
- $sql = 'SELECT u.user_name
- , COUNT(1) AS total
- , SUM(IF(cl2.cl_to IS NULL, 0, 1)) AS reviewed
- , GROUP_CONCAT(DISTINCT cl3.country SEPARATOR "[,]") AS
countries
- , count(DISTINCT cl3.country) AS n_countries
- , GROUP_CONCAT(DISTINCT p.page_title SEPARATOR "[,]") AS images
- , INSTR(GROUP_CONCAT(DISTINCT ug.ug_group), "bot") AS found_bot
- FROM categorylinks cl
- LEFT JOIN categorylinks cl2 ON cl2.cl_from = cl.cl_from
- AND cl2.cl_to = "Reviewed
images_from_Wiki_Loves_Monuments_2011"
- JOIN (SELECT cl.cl_from AS image_id, SUBSTR(cl3.cl_to, 42) AS
country
- FROM categorylinks cl
- JOIN categorylinks cl3 ON cl.cl_from = cl3.cl_from AND
cl3.cl_to LIKE "Images_from_Wiki_Loves_Monuments_2011_in_%"
- WHERE cl.cl_to = "Images_from_Wiki_Loves_Monuments_2011"
- GROUP BY cl.cl_from
- ) cl3 ON cl.cl_from = image_id
- JOIN page p ON cl.cl_from = p.page_id
- AND p.page_namespace = 6 /* image */
- AND p.page_is_redirect = 0
- JOIN image i ON i.img_name = p.page_title
- JOIN user u ON u.user_id = i.img_user
- LEFT JOIN user_groups ug ON ug.ug_user = u.user_id
- WHERE cl.cl_to = "Images_from_Wiki_Loves_Monuments_2011"
- GROUP BY u.user_name
- HAVING found_bot <= 0 OR found_bot IS NULL
- ORDER BY /* n_countries DESC, */ total DESC
- LIMIT '.$limit;
- }
+ // I don't want to go to recentchanges to get the initial
upload
+ // (Rotatebot will reupload a version of the image and be
marked as the user_text)
+ // So I just exclude the bots from the queries
+ $sql = 'SELECT u.user_name
+ , COUNT(1) AS total
+ , SUM(IF(cl2.cl_to IS NULL, 0, 1)) AS reviewed
+ , GROUP_CONCAT(DISTINCT cl3.country SEPARATOR
"[,]") AS countries
+ , count(DISTINCT cl3.country) AS n_countries
+ , GROUP_CONCAT(DISTINCT p.page_title SEPARATOR
"[,]") AS images
+ , INSTR(GROUP_CONCAT(DISTINCT ug.ug_group),
"bot") AS found_bot
+ FROM categorylinks cl
+ LEFT JOIN categorylinks cl2 ON cl2.cl_from = cl.cl_from
+ AND cl2.cl_to = "Reviewed
images_from_Wiki_Loves_Monuments_2011"
+ JOIN (SELECT cl.cl_from AS image_id, SUBSTR(cl3.cl_to,
42) AS country
+ FROM categorylinks cl
+ JOIN categorylinks cl3 ON cl.cl_from =
cl3.cl_from AND cl3.cl_to LIKE "Images_from_Wiki_Loves_Monuments_2011_in_%"
+ WHERE cl.cl_to =
"Images_from_Wiki_Loves_Monuments_2011"
+ GROUP BY cl.cl_from
+ ) cl3 ON cl.cl_from = image_id
+ JOIN page p ON cl.cl_from = p.page_id
+ AND p.page_namespace = 6 /* image */
+ AND p.page_is_redirect = 0
+ JOIN image i ON i.img_name = p.page_title
+ JOIN user u ON u.user_id = i.img_user
+ LEFT JOIN user_groups ug ON ug.ug_user = u.user_id
+ WHERE cl.cl_to = "Images_from_Wiki_Loves_Monuments_2011"
+ GROUP BY u.user_name
+ HAVING found_bot <= 0 OR found_bot IS NULL
+ ORDER BY /* n_countries DESC, */ total DESC
+ LIMIT '.$limit;
+ }
- //print "SQL: $sql\n";
+ //print "SQL: $sql\n";
- $result = $db->query($sql);
+ $result = $db->query($sql);
- echo '<table class="sortable">';
- echo
'<tr><th>'._T('Participant').'</th><th>'._T('Submissions').'</th><th>'._T('Accepted').'</th>';
- if ( !$country ) {
- echo '<th>'._T('Participating in').'</th>';
- }
- if ( in_array('images', $showopts) ) {
- echo '<th>'._T('Images').'</th>';
- }
- echo '</tr>';
- while ($row = $result->fetch_assoc()) {
- if ( in_array('links', $showopts) ) {
- $username = '<a target="_blank"
href="http://commons.wikimedia.org/wiki/Special:ListFiles/'.$row['user_name'].'">'.$row['user_name'].'</a>';
- } else {
- $username = $row['user_name'];
- }
- echo '<tr><td class="lbl">'.$username.'</td>';
- echo '<td>'.$row['total'].'</td><td>'.$row['reviewed'].'</td>';
- if ( !$country ) {
- $countries = explode('[,]', $row['countries']);
- $countries_a = array();
- for($i=0;$i<count($countries);$i++) {
- if ( in_array('links', $showopts) ) {
- $countries_a[] .= '<a target="_blank"
href="rankings.php?limit='.$limit.'&show='.implode('|',$showopts).'&country='.$countries[$i].'">'.$countries[$i].'</a>';
- } else {
- $countries_a[] .= $countries[$i];
- }
- }
- echo '<td>'.implode(',', $countries_a).'
('.$row['n_countries'].')</td>';
- }
- if ( in_array('images', $showopts) ) {
- $images = explode('[,]', $row['images']);
- // GROUP_CONCAT has default 1024 output limit.
- // We use it to determine "..."
- $endmarker = '';
- if ( strlen($row['images']) > 1023 ) {
- array_pop($images);
- $endmarker = '...';
- }
- $images_a = array();
- for($i=0;$i<count($images);$i++) {
- $images_a[] = '<a target="_blank"
href="http://commons.wikimedia.org/wiki/Image:'.$images[$i].'">['.($i+1).']</a>';
- }
- echo '<td><small>'.implode(', ',
$images_a).'</small>'.$endmarker.'</td>';
- }
- echo '</tr>';
- }
- echo '</table>';
+ echo '<table class="sortable">';
+ echo
'<tr><th>'._T('Participant').'</th><th>'._T('Submissions').'</th><th>'._T('Accepted').'</th>';
+ if ( !$country ) {
+ echo '<th>'._T('Participating in').'</th>';
+ }
+ if ( in_array('images', $showopts) ) {
+ echo '<th>'._T('Images').'</th>';
+ }
+ echo '</tr>';
+ while ($row = $result->fetch_assoc()) {
+ if ( in_array('links', $showopts) ) {
+ $username = '<a target="_blank"
href="http://commons.wikimedia.org/wiki/Special:ListFiles/'.$row['user_name'].'">'.$row['user_name'].'</a>';
+ } else {
+ $username = $row['user_name'];
+ }
+ echo '<tr><td class="lbl">'.$username.'</td>';
+ echo '<td>'.$row['total'].'</td><td>'.$row['reviewed'].'</td>';
+ if ( !$country ) {
+ $countries = explode('[,]', $row['countries']);
+ $countries_a = array();
+ for($i=0;$i<count($countries);$i++) {
+ if ( in_array('links', $showopts) ) {
+ $countries_a[] .= '<a target="_blank"
href="rankings.php?limit='.$limit.'&show='.implode('|',$showopts).'&country='.$countries[$i].'">'.$countries[$i].'</a>';
+ } else {
+ $countries_a[] .= $countries[$i];
+ }
+ }
+ echo '<td>'.implode(',', $countries_a).'
('.$row['n_countries'].')</td>';
+ }
+ if ( in_array('images', $showopts) ) {
+ $images = explode('[,]', $row['images']);
+ // GROUP_CONCAT has default 1024 output limit.
+ // We use it to determine "..."
+ $endmarker = '';
+ if ( strlen($row['images']) > 1023 ) {
+ array_pop($images);
+ $endmarker = '...';
+ }
+ $images_a = array();
+ for($i=0;$i<count($images);$i++) {
+ $images_a[] = '<a target="_blank"
href="http://commons.wikimedia.org/wiki/Image:'.$images[$i].'">['.($i+1).']</a>';
+ }
+ echo '<td><small>'.implode(', ',
$images_a).'</small>'.$endmarker.'</td>';
+ }
+ echo '</tr>';
+ }
+ echo '</table>';
}
function getCountryRankings($limit, $showopts) {
- //print "showopts: ".implode('|',$showopts)."\n";
- $ts_pw = posix_getpwuid(posix_getuid());
- $ts_mycnf = parse_ini_file($ts_pw['dir'] . "/.my.cnf");
- $db = new mysqli('commonswiki-p.rrdb.toolserver.org',
- $ts_mycnf['user'],
- $ts_mycnf['password'],
- 'commonswiki_p');
- $db->set_charset('utf-8');
- unset($ts_mycnf);
- unset($ts_pw);
+ //print "showopts: ".implode('|',$showopts)."\n";
+ $ts_pw = posix_getpwuid(posix_getuid());
+ $ts_mycnf = parse_ini_file($ts_pw['dir'] . "/.my.cnf");
+ $db = new mysqli('commonswiki-p.rrdb.toolserver.org',
+ $ts_mycnf['user'],
+ $ts_mycnf['password'],
+ 'commonswiki_p');
+ $db->set_charset('utf-8');
+ unset($ts_mycnf);
+ unset($ts_pw);
- $sql = 'SELECT cl3.country
- , COUNT(1) AS n_images
- , COUNT(DISTINCT u.user_name) AS n_users
- , COUNT(1)/COUNT(DISTINCT u.user_name) AS user_ratio
- FROM categorylinks cl
- JOIN (SELECT cl.cl_from AS image_id, SUBSTR(cl3.cl_to, 42) AS country
- FROM categorylinks cl
- JOIN categorylinks cl3 ON cl.cl_from = cl3.cl_from AND cl3.cl_to
LIKE "Images_from_Wiki_Loves_Monuments_2011_in_%"
- WHERE cl.cl_to = "Images_from_Wiki_Loves_Monuments_2011"
- GROUP BY cl.cl_from
- ) cl3 ON cl.cl_from = image_id
- JOIN page p ON cl.cl_from = p.page_id
- AND p.page_namespace = 6 /* image */
- AND p.page_is_redirect = 0
- JOIN image i ON i.img_name = p.page_title
- JOIN user u ON u.user_id = i.img_user
- WHERE cl.cl_to = "Images_from_Wiki_Loves_Monuments_2011"
- GROUP BY cl3.country
- ORDER BY n_images DESC
- LIMIT '.$limit;
+ $sql = 'SELECT cl3.country
+ , COUNT(1) AS n_images
+ , COUNT(DISTINCT u.user_name) AS n_users
+ , COUNT(1)/COUNT(DISTINCT u.user_name) AS user_ratio
+ FROM categorylinks cl
+ JOIN (SELECT cl.cl_from AS image_id, SUBSTR(cl3.cl_to, 42) AS
country
+ FROM categorylinks cl
+ JOIN categorylinks cl3 ON cl.cl_from = cl3.cl_from AND
cl3.cl_to LIKE "Images_from_Wiki_Loves_Monuments_2011_in_%"
+ WHERE cl.cl_to = "Images_from_Wiki_Loves_Monuments_2011"
+ GROUP BY cl.cl_from
+ ) cl3 ON cl.cl_from = image_id
+ JOIN page p ON cl.cl_from = p.page_id
+ AND p.page_namespace = 6 /* image */
+ AND p.page_is_redirect = 0
+ JOIN image i ON i.img_name = p.page_title
+ JOIN user u ON u.user_id = i.img_user
+ WHERE cl.cl_to = "Images_from_Wiki_Loves_Monuments_2011"
+ GROUP BY cl3.country
+ ORDER BY n_images DESC
+ LIMIT '.$limit;
- //print "SQL: $sql\n";
+ //print "SQL: $sql\n";
- $result = $db->query($sql);
+ $result = $db->query($sql);
- echo '<table class="sortable">';
- echo
'<tr><th>'._T('Country').'</th><th>'._T('Submissions').'</th><th>'._T('Different
Users').'</th><th>'._T('User Ratio').' (%)</th></tr>';
- while ($row = $result->fetch_assoc()) {
- if ( in_array('links', $showopts) ) {
- $country = '<a target="_blank"
href="rankings.php?limit='.$limit.'&show='.implode('|',$showopts).'&country='.$row['country'].'">'.$row['country'].'</a>';
- $images = '<a target="_blank"
href="http://commons.wikimedia.org/wiki/Category:Images from Wiki Loves
Monuments 2011 in '.$row['country'].'">'.$row['n_images'].'</a>';
- } else {
- $country = $row['country'];
- $images = $row['n_images'];
- }
- $users = $row['n_users'];
- $user_ratio = sprintf("%.2f", $row['user_ratio']); // .' %'; // this
breaks sorting :(
+ echo '<table class="sortable">';
+ echo
'<tr><th>'._T('Country').'</th><th>'._T('Submissions').'</th><th>'._T('Different
Users').'</th><th>'._T('User Ratio').' (%)</th></tr>';
+ while ($row = $result->fetch_assoc()) {
+ if ( in_array('links', $showopts) ) {
+ $country = '<a target="_blank"
href="rankings.php?limit='.$limit.'&show='.implode('|',$showopts).'&country='.$row['country'].'">'.$row['country'].'</a>';
+ $images = '<a target="_blank"
href="http://commons.wikimedia.org/wiki/Category:Images from Wiki Loves
Monuments 2011 in '.$row['country'].'">'.$row['n_images'].'</a>';
+ } else {
+ $country = $row['country'];
+ $images = $row['n_images'];
+ }
+ $users = $row['n_users'];
+ $user_ratio = sprintf("%.2f", $row['user_ratio']); // .' %'; //
this breaks sorting :(
- echo '<tr>';
- echo '<td class="lbl">'.$country.'</td>';
- echo '<td>'.$images.'</td>';
- echo '<td>'.$users.'</td>';
- echo '<td>'.$user_ratio.'</td>';
- echo '</tr>';
- }
- echo '</table>';
+ echo '<tr>';
+ echo '<td class="lbl">'.$country.'</td>';
+ echo '<td>'.$images.'</td>';
+ echo '<td>'.$users.'</td>';
+ echo '<td>'.$user_ratio.'</td>';
+ echo '</tr>';
+ }
+ echo '</table>';
}
$limit = 30;
if (isset($_GET['limit'])) {
- $limit = $_GET['limit'];
+ $limit = $_GET['limit'];
}
$lang = 'en';
if (isset($_GET['lang'])) {
- $lang = $_GET['lang'];
+ $lang = $_GET['lang'];
}
$show = ''; // images
if (isset($_GET['show'])) {
- $show = $_GET['show'];
+ $show = $_GET['show'];
}
$showopts = explode('|', $show);
$scope = 'user'; // images
if (isset($_GET['scope'])) {
- $scope = $_GET['scope'];
+ $scope = $_GET['scope'];
}
if ( $scope === 'user' ) {
- getUserRankings($limit, $_GET['country'], $showopts);
+ getUserRankings($limit, $_GET['country'], $showopts);
} else {
- getCountryRankings($limit, $showopts);
+ getCountryRankings($limit, $showopts);
}
?>
diff --git a/tools/stress-test.php b/tools/stress-test.php
index 6bc3e15..cbff9df 100644
--- a/tools/stress-test.php
+++ b/tools/stress-test.php
@@ -1,12 +1,12 @@
<?php
-if ( php_sapi_name() != 'cli' ) {
+if ( PHP_SAPI != 'cli' ) {
die( 'This is a command-line script.' );
}
ini_set( 'user_agent', 'WLM stress test by MaxSem' );
-$countries = array(
+$countries = [
'ad',
'at',
'be-bru',
@@ -33,21 +33,21 @@
'se',
'sk',
'us',
-);
+];
-$searchTerms = array(
+$searchTerms = [
'house',
'casa',
'city',
-);
+];
$site = 'http://toolserver.org/~erfgoed/api/';
$site = 'http://mobile-wlm.wmflabs.org/api/';
-//$site = 'http://localhost/wlm/api/';
+// $site = 'http://localhost/wlm/api/';
$site .= 'api.php?action=search&format=json';
echo "Started stress test, press Ctrl + Break to stop\n";
-$timings = array();
+$timings = [];
$averagingFactor = 10;
while ( true ) {
diff --git a/tools/wlm-latest.php b/tools/wlm-latest.php
index 7450820..ca0cfb9 100644
--- a/tools/wlm-latest.php
+++ b/tools/wlm-latest.php
@@ -1,72 +1,76 @@
-<!DOCTYPE html>
<?php
-$size=150;
-if (isset($_GET["size"])) {
- $size=(int)$_GET["size"];
+$size =150;
+if ( isset( $_GET["size"] ) ) {
+ $size =(int)$_GET["size"];
}
-$margin = intval(10*$size/150); // allow scaled margin
-?><html><head>
- <title></title>
- <style>
- * {
- margin:0;
- padding:0;
- }
- #photos-wlm {
- margin: 0;
- padding: 0;
- }
+$margin = intval( 10*$size/150 ); // allow scaled margin
+?><!DOCTYPE html>
+<html><head>
+ <title></title>
+ <style>
+ * {
+ margin:0;
+ padding:0;
+ }
+ #photos-wlm {
+ margin: 0;
+ padding: 0;
+ }
- #photos-wlm li {
- list-style-type: none;
- }
+ #photos-wlm li {
+ list-style-type: none;
+ }
- #photos-wlm a {
- float: left;
- width: <?php echo $size; ?>px;
- height: <?php echo $size; ?>px;
- margin: 9px;
- background-repeat: no-repeat;
- background-position: center center;
- }
- </style>
+ #photos-wlm a {
+ float: left;
+ width: <?php echo $size; ?>px;
+ height: <?php echo $size; ?>px;
+ margin: 9px;
+ background-repeat: no-repeat;
+ background-position: center center;
+ }
+ </style>
<body>
<div id="photos-wlm">
</div>
<script>
- var photosDiv = document.getElementById('photos-wlm');
- var photos;
+ var photosDiv = document.getElementById('photos-wlm');
+ var photos;
- function jscallback(data) {
- for (var i = 0, l = data.length; i < l; i++) {
- var photo = data[i];
+ function jscallback(data) {
+ for (var i = 0, l = data.length; i < l; i++) {
+ var photo = data[i];
- var li = document.createElement( 'li' );
- var a = document.createElement( 'a' );
- a.href = photo.url;
- a.target = '_blank';
- a.title = 'By: ' + photo.uploader;
- a.style.backgroundImage = 'url("' + photo.image + '")';
- li.appendChild(a);
+ var li = document.createElement( 'li' );
+ var a = document.createElement( 'a' );
+ a.href = photo.url;
+ a.target = '_blank';
+ a.title = 'By: ' + photo.uploader;
+ a.style.backgroundImage = 'url("' + photo.image + '")';
+ li.appendChild(a);
- photos.appendChild(li);
- }
- }
+ photos.appendChild(li);
+ }
+ }
- function loadPhotos() {
- var s = document.createElement('script');
- s.id = 'achterkamer';
- s.src =
'https://tools.wmflabs.org/heritage/tools/wlmlast.php?callback=jscallback';
- s.src = s.src + '<?php if (isset($_GET['country'])) { echo '&country='
. htmlspecialchars(urlencode($_GET['country'])); } if (isset($_GET['number']))
{ echo '&number=' . htmlspecialchars(urlencode($_GET['number'])); } echo
'&size=' . htmlspecialchars(urlencode($size)); ?>';
- document.getElementsByTagName("head")[0].appendChild(s);
- }
- if (photosDiv) {
- photos = document.createElement('ul');
- photosDiv.appendChild(photos);
- loadPhotos();
- }
+ function loadPhotos() {
+ var s = document.createElement('script');
+ s.id = 'achterkamer';
+ s.src =
'https://tools.wmflabs.org/heritage/tools/wlmlast.php?callback=jscallback';
+ s.src = s.src + '<?php if ( isset( $_GET['country'] ) ) { echo
'&country=' . htmlspecialchars( urlencode( $_GET['country'] ) );
+
+} if ( isset( $_GET['number'] ) ) { echo '&number=' . htmlspecialchars(
urlencode( $_GET['number'] ) );
+
+} echo '&size=' . htmlspecialchars( urlencode( $size ) ); ?>';
+ document.getElementsByTagName("head")[0].appendChild(s);
+ }
+ if (photosDiv) {
+ photos = document.createElement('ul');
+ photosDiv.appendChild(photos);
+ loadPhotos();
+ }
</script>
</body></html>
diff --git a/tools/wlm/gallery-all.php b/tools/wlm/gallery-all.php
index 9101b9f..3c6f141 100644
--- a/tools/wlm/gallery-all.php
+++ b/tools/wlm/gallery-all.php
@@ -4,19 +4,19 @@
*
* @author Platonides, Kentaur
*/
-
+
define( 'MEDIAWIKI', 1 );
-require_once dirname( dirname( dirname( __FILE__ ) ) ) . "/common/lib.php";
-require_once dirname( dirname( dirname( __FILE__ ) ) ) . "/common/skin.php";
+require_once dirname( dirname( __DIR__ ) ) . "/common/lib.php";
+require_once dirname( dirname( __DIR__ ) ) . "/common/skin.php";
$wgServer = 'http://commons.wikimedia.org';
$wgArticlePath = '/wiki/$1';
$wgUseImageResize = $wgUseImageMagick = true;
-$wgLocalFileRepo = array(
+$wgLocalFileRepo = [
'class' => 'LocalRepo',
'name' => 'local',
- 'directory' => dirname( __FILE__ ) . '/thumbs', // getScalerType()
wants to make sure that the folders exist, even though we are resizing through
a 404. Ok, I will have a bunch of empty folders there
+ 'directory' => __DIR__ . '/thumbs', // getScalerType() wants to make
sure that the folders exist, even though we are resizing through a 404. Ok, I
will have a bunch of empty folders there
'scriptDirUrl' => $wgScriptPath,
'scriptExtension' => '.php',
'url' => 'http://upload.wikimedia.org/wikipedia/commons',
@@ -25,25 +25,24 @@
'transformVia404' => true,
'deletedDir' => false,
'deletedHashLevels' => 1
-);
+];
$wgMemc = wfGetCache( CACHE_NONE );
$wgUseDatabaseMessages = false;
$passwd = posix_getpwuid( posix_getuid() );
$HOME = $passwd['dir'];
-$conf = parse_ini_file("$HOME/.my.cnf"); /* provides, user, password and host
*/
+$conf = parse_ini_file( "$HOME/.my.cnf" ); /* provides, user, password and
host */
$conf['host'] = 'sql-s4-user.toolserver.org';
$conf['dbname'] = 'commonswiki_p';
$conf['type'] = 'mysql';
$conf['load'] = '';
$conf['flags'] = DBO_DEFAULT;
-$wgDBservers = array( $conf );
+$wgDBservers = [ $conf ];
unset( $conf );
-
-//conf for monument categories
-$monumentCat = array(
+// conf for monument categories
+$monumentCat = [
'ad' => 'Cultural heritage monuments in Andorra with known IDs',
'ar' => 'Monuments in Argentina with known IDs',
'at' => 'Cultural heritage monuments in Austria with known IDs',
@@ -89,49 +88,49 @@
'ua' => 'Cultural heritage monuments in Ukraine with known IDs',
'us' => 'National Register of Historic Places with known IDs',
'us-ca' => 'California Historical Landmarks with known IDs'
-);
+];
-//does monument template use leading zeros in category sortkey
-$leadingZeros = array(
+// does monument template use leading zeros in category sortkey
+$leadingZeros = [
'ee' => 8,
'es' => 8,
'nl' => 8
-);
+];
// Dumb wrappers for function calls
class SillyLanguage {
- function needsGenderDistinction() {
+ function needsGenderDistinction() {
return false;
}
- function getNsText($namespace) {
- if ($namespace != NS_FILE) {
+ function getNsText( $namespace ) {
+ if ( $namespace != NS_FILE ) {
throw new Exception( "getNsText($namespace)" );
}
return "File";
}
-
- function getVal($name) {
+
+ function getVal( $name ) {
return 'render';
}
-
+
function formatNum( $number, $nocommafy = false ) {
return $number;
}
-
- function truncate($text, $length) {
+
+ function truncate( $text, $length ) {
return $text;
}
-
+
function getCode() {
global $I18N;
return $I18N->getLang();
}
-
- function getMessage($name) {
- if ($name == 'nbytes')
+
+ function getMessage( $name ) {
+ if ( $name == 'nbytes' ) {
return '$1 bytes'; // It's the same in most languages
-
- throw new Exception("Requested message $name");
+ }
+ throw new Exception( "Requested message $name" );
}
}
@@ -141,50 +140,48 @@
echo '<style type="text/css">#bodyContent li a { text-decoration: none }
#bodyContent .author { float: right; text-align: right; text-decoration:
underline }</style>';
-$db = DBforCluster( '4-user', 'commonswiki_p');
+$db = DBforCluster( '4-user', 'commonswiki_p' );
-//FIXME: author_text should be author of first image revision
+// FIXME: author_text should be author of first image revision
$query = "SELECT cl_from, img_user_text AS author_text, page_namespace,
page_title FROM image
JOIN page ON img_name=page_title
JOIN categorylinks AS clB ON page_id=clB.cl_from
WHERE page_namespace=6
AND page_is_redirect=0";
-
-if (isset($_GET['country'])) {
- if (isset($monumentCat[$_GET['country']])) {
- $monIdCat = str_replace(" ", "_",
$monumentCat[$_GET['country']]);
- $query .= " AND clB.cl_to=". $db->addQuotes($monIdCat) ;
+if ( isset( $_GET['country'] ) ) {
+ if ( isset( $monumentCat[$_GET['country']] ) ) {
+ $monIdCat = str_replace( " ", "_",
$monumentCat[$_GET['country']] );
+ $query .= " AND clB.cl_to=". $db->addQuotes( $monIdCat );
} else {
- die('No conf for country!');
+ die( 'No conf for country!' );
}
} else {
- die('Parameter country not set!');
+ die( 'Parameter country not set!' );
}
-
-if (isset($_GET['id'])) {
- if (isset($leadingZeros[$_GET['country']])) {
+if ( isset( $_GET['id'] ) ) {
+ if ( isset( $leadingZeros[$_GET['country']] ) ) {
$id_insortkey = ' ' . str_pad( $_GET['id'],
$leadingZeros[$_GET['country']], "0", STR_PAD_LEFT ) . "\n%";
} else {
$id_insortkey = ' ' . $_GET['id'] . "\n%";
}
- $query .= " AND clB.cl_sortkey LIKE '" . $db->strencode( $id_insortkey ) .
"'";
+ $query .= " AND clB.cl_sortkey LIKE '" . $db->strencode( $id_insortkey
) . "'";
- echo "<p>", _html('gallery-header', array( 'raw-variables' => true,
'variables' => array(
- "<a
href=\"http://toolserver.org/~erfgoed/api/api.php?action=search&format=htmllist&srcountry=".
htmlspecialchars( $_GET['country'] ) ."&srlang=&srid=" . htmlspecialchars(
$_GET['id'] ) . '">' . htmlspecialchars( $_GET['id'] ) . '</a>' ) ) ), "
(Username shown is the last uploader.)</p>";
+ echo "<p>", _html( 'gallery-header', [ 'raw-variables' => true,
'variables' => [
+ "<a
href=\"http://toolserver.org/~erfgoed/api/api.php?action=search&format=htmllist&srcountry=".
htmlspecialchars( $_GET['country'] ) ."&srlang=&srid=" . htmlspecialchars(
$_GET['id'] ) . '">' . htmlspecialchars( $_GET['id'] ) . '</a>' ] ] ), "
(Username shown is the last uploader.)</p>";
} else {
exit( 0 );
}
$gallery = new ImageGallery();
-$gallery->mShowBytes = false;
+$gallery->mShowBytes = false;
$res = $db->query( $query );
-foreach ($res as $row) {
- $author_url = $wgServer . '/wiki/User:'. $row->author_text;
- $gallery->add( Title::newFromRow( $row ), Html::element('a', array(
'class' => 'author', 'href' => $author_url ), $row->author_text ) );
+foreach ( $res as $row ) {
+ $author_url = $wgServer . '/wiki/User:'. $row->author_text;
+ $gallery->add( Title::newFromRow( $row ), Html::element( 'a', [ 'class'
=> 'author', 'href' => $author_url ], $row->author_text ) );
}
echo $gallery->toHTML();
diff --git a/tools/wlmlast.php b/tools/wlmlast.php
index 974b0d3..baafd59 100644
--- a/tools/wlmlast.php
+++ b/tools/wlmlast.php
@@ -4,33 +4,33 @@
* if country if given, one of the subcategories.
* TODO: Implement subcats
*/
-header("Cache-Control: no-cache, must-revalidate");
-header("Expires: Thu, 01 Jan 1970 00:00:00 GMT");
-header('Content-type: text/javascript;; charset=utf-8');
-function getLatest($size, $number, $country){
+header( "Cache-Control: no-cache, must-revalidate" );
+header( "Expires: Thu, 01 Jan 1970 00:00:00 GMT" );
+header( 'Content-type: text/javascript;; charset=utf-8' );
+function getLatest( $size, $number, $country ) {
- $config_override = 'database.inc';
- if ( file_exists( dirname( dirname( dirname( __FILE__ ) ) ) .
"/{$config_override}" ) ) {
- require dirname( dirname( dirname( __FILE__ ) ) ) .
"/{$config_override}";
- } elseif ( file_exists( dirname( dirname( __FILE__ ) ) .
"/{$config_override}" ) ) {
- require dirname( dirname( __FILE__ ) ) . "/{$config_override}";
- }
+ $config_override = 'database.inc';
+ if ( file_exists( dirname( dirname( __DIR__ ) ) . "/{$config_override}"
) ) {
+ require dirname( dirname( __DIR__ ) ) . "/{$config_override}";
+ } elseif ( file_exists( dirname( __DIR__ ) . "/{$config_override}" ) ) {
+ require dirname( __DIR__ ) . "/{$config_override}";
+ }
- $db = new mysqli('commonswiki.labsdb',
- $dbUser,
- $dbPassword,
- 'commonswiki_p');
- $db->set_charset('utf-8');
- unset($dbUser);
- unset($dbPassword);
+ $db = new mysqli( 'commonswiki.labsdb',
+ $dbUser,
+ $dbPassword,
+ 'commonswiki_p' );
+ $db->set_charset( 'utf-8' );
+ unset( $dbUser );
+ unset( $dbPassword );
- if($country) {
- $category = 'Images_from_Wiki_Loves_Monuments_2017_in_' .
$db->real_escape_string($country);
- } else {
+ if ( $country ) {
+ $category = 'Images_from_Wiki_Loves_Monuments_2017_in_' .
$db->real_escape_string( $country );
+ } else {
$category = 'Images_from_Wiki_Loves_Monuments_2017';
- }
+ }
- $result = $db->query("SELECT rc_title, img_width, img_user_text,
img_timestamp
+ $result = $db->query( "SELECT rc_title, img_width, img_user_text,
img_timestamp
FROM recentchanges
JOIN page ON (rc_namespace=page_namespace AND rc_title=page_title)
JOIN categorylinks ON page_id=cl_from
@@ -42,50 +42,49 @@
AND page_is_redirect=0
AND cl_to='" . $category . "'
ORDER BY rc_timestamp DESC
- LIMIT " . $number);
+ LIMIT " . $number );
- $returnResult = array();
- $firstrow = True;
+ $returnResult = [];
+ $firstrow = true;
- while ($row = $result->fetch_assoc()) {
- $upload = array();
+ while ( $row = $result->fetch_assoc() ) {
+ $upload = [];
$upload['title'] = $row['rc_title'];
$upload['uploader'] = $row['img_user_text'];
$upload['timestamp'] = $row['img_timestamp'];
$upload['url'] = "http://commons.wikimedia.org/wiki/File:" .
$row['rc_title'];
- $hash = md5($row['rc_title']);
+ $hash = md5( $row['rc_title'] );
$fullimg = "http://upload.wikimedia.org/wikipedia/commons/" . $hash[0]
. "/" . $hash[0] . $hash[1] . "/" . $row['rc_title'];
- $thumbprefix = "http://upload.wikimedia.org/wikipedia/commons/thumb/"
. $hash[0] . "/" . $hash[0] . $hash[1] . "/" . $row['rc_title'];
+ $thumbprefix = "http://upload.wikimedia.org/wikipedia/commons/thumb/" .
$hash[0] . "/" . $hash[0] . $hash[1] . "/" . $row['rc_title'];
- if (!($size==-1) && $size < $row['img_width']) {
- $upload['image'] = $thumbprefix . "/" . (int)$_GET["size"] . "px-"
. $upload['title'];
+ if ( !( $size==-1 ) && $size < $row['img_width'] ) {
+ $upload['image'] = $thumbprefix . "/" . (int)$_GET["size"] .
"px-" . $upload['title'];
} else {
- $upload['image'] = $fullimg;
+ $upload['image'] = $fullimg;
}
- $returnResult[]=$upload;
- }
- return json_encode($returnResult);
+ $returnResult[] =$upload;
+ }
+ return json_encode( $returnResult );
}
-$size=-1;
-if (isset($_GET["size"])) {
- $size=(int)$_GET["size"];
+$size =-1;
+if ( isset( $_GET["size"] ) ) {
+ $size =(int)$_GET["size"];
}
$number=5;
$max_number=20;
-if (isset($_GET["number"])) {
- $number=(int)$_GET["number"];
- if ($number > $max_number) {
+if ( isset( $_GET["number"] ) ) {
+ $number =(int)$_GET["number"];
+ if ( $number > $max_number ) {
$number = $max_number;
- }
+ }
}
$country = '';
-if (isset($_GET["country"])) {
- $country = $_GET["country"];
+if ( isset( $_GET["country"] ) ) {
+ $country = $_GET["country"];
}
-
-$jsonData = getLatest($size, $number, $country);
+$jsonData = getLatest( $size, $number, $country );
echo $_GET['callback'] . '(' . $jsonData . ');';
--
To view, visit https://gerrit.wikimedia.org/r/377921
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I758dd5a83beea050c4ee9d1ea2f1547770b7cf6c
Gerrit-PatchSet: 1
Gerrit-Project: labs/tools/heritage
Gerrit-Branch: master
Gerrit-Owner: Lokal Profil <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits