Skip to content

Commit

Permalink
Bug fix: internal links in the main page are interpreted as chapter l…
Browse files Browse the repository at this point in the history
…inks.
  • Loading branch information
Tpt committed Dec 29, 2011
1 parent 58349af commit 7a6096b
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 6 deletions.
2 changes: 1 addition & 1 deletion book/BookProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public function getChaptersList($title) {
$chapters[] = $chapter;
}
} else {
$list = $this->xPath->query('//html:a[contains(@href,"' . Api::mediawikiUrlEncode($title) . '")][not(contains(@href,":"))][not(contains(@href,"action=edit"))][not(contains(@title,"/Texte entier"))]');
$list = $this->xPath->query('//html:a[contains(@href,"' . Api::mediawikiUrlEncode($title) . '")][not(contains(@href,"#"))][not(contains(@href,":"))][not(contains(@href,"action=edit"))][not(contains(@title,"/Texte entier"))]');
foreach($list as $link) {
$chapter = new Page();
$chapter->title = str_replace(' ', '_', $link->getAttribute('title'));
Expand Down
11 changes: 6 additions & 5 deletions http/book.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,25 @@
include('../book/init.php');

try {
if(!isset($_GET['page']) || $_GET['page'] == '') throw new HttpException('Not Found', 404);
if(!isset($_GET['page']) || $_GET['page'] == '')
include 'help/book.php';
$title = htmlspecialchars(urldecode($_GET['page']));
$format = isset($_GET['format']) ? htmlspecialchars(urldecode($_GET['format'])) : 'epub';
$withPictures = isset($_GET['pictures']) ? (bool) $_GET['pictures'] : true;
$api = new Api();
$provider = new BookProvider($api, $withPictures);
$data = $provider->get($title);
if($format == 'epub-2' | $format == 'epub') {
include('../book/formats/Epub2Generator.php');
include($basePath . '/book/formats/Epub2Generator.php');
$generator = new Epub2Generator();
} else if($format == 'odt') {
include('../book/formats/OdtGenerator.php');
include($basePath . '/book/formats/OdtGenerator.php');
$generator = new OdtGenerator();
} else if($format == 'xhtml') {
include('../book/formats/XhtmlGenerator.php');
include($basePath . '/book/formats/XhtmlGenerator.php');
$generator = new XhtmlGenerator();
} else {
throw new HttpException('Bad Request', 400);
include 'help/book.php';
}
$file = $generator->create($data);
header('Content-Type: ' . $generator->getMimeType());
Expand Down
78 changes: 78 additions & 0 deletions http/help/book.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta content="text/html;charset=UTF-8" http-equiv="content-type"/>
<title>WSexport</title>
<link type="text/css" href="http://twitter.github.com/bootstrap/1.4.0/bootstrap.min.css" rel="stylesheet" />
<style type="text/css">
html, body {
background-color: #eee;
}
.container > footer p {
text-align: center;
}
.content {
background-color: #fff;
padding: 20px;
margin: 0 -20px; /* negative indent the amount of the padding to maintain the grid system */
-webkit-border-radius: 0 0 6px 6px;
-moz-border-radius: 0 0 6px 6px;
border-radius: 0 0 6px 6
-webkit-box-shadow: 0 1px 2px rgba(0,0,0,.15);
-moz-box-shadow: 0 1px 2px rgba(0,0,0,.15);
box-shadow: 0 1px 2px rgba(0,0,0,.15);
}
.page-header {
background-color: #f5f5f5;
padding: 20px 20px 10px;
margin: -20px -20px 20px;
}
</style>
</head>
<body>
<div class="container">
<div class="content">
<div class="page-header">
<h1>Export tool of Wikisource books in many file formats.</h1>
</div>
<form method="get" action="book.php">
<fieldset>
<legend>Export a file</legend>
<div class="clearfix">
<label for="lang">Lang: </label>
<div class="input">
<input name="lang" id="lang" type="text" size="2" maxlength="2" required="required" value="<?php echo Api::getHttpLang(); ?>" />
<span class="help-inline">The code lang of the Wikisource like en or fr</span>
</div>
</div>
<div class="clearfix">
<label for="page">Title of the page: </label>
<div class="input">
<input name="page" id="lang" type="text" size="30" required="required">
<span class="help-inline">Naime of the mainpage of the book in Wikisource</span>
</div>
</div>
<div class="clearfix">
<label for="format">File format: </label>
<div class="input">
<select id="format" name="format" required="required">
<option>epub</option>
<option>xhtml</option>
<option>odt</option>
</select>
<span class="help-inline"></span>
</div>
</div>
<div class="actions">
<input class="btn primary" type="submit" value="Export" />
</div>
</fieldset>
</form>
</div>
<footer>
<p>Tool under <a rel="licence" href="http://www.gnu.org/licenses/gpl.html">GNU GPLv2+ licence.</a></p>
</footer>
</div>
</body>
</html>
<?php exit(); ?>
2 changes: 2 additions & 0 deletions todo
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
Epub: Bug: internal links when the book page has special characters aren't well modified.
Export ODT.
Export MOBI.
...

0 comments on commit 7a6096b

Please sign in to comment.