Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'psr2' into psr2-config
* psr2:
  fix appveyor, download from https always
  Issue #1250, associated unit test
  translation update
  translation update
  fix(TASK_RECENTCHANGES_TRIM event): Add isMedia flag
  rename task event
  add missing visibility indicator and docblocks
  translation update
  refactor: Rename lib/exe/indexer.php to taskrunner.php 🔨
  refactor: Move the remainder of code from lib/exe/indexer.php to TaskRunner::run 🔨
  Fix for Issue#1250 Footnotes break metadata abstract saving
  feat: Trigger new event when changelog is trimmed ✨
  style(TaskRunner): automatic whitespace fixes 🎨
  refactor: Extract code from lib/exe/indexer into new TaskRunner class 🔨
  corectly disable sniff for one file
  translation update
  • Loading branch information
splitbrain committed May 18, 2018
2 parents edba97f + d9d27cd commit de33cda
Show file tree
Hide file tree
Showing 35 changed files with 718 additions and 327 deletions.
47 changes: 47 additions & 0 deletions _test/tests/inc/parser/renderer_metadata.test.php
@@ -0,0 +1,47 @@
<?php

/**
* Class renderer_xhtml_test
*/
class renderer_metadata_test extends DokuWikiTest {
/** @var Doku_Renderer_xhtml */
protected $R;

/**
* Called for each test
*
* @throws Exception
*/
function setUp() {
parent::setUp();
$this->R = new Doku_Renderer_metadata();
}

function tearDown() {
unset($this->R);
}


function test_footnote_and_abstract() {
// avoid issues with the filectime() & filemtime in document_start() & document_end()
$now = time();
$this->R->persistent['date']['created'] = $now;
$this->R->persistent['date']['modified'] = $now;

$this->R->document_start();

$this->R->cdata("abstract: ");

$this->R->footnote_open();
$this->R->cdata(str_pad("footnote: ", Doku_Renderer_metadata::ABSTRACT_MAX, "lotsa junk "));
$this->R->footnote_close();

$this->R->cdata("abstract end.");

$this->R->document_end();

$expected = 'abstract: abstract end.';
$this->assertEquals($expected, $this->R->meta['description']['abstract']);
}

}
2 changes: 1 addition & 1 deletion appveyor.yml
Expand Up @@ -26,7 +26,7 @@ install:
- IF NOT EXIST c:\php mkdir c:\php
- IF NOT EXIST c:\php\%PHP_VERSION% mkdir c:\php\%PHP_VERSION%
- cd c:\php\%PHP_VERSION%
- IF NOT EXIST php-installed.txt appveyor DownloadFile http://windows.php.net/downloads/releases/archives/php-%PHP_VERSION%-Win32-%VC%-x86.zip
- IF NOT EXIST php-installed.txt appveyor DownloadFile https://windows.php.net/downloads/releases/archives/php-%PHP_VERSION%-Win32-%VC%-x86.zip
- IF NOT EXIST php-installed.txt 7z x php-%PHP_VERSION%-Win32-%VC%-x86.zip -y >nul
- IF NOT EXIST php-installed.txt del /Q *.zip
- IF NOT EXIST php-installed.txt copy /Y php.ini-development php.ini
Expand Down
239 changes: 239 additions & 0 deletions inc/TaskRunner.php
@@ -0,0 +1,239 @@
<?php

namespace dokuwiki;

use Doku_Event;
use Sitemapper;
use Subscription;

/**
* Class TaskRunner
*
* Run an asynchronous task.
*/
class TaskRunner
{
/**
* Run the next task
*
* @todo refactor to remove dependencies on globals
* @triggers INDEXER_TASKS_RUN
*/
public function run()
{
global $INPUT, $conf, $ID;

// keep running after browser closes connection
@ignore_user_abort(true);

// check if user abort worked, if yes send output early
$defer = !@ignore_user_abort() || $conf['broken_iua'];
$output = $INPUT->has('debug') && $conf['allowdebug'];
if(!$defer && !$output){
$this->sendGIF();
}

$ID = cleanID($INPUT->str('id'));

// Catch any possible output (e.g. errors)
if(!$output) {
ob_start();
} else {
header('Content-Type: text/plain');
}

// run one of the jobs
$tmp = []; // No event data
$evt = new Doku_Event('INDEXER_TASKS_RUN', $tmp);
if ($evt->advise_before()) {
$this->runIndexer() or
$this->runSitemapper() or
$this->sendDigest() or
$this->runTrimRecentChanges() or
$this->runTrimRecentChanges(true) or
$evt->advise_after();
}

if(!$output) {
ob_end_clean();
if($defer) {
$this->sendGIF();
}
}
}

/**
* Just send a 1x1 pixel blank gif to the browser
*
* @author Andreas Gohr <andi@splitbrain.org>
* @author Harry Fuecks <fuecks@gmail.com>
*/
protected function sendGIF()
{
$img = base64_decode('R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAEALAAAAAABAAEAAAIBTAA7');
header('Content-Type: image/gif');
header('Content-Length: '.strlen($img));
header('Connection: Close');
print $img;
tpl_flush();
// Browser should drop connection after this
// Thinks it's got the whole image
}

/**
* Trims the recent changes cache (or imports the old changelog) as needed.
*
* @param bool $media_changes If the media changelog shall be trimmed instead of
* the page changelog
*
* @return bool
* @triggers TASK_RECENTCHANGES_TRIM
* @author Ben Coburn <btcoburn@silicodon.net>
*/
protected function runTrimRecentChanges($media_changes = false)
{
global $conf;

echo "runTrimRecentChanges($media_changes): started" . NL;

$fn = ($media_changes ? $conf['media_changelog'] : $conf['changelog']);

// Trim the Recent Changes
// Trims the recent changes cache to the last $conf['changes_days'] recent
// changes or $conf['recent'] items, which ever is larger.
// The trimming is only done once a day.
if (file_exists($fn) &&
(@filemtime($fn . '.trimmed') + 86400) < time() &&
!file_exists($fn . '_tmp')) {
@touch($fn . '.trimmed');
io_lock($fn);
$lines = file($fn);
if (count($lines) <= $conf['recent']) {
// nothing to trim
io_unlock($fn);
echo "runTrimRecentChanges($media_changes): finished" . NL;
return false;
}

io_saveFile($fn . '_tmp', ''); // presave tmp as 2nd lock
$trim_time = time() - $conf['recent_days'] * 86400;
$out_lines = [];
$old_lines = [];
for ($i = 0; $i < count($lines); $i++) {
$log = parseChangelogLine($lines[$i]);
if ($log === false) {
continue;
} // discard junk
if ($log['date'] < $trim_time) {
$old_lines[$log['date'] . ".$i"] = $lines[$i]; // keep old lines for now (append .$i to prevent key collisions)
} else {
$out_lines[$log['date'] . ".$i"] = $lines[$i]; // definitely keep these lines
}
}

if (count($lines) == count($out_lines)) {
// nothing to trim
@unlink($fn . '_tmp');
io_unlock($fn);
echo "runTrimRecentChanges($media_changes): finished" . NL;
return false;
}

// sort the final result, it shouldn't be necessary,
// however the extra robustness in making the changelog cache self-correcting is worth it
ksort($out_lines);
$extra = $conf['recent'] - count($out_lines); // do we need extra lines do bring us up to minimum
if ($extra > 0) {
ksort($old_lines);
$out_lines = array_merge(array_slice($old_lines, -$extra), $out_lines);
}

$eventData = [
'isMedia' => $media_changes,
'trimmedChangelogLines' => $out_lines,
'removedChangelogLines' => $extra > 0 ? array_slice($old_lines, 0, -$extra) : $old_lines,
];
trigger_event('TASK_RECENTCHANGES_TRIM', $eventData);
$out_lines = $eventData['trimmedChangelogLines'];

// save trimmed changelog
io_saveFile($fn . '_tmp', implode('', $out_lines));
@unlink($fn);
if (!rename($fn . '_tmp', $fn)) {
// rename failed so try another way...
io_unlock($fn);
io_saveFile($fn, implode('', $out_lines));
@unlink($fn . '_tmp');
} else {
io_unlock($fn);
}
echo "runTrimRecentChanges($media_changes): finished" . NL;
return true;
}

// nothing done
echo "runTrimRecentChanges($media_changes): finished" . NL;
return false;
}


/**
* Runs the indexer for the current page
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
protected function runIndexer()
{
global $ID;
global $conf;
print 'runIndexer(): started' . NL;

if (!$ID) {
return false;
}

// do the work
return idx_addPage($ID, true);
}

/**
* Builds a Google Sitemap of all public pages known to the indexer
*
* The map is placed in the root directory named sitemap.xml.gz - This
* file needs to be writable!
*
* @author Andreas Gohr
* @link https://www.google.com/webmasters/sitemaps/docs/en/about.html
*/
protected function runSitemapper()
{
print 'runSitemapper(): started' . NL;
$result = Sitemapper::generate() && Sitemapper::pingSearchEngines();
print 'runSitemapper(): finished' . NL;
return $result;
}

/**
* Send digest and list mails for all subscriptions which are in effect for the
* current page
*
* @author Adrian Lang <lang@cosmocode.de>
*/
protected function sendDigest()
{
global $conf;
global $ID;

echo 'sendDigest(): started' . NL;
if (!actionOK('subscribe')) {
echo 'sendDigest(): disabled' . NL;
return false;
}
$sub = new Subscription();
$sent = $sub->send_bulk($ID);

echo "sendDigest(): sent $sent mails" . NL;
echo 'sendDigest(): finished' . NL;
return (bool)$sent;
}
}
7 changes: 7 additions & 0 deletions inc/lang/cs/lang.php
Expand Up @@ -3,6 +3,7 @@
/**
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
*
* @author Martin Hořínek <hev@hev.cz>
* @author Jonáš Dyba <jonas.dyba@gmail.com>
* @author Bohumir Zamecnik <bohumir@zamecnik.org>
* @author Tomas Valenta <t.valenta@sh.cvut.cz>
Expand Down Expand Up @@ -81,7 +82,9 @@
$lang['minoredit'] = 'Drobné změny';
$lang['draftdate'] = 'Koncept automaticky uložen v';
$lang['nosecedit'] = 'Stránka byla v mezičase změněna. Informace o sekci již nebylo platné, byla načtena celá stránka.';
$lang['searchcreatepage'] = 'Pokud jste nenašli to, co jste hledali, můžete vytvořit nebo upravit stránku% s, pojmenovanou podle vašeho dotazu.';
$lang['search_fullresults'] = 'Fulltextové výsledky';
$lang['js']['search_toggle_tools'] = 'Zobrazit/skrýt vyhledávací nástroje';
$lang['js']['willexpire'] = 'Váš zámek pro editaci za chvíli vyprší.\nAbyste předešli konfliktům, stiskněte tlačítko Náhled a zámek se prodlouží.';
$lang['js']['notsavedyet'] = 'Jsou tu neuložené změny, které budou ztraceny.
Chcete opravdu pokračovat?';
Expand Down Expand Up @@ -125,13 +128,17 @@
$lang['js']['media_drop'] = 'Sem přetáhněte soubory pro nahrátí';
$lang['js']['media_cancel'] = 'odstranit';
$lang['js']['media_overwrt'] = 'Přepsat existující soubory';
$lang['search_exact_match'] = 'Přesná shoda';
$lang['search_starts_with'] = 'Začíná s';
$lang['search_ends_with'] = 'Končí s';
$lang['search_contains'] = 'Obsahuje';
$lang['search_custom_match'] = 'Vlastní';
$lang['search_any_ns'] = 'Jakýkoliv jmenný prostor';
$lang['search_any_time'] = 'Jakýkoliv čas';
$lang['search_past_7_days'] = 'Minulý týden';
$lang['search_past_month'] = 'Minulý měsíc';
$lang['search_past_year'] = 'Minulý rok';
$lang['search_sort_by_hits'] = 'Řadit podle shody';
$lang['search_sort_by_mtime'] = 'Řadit podle naposledy změněných';
$lang['regmissing'] = 'Musíte vyplnit všechny údaje.';
$lang['reguexists'] = 'Uživatel se stejným jménem už je zaregistrován.';
Expand Down
6 changes: 6 additions & 0 deletions inc/lang/it/lang.php
Expand Up @@ -3,6 +3,7 @@
/**
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
*
* @author Stefano <stefano.stefano@gmail.com>
* @author damiano <damiano@spagnuolo.eu>
* @author Torpedo <dgtorpedo@gmail.com>
* @author Giorgio Vecchiocattivi <giorgio@vecchio.it>
Expand Down Expand Up @@ -135,6 +136,11 @@
$lang['search_custom_match'] = 'Personalizza';
$lang['search_any_ns'] = 'Qualsiasi spazio dei nomi';
$lang['search_any_time'] = 'Ogni volta';
$lang['search_past_7_days'] = 'scorsa settimana';
$lang['search_past_month'] = 'scorso mese';
$lang['search_past_year'] = 'scorso anno';
$lang['search_sort_by_hits'] = 'ordinato per selezione';
$lang['search_sort_by_mtime'] = 'ordinato per ultima modifica';
$lang['regmissing'] = 'Devi riempire tutti i campi.';
$lang['reguexists'] = 'Il nome utente inserito esiste già.';
$lang['regsuccess'] = 'L\'utente è stato creato. La password è stata spedita via email.';
Expand Down

0 comments on commit de33cda

Please sign in to comment.