/
SpecialNewArticles.php
180 lines (142 loc) · 4.49 KB
/
SpecialNewArticles.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<?php
use MediaWiki\Extension\ArticleContentArea\ArticleContentArea;
/**
* Special page to display list of pages moved from NS_DRAFT to NS_MAIN
*
*/
class SpecialNewArticles extends FormSpecialPage {
/**
* Constructor
*/
function __construct( $name = 'NewArticles' ) {
parent::__construct( $name );
}
protected function getGroupName() {
return 'changes';
}
public function onSubmit( array $data ) {
$contentarea = $this->getRequest()->getVal( 'contentarea' );
$pager = new NewArticlesPager( $contentarea );
# Insert list
$logBody = $pager->getBody();
if ( $logBody ) {
$this->getOutput()->addHTML(
$pager->getNavigationBar() .
$logBody .
$pager->getNavigationBar()
);
} else {
$this->getOutput()->addWikiMsg( 'logempty' );
}
}
protected function alterForm( HTMLForm $form ) {
$form->setMethod( 'get' );
}
protected function getFormFields() {
$fields = [];
if ( ExtensionRegistry::getInstance()->isLoaded( 'ArticleContentArea' ) ) {
$fields['contentarea'] = [
'type' => 'select',
'name' => 'contentarea',
'label-message' => 'newarticles-filter-contentarea',
'options' => self::getContentAreaOptions(),
];
}
return $fields;
}
private static function makeOptionsForSelect( $arr ) {
$arr = array_filter( $arr ); // Remove empty elements
$arr = array_combine( $arr, $arr );
return $arr;
}
private static function makeOptionsWithAllForSelect( $arr ) {
$arr = [ 'הכל' => '' ] + self::makeOptionsForSelect( $arr ); // @todo i18n
return $arr;
}
private static function getContentAreaOptions() {
return self::makeOptionsWithAllForSelect( ArticleContentArea::getValidContentAreas() );
}
/**
* @inheritDoc
*/
protected function getDisplayFormat() {
return 'ooui';
}
}
/**
* @ingroup SpecialPage Pager
*/
class NewArticlesPager extends LogPager {
protected $contentArea;
function __construct( $contentArea = null ) {
$loglist = new LogEventsList(
$this->getContext(),
null,
0
);
$extraConds = [
'log_namespace' => NS_WR_DRAFTS
];
$this->contentArea = $contentArea;
parent::__construct(
$loglist,
[ 'move' ],
'', '', '',
$extraConds
);
}
public function getQueryInfo() {
$info = parent::getQueryInfo();
if ( ExtensionRegistry::getInstance()->isLoaded ( 'ArticleContentArea' ) ) {
$contentAreaQuery = \MediaWiki\Extension\ArticleContentArea\ArticleContentArea::getJoin( $this->contentArea, 'log_page' );
$info = array_merge_recursive( $info, $contentAreaQuery );
}
// if Extension:WRArticleType is available
if ( ExtensionRegistry::getInstance()->isLoaded ( 'ArticleType' ) ) {
$articleTypeQuery = \MediaWiki\Extension\ArticleType\ArticleType::getJoin( null, 'log_page' );
$info = array_merge_recursive( $info, $articleTypeQuery );
}
return $info;
}
function formatRow( $row ) {
$time = htmlspecialchars(
$this->getLanguage()->userDate(
$row->log_timestamp,
$this->getUser()
)
);
$paramsSerialized = unserialize( $row->log_params );
$paramsOldFormat = null;
// If the params aren't serialized, it's an older log format
if ( $paramsSerialized === false ) {
$paramsOldFormat = explode( "\n", $row->log_params );
}
$targetName = $paramsSerialized === false ? $paramsOldFormat[0] : $paramsSerialized['4::target'];
$logPageId = isset( $row->log_page ) ? (int)$row->log_page : 0;
$currentTitle = ( $logPageId !== 0 ) ? Title::newFromID( $logPageId ) : null;
$targetTitleObj = Title::newFromText( $targetName );
// Make sure the target is NS_MAIN
if ( $targetTitleObj->getNamespace() !== NS_MAIN ) {
return false;
}
$originalNameDisplay = '';
if ( $currentTitle && $targetName !== $currentTitle->getFullText() ) {
$originalNameDisplay = ' ' . $this->msg( 'newarticles-original-title' )->params( $targetName );
}
$pageLink = $this->getLinkRenderer()->makeLink( $originalNameDisplay ? $currentTitle : $targetTitleObj );
$articleTypeDisplay = '';
if ( isset( $row->article_type ) && $row->article_type === 'portal' ) {
$pageLink = Html::rawElement( 'strong', [], $pageLink );
}
$articleTypeReadable = WRArticleType::getReadableArticleTypeFromCode( $row->article_type );
$articleTypeDisplay = $this->msg( 'newarticles-articletype' )
->params( $articleTypeReadable )->text();
$articleTypeDisplay = ' ' . $articleTypeDisplay;
$formattedRow = Html::rawElement(
'li',
[],
"{$time}: {$pageLink}{$articleTypeDisplay}{$originalNameDisplay}"
) . "\n";
return $formattedRow;
}
}