forked from WikiToLearn/Wiki2Latex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
w2lContentCatcher.php
executable file
·75 lines (63 loc) · 1.57 KB
/
w2lContentCatcher.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
<?php
/*
* File: w2lContentCatcher.php
*
* Purpose:
* Fetches Content from DB or URLs
*
* License:
* 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.
*/
if ( !defined('MEDIAWIKI') ) {
$msg = 'To install Wiki2LaTeX, put the following line in LocalSettings.php:<br/>';
$msg .= '<tt>require_once( $IP."/extensions/path_to_Wiki2LaTeX_files/wiki2latex.php" );</tt>';
echo $msg;
exit( 1 );
}
class Wiki2LaTeXContentCatcher {
function __construct() {
}
function getTextByTitle( $title_str ) {
$title = $this->getTitleObject('text', $title_str);
if ( $title == '' ) {
return '';
}
if ( $title->exists() ) {
$rev = new Article( $title, 0 );
$text = $rev->getContent();
} else {
$text = $title_str;
}
return $text;
}
function getTitleObject( $type = 'text', $title_data, $namespace = NS_MAIN ) {
switch ($type) {
case 'text':
$title_data = trim($title_data);
$title = Title::newFromText( $title_data, $namespace );
break;
case 'id':
$title = Title::newFromID( $title_data );
break;
}
if ( !is_a( $title, 'Title' ) ) {
return $title_data;
}
if ( !$title->UserCanRead() ) {
return '';
}
return $title;
}
function getTextById($id) {
$title = $this->getTitleObject('id', $id);
if ( $title == '' ) {
return '';
}
$rev = new Article( $title, 0 );
$text = $rev->getContent();
return $text;
}
}