Permalink
Browse files

Convert tool to use local config files rather than on-wiki config

  • Loading branch information...
Matthewrbowker committed Apr 4, 2016
1 parent ebac269 commit 413804518af3bed26552759826d6d7b040bbf548
@@ -17,9 +17,9 @@ public function __construct(translate $k = NULL) {
throw new arException("Key File Broken.");
}
$url = "{$GLOBALS['url']}/index.php?title={$GLOBALS["basePage"]}/category&action=raw";
$path = "includes/config/category.xml";
$this->values = parse_ini_string(file_get_contents($url), TRUE) or $this->errorCatchString("Category file broken");
$this->values = parse_ini_string(file_get_contents($path), TRUE) or $this->errorCatchString("Category file broken");
$this->catBuffer = "<div class='well' id='well_cat'>\r\n";
$this->catBuffer .= "<h3>";
@@ -1,8 +1,4 @@
<?php
$GLOBALS["role"] = "live";
$GLOBALS["version"] = "0.1devel8";
$GLOBALS["url"] = "http://en.wikipedia.org/w";
$GLOBALS["basePage"] = "User:Matthewrbot/Config/1";
$GLOBALS["version"] = "0.1devel8";
@@ -0,0 +1,36 @@
[Applied arts and sciences]
Agriculture = "";
Architecture = "Architects, firms, organizations; Buildings; General concepts, styles; Urban studies and planning";
Communications = "";
Computer science, computing, and Internet = "";
Design = "";
Education = "";
Electronics = "";
Fishing, fisheries, and aquaculture = "";
Industry = "";
Law = "";
Crime = "";
Electronics = "";
Library sciences = "";
Medicine = "";
Technology and tools = "";
Transportation = "";
[Arts and entertainment]
Design = "Furniture design; Graphic design; Metal crafts; Retail design; Set design; Typography";
Fashion = "";
Film, radio and television = "";
Food, drink and nutrition = "People; Non-people - Organizations; Non-people = Other (non-people and non-organization); Unsorted";
Internet and tech culture = "";
Literature = "";
Media networks and organizations = "";
Museums = "Museum-related";
Music = "";
National or ethnic cultures = "";
Performing arts = "";
Print media = "";
Recreation and hobbies = "General; Games and toys - General; Games and toys - Card Games; Games and toys - Charles Roberts Award winners; Games and toys - Game design (Non-video-games only); Games and toys - Radio-controlled models; Games and toys - Role-playing games (tabletop, paper & dice, and LARP); Games and toys - Video games";
Surrealism = "";
Theory = "";
Tourism = "";
Visual arts = "";
@@ -0,0 +1,23 @@
[web]
id = "Web Source";
label = "Add a web source";
shorthand = "web";
fields = "url|title|author";
field_labels = "Web Address|Title of the Webpage|Author of the webpage";
template = "cite web";
[book]
id="Book Source";
label = "Add a book source";
shorthand = "book";
fields = "title|author|date";
field_labels = "Title of the book|Author of the book|Date of publication";
template = "cite book";
[journal]
id="Journal Source";
label = "Add a journal source";
shorthand = "journal";
fields = "title|author|date|publisher|volume|edition";
field_labels = "Title of the article|Author of the article|Date the article was published|Publisher|Volume|Edition";
template = "cite journal";
@@ -5,6 +5,12 @@ class site {
private $k;
private $smarty;
private function parseFooter($string) {
$string = str_replace("{v}", $GLOBALS["version"], $string);
$string = str_replace("{a}", $this->k->_r("about"), $string);
return $string;
}
private function gen_navbar() {
$navs = [];
$navsRight = [];
@@ -47,12 +53,9 @@ public function __construct(translate $k = NULL, $page = "") {
$this->Assign("nojavascript", $this->k->_r("no-javascript"));
// Footer
$this->assign("footer", $this->k->_r("footer"));
$this->assign("footer1", $this->parseFooter($this->k->_r("footer1")));
$this->assign("footer2", $this->parseFooter($this->k->_r("footer2")));
$this->assign("version", $GLOBALS["version"]);
$this->assign("wpurl", $this->k->_r("wp-url"));
$this->assign("edit", $this->k->_r("edit"));
$this->assign("wpallurl", $this->k->_r("wp-all-url"));
$this->assign("editall", $this->k->_r("edit-all"));
$this->assign("about", $this->k->_r("about"));
$this->gen_navbar();
@@ -6,8 +6,8 @@ class sources {
private $divBuffer;
public function __construct() {
$url = "{$GLOBALS['url']}/index.php?title={$GLOBALS["basePage"]}/sources&action=raw";
$this->values = parse_ini_string(file_get_contents($url), TRUE) or $this->errorCatchString("Sources file broken");
$path = "includes/config/sources.xml";
$this->values = parse_ini_string(file_get_contents($path), TRUE) or $this->errorCatchString("Sources file broken");
$this->buttonBuffer = "";
$this->divBuffer = "";
@@ -4,56 +4,25 @@ class translate {
private $keys;
public function __construct($lang = 'en', $page = "") {
$urlArray = array();
$wpPage = "{$GLOBALS["basePage"]}/interface";
public function __construct($lang = 'en', $page = "index") {
$this->keys = array();
$path = "includes/translate";
if ($lang != 'en') {
$wpPage .= "/$lang";
}
if ($GLOBALS["role"] == "staging") {
$wpPage .= "/dev";
}
$allPage = $wpPage . "/all";
if ($page != "") {
$wpPage .= "/" . $page;
}
$urlArray["wp-page"] = $wpPage;
$urlArray["wp-all-page"] = $allPage;
$url = "{$GLOBALS['url']}/index.php?title=" . urlencode($wpPage);
$allURL = "{$GLOBALS['url']}/index.php?title=" . urlencode($allPage);
$path .= "/$lang";
$urlArray["wp-url"] = $url;
$urlArray["wp-all-url"] = $allURL;
$wpPage = "$path/$page.xml";
$wpAllPage = "$path/all.xml";
$url .= "&action=raw";
$allURL .= "&action=raw";
@$wpKeys = parse_ini_string(file_get_contents($wpPage)) or $this->errorMessage("Unable to get page config");
if ($GLOBALS["role"] == "autotest") {
$url = explode("?", $url)[0];
$allURL = explode("?", $allURL)[0];
}
$this->keys = $urlArray;
@$wpKeys = parse_ini_string(file_get_contents($url)) or $this->errorMessage("Unable to get page config");
@$allKeys = parse_ini_string(file_get_contents($allURL)) or $this->errorMessage("Unable to get general config");
@$allKeys = parse_ini_string(file_get_contents($wpAllPage)) or $this->errorMessage("Unable to get general config");
$this -> keys = array_merge($this->keys, $wpKeys);
$this -> keys = array_merge($this->keys, $allKeys);
}
public function errorMessage($message) {
throw new arException($message);
}
@@ -63,8 +32,6 @@ public function _r($key) {
}
else if (array_key_exists($key, $this ->keys)) {
$string = str_replace("{star}", "<i class=\"glyphicon glyphicon-star\"></i>", $this-> keys[$key]);
if (array_key_exists("about", $this->keys)) {$string = str_replace("{a}", $this->keys["about"], $string); }
else {$string = str_replace("{a}", "{{about}}", $string); }
return $string;
}
else {
@@ -0,0 +1,7 @@
content = "Wikipedia article request tool written by <a href=\"http://en.wikipedia.org/wiki/User:Matthewrbowker\" target=_blank>Matthew Bowker</a> and hosted on the Wikimedia Labs cluster. Please look on GitHub for the source code to <a href=\"http://github.com/Matthewrbowker/articlerequest\" target=_blank>the web interface</a> and <a href=\"http://github.com/Matthewrbowker/labsBots\" target=_blank>the bot</a>.
<br><br>
Report bugs to <a href=\"https://phabricator.wikimedia.org/maniphest/task/create/?projects=Tool-Labs-tools-Article-request\">Phabricator</a>.
<br><br>
<a href=\"http://getbootstrap.com/\" target=_blank>Twitter Bootstrap</a> licensed under the <a href=\"http://www.apache.org/licenses/LICENSE-2.0\" target=_blank>Apache Licence 2.0</a>.
<br><br>
<a href=\"http://glyphicons.com/\" target=_blank>Glyphicons Free</a> licensed under <a href=\"http://creativecommons.org/licenses/by/3.0/\" target=_blank>CC-BY-SA</a>.";
@@ -0,0 +1,19 @@
article_on = "1";
article = "Request Article";
redirect_on = "0";
redirect = "Request Redirect";
about_on = "1";
about = "About this tool";
search_on = "0";
search = "Search";
return_on = "1";
return = "Return to the English Wikipedia";
return_url = "//en.wikipedia.org/wiki/Main_page"
title = "Request an article";
message = "1";
message-text = "This is a test server. Please expect things to break.";
no-javascript = "This form requires Javascript to work! Please enable Javascript in your browser to continue.";
error = "There was an error processing your form input. Please correct the errors highlighted below and re-submit";
footer1 = "Article request tool &middot; Written by Matthewrbowker";
footer2 = "{v} &middot; <a href='about.php'>{a}</a>";
@@ -0,0 +1,27 @@
intro = "If you would like to request an article to be created, please fill out the information below. Fields with a {star} are required.";
subject = "{star} Subject (topic) of the article : ";
description = "Description/Comments:";
category = "{star} Category : "
sub-category = "{star} Sub-category : ";
sub-sub-category = "{star} Sub-sub-category : ";
username = "Your Wikipedia username (if you have one) : ";
sources = "{star} <a href=\"http://en.wikipedia.org/wiki/Wikipedia:RS\" title=\"Wikipedia:RS\" target=_blank>Reliable Sources</a> (please provide between two and six) : ";
check_1 = "{star} The subject of this request is important enough for its own article, per <a href=\"http://en.wikipedia.org/wiki/Wikipedia:N\" title=\"Wikipedia:N\" target=_blank>Wikipedia's requirements</a>.";
check_2 = "This is not a duplicate of a prior request I have made. ";
reset = "Reset form";
submit = "Request article!";
select = "[add]";
editInfo = "[edit]";
delete = "[delete]"
clearInfo = "Clear Information";
modalSave = "Save";
category-heading = "Select Category";
cat="{star} Category:";
subcat = "{star} Sub-Category:";
subsubcat = "{star} Sub-sub-category:";
sources-heading = "Select Sources";
sources_add = "Add Source +";
sources_remove = "Remove -";
@@ -0,0 +1,6 @@
intro = "Request a redirect here.";
redirname = "Name of the article";
targetname = "Target of the redirect";
username = "Your Wikipedia username (if applicable)";
reset = "Reset this form";
submit = "Submit request";
@@ -0,0 +1,5 @@
success = "The request has been successfully processed! Thank you for your contribution to Wikipedia!";
failure = "We were unable to process the request. Please go back and try again.";
go_back = "Go back";
done = "Return to Wikipedia";
dev = "Here is the data, for debugging purposes";
@@ -0,0 +1,4 @@
info = "This page allows you to search for requests.";
label = "Search terms:";
searchBtn = "Search requests";
resetBtn = "Reset form";
@@ -10,7 +10,7 @@
try {
$fi = new fileLoader();
$k = new translate($lang, "");
$k = new translate($lang, "index");
$site = new site($k, "");
@@ -1,8 +1,8 @@
<!-- BEGIN: footer.tpl -->
<hr>
<div class="footer">
<p style="text-align:right"><small>{$footer} &middot; Version {$version}<br />
<a href="{$wpurl}" target=_blank>{$edit}</a> &middot; <a href="{$wpallurl}" target=_blank>{$editall}</a> &middot; <a href="about.php">{$about}</a> </small>
<p style="text-align:right"><small>{$footer1}<br />
{$footer2} </small>
</p>
</div>

This file was deleted.

Oops, something went wrong.
@@ -10,7 +10,7 @@ class siteTest extends PHPUnit_Framework_TestCase
private $s;
function setUp() {
$t = new Translate("en", "Testpage" );
$t = new Translate("en", "test" );
$this->s = new site($t);
}
@@ -12,19 +12,7 @@ class TranslateTest extends PHPUnit_Framework_TestCase
protected $translateLive;
function setUp() {
$this->translate = new Translate("en", "testpage" );
$this->translateZYX = new Translate("zyx", "testpage" );
/*
// Dev
$GLOBALS["role"] = "staging";
$this->translateSt = new Translate("en", "testpage");
// Live
$GLOBALS["role"] = "live";
$this->translateLive = new Translate("en", "testpage");
$GLOBALS["role"] = "autotest";*/
$this->translate = new Translate("en", "test" );
}
function tearDown() {
@@ -51,16 +39,6 @@ public function testReturn() {
$this->assertRegExp("/not found in the configuration file/", $string);
}
public function testLangCode() {
$this->assertContains("zyx", $this->translateZYX->_r("wp-page"));
$this->assertNotContains("zyx", $this->translate->_r("wp-page"));
}
public function testDev() {
// $this->assertContains("/dev", $this->translateSt->_r("wp-page"));
$this->assertNotContains("/dev", $this->translate->_r("wp-page"));
}
public function testKeys() {
$_GET["keys"] = 1;
$this->assertEquals($this->translate->_r("test1"), "{{test1}}");

0 comments on commit 4138045

Please sign in to comment.