void HuggleFeedProviderWiki::ProcessEdit(QDomElement item) { WikiEdit *edit = new WikiEdit(); edit->Page = new WikiPage(item.attribute("title")); QString type = item.attribute("type"); if (type == "new") edit->NewPage = true; if (item.attributes().contains("newlen") && item.attributes().contains("oldlen")) edit->Size = item.attribute("newlen").toInt() - item.attribute("oldlen").toInt(); if (item.attributes().contains("user")) edit->User = new WikiUser(item.attribute("user")); if (item.attributes().contains("comment")) edit->Summary = item.attribute("comment"); if (item.attributes().contains("bot")) edit->Bot = true; if (item.attributes().contains("anon")) edit->User->ForceIP(); if (item.attributes().contains("revid")) { edit->RevID = QString(item.attribute("revid")).toInt(); if (edit->RevID == 0) { edit->RevID = WIKI_UNKNOWN_REVID; } } if (item.attributes().contains("minor")) edit->Minor = true; edit->IncRef(); this->InsertEdit(edit); }
bool HuggleEditJS::record_score(const QJSValue& edit, const QString& name, int score) { WikiEdit *we = getEdit("record_score(edit, name, score)", edit); if (!we) return false; we->RecordScore("ext_" + this->script->GetName() + "_" + name, static_cast<score_ht>(score)); return true; }
void HistoryForm::GetEdit(long revid, QString prev, QString user, QString html, bool turtlemode) { this->RetrievingEdit = true; Collectable_SmartPtr<WikiEdit> edit = WikiEdit::FromCacheByRevID(revid, prev); if (edit != nullptr) { MainWindow::HuggleMain->ProcessEdit(edit, false, true); this->RetrievingEdit = false; this->MakeSelectedRowBold(); MainWindow::HuggleMain->wEditBar->RefreshPage(); return; } // there is no such edit, let's get it WikiEdit *w = new WikiEdit(); // this is some weird work around for weird logic used somewhere deep in // mediawiki internals if (prev == "prev") { w->DiffTo = prev; w->RevID = revid; } else { w->DiffTo = QString::number(revid); w->RevID = prev.toLongLong(); } w->User = new WikiUser(user); w->User->Site = this->CurrentEdit->GetSite(); w->Page = new WikiPage(this->CurrentEdit->Page); if (QueryPool::HugglePool == nullptr) { // Huggle is shutting down now w->SafeDelete(); return; } QueryPool::HugglePool->PreProcessEdit(w); QueryPool::HugglePool->PostProcessEdit(w); if (this->t1 != nullptr) delete this->t1; this->RetrievedEdit = w; MainWindow::HuggleMain->LockPage(); MainWindow::HuggleMain->Browser->RenderHtml(html); this->t1 = new QTimer(); connect(this->t1, SIGNAL(timeout()), this, SLOT(onTick01())); if (!turtlemode) { this->t1->start(HUGGLE_TIMER); return; } this->t1->start(HUGGLE_TIMER * 10); }
void HuggleFeedProviderIRC::ParseEdit(QString line) { // skip edits if provider is disabled if (this->Paused) { return; } if (!line.contains(QString(QChar(003)) + "07")) { HUGGLE_DEBUG("Invalid line (no07):" + line, 1); return; } line = line.mid(line.indexOf(QString(QChar(003)) + "07") + 3); if (!line.contains(QString(QChar(003)) + "14")) { HUGGLE_DEBUG("Invalid line (no14):" + line, 1); return; } WikiEdit *edit = new WikiEdit(); edit->Page = new WikiPage(line.mid(0, line.indexOf(QString(QChar(003)) + "14"))); edit->IncRef(); if (!line.contains(QString(QChar(003)) + "4 ")) { HUGGLE_DEBUG("Invalid line (no:x4:" + line, 1); edit->DecRef(); return; } line = line.mid(line.indexOf(QString(QChar(003)) + "4 ") + 2); QString flags = line.mid(0, line.indexOf(QChar(003))); edit->Bot = flags.contains("B"); edit->NewPage = flags.contains("N"); edit->Minor = flags.contains("M"); // this below looks like a nasty hack to filter out just what we need // but I will later use all of these actions for something too if (flags.contains("thank") || flags.contains("modify") || flags.contains("rights") || flags.contains("review") || flags.contains("block") || flags.contains("protect") || flags.contains("reblock") || flags.contains("unhelpful") || flags.contains("helpful") || flags.contains("approve") || flags.contains("resolve") || flags.contains("upload") || flags.contains("feature") || flags.contains("noaction") || flags.contains("selfadd") || flags.contains("overwrite") || flags.contains("create") || flags.contains("delete") || flags.contains("restore") || flags.contains("move") || flags.contains("tag") || /* abuse filter */flags.contains("hit") || flags.contains("patrol") || flags.contains("revision")) { edit->DecRef(); return; } if (!edit->NewPage) { if (!line.contains("?diff=")) { HUGGLE_DEBUG("Invalid line (flags: " + flags + ") (no diff):" + line, 1); edit->DecRef(); return; } line = line.mid(line.indexOf("?diff=") + 6); if (!line.contains("&")) { HUGGLE_DEBUG("Invalid line (no &):" + line, 1); edit->DecRef(); return; } edit->Diff = line.mid(0, line.indexOf("&")).toInt(); edit->RevID = line.mid(0, line.indexOf("&")).toInt(); } if (!line.contains("oldid=")) { HUGGLE_DEBUG("Invalid line (no oldid?):" + line, 1); edit->DecRef(); return; } line = line.mid(line.indexOf("oldid=") + 6); if (!line.contains(QString(QChar(003)))) { HUGGLE_DEBUG("Invalid line (no termin):" + line, 1); edit->DecRef(); return; } edit->OldID = line.mid(0, line.indexOf(QString(QChar(003)))).toInt(); if (!line.contains(QString(QChar(003)) + "03")) { HUGGLE_DEBUG("Invalid line, no user: "******"03") + 3); if (!line.contains(QString(QChar(3)))) { HUGGLE_DEBUG("Invalid line (no termin):" + line, 1); edit->DecRef(); return; } QString name = line.mid(0, line.indexOf(QString(QChar(3)))); if (name.length() <= 0) { edit->DecRef(); return; } edit->User = new WikiUser(name); if (line.contains(QString(QChar(3)) + " (")) { line = line.mid(line.indexOf(QString(QChar(3)) + " (") + 3); if (line.contains(")")) { QString xx = line.mid(0, line.indexOf(")")); xx = xx.replace("\002", ""); int size = 0; if (xx.startsWith("+")) { xx = xx.mid(1); size = xx.toInt(); edit->Size = size; } else if (xx.startsWith("-")) { xx = xx.mid(1); size = xx.toInt() * -1; edit->Size = size; } else { HUGGLE_DEBUG("No size information for " + edit->Page->PageName, 1); } }else { HUGGLE_DEBUG("No size information for " + edit->Page->PageName, 1); } } else { HUGGLE_DEBUG("No size information for " + edit->Page->PageName, 1); } if (line.contains(QString(QChar(3)) + "10")) { line = line.mid(line.indexOf(QString(QChar(3)) + "10") + 3); if (line.contains(QString(QChar(3)))) { edit->Summary = line.mid(0, line.indexOf(QString(QChar(3)))); } } this->InsertEdit(edit); }
void HuggleQueue::ResortItem(QLayoutItem *item, int position) { HUGGLE_PROFILER_INCRCALL(BOOST_CURRENT_FUNCTION); if (position < 0) { // we don't know the position so we need to calculate it position = 0; while (position < this->ui->itemList->count() - 1) { if (item == this->ui->itemList->itemAt(position)) { break; } position++; } if (position == this->ui->itemList->count() - 1) { HUGGLE_DEBUG("Unable to sort the queue because item wasn't present", 1); return; } } // first we get the item HuggleQueueItemLabel *q1 = (HuggleQueueItemLabel*)item->widget(); int Score = q1->Edit->Score; int x = 0; bool sorted = true; while (x < position) { // every item on left side has to be lower than this one // get the item by index and compare the size QLayoutItem *l2 = this->ui->itemList->itemAt(x); if (l2 != item) { HuggleQueueItemLabel *q2 = (HuggleQueueItemLabel*)l2->widget(); if (q2->Edit->Score < Score) { sorted = false; break; } } x++; } while (x < this->ui->itemList->count() - 1) { // every item on right side has to be bigger than this one // get the item by index and compare the size QLayoutItem *l2 = this->ui->itemList->itemAt(x); if (l2 != item) { HuggleQueueItemLabel *q2 = (HuggleQueueItemLabel*)l2->widget(); // we need to check here if we accidentaly didn't get some // element that actually isn't an item if (q2 != nullptr && q2->Edit->Score > Score) { sorted = false; break; } } x++; } if (!sorted) { // now we need to remove the item and place it again // because QT doesn't allow manual insertion of item for unknown reasons, we need to readd whole item WikiEdit *page = q1->Edit; page->RegisterConsumer("HuggleQueue::ResortItem"); this->DeleteItem(q1); this->AddItem(page); page->UnregisterConsumer("HuggleQueue::ResortItem"); } }
void HistoryForm::Display(int row, QString html, bool turtlemode) { if (row == this->SelectedRow) { // there is nothing to do because we want to display exactly that row which was already selected return; } if (this->query != nullptr || this->RetrievingEdit || this->ui->tableWidget->rowCount() == 0 || this->CurrentEdit == nullptr) { // we must not retrieve edit until previous operation did finish return; } this->PreviouslySelectedRow = this->SelectedRow; this->SelectedRow = row; this->RetrievingEdit = true; // check if we don't have this edit in a buffer int x = 0; int revid = this->ui->tableWidget->item(row, 4)->text().toInt(); if (revid == 0) { this->RetrievingEdit = false; return; } WikiEdit::Lock_EditList->lock(); while (x < WikiEdit::EditList.count()) { WikiEdit *edit = WikiEdit::EditList.at(x); x++; if (edit->RevID == revid) { MainWindow::HuggleMain->ProcessEdit(edit, false, true); this->RetrievingEdit = false; WikiEdit::Lock_EditList->unlock(); this->MakeSelectedRowBold(); return; } } WikiEdit::Lock_EditList->unlock(); // there is no such edit, let's get it WikiEdit *w = new WikiEdit(); w->User = new WikiUser(this->ui->tableWidget->item(row, 1)->text()); w->Page = new WikiPage(this->CurrentEdit->Page); w->RevID = revid; w->RegisterConsumer(HUGGLECONSUMER_HISTORYWIDGET); if (this->RetrievedEdit != nullptr) { this->RetrievedEdit->UnregisterConsumer(HUGGLECONSUMER_HISTORYWIDGET); } QueryPool::HugglePool->PostProcessEdit(w); if (this->t1 != nullptr) { delete this->t1; } this->RetrievedEdit = w; MainWindow::HuggleMain->LockPage(); MainWindow::HuggleMain->Browser->RenderHtml(html); this->t1 = new QTimer(); connect(this->t1, SIGNAL(timeout()), this, SLOT(onTick01())); if (!turtlemode) { this->t1->start(200); return; } this->t1->start(2000); }