-
Notifications
You must be signed in to change notification settings - Fork 0
/
SpecialNoSuchWiki.php
115 lines (102 loc) · 2.5 KB
/
SpecialNoSuchWiki.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
/**
* Special page
*
* @file
* @ingroup Extensions
*
* @author Lewis Cawte
* @copyright Lewis Cawte © 2014
* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
*/
class SpecialNoSuchWiki extends SpecialPage {
/**
* Constructor
*/
public function __construct() {
parent::__construct( 'NoSuchWiki' );
}
public function execute( $par ) {
$out = $this->getOutput();
$out->addModuleStyles( 'ext.nosuchwiki' );
$reqSite = $this->getSite( $par );
$this->formatAndOutputLogs( $reqSite );
//$this->addOtherWikis();
}
/**
* Get and parse the requested site.
*
* @return string
*/
private function getSite( $par ) {
$par = htmlspecialchars( $par );
if( isset( $par ) ) {
if( $this->requestedWikiCheck( $par ) ) {
$reqWiki = $par;
} else { $reqWiki = null; }
} else {
$reqWiki = null;
}
unset( $par );
return $reqWiki;
}
private function requestedWikiCheck( $wiki ) {
if( isset( $wiki ) ) {
$wikiArray = explode( '.', $wiki );
$count = count( $wikiArray );
if ( 0 < $count && $count < 3 ) {
return true;
} else {
return false;
}
} else {
return false;
}
}
private function getLogs( $deletedWiki ) {
$dbr = wfGetDB( DB_SLAVE );
$res = $dbr->select(
array( 'logging', 'log_search' ),
'*',
array(
'log_type' => 'createwiki',
'log_action' => 'delete',
'ls_field' => 'deletedwiki',
'ls_value' => $deletedWiki
),
__METHOD__,
array(
'LIMIT' => 2,
'ORDER BY' => 'ls_log_id DESC',
),
array(
'log_search' => array( 'INNER JOIN', 'log_id = ls_log_id' )
)
);
if ( $dbr->numRows( $res ) === 0 ) {
return null;
} else {
return $res;
}
}
private function formatAndOutputLogs( $requestedSite ) {
$out = $this->getOutput();
$logs = $this->getLogs( $requestedSite );
$out->addHTML( '<div id="nosuchwiki-logwrapper">');
if( $logs === null ) {
$out->addHTML( $this->msg( 'nosuchwiki-nevercreated')->parse() );
} else {
$out->addHTML( $out->msg( 'nosuchwiki-requestedsite' )->params( $requestedSite )->parse() );
foreach( $logs as $log ) {
$timestamp = $this->getLanguage()->userTimeAndDate( $log->log_timestamp, $this->getUser() );
$out->addHTML( '<div class="nosuchwiki-logitem">' );
$out->addHTML( $out->msg( 'nosuchwiki-logentry')
->params( $requestedSite, $log->log_user_text, $timestamp, $log->log_comment )
->parse() );
$out->addHTML( '</div>' );
};
};
$out->addHTML( '</div>' );
unset( $logs );
}
}