/**
  * Get the Title object of a form suitable for editing the target page.
  *
  * @return Title
  * @throws MWException
  */
 protected function getFormTitle()
 {
     // if no form was explicitly specified, try for explicitly set alternate forms
     if ($this->mOptions['form'] === '') {
         $this->logMessage('No form specified. Will try to find the default form for the target page.', self::DEBUG);
         $formNames = array();
         // try explicitly set alternative forms
         if (array_key_exists('alt_form', $this->mOptions)) {
             $formNames = (array) $this->mOptions['alt_form'];
             // cast to array to make sure we get an array, even if only a string was sent
         }
         // if no alternate forms were explicitly set, try finding a default form for the target page
         if (count($formNames) === 0) {
             // if no form and and no alt forms and no target page was specified, give up
             if ($this->mOptions['target'] === '') {
                 throw new MWException(wfMessage('sf_autoedit_notargetspecified')->parse());
             }
             $targetTitle = Title::newFromText($this->mOptions['target']);
             // if the specified target title is invalid, give up
             if (!$targetTitle instanceof Title) {
                 throw new MWException(wfMessage('sf_autoedit_invalidtargetspecified', $this->mOptions['target'])->parse());
             }
             $formNames = SFFormLinker::getDefaultFormsForPage($targetTitle);
             // if no default form can be found, try alternate forms
             if (count($formNames) === 0) {
                 $formNames = SFFormLinker::getFormsThatPagePointsTo($targetTitle->getText(), $targetTitle->getNamespace(), SFFormLinker::ALTERNATE_FORM);
                 // if still no form can be found, give up
                 if (count($formNames) === 0) {
                     throw new MWException(wfMessage('sf_autoedit_noformfound')->parse());
                 }
             }
         }
         // if more than one form was found, issue a notice and give up
         // this happens if no default form but several alternate forms are defined
         if (count($formNames) > 1) {
             throw new MWException(wfMessage('sf_autoedit_toomanyformsfound')->parse(), self::DEBUG);
         }
         $this->mOptions['form'] = $formNames[0];
         $this->logMessage('Using ' . $this->mOptions['form'] . ' as default form.', self::DEBUG);
     }
     $formTitle = Title::makeTitleSafe(SF_NS_FORM, $this->mOptions['form']);
     // if the given form is not a valid title, give up
     if (!$formTitle instanceof Title) {
         throw new MWException(wfMessage('sf_autoedit_invalidform', $this->mOptions['form'])->parse());
     }
     // if the form page is a redirect, follow the redirect
     if ($formTitle->isRedirect()) {
         $this->logMessage('Form ' . $this->mOptions['form'] . ' is a redirect. Finding target.', self::DEBUG);
         $formWikiPage = WikiPage::factory($formTitle);
         if (method_exists($formWikiPage, 'getContent')) {
             // MW 1.21+
             $formTitle = $formWikiPage->getContent(Revision::RAW)->getUltimateRedirectTarget();
         } else {
             $formTitle = Title::newFromRedirectRecurse($formWikiPage->getRawText());
         }
         // if we exeeded $wgMaxRedirects or encountered an invalid redirect target, give up
         if ($formTitle->isRedirect()) {
             $newTitle = WikiPage::factory($formTitle)->getRedirectTarget();
             if ($newTitle instanceof Title && $newTitle->isValidRedirectTarget()) {
                 throw new MWException(wfMessage('sf_autoedit_redirectlimitexeeded', $this->mOptions['form'])->parse());
             } else {
                 throw new MWException(wfMessage('sf_autoedit_invalidredirecttarget', $newTitle->getFullText(), $this->mOptions['form'])->parse());
             }
         }
     }
     // if specified or found form does not exist (e.g. is a red link), give up
     // FIXME: Throw specialized error message, so a list of alternative forms can be shown
     if (!$formTitle->exists()) {
         throw new MWException(wfMessage('sf_autoedit_invalidform', $this->mOptions['form'])->parse());
     }
     return $formTitle;
 }