Skip to content

Commit efa39fe

Browse files
authored
Merge pull request #18 from attogram/v0.4.12
V0.4.12
2 parents 0ec6e4f + d44fe5f commit efa39fe

File tree

9 files changed

+45
-58
lines changed

9 files changed

+45
-58
lines changed

public/index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77
$verbose = false;
88

9-
$vendor = '../vendor/autoload.php';
9+
$vendor = '..' . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
1010
if (!is_readable($vendor)) {
1111
exit('Site down for maintenance');
1212
}

public/style.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ a:active {
3636
background-color:yellow;
3737
color:black;
3838
}
39-
.missing {
39+
.missing, a.missing {
4040
color:blueviolet;
4141
}
4242
.head {

src/Base.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
class Base
2424
{
25-
const VERSION = '0.4.11';
25+
const VERSION = '0.4.12';
2626

2727
/**
2828
* @var bool - print verbose debug messages to STDOUT
@@ -160,6 +160,7 @@ protected function encodeLink($query)
160160

161161
/**
162162
* set $this->topic to string from URL elements, or empty string
163+
* @return bool
163164
*/
164165
protected function setTopicFromUrl()
165166
{
@@ -179,15 +180,19 @@ protected function setTopicFromUrl()
179180
if (!is_string($this->topic) || !strlen($this->topic)) {
180181
$this->topic = '';
181182

182-
return;
183+
return false;
183184
}
184185
// format query
185186
$this->topic = trim($this->topic);
186187
$this->topic = str_replace('_', ' ', $this->topic);
187188
$this->topic = urldecode($this->topic);
188189
if (!is_string($this->topic) || !strlen($this->topic)) {
189190
$this->topic = '';
191+
192+
return false;
190193
}
194+
195+
return true;
191196
}
192197

193198
protected function initFilesystem()

src/Mediawiki.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function links($query)
5959
) {
6060
$result['title'] = $query;
6161
$result['error'] = true;
62-
$this->error('links: 404 NOT FOUND: ' . $query);
62+
//$this->error('links: 404 NOT FOUND: ' . $query);
6363

6464
return $result;
6565
}

src/Topic.php

Lines changed: 34 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -22,65 +22,76 @@ class Topic extends Base
2222
private $data = []; // topic data
2323
private $vars = []; // template variables
2424

25+
const ERROR_NOT_FOUND = 'Topic Not Found';
26+
2527
/**
2628
* Get a topic
29+
* @return void
2730
*/
2831
public function get()
2932
{
30-
$this->setTopicFromUrl();
31-
if (!$this->topic) {
32-
$this->error404('Not Found');
33+
if (!$this->setTopicFromUrl()) { // build topic from URL
34+
$this->error404(self::ERROR_NOT_FOUND);
3335
}
3436

35-
// get topic from Cache
36-
$this->setDataFromCache();
37-
if ($this->data) {
37+
if ($this->setDataFromCache()) { // get topic data from Cache
3838
if (!empty($this->data['error'])) {
39-
$this->error404('Topic Not Found', $this->topic);
39+
$this->error404(self::ERROR_NOT_FOUND, $this->topic);
40+
4041
return;
4142
}
4243
$this->display(); // show cached results
44+
4345
return;
4446
}
4547

46-
// get topic from API
47-
$this->setDataFromApi();
48-
if ($this->data) {
49-
// save results to cache
50-
$this->filesystem->set($this->topic, json_encode($this->data));
51-
if (!empty($this->data['error'])) {
52-
$this->error404('Topic Not Found', $this->topic);
48+
if ($this->setDataFromApi()) { // get topic data from API
49+
$this->filesystem->set($this->topic, json_encode($this->data)); // save results to cache
50+
if (!empty($this->data['error'])) { // if API reported an error
51+
$this->error404(self::ERROR_NOT_FOUND, $this->topic);
52+
5353
return;
5454
}
5555
$this->display(); // show api results
56+
5657
return;
5758
}
5859

59-
$this->error404('Topic Not Found');
60+
$this->error404(self::ERROR_NOT_FOUND);
6061
}
6162

6263
/**
6364
* set $this->data to array from cached file, or empty array
65+
* @return bool
6466
*/
6567
private function setDataFromCache()
6668
{
6769
$this->initFilesystem();
6870
$this->data = $this->filesystem->get($this->topic);
6971
if (!is_array($this->data)) {
7072
$this->data = [];
73+
74+
return false;
7175
}
76+
77+
return true;
7278
}
7379

7480
/**
7581
* set $this->data to array from api response, or empty array
82+
* @return bool
7683
*/
7784
private function setDataFromApi()
7885
{
7986
$this->initMediawiki();
8087
$this->data = $this->mediawiki->links($this->topic);
8188
if (!is_array($this->data)) {
8289
$this->data = [];
90+
91+
return false;
8392
}
93+
94+
return true;
8495
}
8596

8697
private function display()
@@ -114,20 +125,17 @@ private function setTemplateVars()
114125
$this->setTemplateExists();
115126
$this->removeTemplateTopics();
116127
foreach (array_keys($this->vars) as $index) {
117-
// set counts
118-
$this->template->set($index . '_count', count($this->vars[$index]));
119-
// sort var lists alphabetically
120-
sort($this->vars[$index]);
121-
// set html list
122-
$this->template->set($index . '_list', $this->listify($index));
128+
$this->template->set($index . '_count', count($this->vars[$index])); // set counts
129+
sort($this->vars[$index]); // sort var lists alphabetically
130+
$this->template->set($index . '_list', $this->listify($index)); // set html list
123131
}
124132
}
125133

126134
private function initVars()
127135
{
128136
$namespaces = [
129-
'main', 'talk',
130-
'template', 'template_talk',
137+
'main', 'talk', 'main_secondary',
138+
'template', 'template_talk', 'template_secondary',
131139
'portal', 'portal_talk',
132140
'wikipedia', 'wikipedia_talk',
133141
'help', 'help_talk',
@@ -137,8 +145,6 @@ private function initVars()
137145
'refs',
138146
'missing',
139147
'exists',
140-
'main_secondary',
141-
'template_secondary',
142148
];
143149
foreach ($namespaces as $index) {
144150
$this->vars[$index] = [];
@@ -149,11 +155,9 @@ private function setNamespaces()
149155
{
150156
foreach ($this->data['topics'] as $topic) {
151157
if (!isset($topic['exists'])) {
152-
// page does not exist
153-
$this->vars['missing'][] = $topic['*'];
158+
$this->vars['missing'][] = $topic['*']; // page does not exist
154159
}
155-
// @see https://en.wikipedia.org/wiki/Wikipedia:Namespace
156-
switch ($topic['ns']) {
160+
switch ($topic['ns']) { // @see https://en.wikipedia.org/wiki/Wikipedia:Namespace
157161
case '0': // Mainspace
158162
$this->vars['main'][] = $topic['*'];
159163
break;
@@ -202,18 +206,6 @@ private function setNamespaces()
202206
case '829': // Module_talk
203207
$this->vars['module_talk'][] = $topic['*'];
204208
break;
205-
/*
206-
case '6': // File
207-
case '7': // File_talk
208-
case '8': // Mediawiki
209-
case '9': // Mediawiki_talk
210-
case '14': // Category
211-
case '15': // Category_talk
212-
case '108': // Book
213-
case '109': // Book_talk
214-
case '710': // TimedText
215-
case '711': // TimedText_talk
216-
*/
217209
default:
218210
break;
219211
}
@@ -283,8 +275,7 @@ private function removeTemplateTopics()
283275
}
284276
foreach ($templateData['topics'] as $exTopic) {
285277
if ($exTopic['ns'] == '0' && in_array($exTopic['*'], $this->vars['main'])) {
286-
// main namespace only
287-
// remove this template topic from master topic list
278+
// main namespace only - remove this template topic from master topic list
288279
unset($this->vars['main'][array_search($exTopic['*'], $this->vars['main'])]);
289280
$this->vars['main_secondary'][] = $exTopic['*'];
290281
}

templates/about.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
* About Page template
66
* @uses $this - \Attogram\Justrefs\Template
77
*/
8-
98
$this->include('html_head');
109
$this->include('header');
11-
1210
?><div class="body">
1311
<h1>
1412
About <b><?= $this->get('name') ?></b> <small>v<?= $this->get('version') ?></small>
@@ -42,5 +40,4 @@
4240
&lt;<a href="https://github.com/attogram/justrefs">https://github.com/attogram/justrefs</a>&gt;
4341
<p>
4442
</div><?php
45-
4643
$this->include('footer');

templates/footer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php
22
/**
33
* Just Refs - https://github.com/attogram/justrefs
4-
* Footer template
54
*
5+
* Footer template
66
* @uses $this - \Attogram\Justrefs\Template
77
*/
88
?><footer>

templates/home.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
* Home Page template
66
* @uses $this - \Attogram\Justrefs\Template
77
*/
8-
98
$this->include('html_head');
10-
119
?><div class="body">
1210
<h1>Just Refs</h1>
1311
<ul>
@@ -42,5 +40,4 @@
4240
</ul>
4341
<br />
4442
</div><?php
45-
4643
$this->include('footer');

templates/topic.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
* Topic page template
66
* @uses $this - \Attogram\Justrefs\Template
77
*/
8-
98
$this->include('html_head');
109
$this->include('header');
11-
1210
?><div class="body">
1311
<h1><?= $this->get('h1') ?></h1>
1412
<hr />
@@ -97,5 +95,4 @@
9795
</div>
9896
<hr />
9997
</div><?php
100-
10198
$this->include('footer');

0 commit comments

Comments
 (0)