-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathindex.php
86 lines (75 loc) · 4.43 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
/*
Template transclusion counter © 2011, 214 Harry Burt <[email protected]>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
( at your option ) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
ini_set( 'display_errors', 1 );
error_reporting( E_ALL );
require_once( '/data/project/jarry-common/public_html/global.php' );
$I18N->setDomain( 'templatecount' );
$oldtime = time();
list( $interfaceLang, ) = explode( '-', $I18N->getLang() );
$language = ( isset( $_GET['lang'] ) && $_GET["lang"] != "" ) ? htmlspecialchars( $_GET['lang'] ) : $interfaceLang;
$namespace = ( isset( $_GET['namespace'] ) && $_GET["namespace"] != "" ) ? htmlspecialchars( $_GET['namespace'] ) : 10; //10 is template namespace
$templateName = ( isset( $_GET['name'] ) && $_GET["name"] != "" ) ? str_replace( "_", " ", htmlspecialchars( $_GET['name'], ENT_QUOTES ) ) : '';
echo get_html( 'header', 'Template transclusion count' );
if( !preg_match( "/^[a-z-]{2,10}$/", $language ) ) { // Safety precaution
echo '<b>Error:</b> Language parameter with invalid format.<br>';
die( get_html( 'footer' ) );
}
if( !is_numeric( $namespace ) ) { // Safety precaution
echo '<b>Error:</b> Namespace parameter must be numerical.<br>';
die( get_html( 'footer' ) );
}
?>
<h3><?php echo _html( 'enter-details' ); ?></h3>
<p><?php echo _html( 'introduction' ); ?></p>
<form action="index.php" method="GET">
<p><label for="lang"><?php echo _html( 'language-label' ) . _g( 'colon-separator' );?> </label><input type="text" name="lang" id="lang" value="<?php echo $language; ?>" style="width:80px;" maxlength="10" required="required">.wikipedia.org<br />
<label for="namespace"><?php echo _html( 'namespace-label' ) . _g( 'colon-separator' );?> </label><?php echo getNamespaceSelect( $interfaceLang, $namespace ); ?><br />
<label for="name"><?php echo _html( 'pagename-label' ) . _g( 'colon-separator' );?> </label><input type="text" name="name" id="name" style="width:200px;" value="<?php echo $templateName; ?>" required="required"/>
<input type="submit" value="<?php echo _g( 'form-submit'); ?>" /></p>
</form>
<?php
if( isset( $_GET['lang'] ) && $templateName != '' ){
Counter::increment( 'templatecount/sincejune2011.txt' );
$templateName = str_replace( "Template:", "", $templateName );
$templateName = mb_strtoupper( mb_substr( $templateName, 0, 1 ) ) . mb_substr( $templateName, 1 ); // For Xeno
$templateName = str_replace( " ", "_", $templateName );
// echo "<!-- Actually checking database for query '" . htmlspecialchars( $db->real_escape_string( $templateName ) ) . "' -->\n";
$db = dbconnect( $language . 'wiki-p' );
$result = $db->query( "SELECT count(*) FROM templatelinks INNER JOIN linktarget ON tl_target_id = lt_id WHERE lt_title = '" . $db->real_escape_string( $templateName ) ."' AND lt_namespace = " . $db->real_escape_string( $namespace ) . ";" );
$row = $result->fetch_array();
$count = $row[0];
echo "<h3>" . _html( 'transclusion-count-label' ) . "</h3>\n";
$result = "<p>" . _html( 'transclusion-count', array( 'variables' => array( $count ) ) );
if ( $count === 0 ) {
$result .= " " . _html( 'error-suggestion' );
}
echo $result . "</p>\n";
$diff = time() - $oldtime;
echo "<p style=\"font-size:60%;\">" . _html( 'time-label' ) . _g( 'colon-separator' ) . " $diff " . _g( 'seconds', array( 'variables' => array( $diff ) ) ) . ".</p>";
}
?>
<a name="bottom" id="bottom"></a>
<script type="text/javascript">
<?php
if( isset( $_GET['lang'] ) && $_GET["lang"] != "" && $templateName != '' ){
echo "document.location='#bottom';\n";
}
?>
$( document ).ready( function(){ $( "#translateform" ).html5form( { async:false } ); } );
</script>
<?php echo '<!-- Used ' . Counter::getCounter( 'templatecount/sincejune2011.txt' ) . " times since early June 2011. -->"; ?>
<?php
echo get_html( 'footer' );