forked from wikimedia/mediawiki-extensions-Drafts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpecialDrafts.php
More file actions
79 lines (73 loc) · 1.83 KB
/
SpecialDrafts.php
File metadata and controls
79 lines (73 loc) · 1.83 KB
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
<?php
/**
* Special Pages for Drafts extension
*
* @file
* @ingroup Extensions
*/
class SpecialDrafts extends SpecialPage {
public function __construct() {
parent::__construct( 'Drafts' );
}
public function doesWrites() {
return true;
}
/**
* Executes special page rendering and data processing
*
* @param $sub Mixed: MediaWiki supplied sub-page path
* @throws PermissionsError
*/
public function execute( $sub ) {
global $egDraftsLifeSpan;
$out = $this->getOutput();
$user = $this->getUser();
$request = $this->getRequest();
// Begin output
$this->setHeaders();
// Make sure the user is logged in
if ( !$user->isLoggedIn() ) {
throw new PermissionsError( 'read' );
}
// Handle discarding
$draft = Draft::newFromID( $request->getIntOrNull( 'discard' ) );
if ( $draft->exists() ) {
// Discard draft
$draft->discard();
// Redirect to the article editor or view if returnto was set
$section = $request->getIntOrNull( 'section' );
$urlSection = $section !== null ? "§ion={$section}" : '';
switch( $request->getText( 'returnto' ) ) {
case 'edit':
$title = Title::newFromDBKey( $draft->getTitle() );
$out->redirect(
wfExpandURL( $title->getEditURL() . $urlSection )
);
break;
case 'view':
$title = Title::newFromDBKey( $draft->getTitle() );
$out->redirect(
wfExpandURL( $title->getFullURL() . $urlSection )
);
break;
}
}
$count = Drafts::num();
if ( $count === 0 ) {
$out->addWikiMsg( 'drafts-view-nonesaved' );
} else {
// Add a summary
$out->wrapWikiMsg(
'<div class="mw-drafts-summary">$1</div>',
array(
'drafts-view-summary',
$this->getLanguage()->formatNum( $egDraftsLifeSpan )
)
);
$out->addHTML( Drafts::display() );
}
}
protected function getGroupName() {
return 'pagetools';
}
}