Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Gadget API-Do not echo stuff to wikipedia #251

Merged
merged 32 commits into from
Oct 31, 2017
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
8f52561
add $echo_html option
GlazerMann Oct 20, 2017
2b2b8bc
Do not print "processing page ...." stuff
GlazerMann Oct 20, 2017
ef101cb
more standard method
GlazerMann Oct 21, 2017
e12e4e1
Better name for variable
GlazerMann Oct 22, 2017
f67b3a2
That's not right
GlazerMann Oct 22, 2017
c56c1d3
better
GlazerMann Oct 22, 2017
94fbc06
not needed
GlazerMann Oct 22, 2017
e94b345
comment to explain my problems in the code
GlazerMann Oct 22, 2017
b1b2631
move to gadget page
GlazerMann Oct 22, 2017
b313d0e
kill output in gadget where it belongs
GlazerMann Oct 22, 2017
e747c52
Not true after this pull
GlazerMann Oct 22, 2017
5745ae8
That does not matter anymore
GlazerMann Oct 22, 2017
df68e23
Get much more paranoid about rogue output
GlazerMann Oct 24, 2017
3710f02
oops
GlazerMann Oct 24, 2017
0088749
update documentation
GlazerMann Oct 24, 2017
b039a58
add a test (broken now, but want to see output)
GlazerMann Oct 24, 2017
6c9dc89
Update TemplateTest.php
GlazerMann Oct 24, 2017
aa2824c
Just me being an idiot
GlazerMann Oct 24, 2017
154e041
update output to match reality
GlazerMann Oct 24, 2017
be61e5b
assert seems to not like all the special stuff
GlazerMann Oct 24, 2017
3c2162c
White spaces
GlazerMann Oct 24, 2017
73c60c1
update comments
GlazerMann Oct 24, 2017
23a7ad2
remove base64 stuff
GlazerMann Oct 24, 2017
4522c2a
die vs. exit
GlazerMann Oct 25, 2017
395b6e2
less white space changes
GlazerMann Oct 28, 2017
21ec45e
Merge branch 'development' into patch-1
GlazerMann Oct 30, 2017
ab1e38d
Merge branch 'development' into patch-1
GlazerMann Oct 30, 2017
5e869d1
Do not catch exceptions-we can use as debug info
GlazerMann Oct 30, 2017
e9368eb
Less verbose
GlazerMann Oct 30, 2017
c00f701
This test does nothing useful
GlazerMann Oct 31, 2017
5ce74e4
white space
GlazerMann Oct 31, 2017
83993e6
worthless test is gone
GlazerMann Oct 31, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 0 additions & 11 deletions Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,6 @@ public function expand_text() {
return FALSE;
}

//this is set to -1 only in [erstwhile file?] text.php, because there's no need to output
// a buffer of text for the citation-expander gadget
if (HTML_OUTPUT === -1) {
ob_start();
}

// COMMENTS //
$comments = $this->extract_object('Comment');
$nowiki = $this->extract_object('Nowiki');
Expand Down Expand Up @@ -135,11 +129,6 @@ public function expand_text() {

$this->replace_object($comments);
$this->replace_object($nowiki);

// seems to be set as -1 in text.php and then re-set
if (HTML_OUTPUT === -1) {
ob_end_clean();
}

return strcasecmp($this->text, $this->start_text) != 0;
}
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ Bugs and requested changes are listed here: https://en.wikipedia.org/wiki/User_t
## Structure

Basic structure of a Citation bot script:
* define configuration constants (for instance, `html_output` will allow or suppress
buffered output)
* define configuration constants
* require `expandFns.php`, which will set up the rest of the needed functions
* use Page functions to fetch/expand/post the page's text

Expand Down
12 changes: 9 additions & 3 deletions gadgetapi.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
header("Access-Control-Allow-Origin: *"); //This is ok because the API is not authenticated
header("Content-Type: text/json");

//Configure setting to suppress buffered output
define("HTML_OUTPUT", -1);
// This code is not tested, but we have a copy of this code in the tests

// This is needed because the Gadget API expects only JSON back
// ALL output from the citation bot is throw away
ob_start();

//Set up tool requirements
require_once __DIR__ . '/expandFns.php';

Expand All @@ -27,4 +30,7 @@
'editsummary' => $editSummary,
);

echo json_encode($result);
// Throw away all output
ob_end_clean();

echo json_encode($result); // On error returns "FALSE", which makes echo print nothing. Thus we do not have to check for FALSE
24 changes: 24 additions & 0 deletions tests/phpunit/TemplateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,30 @@ public function testConvertJournalToBook() {
$this->assertEquals('cite book', $expanded->wikiname());
}

public function testGadgetAPI() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What we need to test, if anything, is that nothing is echoed when gadgetapi.php is run (except the final output). As you say, the functionality itself is tested in TemplateTest.php and elsewhere. It's not clear that this tests that.

// This does not really test API right now, but it does emulate it without firing up a webserver etc.
$originalText = 'This is a page. {{Cite web|website=apple.com/phones/buy_android}}. Indeed it is';
$editSummary = 'I made this page';

$page = new Page();
$page->text = $originalText;
$page->start_text = $originalText; // Only in test environment. Not in GadgetAPI
$page->expand_text();

//Modify edit summary to identify bot-assisted edits
if ($editSummary) {
$editSummary .= " | ";
}
$editSummary .= "[[WP:UCB|Assisted by Citation bot]]";

$result = array(
'expandedtext' => $page->text,
'editsummary' => $editSummary,
);
$expanded = json_encode($result);
$this->assertEquals('{"expandedtext":"This is a page. {{Cite web|url=http:\/\/apple.com\/phones\/buy_android}}. Indeed it is","editsummary":"I made this page | [[WP:UCB|Assisted by Citation bot]]"}',$expanded);
}

public function testPagesDash() {
$text = '{{cite journal|pages=1-2|title=do change}}';
$expanded = $this->process_citation($text);
Expand Down