Exemple #1
0
void Core::LoadDefs()
{
    QFile defs(Configuration::GetConfigurationPath() + "users.xml");
    if (QFile(Configuration::GetConfigurationPath() + "users.xml~").exists())
    {
        Huggle::Syslog::HuggleLogs->Log("WARNING: recovering definitions from last session");
        QFile(Configuration::GetConfigurationPath() + "users.xml").remove();
        if (QFile(Configuration::GetConfigurationPath() + "users.xml~").copy(Configuration::GetConfigurationPath() + "users.xml"))
        {
            QFile().remove(Configuration::GetConfigurationPath() + "users.xml~");
        } else
        {
            Huggle::Syslog::HuggleLogs->Log("WARNING: Unable to recover the definitions");
        }
    }
    if (!defs.exists())
    {
        return;
    }
    defs.open(QIODevice::ReadOnly);
    QString Contents(defs.readAll());
    QDomDocument list;
    list.setContent(Contents);
    QDomNodeList l = list.elementsByTagName("user");
    if (l.count() > 0)
    {
        int i=0;
        while (i<l.count())
        {
            WikiUser *user;
            QDomElement e = l.at(i).toElement();
            if (!e.attributes().contains("name"))
            {
                i++;
                continue;
            }
            user = new WikiUser();
            user->Username = e.attribute("name");
            if (e.attributes().contains("badness"))
            {
                // do not resync this user while we init the db, this is first time it's written to it so there is no point in that
                user->SetBadnessScore(e.attribute("badness").toInt(), false, false);
            }
            WikiUser::ProblematicUsers.append(user);
            i++;
        }
    }
    HUGGLE_DEBUG1("Loaded " + QString::number(WikiUser::ProblematicUsers.count()) + " records from last session");
    defs.close();
}
Exemple #2
0
void WikiUser::TrimProblematicUsersList()
{
    WikiUser::ProblematicUserListLock.lock();
    int i = 0;
    while (i < WikiUser::ProblematicUsers.count())
    {
        WikiUser *user = WikiUser::ProblematicUsers.at(i);
        if (user->GetBadnessScore() == 0 && user->WarningLevel == 0)
        {
            // there is no point to hold information for them
            WikiUser::ProblematicUsers.removeAt(i);
            delete user;
            continue;
        }
        i++;
    }
    WikiUser::ProblematicUserListLock.unlock();
}
Exemple #3
0
void WikiUser::Resync()
{
    WikiUser::ProblematicUserListLock.lock();
    WikiUser *user = WikiUser::RetrieveUser(this);
    if (user)
    {
        this->BadnessScore = user->BadnessScore;
        this->ContentsOfTalkPage = user->TalkPage_GetContents();
        this->_talkPageWasRetrieved = user->_talkPageWasRetrieved;
        this->DateOfTalkPage = user->DateOfTalkPage;
        if (user->WarningLevel > this->WarningLevel)
            this->WarningLevel = user->WarningLevel;
        if (this->EditCount < 0)
            this->EditCount = user->EditCount;
    }
    // we can finally unlock it
    WikiUser::ProblematicUserListLock.unlock();
}
Exemple #4
0
QString WikiUser::TalkPage_GetContents()
{
    // first we need to lock this object because it might be accessed from another thread in same moment
    this->UserLock->lock();
    // check if there isn't some global talk page
    WikiUser *user = WikiUser::RetrieveUser(this);
    // we need to copy the value to local variable so that if someone change it from different
    // thread we are still working with same data
    QString contents = "";
    if (user != nullptr && user->TalkPage_WasRetrieved())
    {
        // we return a value of user from global db instead of local
        contents = user->ContentsOfTalkPage;
        this->UserLock->unlock();
        return contents;
    }
    contents = this->ContentsOfTalkPage;
    this->UserLock->unlock();
    return contents;
}
Exemple #5
0
void HistoryForm::onTick01()
{
    if (this->CurrentEdit == nullptr)
        throw new Huggle::NullPointerException("local WikiEdit CurrentEdit", BOOST_CURRENT_FUNCTION);

    if (this->RetrievingEdit && this->RetrievedEdit != nullptr)
    {
        if (this->RetrievedEdit->IsPostProcessed())
        {
            MainWindow::HuggleMain->ProcessEdit(this->RetrievedEdit, false, true);
            this->RetrievingEdit = false;
            this->RetrievedEdit = nullptr;
            this->t1->stop();
            this->MakeSelectedRowBold();
            MainWindow::HuggleMain->wEditBar->RefreshPage();
        }
        return;
    }

    if (this->query == nullptr || !this->query->IsProcessed())
        return;

    if (this->query->IsFailed())
    {
        this->ui->pushButton->setEnabled(true);
        Huggle::Syslog::HuggleLogs->ErrorLog(_l("history-failure"));
        this->query = nullptr;
        this->t1->stop();
        return;
    }
    bool IsLatest = false;
    QList<ApiQueryResultNode*> revision_data = this->query->GetApiQueryResult()->GetNodes("rev");
    int x = 0;
    while (x < revision_data.count())
    {
        ApiQueryResultNode *rv = revision_data.at(x);
        WikiPageHistoryItem *item = new WikiPageHistoryItem(this->query->GetSite());
        if (rv->Attributes.contains("revid"))
        {
            item->RevID = rv->GetAttribute("revid");
        }
        else
        {
            x++;
            continue;
        }
        bool founder = false;
        item->Name = this->CurrentEdit->Page->PageName;
        item->Site = this->CurrentEdit->GetSite();
        if (rv->Attributes.contains("user"))
            item->User = rv->GetAttribute("user");
        if (rv->Attributes.contains("size"))
            item->Size = rv->GetAttribute("size");
        if (rv->Attributes.contains("timestamp"))
            item->Date = rv->GetAttribute("timestamp");
        if (rv->Attributes.contains("comment") && !rv->GetAttribute("comment").isEmpty())
            item->Summary = rv->GetAttribute("comment");
        this->ui->tableWidget->insertRow(x);
        QIcon icon(":/huggle/pictures/Resources/blob-none.png");
        if (this->CurrentEdit->Page->FounderKnown() && WikiUser::CompareUsernames(item->User, this->CurrentEdit->Page->GetFounder()))
            founder = true;
        if (WikiUtil::IsRevert(item->Summary))
        {
            item->Type = EditType_Revert;
            icon = QIcon(":/huggle/pictures/Resources/blob-revert.png");
        }
        else if (WikiUser::IsIPv6(item->User) || WikiUser::IsIPv4(item->User))
        {
            item->Type = EditType_Anon;
            icon = QIcon(":/huggle/pictures/Resources/blob-anon.png");
        }
        else if (this->CurrentEdit->GetSite()->GetProjectConfig()->WhiteList.contains(item->User))
        {
            item->Type = EditType_W;
            icon = QIcon(":/huggle/pictures/Resources/blob-ignored.png");
        }
        WikiUser *wu = WikiUser::RetrieveUser(item->User, item->Site);
        if (wu != nullptr)
        {
            if (wu->IsReported)
            {
                item->Type = EditType_Reported;
                icon = QIcon(":/huggle/pictures/Resources/blob-reported.png");
            }
            else if (wu->GetWarningLevel() > 0)
            {
                switch (wu->GetWarningLevel())
                {
                case 1:
                    item->Type = EditType_1;
                    icon = QIcon(":/huggle/pictures/Resources/blob-warn-1.png");
                    break;
                case 2:
                    item->Type = EditType_2;
                    icon = QIcon(":/huggle/pictures/Resources/blob-warn-2.png");
                    break;
                case 3:
                    item->Type = EditType_3;
                    icon = QIcon(":/huggle/pictures/Resources/blob-warn-3.png");
                    break;
                case 4:
                    item->Type = EditType_4;
                    icon = QIcon(":/huggle/pictures/Resources/blob-warn-4.png");
                    break;
                }
            }
        }
        bool selected = this->CurrentEdit->RevID == item->RevID.toInt();
        if (selected && x == 0)
            IsLatest = true;
        item->IsCurrent = true;
        if (selected)
            this->SelectedRow = x;
        QFont font;
        font.setItalic(founder);
        font.setBold(selected);
        QTableWidgetItem *i = new QTableWidgetItem(icon, "");
        this->ui->tableWidget->setItem(x, 0, i);
        i = new QTableWidgetItem(item->User);
        i->setFont(font);
        this->ui->tableWidget->setItem(x, 1, i);
        i = new QTableWidgetItem(item->Size);
        i->setFont(font);
        this->ui->tableWidget->setItem(x, 2, i);
        i = new QTableWidgetItem(item->Summary);
        i->setFont(font);
        this->ui->tableWidget->setItem(x, 3, i);
        i = new QTableWidgetItem(item->Date);
        i->setFont(font);
        this->ui->tableWidget->setItem(x, 4, i);
        i = new QTableWidgetItem(item->RevID);
        i->setFont(font);
        this->ui->tableWidget->setItem(x, 5, i);
        this->Items.append(item);
        x++;
    }
    this->ui->tableWidget->resizeRowsToContents();
    this->query = nullptr;
    this->t1->stop();
    if (!this->CurrentEdit->NewPage && !Configuration::HuggleConfiguration->ForceNoEditJump && !IsLatest)
    {
        if (Configuration::HuggleConfiguration->UserConfig->LastEdit)
        {
            this->Display(0, Resources::Html_StopFire, true);
            return;
        }
        else
        {
            QPoint pntr(0, this->pos().y());
            if (this->pos().x() > 400)
                pntr.setX(this->pos().x() - 200);
            else
                pntr.setX(this->pos().x() + 100);

            if (hcfg->UserConfig->ShowWarningIfNotOnLastRevision)
                QToolTip::showText(pntr, "<b><big>" + _l("historyform-not-latest-tip") + "</big></b>", this);
        }
    }
    if (hcfg->UserConfig->AutomaticallyGroup)
    {
        // Check if edits made around of this one weren't made by same user
        // in case they were we need to display a range of them
        QString user = this->CurrentEdit->User->Username;
        int RangeStart = this->SelectedRow;
        int RangeEnd = this->SelectedRow;
        int row = this->SelectedRow;
        while (row > 0)
        {
            if (user != this->ui->tableWidget->item(row - 1, 1)->text())
                break;
            row--;
        }
        RangeStart = row;
        row = this->SelectedRow;
        while (row < (this->ui->tableWidget->rowCount() - 1))
        {
            if (user != this->ui->tableWidget->item(row + 1, 1)->text())
                break;
            row++;
        }
        RangeEnd = row;
        if (RangeStart != RangeEnd)
        {
            QItemSelectionModel *selectionModel = this->ui->tableWidget->selectionModel();
            row = RangeStart;
            this->IgnoreSelectionChanges = true;
            this->ui->tableWidget->clearSelection();
            QItemSelection itemSelection = selectionModel->selection();
            while (row <= RangeEnd)
            {
                this->ui->tableWidget->selectRow(row++);
                itemSelection.merge(selectionModel->selection(), QItemSelectionModel::Select);
            }
            selectionModel->clearSelection();
            this->IgnoreSelectionChanges = false;
            selectionModel->select(itemSelection, QItemSelectionModel::Select);
        }
    }
    this->IgnoreSelectionChanges = false;
    MainWindow::HuggleMain->wEditBar->RefreshPage();
}
void HistoryForm::onTick01()
{
    if (this->CurrentEdit == nullptr)
        throw new Huggle::NullPointerException("local WikiEdit CurrentEdit", BOOST_CURRENT_FUNCTION);

    if (this->RetrievingEdit && this->RetrievedEdit != nullptr)
    {
        if (this->RetrievedEdit->IsPostProcessed())
        {
            MainWindow::HuggleMain->ProcessEdit(this->RetrievedEdit, false, true);
            this->RetrievingEdit = false;
            this->RetrievedEdit = nullptr;
            this->t1->stop();
            this->MakeSelectedRowBold();
            MainWindow::HuggleMain->wEditBar->RefreshPage();
        }
        return;
    }

    if (this->query == nullptr || !this->query->IsProcessed())
        return;

    if (this->query->IsFailed())
    {
        this->ui->pushButton->setEnabled(true);
        Huggle::Syslog::HuggleLogs->ErrorLog(_l("history-failure"));
        this->query = nullptr;
        this->t1->stop();
        return;
    }
    bool IsLatest = false;
    QList<ApiQueryResultNode*>revision_data = this->query->GetApiQueryResult()->GetNodes("rev");
    int x=0;
    QColor xb;
    bool xt = false;
    while (x < revision_data.count())
    {
        if (xt)
        {
            xb = QColor(206, 202, 250);
        } else
        {
            xb = QColor(224, 222, 250);
        }
        xt = !xt;
        ApiQueryResultNode *rv = revision_data.at(x);
        WikiPageHistoryItem *item = new WikiPageHistoryItem();
        if (rv->Attributes.contains("revid"))
        {
            item->RevID = rv->GetAttribute("revid");
        } else
        {
            x++;
            continue;
        }
        item->Name = this->CurrentEdit->Page->PageName;
        item->Site = this->CurrentEdit->GetSite();
        if (rv->Attributes.contains("user"))
            item->User = rv->GetAttribute("user");
        if (rv->Attributes.contains("size"))
            item->Size = rv->GetAttribute("size");
        if (rv->Attributes.contains("timestamp"))
            item->Date = rv->GetAttribute("timestamp");
        if (rv->Attributes.contains("comment") && !rv->GetAttribute("comment").isEmpty())
            item->Summary = rv->GetAttribute("comment");
        this->ui->tableWidget->insertRow(x);
        QIcon icon(":/huggle/pictures/Resources/blob-none.png");
        if (WikiUtil::IsRevert(item->Summary))
        {
            item->Type = EditType_Revert;
            icon = QIcon(":/huggle/pictures/Resources/blob-revert.png");
        }
        else if (WikiUser::IsIPv6(item->User) || WikiUser::IsIPv4(item->User))
        {
            item->Type = EditType_Anon;
            icon = QIcon(":/huggle/pictures/Resources/blob-anon.png");
        }
        else if (this->CurrentEdit->GetSite()->GetProjectConfig()->WhiteList.contains(item->User))
        {
            item->Type = EditType_W;
            icon = QIcon(":/huggle/pictures/Resources/blob-ignored.png");
        }
        WikiUser *wu = WikiUser::RetrieveUser(item->User, item->Site);
        if (wu != nullptr)
        {
            if (wu->IsReported)
            {
                item->Type = EditType_Reported;
                icon = QIcon(":/huggle/pictures/Resources/blob-reported.png");
            } else if (wu->GetWarningLevel() > 0)
            {
                switch(wu->GetWarningLevel())
                {
                    case 1:
                        item->Type = EditType_1;
                        icon = QIcon(":/huggle/pictures/Resources/blob-warn-1.png");
                        break;
                    case 2:
                        item->Type = EditType_2;
                        icon = QIcon(":/huggle/pictures/Resources/blob-warn-2.png");
                        break;
                    case 3:
                        item->Type = EditType_3;
                        icon = QIcon(":/huggle/pictures/Resources/blob-warn-3.png");
                        break;
                    case 4:
                        item->Type = EditType_4;
                        icon = QIcon(":/huggle/pictures/Resources/blob-warn-4.png");
                        break;
                }
            }
        }
        if (this->CurrentEdit->RevID == item->RevID.toInt())
        {
            if (x == 0)
                IsLatest = true;
            item->IsCurrent = true;
            this->SelectedRow = x;
            QFont font;
            font.setBold(true);
            QTableWidgetItem *i = new QTableWidgetItem(icon, "");
            i->setBackgroundColor(xb);
            this->ui->tableWidget->setItem(x, 0, i);
            i = new QTableWidgetItem(item->User);
            i->setFont(font);
            i->setBackgroundColor(xb);
            this->ui->tableWidget->setItem(x, 1, i);
            i = new QTableWidgetItem(item->Size);
            i->setFont(font);
            i->setBackgroundColor(xb);
            this->ui->tableWidget->setItem(x, 2, i);
            i = new QTableWidgetItem(item->Summary);
            i->setFont(font);
            i->setBackgroundColor(xb);
            this->ui->tableWidget->setItem(x, 3, i);
            i = new QTableWidgetItem(item->RevID);
            i->setFont(font);
            i->setBackgroundColor(xb);
            this->ui->tableWidget->setItem(x, 4, i);
            i = new QTableWidgetItem(item->Date);
            i->setFont(font);
            i->setBackgroundColor(xb);
            this->ui->tableWidget->setItem(x, 5, i);
        } else
        {
            QTableWidgetItem *i = new QTableWidgetItem(icon, "");
            i->setBackgroundColor(xb);
            this->ui->tableWidget->setItem(x, 0, i);
            i = new QTableWidgetItem(item->User);
            i->setBackgroundColor(xb);
            this->ui->tableWidget->setItem(x, 1, i);
            i = new QTableWidgetItem(item->Size);
            i->setBackgroundColor(xb);
            this->ui->tableWidget->setItem(x, 2, i);
            i = new QTableWidgetItem(item->Summary);
            i->setBackgroundColor(xb);
            this->ui->tableWidget->setItem(x, 3, i);
            i = new QTableWidgetItem(item->RevID);
            i->setBackgroundColor(xb);
            this->ui->tableWidget->setItem(x, 4, i);
            i = new QTableWidgetItem(item->Date);
            i->setBackgroundColor(xb);
            this->ui->tableWidget->setItem(x, 5, i);
        }
        this->Items.append(item);
        x++;
    }
    this->ui->tableWidget->resizeRowsToContents();
    this->query = nullptr;
    this->t1->stop();
    if (!this->CurrentEdit->NewPage && !Configuration::HuggleConfiguration->ForcedNoEditJump && !IsLatest)
    {
        if (Configuration::HuggleConfiguration->UserConfig->LastEdit)
        {
            this->Display(0, Resources::Html_StopFire, true);
        } else
        {
            QPoint pntr(0, this->pos().y());
            if (this->pos().x() > 400)
                pntr.setX(this->pos().x() - 200);
            else
                pntr.setX(this->pos().x() + 100);

            // display a tip
            QToolTip::showText(pntr, "<b><big>" + _l("historyform-not-latest-tip") + "</big></b>", this);
        }
    }
    MainWindow::HuggleMain->wEditBar->RefreshPage();
}