File indexing completed on 2025-01-05 03:53:37
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2011-03-22 0007 * Description : a Iface C++ interface 0008 * 0009 * SPDX-FileCopyrightText: 2011-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0010 * SPDX-FileCopyrightText: 2011 by Hormiere Guillaume <hormiere dot guillaume at gmail dot com> 0011 * SPDX-FileCopyrightText: 2011 by Manuel Campomanes <campomanes dot manuel at gmail dot com> 0012 * 0013 * SPDX-License-Identifier: GPL-2.0-or-later 0014 * 0015 * ============================================================ */ 0016 0017 #include "mediawiki_querysiteinfogeneral.h" 0018 0019 // Qt includes 0020 0021 #include <QTimer> 0022 #include <QUrl> 0023 #include <QUrlQuery> 0024 #include <QXmlStreamReader> 0025 #include <QNetworkAccessManager> 0026 #include <QNetworkReply> 0027 #include <QNetworkRequest> 0028 0029 // Local includes 0030 0031 #include "mediawiki_iface.h" 0032 #include "mediawiki_job_p.h" 0033 0034 namespace MediaWiki 0035 { 0036 0037 class Q_DECL_HIDDEN QuerySiteInfoGeneralPrivate : public JobPrivate 0038 { 0039 public: 0040 0041 explicit QuerySiteInfoGeneralPrivate(Iface& MediaWiki) 0042 : JobPrivate(MediaWiki) 0043 { 0044 } 0045 }; 0046 0047 QuerySiteInfoGeneral::QuerySiteInfoGeneral(Iface& MediaWiki, QObject* const /*parent*/) 0048 : Job(*new QuerySiteInfoGeneralPrivate(MediaWiki)) 0049 { 0050 } 0051 0052 QuerySiteInfoGeneral::~QuerySiteInfoGeneral() 0053 { 0054 } 0055 0056 void QuerySiteInfoGeneral::start() 0057 { 0058 QTimer::singleShot(0, this, SLOT(doWorkSendRequest())); 0059 } 0060 0061 void QuerySiteInfoGeneral::doWorkSendRequest() 0062 { 0063 Q_D(QuerySiteInfoGeneral); 0064 0065 // Set the url 0066 QUrl url = d->MediaWiki.url(); 0067 QUrlQuery query; 0068 query.addQueryItem(QStringLiteral("format"), QStringLiteral("xml")); 0069 query.addQueryItem(QStringLiteral("action"), QStringLiteral("query")); 0070 query.addQueryItem(QStringLiteral("meta"), QStringLiteral("siteinfo")); 0071 query.addQueryItem(QStringLiteral("siprop"), QStringLiteral("general")); 0072 url.setQuery(query); 0073 0074 // Set the request 0075 QNetworkRequest request(url); 0076 request.setRawHeader("User-Agent", d->MediaWiki.userAgent().toUtf8()); 0077 0078 // Send the request 0079 d->reply = d->manager->get(request); 0080 connectReply(); 0081 0082 connect(d->reply, SIGNAL(finished()), 0083 this, SLOT(doWorkProcessReply())); 0084 } 0085 0086 void QuerySiteInfoGeneral::doWorkProcessReply() 0087 { 0088 Q_D(QuerySiteInfoGeneral); 0089 0090 disconnect(d->reply, SIGNAL(finished()), 0091 this, SLOT(doWorkProcessReply())); 0092 0093 if (d->reply->error() != QNetworkReply::NoError) 0094 { 0095 this->setError(Job::NetworkError); 0096 d->reply->close(); 0097 d->reply->deleteLater(); 0098 emitResult(); 0099 return; 0100 } 0101 0102 Generalinfo generalinfo; 0103 QXmlStreamReader reader(d->reply); 0104 0105 while(!reader.atEnd() && !reader.hasError()) 0106 { 0107 QXmlStreamReader::TokenType token = reader.readNext(); 0108 0109 if (token == QXmlStreamReader::StartElement) 0110 { 0111 if (reader.name() == QLatin1String("general")) 0112 { 0113 generalinfo.setMainPage(reader.attributes().value(QStringLiteral("mainpage")).toString()); 0114 generalinfo.setUrl(QUrl::fromEncoded(reader.attributes().value(QStringLiteral("base")).toString().toLocal8Bit())); 0115 generalinfo.setSiteName(reader.attributes().value(QStringLiteral("sitename")).toString()); 0116 generalinfo.setGenerator(reader.attributes().value(QStringLiteral("generator")).toString()); 0117 generalinfo.setPhpVersion(reader.attributes().value(QStringLiteral("phpversion")).toString()); 0118 generalinfo.setPhpApi(reader.attributes().value(QStringLiteral("phpsapi")).toString()); 0119 generalinfo.setDataBaseType(reader.attributes().value(QStringLiteral("dbtype")).toString()); 0120 generalinfo.setDataBaseVersion(reader.attributes().value(QStringLiteral("dbversion")).toString()); 0121 generalinfo.setRev(reader.attributes().value(QStringLiteral("rev")).toString()); 0122 generalinfo.setCas(reader.attributes().value(QStringLiteral("case")).toString()); 0123 generalinfo.setLicense(reader.attributes().value(QStringLiteral("rights")).toString()); 0124 generalinfo.setLanguage(reader.attributes().value(QStringLiteral("lang")).toString()); 0125 generalinfo.setFallBack8bitEncoding(reader.attributes().value(QStringLiteral("fallback8bitEncoding")).toString()); 0126 generalinfo.setWriteApi(reader.attributes().value(QStringLiteral("writeapi")).toString()); 0127 generalinfo.setTimeZone(reader.attributes().value(QStringLiteral("timezone")).toString()); 0128 generalinfo.setTimeOffset(reader.attributes().value(QStringLiteral("timeoffset")).toString()); 0129 generalinfo.setArticlePath(reader.attributes().value(QStringLiteral("articlepath")).toString()); 0130 generalinfo.setScriptPath(reader.attributes().value(QStringLiteral("scriptpath")).toString()); 0131 generalinfo.setScript(reader.attributes().value(QStringLiteral("script")).toString()); 0132 generalinfo.setVariantArticlePath(reader.attributes().value(QStringLiteral("variantarticlepath")).toString()); 0133 generalinfo.setServerUrl(QUrl::fromEncoded(reader.attributes().value(QStringLiteral("server")).toString().toLocal8Bit())); 0134 generalinfo.setWikiId(reader.attributes().value(QStringLiteral("wikiid")).toString()); 0135 generalinfo.setTime(QDateTime::fromString(reader.attributes().value(QStringLiteral("time")).toString(), QStringLiteral("yyyy-MM-dd'T'hh:mm:ss'Z'"))); 0136 } 0137 else if (reader.name() == QLatin1String("error")) 0138 { 0139 this->setError(QuerySiteInfoGeneral::IncludeAllDenied); 0140 d->reply->close(); 0141 d->reply->deleteLater(); 0142 emitResult(); 0143 return; 0144 } 0145 } 0146 } 0147 0148 if (reader.hasError()) 0149 { 0150 this->setError(Job::XmlError); 0151 } 0152 else 0153 { 0154 Q_EMIT result(generalinfo); 0155 this->setError(Job::NoError); 0156 } 0157 0158 d->reply->close(); 0159 d->reply->deleteLater(); 0160 emitResult(); 0161 } 0162 0163 } // namespace MediaWiki 0164 0165 #include "moc_mediawiki_querysiteinfogeneral.cpp"