forked from Illvili/MsUpload-Moegirl
-
Notifications
You must be signed in to change notification settings - Fork 1
/
MsUpload.body.php
71 lines (62 loc) · 2.3 KB
/
MsUpload.body.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
<?php
class MsUpload {
static function start() {
global $wgOut, $wgScriptPath, $wgJsMimeType, $wgMSL_FileTypes, $wgMSU_useMsLinks, $wgMSU_showAutoCat, $wgMSU_autoIndex, $wgMSU_checkAutoCat, $wgMSU_confirmReplace, $wgMSU_useDragDrop, $wgMSU_imgParams, $wgFileExtensions;
$wgOut->addModules( 'ext.MsUpload' );
$wgOut->addJsConfigVars( array(
'wgFileExtensions' => array_values( array_unique( $wgFileExtensions ) ),
));
if ( $wgMSU_imgParams ) {
$wgMSU_imgParams = '|' . $wgMSU_imgParams;
}
$msuVars = array(
'path' => $wgScriptPath . '/extensions/MsUpload',
'useDragDrop' => $wgMSU_useDragDrop,
'showAutoCat' => $wgMSU_showAutoCat,
'checkAutoCat' => $wgMSU_checkAutoCat,
'useMsLinks' => $wgMSU_useMsLinks,
'confirmReplace' => $wgMSU_confirmReplace,
'imgParams' => $wgMSU_imgParams,
//'autoIndex' => $wgMSU_autoIndex,
);
$msuVars = json_encode( $msuVars );
$wgOut->addScript( "<script type=\"$wgJsMimeType\">var msuVars = $msuVars;</script>\n" );
return true;
}
static function saveCat( $filename, $category ) {
global $wgContLang, $wgUser;
$mediaString = strtolower( $wgContLang->getNsText( NS_FILE ) );
$title = $mediaString . ':' . $filename;
$text = "\n[[" . $category . "]]";
$wgEnableWriteAPI = true;
$params = new FauxRequest(array (
'action' => 'edit',
'section'=> 'new',
'title' => $title,
'text' => $text,
'token' => $wgUser->editToken(),//$token."%2B%5C",
), true, $_SESSION );
$enableWrite = true; // This is set to false by default, in the ApiMain constructor
$api = new ApiMain( $params, $enableWrite );
$api->execute();
if ( defined( 'ApiResult::META_CONTENT' ) ) {
$data = $api->getResult()->getResultData();
} else {
$data = &$api->getResultData();
}
return $mediaString;
/* The code below does the same and is better, but for some reason it doesn't update the categorylinks table
global $wgContLang, $wgUser;
$title = Title::newFromText( $filename, NS_FILE );
$page = new WikiPage( $title );
$text = $page->getText();
$text .= "\n\n[[" . $category . "]]";
$summary = wfMessage( 'msu-comment' );
$status = $page->doEditContent( $text, $summary, EDIT_UPDATE, false, $wgUser );
$value = $status->value;
$revision = $value['revision'];
$page->doEditUpdates( $revision, $wgUser );
return true;
*/
}
}