Пример #1
0
 public function execute()
 {
     global $wgCityId;
     $db = wfGetDB(DB_MASTER);
     (new WikiaSQL())->SELECT('*')->FROM('page')->WHERE('page_is_redirect')->EQUAL_TO(1)->runLoop($db, function ($a, $row) use($db) {
         $title = Title::newFromID($row->page_id);
         if (!$title->isDeleted()) {
             $rev = Revision::newFromTitle($title);
             $text = $rev->getText();
             $rt = Title::newFromRedirectRecurse($text);
             if (!$rt) {
                 // page is marked as redirect but $text is not valid redirect
                 $this->output('Fixed ID: ' . $title->getArticleID() . ' Title: ' . $title->getText() . "\n");
                 // Fix page table
                 (new WikiaSQL())->UPDATE('page')->SET('page_is_redirect', 0)->WHERE('page_id')->EQUAL_TO($row->page_id)->RUN($db);
                 // remove redirect from redirect table
                 (new WikiaSQL())->DELETE('redirect')->WHERE('rd_from')->EQUAL_TO($row->page_id)->RUN($db);
                 // clear cache
                 LinkCache::singleton()->addGoodLinkObj($row->page_id, $title, strlen($text), 0, $rev->getId());
                 if ($title->getNamespace() == NS_FILE) {
                     RepoGroup::singleton()->getLocalRepo()->invalidateImageRedirect($title);
                 }
             }
         }
     });
 }
Пример #2
0
 /**
 * Update the page record to point to a newly saved revision.
 *
 * @param $dbw DatabaseBase: object
 * @param $revision Revision: For ID number, and text used to set
                    length and redirect status fields
 * @param $lastRevision Integer: if given, will not overwrite the page field
 *                      when different from the currently set value.
 *                      Giving 0 indicates the new page flag should be set
 *                      on.
 * @param $lastRevIsRedirect Boolean: if given, will optimize adding and
 *                           removing rows in redirect table.
 * @return bool true on success, false on failure
 * @private
 */
 public function updateRevisionOn(&$dbw, $revision, $lastRevision = null, $lastRevIsRedirect = null)
 {
     wfProfileIn(__METHOD__);
     $text = $revision->getText();
     $rt = Title::newFromRedirectRecurse($text);
     $conditions = array('page_id' => $this->getId());
     if (!is_null($lastRevision)) {
         # An extra check against threads stepping on each other
         $conditions['page_latest'] = $lastRevision;
     }
     $dbw->update('page', array('page_latest' => $revision->getId(), 'page_touched' => $dbw->timestamp(), 'page_is_new' => $lastRevision === 0 ? 1 : 0, 'page_is_redirect' => $rt !== null ? 1 : 0, 'page_len' => strlen($text)), $conditions, __METHOD__);
     $result = $dbw->affectedRows() != 0;
     if ($result) {
         $this->updateRedirectOn($dbw, $rt, $lastRevIsRedirect);
     }
     wfProfileOut(__METHOD__);
     return $result;
 }
Пример #3
0
 /**
  * Tests if the article text represents a redirect
  *
  * @param $text String: FIXME
  * @return bool
  */
 public function isRedirect($text = false)
 {
     if ($text === false) {
         if ($this->mDataLoaded) {
             return $this->mIsRedirect;
         }
         // Apparently loadPageData was never called
         $this->loadContent();
         $titleObj = Title::newFromRedirectRecurse($this->fetchContent());
     } else {
         $titleObj = Title::newFromRedirect($text);
     }
     return $titleObj !== null;
 }
Пример #4
0
 static function printForm(&$form_name, &$target_name, $alt_forms = array(), $redirectOnError = false)
 {
     global $wgOut, $wgRequest, $wgUser, $sfgFormPrinter;
     // initialize some variables
     $target_title = null;
     $page_name_formula = null;
     $form_title = Title::makeTitleSafe(SF_NS_FORM, $form_name);
     // If the given form is not a valid title, bail out.
     if (!$form_title) {
         return 'sf_formedit_badurl';
     }
     $form_article = new Article($form_title, 0);
     $form_definition = $form_article->getContent();
     // If the form page is a redirect, use the other form
     // instead.
     if ($form_title->isRedirect()) {
         $form_title = Title::newFromRedirectRecurse($form_definition);
         $form_article = new Article($form_title, 0);
         $form_definition = $form_article->getContent();
     }
     $form_definition = StringUtils::delimiterReplace('<noinclude>', '</noinclude>', '', $form_definition);
     if (is_null($target_name)) {
         $target_name = '';
     }
     if ($target_name === '') {
         // parse the form to see if it has a 'page name' value set
         $matches;
         if (preg_match('/{{{info.*page name\\s*=\\s*(.*)}}}/m', $form_definition, $matches)) {
             $page_name_elements = SFUtils::getFormTagComponents($matches[1]);
             $page_name_formula = $page_name_elements[0];
         } elseif (count($alt_forms) == 0) {
             return 'sf_formedit_badurl';
         }
     } else {
         $target_title = Title::newFromText($target_name);
         if ($target_title && $target_title->exists()) {
             if ($wgRequest->getVal('query') == 'true') {
                 $page_contents = null;
                 //$page_is_source = false;
             } else {
                 // If page already exists and 'redlink'
                 // is in the query string, redirect to
                 // the actual page, just like
                 // MediaWiki does it.
                 if ($wgRequest->getBool('redlink')) {
                     $wgOut->redirect($target_title->getFullURL());
                     wfProfileOut(__METHOD__);
                     return;
                 }
                 $target_article = new Article($target_title, 0);
                 $page_contents = $target_article->getContent();
                 //$page_is_source = true;
             }
         } else {
             $target_name = str_replace('_', ' ', $target_name);
         }
     }
     if (!$form_title || !$form_title->exists()) {
         if (count($alt_forms) > 0) {
             $text = '<div class="infoMessage">' . wfMsg('sf_formedit_altformsonly') . ' ' . self::printAltFormsList($alt_forms, $form_name) . "</div>\n";
         } else {
             $text = Html::rawElement('p', array('class' => 'error'), wfMsgExt('sf_formstart_badform', 'parseinline', SFUtils::linkText(SF_NS_FORM, $form_name))) . "\n";
         }
     } elseif ($target_name === '' && $page_name_formula === '') {
         $text = Html::element('p', array('class' => 'error'), wfMsg('sf_formedit_badurl')) . "\n";
     } else {
         $save_page = $wgRequest->getCheck('wpSave');
         $preview_page = $wgRequest->getCheck('wpPreview');
         $diff_page = $wgRequest->getCheck('wpDiff');
         $form_submitted = $save_page || $preview_page || $diff_page;
         // get 'preload' query value, if it exists
         if (!$form_submitted) {
             if ($wgRequest->getCheck('preload')) {
                 $page_is_source = true;
                 $page_contents = SFFormUtils::getPreloadedText($wgRequest->getVal('preload'));
             } else {
                 // let other extensions preload the page, if they want
                 wfRunHooks('sfEditFormPreloadText', array(&$page_contents, $target_title, $form_title));
                 $page_is_source = $page_contents != null;
             }
         } else {
             $page_is_source = false;
             $page_contents = null;
         }
         list($form_text, $javascript_text, $data_text, $form_page_title, $generated_page_name) = $sfgFormPrinter->formHTML($form_definition, $form_submitted, $page_is_source, $form_article->getID(), $page_contents, $target_name, $page_name_formula);
         // Before we do anything else, set the form header
         // title - this needs to be done after formHTML() is
         // called, because otherwise it doesn't take hold
         // for some reason if the form is disabled.
         if (empty($target_title)) {
             $s = wfMsg('sf_formedit_createtitlenotarget', $form_title->getText());
         } elseif ($target_title->exists()) {
             $s = wfMsg('sf_formedit_edittitle', $form_title->getText(), $target_title->getPrefixedText());
         } else {
             $s = wfMsg('sf_formedit_createtitle', $form_title->getText(), $target_title->getPrefixedText());
         }
         $wgOut->setPageTitle($s);
         if ($form_submitted) {
             if (!is_null($page_name_formula) && $page_name_formula !== '') {
                 $target_name = $generated_page_name;
                 // prepend a super-page, if one was specified
                 if ($wgRequest->getCheck('super_page')) {
                     $target_name = $wgRequest->getVal('super_page') . '/' . $target_name;
                 }
                 // prepend a namespace, if one was specified
                 if ($wgRequest->getCheck('namespace')) {
                     $target_name = $wgRequest->getVal('namespace') . ':' . $target_name;
                 }
                 // replace "unique number" tag with one
                 // that won't get erased by the next line
                 $target_name = preg_replace('/<unique number(.*)>/', '{num\\1}', $target_name, 1);
                 // if any formula stuff is still in the
                 // name after the parsing, just remove it
                 $target_name = StringUtils::delimiterReplace('<', '>', '', $target_name);
                 // now run the parser on it
                 global $wgParser;
                 // ...but first, replace spaces back
                 // with underlines, in case a magic word
                 // or parser function name contains
                 // underlines - hopefully this won't
                 // cause problems of its own
                 $target_name = str_replace(' ', '_', $target_name);
                 $target_name = $wgParser->preprocess($target_name, $wgOut->getTitle(), ParserOptions::newFromUser(null));
                 $title_number = "";
                 $isRandom = false;
                 $randomNumHasPadding = false;
                 $randomNumDigits = 6;
                 if (strpos($target_name, '{num') !== false) {
                     // Random number
                     if (preg_match('/{num;random(;(0)?([1-9][0-9]*))?}/', $target_name, $matches)) {
                         $isRandom = true;
                         $randomNumHasPadding = array_key_exists(2, $matches);
                         $randomNumDigits = array_key_exists(3, $matches) ? $matches[3] : $randomNumDigits;
                         $title_number = self::makeRandomNumber($randomNumDigits, $randomNumHasPadding);
                     } else {
                         // get unique number start value
                         // from target name; if it's not
                         // there, or it's not a positive
                         // number, start it out as blank
                         preg_match('/{num.*start[_]*=[_]*([^;]*).*}/', $target_name, $matches);
                         if (count($matches) == 2 && is_numeric($matches[1]) && $matches[1] >= 0) {
                             // the "start" value"
                             $title_number = $matches[1];
                         }
                     }
                     // set target title
                     $target_title = Title::newFromText(preg_replace('/{num.*}/', $title_number, $target_name));
                     // if title exists already
                     // cycle through numbers for
                     // this tag until we find one
                     // that gives a nonexistent page
                     // title
                     while ($target_title->exists()) {
                         if ($isRandom) {
                             $title_number = self::makeRandomNumber($randomNumDigits, $randomNumHasPadding);
                         } elseif ($title_number == "") {
                             $title_number = 2;
                         } else {
                             $title_number = str_pad($title_number + 1, strlen($title_number), '0', STR_PAD_LEFT);
                         }
                         $target_title = Title::newFromText(preg_replace('/{num.*}/', $title_number, $target_name));
                     }
                     $target_name = $target_title->getPrefixedText();
                 } else {
                     $target_title = Title::newFromText($target_name);
                 }
             }
             if (is_null($target_title)) {
                 if ($target_name) {
                     return array('sf_formstart_badtitle', array($target_name));
                 } else {
                     return 'sf_formedit_emptytitle';
                 }
             }
             if ($save_page) {
                 $permErrors = $target_title->getUserPermissionsErrors('edit', $wgUser);
                 if ($permErrors) {
                     // just return the first error and let them fix it one by one
                     return array_shift($permErrors);
                 }
                 // Set up all the variables for the
                 // page save.
                 $data = array('wpTextbox1' => $data_text, 'wpSummary' => $wgRequest->getVal('wpSummary'), 'wpStarttime' => $wgRequest->getVal('wpStarttime'), 'wpEdittime' => $wgRequest->getVal('wpEdittime'), 'wpEditToken' => $wgUser->isLoggedIn() ? $wgUser->editToken() : EDIT_TOKEN_SUFFIX, 'wpSave' => '', 'action' => 'submit');
                 if ($wgRequest->getCheck('wpMinoredit')) {
                     $data['wpMinoredit'] = true;
                 }
                 if ($wgRequest->getCheck('wpWatchthis')) {
                     $data['wpWatchthis'] = true;
                 }
                 $request = new FauxRequest($data, true);
                 // Find existing article if it exists,
                 // or create a new one.
                 $article = new Article($target_title, 0);
                 $editor = new EditPage($article);
                 $editor->importFormData($request);
                 // Try to save the page!
                 $resultDetails = array();
                 $saveResult = $editor->internalAttemptSave($resultDetails);
                 // Return value was made an object in MW 1.19
                 if (is_object($saveResult)) {
                     $saveResultCode = $saveResult->value;
                 } else {
                     $saveResultCode = $saveResult;
                 }
                 if (($saveResultCode == EditPage::AS_HOOK_ERROR || $saveResultCode == EditPage::AS_HOOK_ERROR_EXPECTED) && $redirectOnError) {
                     $wgOut->clearHTML();
                     $wgOut->setArticleBodyOnly(true);
                     // Lets other code process additional form-definition syntax
                     wfRunHooks('sfWritePageData', array($form_name, $target_title, &$data_text));
                     $text = SFUtils::printRedirectForm($target_title, $data_text, $wgRequest->getVal('wpSummary'), $save_page, $preview_page, $diff_page, $wgRequest->getCheck('wpMinoredit'), $wgRequest->getCheck('wpWatchthis'), $wgRequest->getVal('wpStarttime'), $wgRequest->getVal('wpEdittime'));
                 } else {
                     if ($saveResultCode == EditPage::AS_SUCCESS_UPDATE || $saveResultCode == EditPage::AS_SUCCESS_NEW_ARTICLE) {
                         $wgOut->redirect($target_title->getFullURL());
                     }
                     return SFUtils::processEditErrors($saveResultCode);
                 }
             } else {
                 // Lets other code process additional form-definition syntax
                 wfRunHooks('sfWritePageData', array($form_name, $target_title, &$data_text));
                 $text = SFUtils::printRedirectForm($target_title, $data_text, $wgRequest->getVal('wpSummary'), $save_page, $preview_page, $diff_page, $wgRequest->getCheck('wpMinoredit'), $wgRequest->getCheck('wpWatchthis'), $wgRequest->getVal('wpStarttime'), $wgRequest->getVal('wpEdittime'));
                 // extract its data
             }
         } else {
             // override the default title for this page if
             // a title was specified in the form
             if ($form_page_title != null) {
                 if ($target_name === '') {
                     $wgOut->setPageTitle($form_page_title);
                 } else {
                     $wgOut->setPageTitle("{$form_page_title}: {$target_title->getPrefixedText()}");
                 }
             }
             $text = "";
             if (count($alt_forms) > 0) {
                 $text .= '<div class="infoMessage">' . wfMsg('sf_formedit_altforms') . ' ';
                 $text .= self::printAltFormsList($alt_forms, $target_name);
                 $text .= "</div>\n";
             }
             $text .= '<form name="createbox" id="sfForm" method="post" class="createbox">';
             $pre_form_html = '';
             wfRunHooks('sfHTMLBeforeForm', array(&$target_title, &$pre_form_html));
             $text .= $pre_form_html;
             $text .= $form_text;
         }
     }
     SFUtils::addJavascriptAndCSS();
     if (!empty($javascript_text)) {
         $wgOut->addScript('		<script type="text/javascript">' . "\n{$javascript_text}\n" . '</script>' . "\n");
     }
     $wgOut->addHTML($text);
     return null;
 }
 private function resolveRedirects($title)
 {
     if (!$title->isRedirect()) {
         return $title;
     }
     $article = new Article($title, 0);
     if (method_exists($title, 'newFromRedirectRecurse')) {
         return Title::newFromRedirectRecurse($article->getContent());
     } else {
         return Title::newFromRedirect($article->getContent());
     }
 }
Пример #6
0
 /**
  * Get the contents to be preloaded into the box, either set by
  * an earlier setPreloadText() or by loading the given page.
  *
  * @param $preload String: representing the title to preload from.
  * @return String
  */
 protected function getPreloadedText($preload)
 {
     global $wgUser, $wgParser;
     if (!empty($this->mPreloadText)) {
         return $this->mPreloadText;
     } elseif ($preload !== '') {
         $title = Title::newFromText($preload);
         # Check for existence to avoid getting MediaWiki:Noarticletext
         if (isset($title) && $title->exists() && $title->userCanRead()) {
             $article = new Article($title);
             if ($article->isRedirect()) {
                 $title = Title::newFromRedirectRecurse($article->getContent());
                 # Redirects to missing titles are displayed, to hidden pages are followed
                 # Copying observed behaviour from ?action=view
                 if ($title->exists()) {
                     if ($title->userCanRead()) {
                         $article = new Article($title);
                     } else {
                         return "";
                     }
                 }
             }
             $parserOptions = ParserOptions::newFromUser($wgUser);
             return $wgParser->getPreloadText($article->getContent(), $title, $parserOptions);
         }
     }
     return '';
 }
 /**
  * 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;
 }
Пример #8
0
 /**
  * Update the page record to point to a newly saved revision.
  *
  * @param $dbw DatabaseBase: object
  * @param $revision Revision: For ID number, and text used to set
  *                  length and redirect status fields
  * @param $lastRevision Integer: if given, will not overwrite the page field
  *                      when different from the currently set value.
  *                      Giving 0 indicates the new page flag should be set
  *                      on.
  * @param $lastRevIsRedirect Boolean: if given, will optimize adding and
  *                           removing rows in redirect table.
  * @return bool true on success, false on failure
  * @private
  */
 public function updateRevisionOn($dbw, $revision, $lastRevision = null, $lastRevIsRedirect = null)
 {
     wfProfileIn(__METHOD__);
     $text = $revision->getText();
     $len = strlen($text);
     $rt = Title::newFromRedirectRecurse($text);
     $conditions = array('page_id' => $this->getId());
     if (!is_null($lastRevision)) {
         # An extra check against threads stepping on each other
         $conditions['page_latest'] = $lastRevision;
     }
     $now = wfTimestampNow();
     $dbw->update('page', array('page_latest' => $revision->getId(), 'page_touched' => $dbw->timestamp($now), 'page_is_new' => $lastRevision === 0 ? 1 : 0, 'page_is_redirect' => $rt !== null ? 1 : 0, 'page_len' => $len), $conditions, __METHOD__);
     $result = $dbw->affectedRows() > 0;
     if ($result) {
         $this->updateRedirectOn($dbw, $rt, $lastRevIsRedirect);
         $this->setLastEdit($revision);
         $this->setCachedLastEditTime($now);
         $this->mLatest = $revision->getId();
         $this->mIsRedirect = (bool) $rt;
         # Update the LinkCache.
         LinkCache::singleton()->addGoodLinkObj($this->getId(), $this->mTitle, $len, $this->mIsRedirect, $this->mLatest);
     }
     wfProfileOut(__METHOD__);
     return $result;
 }
 public static function overrideRedirect(Title $title, WebRequest $request, &$ignoreRedirect, &$target, Article &$article)
 {
     global $wgMemc, $wgParserCacheExpireTime;
     $fa = FlaggableWikiPage::getTitleInstance($title);
     // on $wgTitle
     if (!$fa->isReviewable()) {
         return true;
         // nothing to do
     }
     # Viewing an old reviewed version...
     if ($request->getVal('stableid')) {
         $ignoreRedirect = true;
         // don't redirect (same as ?oldid=x)
         return true;
     }
     $srev = $fa->getStableRev();
     $view = FlaggablePageView::singleton();
     # Check if we are viewing an unsynced stable version...
     if ($srev && $view->showingStable() && $srev->getRevId() != $article->getLatest()) {
         # Check the stable redirect properties from the cache...
         $key = wfMemcKey('flaggedrevs', 'overrideRedirect', $article->getId());
         $tuple = FlaggedRevs::getMemcValue($wgMemc->get($key), $article);
         if (is_array($tuple)) {
             // cache hit
             list($ignoreRedirect, $target) = $tuple;
         } else {
             // cache miss; fetch the stable rev text...
             $text = $srev->getRevText();
             $redirect = $fa->getRedirectURL(Title::newFromRedirectRecurse($text));
             if ($redirect) {
                 $target = $redirect;
                 // use stable redirect
             } else {
                 $ignoreRedirect = true;
                 // make MW skip redirection
             }
             $data = FlaggedRevs::makeMemcObj(array($ignoreRedirect, $target));
             $wgMemc->set($key, $data, $wgParserCacheExpireTime);
             // cache results
         }
         $clearEnvironment = (bool) $target;
         # Check if the we are viewing a draft or synced stable version...
     } else {
         # In both cases, we can just let MW use followRedirect()
         # on the draft as normal, avoiding any page text hits.
         $clearEnvironment = $article->isRedirect();
     }
     # Environment (e.g. $wgTitle) will change in MediaWiki::initializeArticle
     if ($clearEnvironment) {
         $view->clear();
     }
     return true;
 }
 /**
  * @brief Return current title object
  *
  * Return current title, which is later used by getUserFromTitle method
  * @return Title
  *
  */
 public function getCurrentTitle()
 {
     $this->app->wf->ProfileIn(__METHOD__);
     $title = $this->getVal('title');
     if (!empty($title) && is_string($title) && strpos($title, ':') !== false) {
         $title = F::build('Title', array($title), 'newFromText');
     }
     if ($title instanceof Title && $title->isRedirect()) {
         $article = new Article($title);
         $redirect = Title::newFromRedirectRecurse($article->getContent());
         if ($redirect instanceof Title) {
             $title = $redirect;
         }
     }
     $this->app->wf->ProfileOut(__METHOD__);
     return $title;
 }
Пример #11
0
 /**
  * Get the Title object of a form suitable for editing the target page.
  *
  * @return Title
  * @throws MWException
  */
 protected function getFormTitle()
 {
     // if no form was specified, try finding the default form for the target page.
     if ($this->mOptions['form'] === '') {
         $this->logMessage('No form specified. Will try to find the default form for the target page.', self::DEBUG);
         // if no form 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 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 warning and use the first form
         // FIXME: If we have more than one form, should we stop?
         if (count($formNames) > 1) {
             $this->logMessage(wfMessage('sf_autoedit_toomanyformsfound')->parse(), self::WARNING);
         }
         $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);
         // FIXME: Title::newFromRedirectRecurse is deprecated as of MW 1.21
         $formTitle = Title::newFromRedirectRecurse(WikiPage::factory($formTitle)->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;
 }