JGonera has submitted this change and it was merged.
Change subject: Removes Special:MobileFeedback and associated conf
......................................................................
Removes Special:MobileFeedback and associated conf
Change-Id: I68485a0b70028d322b92b25864465346f9cdc5c7
---
M MobileFrontend.i18n.php
M MobileFrontend.php
D includes/specials/SpecialMobileFeedback.php
3 files changed, 0 insertions(+), 565 deletions(-)
Approvals:
JGonera: Verified; Looks good to me, approved
jenkins-bot: Checked
diff --git a/MobileFrontend.i18n.php b/MobileFrontend.i18n.php
index 4eb7362..540d72d 100644
--- a/MobileFrontend.i18n.php
+++ b/MobileFrontend.i18n.php
@@ -65,34 +65,6 @@
'mobile-frontend-footer-contributors-text' => 'Page by [$1
contributors] like you',
'mobile-frontend-featured-article' => 'Today\'s Featured Article',
'mobile-frontend-news-items' => 'In The News',
- 'mobile-frontend-leave-feedback-notice' => 'Your feedback helps us to
improve your mobile site experience. It will be posted publicly (along with
your user name, browser version and operating system) to the page
"$1". Please try to choose an informative subject line, e.g.
"Formatting issues with wide tables". Your feedback is subject to our terms of
use.',
- 'mobile-frontend-leave-feedback-warning' => 'Unless you agree to have
your information made public, please do not include personal information in
your comments.',
- 'mobile-frontend-leave-feedback-subject' => 'Subject:',
- 'mobile-frontend-leave-feedback-message' => 'Message:',
- 'mobile-frontend-leave-feedback-submit' => 'Submit feedback',
- 'mobile-frontend-leave-feedback-link-text' => 'MobileFrontend Extension
feedback',
- 'mobile-frontend-leave-feedback' => 'Mobile site feedback',
- 'mobile-frontend-leave-feedback-title' => 'Mobile site feedback',
- 'mobile-frontend-leave-feedback-technical-problem-section-header' =>
'Technical problem',
- 'mobile-frontend-leave-feedback-general-section-header' => 'General',
- 'mobile-frontend-leave-feedback-article-feedback-section-header' =>
'Article feedback',
- 'mobile-frontend-leave-feedback-email-body' => 'Please describe the
problem you are experiencing with {{SITENAME}} above this line. Please note
that we cannot reply to every message we receive.',
- 'mobile-frontend-leave-feedback-technical-link-text' => 'Technical
problem',
- 'mobile-frontend-leave-feedback-general-link-text' => 'General
feedback',
- 'mobile-frontend-leave-feedback-article-personal-link-text' =>
'Regarding me, a person, or a company I represent',
- 'mobile-frontend-leave-feedback-article-factual-link-text' =>
'Regarding a factual error',
- 'mobile-frontend-leave-feedback-article-other-link-text' => 'Regarding
another problem',
- 'mobile-frontend-leave-feedback-form-subject-placeholder' => 'Message
subject',
- 'mobile-frontend-leave-feedback-form-message-placeholder' => 'Type your
comment here',
- 'mobile-frontend-leave-feedback-page-title' => 'Mobile site feedback',
- 'mobile-frontend-feedback-page' => 'Project:Mobile Extension Feedback',
- 'mobile-frontend-leave-feedback-special-title' => 'Contact us',
- 'mobile-frontend-feedback-no-subject' => '(no subject)',
- 'mobile-frontend-feedback-no-subject-field' => 'Please enter a subject',
- 'mobile-frontend-feedback-no-message' => 'Please enter a message here',
- 'mobile-frontend-feedback-edit-summary' => '$1 - automatically posted
using the [[Special:MobileFeedback|mobile feedback tool]]',
- 'mobile-frontend-leave-feedback-thanks' => 'Thanks for your feedback!',
- 'mobile-frontend-leave-feedback-post-error' => 'There was an error
processing your message. Please try again later.',
'mobile-frontend-language' => 'Language:',
'mobile-frontend-language-article-heading' => 'Read in another
language',
'mobile-frontend-current-language' => '{{#language:{{CONTENTLANG}}}}',
@@ -359,50 +331,6 @@
'mobile-frontend-footer-contributors-text' => 'Link to history page',
'mobile-frontend-featured-article' => 'The title that will appear
before the element with the mf-tfa selector.',
'mobile-frontend-news-items' => 'The title that will appear before the
element with the mf-itn selector.',
- 'mobile-frontend-leave-feedback-notice' => 'Parameters:
-* "$1" is a link to the page where the feedback will be posted.',
- 'mobile-frontend-leave-feedback-warning' => 'Used as warning in
[[Special:MobileFeedback]].',
- 'mobile-frontend-leave-feedback-subject' => '{{Identical|Subject}}',
- 'mobile-frontend-leave-feedback-message' => '{{Identical|Message}}',
- 'mobile-frontend-leave-feedback-submit' => 'Used as label for the
Submit button in [[Special:MobileFeedback]].',
- 'mobile-frontend-leave-feedback-link-text' => 'Unused at this time.',
- 'mobile-frontend-leave-feedback' => 'Unused at this time.',
- 'mobile-frontend-leave-feedback-title' =>
'{{doc-special|MobileFeedback|unlisted=1}}',
- 'mobile-frontend-leave-feedback-technical-problem-section-header' =>
'Section header text for technical feedback portion of feedback form',
- 'mobile-frontend-leave-feedback-general-section-header' => 'Section
header text for general feedback portion of feedback form
-{{Identical|General}}',
- 'mobile-frontend-leave-feedback-article-feedback-section-header' =>
'Section header text for article feedback portion of feedback form',
- 'mobile-frontend-leave-feedback-email-body' => "Text that will appear
in the e-mail body for feedback e-mails, instructing users to reply above this
line of text with their technical problem. Please ensure that this doesn't
request an e-mail address as we have this already! Also include a reference to
the fact that they may not receive a reply to prevent follow ups.",
- 'mobile-frontend-leave-feedback-technical-link-text' => 'Text for a
link to give feedback about a technical problem.',
- 'mobile-frontend-leave-feedback-general-link-text' => 'Text for a link
to give general feedback',
- 'mobile-frontend-leave-feedback-article-personal-link-text' => 'Text
for a link to give article feedback regarding the user or another person',
- 'mobile-frontend-leave-feedback-article-factual-link-text' => 'Text for
a link to give article feedback regarding a factual error',
- 'mobile-frontend-leave-feedback-article-other-link-text' => 'Text for a
link to give article feedback regarding some other problem',
- 'mobile-frontend-leave-feedback-form-subject-placeholder' =>
'Placeholder for the "subject" field in the feedback form, which regards the
subject of the message being submitted',
- 'mobile-frontend-leave-feedback-form-message-placeholder' =>
'Placeholder for the "message" field in the feedback form, which regards the
feedback the user is submitting',
- 'mobile-frontend-leave-feedback-page-title' => 'Special page title',
- 'mobile-frontend-feedback-page' => '{{optional}}',
- 'mobile-frontend-leave-feedback-special-title' => 'Title of special
page containing the feedback form',
- 'mobile-frontend-feedback-no-subject' => 'Used for section heading on
the feedback page if user entered no subject',
- 'mobile-frontend-feedback-no-subject-field' => 'Error message on
feedback form in [[Special:MobileFeedback]].
-
-See also:
-* {{msg-mw|Mobile-frontend-feedback-no-message}}',
- 'mobile-frontend-feedback-no-message' => 'Error message on feedback
form in [[Special:MobileFeedback]].
-
-See also:
-* {{msg-mw|Mobile-frontend-feedback-no-subject-field}}',
- 'mobile-frontend-feedback-edit-summary' => '{{doc-important|Do not
translate the special page name "<code>Special:MobileFeedback</code>".}}
-Edit summary. Parameters:
-* $1 - feedback subject',
- 'mobile-frontend-leave-feedback-thanks' => 'Used as success message in
[[Special:MobileFeedback]].
-
-See also:
-* {{msg-mw|Mobile-frontend-leave-feedback-post-error}}',
- 'mobile-frontend-leave-feedback-post-error' => 'Message displayed to
user in [[Special:MobileFeedback]], when there is an internal error processing
form submission.
-
-See also:
-* {{msg-mw|Mobile-frontend-leave-feedback-thanks}}',
'mobile-frontend-language' => '{{Identical|Language}}',
'mobile-frontend-language-article-heading' => 'A heading within the
article the content of which lists the other languages available for this
article: translate the message considering the list to have an undetermined
number of items.',
'mobile-frontend-current-language' => '{{optional}}',
diff --git a/MobileFrontend.php b/MobileFrontend.php
index aeaaada..2271887 100644
--- a/MobileFrontend.php
+++ b/MobileFrontend.php
@@ -56,7 +56,6 @@
'SpecialUploads' => 'specials/SpecialUploads',
'SpecialMobileDiff' => 'specials/SpecialMobileDiff',
- 'SpecialMobileFeedback' => 'specials/SpecialMobileFeedback',
'SpecialMobileOptions' => 'specials/SpecialMobileOptions',
'SpecialMobileMenu' => 'specials/SpecialMobileMenu',
'SpecialMobileWatchlist' => 'specials/SpecialMobileWatchlist',
@@ -109,7 +108,6 @@
$wgSpecialPages['Uploads'] = 'SpecialUploads';
$wgSpecialPages['MobileDiff'] = 'SpecialMobileDiff';
-$wgSpecialPages['MobileFeedback'] = 'SpecialMobileFeedback';
$wgSpecialPages['MobileOptions'] = 'SpecialMobileOptions';
$wgSpecialPages['MobileMenu'] = 'SpecialMobileMenu';
@@ -761,55 +759,9 @@
$wgMobileFrontendFormatCookieExpiry = null;
/**
- * When set to true, the feedback form will post to a remote wiki, which
- * must also be configured.
- * @param bool
- */
-$wgMFRemotePostFeedback = false;
-$wgMFRemotePostFeedbackUrl = null;
-$wgMFRemotePostFeedbackUsername = null;
-$wgMFRemotePostFeedbackPassword = null;
-$wgMFRemotePostFeedbackArticle = null;
-
-/**
- * Configure the href links for the various links that appear on the
- * MobileFrontend feedback form.
- *
- * These can be any value that you can use as an href value in <a href="">,
- * eg "GeneralFeedback", "http://mysite.com/wiki/GeneralFeedback",
- * "mailto:[email protected]"
- *
- * Leaving a value empty will default to a value of '#'
- *
- * Alternatively, you can invoke the 'MobileFrontendOverrideFeedbackLinks' hook
- * rather than just set this var in your LocalSettings. This is really useful
- * if you have more complicated/variable needs for setting up this
configuration
- * var that you might not want running on every single page load.
- */
-$wgMFFeedbackLinks = array(
- 'General' => '', // General feedback
- 'ArticlePersonal' => '', // Regarding me, a person, or a company I work
for
- 'ArticleFactual' => '', // Regarding a factual error
- 'ArticleOther' => '', // Regarding another problem
-);
-
-/**
* @var ExtMobileFrontend $wgExtMobileFrontend
*/
$wgExtMobileFrontend = null;
-
-/**
- * A fallback URL for a 'contact us' page if one cannot be dynamically
- * determined for the project (using wfMessage( 'contact-us' )). This is only
- * used in non-beta mode.
- */
-$wgMFFeedbackFallbackURL = '#';
-
-/**
- * Whether or not to display sections other than 'Technical feedback' on
feedback page
- * @param bool
- */
-$wgMFDisplayNonTechnicalFeedback = false;
/**
* Make the classes, tags and ids stripped from page content configurable.
diff --git a/includes/specials/SpecialMobileFeedback.php
b/includes/specials/SpecialMobileFeedback.php
deleted file mode 100644
index 151e610..0000000
--- a/includes/specials/SpecialMobileFeedback.php
+++ /dev/null
@@ -1,445 +0,0 @@
-<?php
-
-class SpecialMobileFeedback extends UnlistedSpecialMobilePage {
- public function __construct() {
- parent::__construct( 'MobileFeedback' );
- }
-
- public function execute( $par = '' ) {
- $this->setHeaders();
- $this->getOutput()->setPageTitle( $this->msg(
'mobile-frontend-leave-feedback-special-title' )->text() );
- $this->getOutput()->addHtml( Html::openElement( 'div', array(
'class' => 'content' ) ) );
- $context = MobileContext::singleton();
- $context->setForceMobileView( true );
- $context->setContentTransformations( false );
-
- if ( $par == 'thanks' ) {
- $this->showThanks();
- } elseif ( $par == 'error' ) {
- $this->showError();
- } else {
- $this->renderFeedbackHtml();
- }
- }
-
- protected function renderFeedbackHtml() {
- global $wgMFFeedbackLinks, $wgMFDisplayNonTechnicalFeedback;
- /** Section header text **/
- $technicalProblemSectionHeader = $this->msg(
'mobile-frontend-leave-feedback-technical-problem-section-header' )->escaped();
-
- wfRunHooks( 'MobileFrontendOverrideFeedbackLinks', array(
- $this->getRequest()->getText( 'feedbacksource', '' ),
- $this->getRequest()->getText( 'returnto', '' ),
- ) );
-
- /** Links **/
- $allowedLinks = array(
- 'Technical',
- 'General',
- 'ArticlePersonal',
- 'ArticleFactual',
- 'ArticleOther',
- );
-
- // get configured link values
- foreach ( $allowedLinks as $v ) {
- if ( !isset( $wgMFFeedbackLinks[ $v ] ) || !strlen(
trim( $wgMFFeedbackLinks[ $v ] ) ) ) {
- $linkVal = '#';
- } else {
- $linkVal = htmlspecialchars(
$wgMFFeedbackLinks[ $v ], ENT_QUOTES, 'UTF-8', false );
- }
- $varName = 'feedback' . $v . 'Link';
- $ { $varName } = $linkVal;
- }
-
- // Do we display the feedback form or use the link?
- if ( isset( $feedbackTechnicalLink ) && $feedbackTechnicalLink
!= '#' ) {
- $useFeedbackForm = false;
- } else {
- $useFeedbackForm = true;
- }
-
- /** Link text **/
- $feedbackTechnicalLinkText = ( $useFeedbackForm ) ? '' :
$this->msg( 'mobile-frontend-leave-feedback-technical-link-text' )->escaped();
-
- $warning = $this->msg( 'mobile-frontend-leave-feedback-warning'
);
-
- $html = <<<HTML
- {$warning}
- <div class='feedback'>
- <h2 class="section_heading"
id="section_1">{$technicalProblemSectionHeader}</h2>
- <div class="content_block" id="content_1">
-HTML;
- $this->getOutput()->addHtml( $html );
-
- if ( $useFeedbackForm ) {
- /** Fetch form HTML **/
- $form = new HTMLForm( $this->getForm(), $this );
- $form->setDisplayFormat( 'raw' );
- $form->setTitle( $this->getTitle() );
- $form->setId( 'mf-feedback-form' );
- $form->setSubmitText( $this->msg(
'mobile-frontend-leave-feedback-submit' )->escaped() );
- $form->setSubmitCallback( array( $this, 'postFeedback'
) );
- $form->setAction( $this->getRequest()->getRequestURL()
. "#mf-feedback-form" );
- $form->show();
- } else {
- $html = <<<HTML
- <ul>
- <li><a
href="{$feedbackTechnicalLink}">{$feedbackTechnicalLinkText}</a></li>
- </ul>
-HTML;
- $this->getOutput()->addHtml( $html );
- }
-
- $html = "</div>";
- if ( $wgMFDisplayNonTechnicalFeedback ) {
- $generalSectionHeader = $this->msg(
'mobile-frontend-leave-feedback-general-section-header' )->escaped();
- $articleFeedbackSectionHeader = $this->msg(
'mobile-frontend-leave-feedback-article-feedback-section-header' )->escaped();
- $feedbackGeneralLinkText = $this->msg(
'mobile-frontend-leave-feedback-general-link-text' )->escaped();
- $feedbackArticlePersonalLinkText = $this->msg(
'mobile-frontend-leave-feedback-article-personal-link-text' )->escaped();
- $feedbackArticleFactualLinkText = $this->msg(
'mobile-frontend-leave-feedback-article-factual-link-text' )->escaped();
- $feedbackArticleOtherLinkText = $this->msg(
'mobile-frontend-leave-feedback-article-other-link-text' )->escaped();
-
- $html .= <<<HTML
- <h2 class="section_heading"
id="section_2">{$generalSectionHeader}</h2>
- <div class="content_block" id="content_2">
- <ul>
- <li><a
href="{$feedbackGeneralLink}">{$feedbackGeneralLinkText}</a></li>
- </ul>
- </div>
- <h2 class="section_heading"
id="section_3">{$articleFeedbackSectionHeader}</h2>
- <div class="content_block" id="content_3">
- <ul>
- <li>
- <a
href="{$feedbackArticlePersonalLink}">{$feedbackArticlePersonalLinkText}</a>
- </li>
- <li>
- <a
href="{$feedbackArticleFactualLink}">{$feedbackArticleFactualLinkText}</a>
- </li>
- <li>
- <a
href="{$feedbackArticleOtherLink}">{$feedbackArticleOtherLinkText}</a>
- </li>
- </ul>
- </div>
-HTML;
- }
- $html .= "</div>"; // close .content
- $this->getOutput()->addHtml( $html );
- }
-
- protected function getForm( $displaySuffix = '' ) {
- $subjectPlaceholder = $this->msg(
'mobile-frontend-leave-feedback-form-subject-placeholder' )->escaped();
- $messagePlaceholder = $this->msg(
'mobile-frontend-leave-feedback-form-message-placeholder' )->escaped();
- return array(
- 'returnto' => array(
- 'type' => 'hidden' . $displaySuffix,
- 'default' => $this->getRequest()->getText(
'returnto', '' ),
- ),
- 'source' => array(
- 'type' => 'hidden' . $displaySuffix,
- 'default' => $this->getRequest()->getText(
'feedbacksource', '' )
- ),
- 'subject' => array(
- 'type' => 'text' . $displaySuffix,
- 'maxlength' => 60,
- 'validation-callback' => array( $this,
'validateSubject' ),
- 'placeholder' => $subjectPlaceholder,
- ),
- 'message' => array(
- 'type' => 'textarea' . $displaySuffix,
- 'rows' => 5,
- 'cols' => 60,
- 'validation-callback' => array( $this,
'validateMessage' ),
- 'placeholder' => $messagePlaceholder,
- ),
- );
- }
-
- public function postFeedback( $form ) {
- global $wgMFRemotePostFeedback;
-
- $subject = $this->getFormattedSubject( $form );
- $message = $this->getFormattedMessage( $form );
- $returnTo = $form['returnto'];
- $context = MobileContext::singleton();
- if ( $wgMFRemotePostFeedback === true ) {
- $success = $this->postRemoteFeedback( $subject,
$message );
- } else {
- $success = $this->postLocalFeedback( $subject, $message
);
- }
-
- if ( $success === true ) {
- $location = $context->getMobileUrl(
- $this->getTitle( 'thanks' )->getFullURL( array(
'returnto' => $returnTo ) ) );
- $this->getRequest()->response()->header( 'Location: ' .
$location );
- exit;
- } else {
- $location = $context->getMobileUrl(
- $this->getTitle( 'error' )->getFullURL( array(
'returnto' => $returnTo ) ) );
- $this->getRequest()->response()->header( 'Location: ' .
$location );
- exit;
- }
- }
-
- protected function postLocalFeedback( $subject, $message ) {
- wfProfileIn( __METHOD__ );
-
- // Is this really right? Are people really checking all of the
different
- // language variants of this page?
- // Perhaps this makes more sense as something non-language
specific...
- $title = Title::newFromText( wfMessage(
'mobile-frontend-feedback-page' )->inContentLanguage()->plain() );
-
- if ( $title->userCan( 'edit' ) &&
- !$this->getUser()->isBlockedFrom( $title ) ) {
- $article = new Article( $title, 0 );
- $rawtext = $article->getRawText();
- $rawtext .= "\n== {$subject} ==\n";
- $rawtext .= $message;
- $article->doEdit( $rawtext,
- $this->msg(
'mobile-frontend-feedback-edit-summary', $subject )->inContentLanguage()->text()
- );
- $ret = true;
- } else {
- $ret = false;
- }
-
- wfProfileOut( __METHOD__ );
- return $ret;
- }
-
- protected function getFormattedSubject( $form ) {
- $subject = $form['subject']
- ? $form['subject']
- : $this->msg( 'mobile-frontend-feedback-no-subject'
)->inContentLanguage()->text();
- return $subject;
- }
-
- protected function getFormattedMessage( $form ) {
- $rawMsg = trim( $form['message'] );
- $feedbackSource = trim( $form['source'] );
- $returnTo = trim( $form['returnto'] );
- $msg = "{$rawMsg} ~~~~\n<br><small>User agent:
<code>{$_SERVER['HTTP_USER_AGENT']}</code> Source:
<code>{$feedbackSource}</code> Referring page: {$returnTo}</small> ";
- return $msg;
- }
-
- protected function postRemoteFeedback( $subject, $message ) {
- global $wgMFRemotePostFeedbackUrl,
$wgMFRemotePostFeedbackUsername,
- $wgMFRemotePostFeedbackPassword,
$wgMFRemotePostFeedbackArticle;
-
- try {
- $apiClient = new MobileFrontendMWApiClient(
$wgMFRemotePostFeedbackUrl,
- $wgMFRemotePostFeedbackUsername,
$wgMFRemotePostFeedbackPassword );
- return $apiClient->editArticle(
$wgMFRemotePostFeedbackArticle, $subject, $message );
- } catch ( Exception $e ) {
- return false;
- }
- }
-
- public function validateSubject( $textfield ) {
- if ( mb_strlen( trim( $textfield ) ) < 1 ) {
- return $this->msg(
'mobile-frontend-feedback-no-subject-field' )->text();
- }
- return true;
- }
-
- public function validateMessage( $textarea ) {
- if ( mb_strlen( trim( $textarea ) ) < 1 ) {
- return $this->msg(
'mobile-frontend-feedback-no-message' )->text();
- }
- return true;
- }
-
- protected function showThanks() {
- $this->showPostFeedbackOutput(
'mobile-frontend-leave-feedback-thanks' );
- }
-
- protected function showError() {
- $this->showPostFeedbackOutput(
'mobile-frontend-leave-feedback-post-error' );
- }
-
- protected function showPostFeedbackOutput( $msg ) {
- $out = $this->getOutput();
- $out->addHtml( "<div class=mwm-message mwm-notice'>{$this->msg(
$msg )->parse()}</div>" );
- $t = Title::newFromText( $this->getRequest()->getText(
'returnto' ) );
- if ( $t ) {
- $out->addReturnTo( $t );
- } else {
- $out->returnToMain();
- }
- }
-}
-
-class MobileFrontendMWApiClient {
- protected $username;
- protected $password;
- protected $cookieJar;
- protected $url;
- protected $loggedIn = false;
-
- public function __construct( $url = null, $username = null, $password =
null ) {
- $opts = array( 'url', 'username', 'password' );
- foreach ( $opts as $opt ) {
- if ( !is_null( $ { $opt } ) ) {
- $setMethodName = "set" . ucfirst( $opt );
- $this->$setMethodName( $ { $opt } );
- }
- }
- }
-
- public function setUsername( $username ) {
- if ( !strlen( $username ) ) {
- throw new Exception ( 'Invalid username' );
- }
- $this->username = $username;
- }
-
- public function getUsername() {
- return $this->username;
- }
-
- public function setCookieJar( $cookieJar ) {
- $this->cookieJar = $cookieJar;
- }
-
- public function getCookieJar() {
- return $this->cookieJar;
- }
-
- public function setPassword( $password ) {
- if ( !strlen( $password ) ) {
- throw new Exception ( 'Invalid password' );
- }
- $this->password = $password;
- }
-
- public function getPassword() {
- return $this->password;
- }
-
- public function setUrl( $url ) {
- if ( !strlen( $url ) ) {
- throw new Exception ( 'Invalid URL' );
- }
- $this->url = $url;
- }
-
- public function getUrl() {
- return $this->url;
- }
-
- public function login() {
- // login
- $options = array(
- 'postData' => array(
- 'action' => 'login',
- 'lgname' => $this->getUsername(),
- 'lgpassword' => $this->getPassword(),
- 'format' => 'json',
- ),
- 'method' => 'POST',
- );
- $req = MwHttpRequest::factory( $this->getUrl(), $options );
- $status = $req->execute();
- if ( !$status->isGood() ) {
- throw new Exception( 'Remote posting login request
failed.' );
- }
- $loginResponse = $req->getContent();
- $loginResponse = json_decode( $loginResponse, true );
- $loginResult = $loginResponse['login']['result'];
- if ( $loginResult == 'NeedToken' ) {
- // fetch cookie jar (session info needed for auth)
- $this->setCookieJar( $req->getCookieJar() );
- $token = $loginResponse['login']['token'];
- $options['postData']['lgtoken'] = $token;
- $req = MwHttpRequest::factory( $this->getUrl(),
$options );
- // set cookie jar
- $req->setCookieJar( $this->getCookieJar() );
- $status = $req->execute();
- if ( !$status->isGood() ) {
- throw new Exception( 'Remote posting login
failed after token.' );
- }
- $loginResponse = $req->getContent();
- $loginResponse = json_decode( $loginResponse, true );
- $loginResult = $loginResponse['login']['result'];
- }
-
- if ( $loginResult != 'Success' ) {
- // there's some kind of problem
- throw new Exception( 'Remote posting login failed.' );
- }
- $this->loggedIn = true;
- return true;
- }
-
- public function getEditToken( $articleName ) {
- // get edit token
- $options = array(
- 'postData' => array(
- 'action' => 'query',
- 'prop' => 'info|revisions',
- 'intoken' => 'edit',
- 'titles' => $articleName,
- 'format' => 'json',
- ),
- 'method' => 'POST',
- );
- $req = MwHttpRequest::factory( $this->getUrl(), $options );
- $req->setCookieJar( $this->getCookieJar() );
- $status = $req->execute();
-
- if ( !$status->isGood() ) {
- // make some kind of error?
- throw new Exception( 'Failed fetching edit token.' );
- }
- $response = $req->getContent();
- $response = json_decode( $response, true );
- $pages = $response['query']['pages'];
- $editToken = null;
- foreach ( $pages as $page ) {
- if ( isset( $page['edittoken'] ) ) $editToken =
$page['edittoken'];
- if ( !is_null( $editToken ) ) break;
- }
- // what happens if no edit token present?!
- return $editToken;
- }
-
- public function editArticle( $articleName, $sectionTitle, $text,
$section = 'new' ) {
- if ( $this->shouldLogIn() ) {
- if ( !$this->login() ) {
- throw new Exception( 'Login failed.' );
- }
- }
-
- // edit page
- $options = array(
- 'postData' => array(
- 'action' => 'edit',
- 'title' => $articleName,
- 'section' => $section,
- 'sectiontitle' => $sectionTitle, // change to
be subject of form submit
- 'text' => $text, // change to be message of
form submit + incl UA (See old post method)
- 'token' => $this->getEditToken( $articleName ),
- 'bot' => true,
- 'md5' => md5( $text ),
- 'format' => 'json',
- // use timestamp options?
- ),
- 'method' => 'POST',
- );
- $req = MwHttpRequest::factory( $this->getUrl(), $options );
- $req->setCookieJar( $this->getCookieJar() );
- $status = $req->execute();
- if ( !$status->isGood() ) {
- return false;
- }
- $req->getContent();
- return true;
- }
-
- public function shouldLogIn() {
- if ( !$this->loggedIn && isset( $this->username ) && isset(
$this->password ) ) {
- return true;
- }
- return false;
- }
-}
--
To view, visit https://gerrit.wikimedia.org/r/60339
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I68485a0b70028d322b92b25864465346f9cdc5c7
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: awjrichards <[email protected]>
Gerrit-Reviewer: JGonera <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits