示例#1
0
 /**
  * Show the form
  *
  * @param array $err Error messages. Each item is an error message.
  *    It may either be a string message name or array message name and
  *    parameters, like the second argument to OutputPage::wrapWikiMsg().
  */
 function showForm($err)
 {
     global $wgContLang;
     $this->getSkin()->setRelevantTitle($this->oldTitle);
     $oldTitleLink = Linker::link($this->oldTitle);
     $out = $this->getOutput();
     $out->setPageTitle($this->msg('move-page', $this->oldTitle->getPrefixedText()));
     $out->addModules('mediawiki.special.movePage');
     $out->addModuleStyles('mediawiki.special.movePage.styles');
     $this->addHelpLink('Help:Moving a page');
     $newTitle = $this->newTitle;
     if (!$newTitle) {
         # Show the current title as a default
         # when the form is first opened.
         $newTitle = $this->oldTitle;
     } elseif (!count($err)) {
         # If a title was supplied, probably from the move log revert
         # link, check for validity. We can then show some diagnostic
         # information and save a click.
         $newerr = $this->oldTitle->isValidMoveOperation($newTitle);
         if (is_array($newerr)) {
             $err = $newerr;
         }
     }
     $user = $this->getUser();
     if (count($err) == 1 && isset($err[0][0]) && $err[0][0] == 'articleexists' && $newTitle->quickUserCan('delete', $user)) {
         $out->addWikiMsg('delete_and_move_text', $newTitle->getPrefixedText());
         $movepagebtn = $this->msg('delete_and_move')->text();
         $submitVar = 'wpDeleteAndMove';
         $confirm = true;
         $err = array();
     } else {
         if ($this->oldTitle->getNamespace() == NS_USER && !$this->oldTitle->isSubpage()) {
             $out->wrapWikiMsg("<div class=\"error mw-moveuserpage-warning\">\n\$1\n</div>", 'moveuserpage-warning');
         } elseif ($this->oldTitle->getNamespace() == NS_CATEGORY) {
             $out->wrapWikiMsg("<div class=\"error mw-movecategorypage-warning\">\n\$1\n</div>", 'movecategorypage-warning');
         }
         $out->addWikiMsg($this->getConfig()->get('FixDoubleRedirects') ? 'movepagetext' : 'movepagetext-noredirectfixer');
         $movepagebtn = $this->msg('movepagebtn')->text();
         $submitVar = 'wpMove';
         $confirm = false;
     }
     if (count($err) == 1 && isset($err[0][0]) && $err[0][0] == 'file-exists-sharedrepo' && $user->isAllowed('reupload-shared')) {
         $out->addWikiMsg('move-over-sharedrepo', $newTitle->getPrefixedText());
         $submitVar = 'wpMoveOverSharedFile';
         $err = array();
     }
     $oldTalk = $this->oldTitle->getTalkPage();
     $oldTitleSubpages = $this->oldTitle->hasSubpages();
     $oldTitleTalkSubpages = $this->oldTitle->getTalkPage()->hasSubpages();
     $canMoveSubpage = ($oldTitleSubpages || $oldTitleTalkSubpages) && !count($this->oldTitle->getUserPermissionsErrors('move-subpages', $user));
     # We also want to be able to move assoc. subpage talk-pages even if base page
     # has no associated talk page, so || with $oldTitleTalkSubpages.
     $considerTalk = !$this->oldTitle->isTalkPage() && ($oldTalk->exists() || $oldTitleTalkSubpages && $canMoveSubpage);
     $dbr = wfGetDB(DB_SLAVE);
     if ($this->getConfig()->get('FixDoubleRedirects')) {
         $hasRedirects = $dbr->selectField('redirect', '1', array('rd_namespace' => $this->oldTitle->getNamespace(), 'rd_title' => $this->oldTitle->getDBkey()), __METHOD__);
     } else {
         $hasRedirects = false;
     }
     if ($considerTalk) {
         $out->addWikiMsg('movepagetalktext');
     }
     if (count($err)) {
         $out->addHTML("<div class='error'>\n");
         $action_desc = $this->msg('action-move')->plain();
         $out->addWikiMsg('permissionserrorstext-withaction', count($err), $action_desc);
         if (count($err) == 1) {
             $errMsg = $err[0];
             $errMsgName = array_shift($errMsg);
             if ($errMsgName == 'hookaborted') {
                 $out->addHTML("<p>{$errMsg[0]}</p>\n");
             } else {
                 $out->addWikiMsgArray($errMsgName, $errMsg);
             }
         } else {
             $errStr = array();
             foreach ($err as $errMsg) {
                 if ($errMsg[0] == 'hookaborted') {
                     $errStr[] = $errMsg[1];
                 } else {
                     $errMsgName = array_shift($errMsg);
                     $errStr[] = $this->msg($errMsgName, $errMsg)->parse();
                 }
             }
             $out->addHTML('<ul><li>' . implode("</li>\n<li>", $errStr) . "</li></ul>\n");
         }
         $out->addHTML("</div>\n");
     }
     if ($this->oldTitle->isProtected('move')) {
         # Is the title semi-protected?
         if ($this->oldTitle->isSemiProtected('move')) {
             $noticeMsg = 'semiprotectedpagemovewarning';
             $classes[] = 'mw-textarea-sprotected';
         } else {
             # Then it must be protected based on static groups (regular)
             $noticeMsg = 'protectedpagemovewarning';
             $classes[] = 'mw-textarea-protected';
         }
         $out->addHTML("<div class='mw-warning-with-logexcerpt'>\n");
         $out->addWikiMsg($noticeMsg);
         LogEventsList::showLogExtract($out, 'protect', $this->oldTitle, '', array('lim' => 1));
         $out->addHTML("</div>\n");
     }
     // Byte limit (not string length limit) for wpReason and wpNewTitleMain
     // is enforced in the mediawiki.special.movePage module
     $immovableNamespaces = array();
     foreach (array_keys($this->getLanguage()->getNamespaces()) as $nsId) {
         if (!MWNamespace::isMovable($nsId)) {
             $immovableNamespaces[] = $nsId;
         }
     }
     $handler = ContentHandler::getForTitle($this->oldTitle);
     $out->enableOOUI();
     $fields = array();
     $fields[] = new OOUI\FieldLayout(new OOUI\LabelWidget(array('label' => new OOUI\HtmlSnippet("<strong>{$oldTitleLink}</strong>"))), array('label' => $this->msg('movearticle')->text(), 'align' => 'top'));
     $fields[] = new OOUI\FieldLayout(new MediaWiki\Widget\ComplexTitleInputWidget(array('id' => 'wpNewTitle', 'namespace' => array('id' => 'wpNewTitleNs', 'name' => 'wpNewTitleNs', 'value' => $newTitle->getNamespace(), 'exclude' => $immovableNamespaces), 'title' => array('id' => 'wpNewTitleMain', 'name' => 'wpNewTitleMain', 'value' => $wgContLang->recodeForEdit($newTitle->getText()), 'suggestions' => false), 'infusable' => true)), array('label' => $this->msg('newtitle')->text(), 'align' => 'top'));
     $fields[] = new OOUI\FieldLayout(new OOUI\TextInputWidget(array('name' => 'wpReason', 'id' => 'wpReason', 'maxLength' => 200, 'infusable' => true, 'value' => $this->reason)), array('label' => $this->msg('movereason')->text(), 'align' => 'top'));
     if ($considerTalk) {
         $fields[] = new OOUI\FieldLayout(new OOUI\CheckboxInputWidget(array('name' => 'wpMovetalk', 'id' => 'wpMovetalk', 'value' => '1', 'selected' => $this->moveTalk)), array('label' => $this->msg('movetalk')->text(), 'align' => 'inline'));
     }
     if ($user->isAllowed('suppressredirect')) {
         if ($handler->supportsRedirects()) {
             $isChecked = $this->leaveRedirect;
             $isDisabled = false;
         } else {
             $isChecked = false;
             $isDisabled = true;
         }
         $fields[] = new OOUI\FieldLayout(new OOUI\CheckboxInputWidget(array('name' => 'wpLeaveRedirect', 'id' => 'wpLeaveRedirect', 'value' => '1', 'selected' => $isChecked, 'disabled' => $isDisabled)), array('label' => $this->msg('move-leave-redirect')->text(), 'align' => 'inline'));
     }
     if ($hasRedirects) {
         $fields[] = new OOUI\FieldLayout(new OOUI\CheckboxInputWidget(array('name' => 'wpFixRedirects', 'id' => 'wpFixRedirects', 'value' => '1', 'selected' => $this->fixRedirects)), array('label' => $this->msg('fix-double-redirects')->text(), 'align' => 'inline'));
     }
     if ($canMoveSubpage) {
         $maximumMovedPages = $this->getConfig()->get('MaximumMovedPages');
         $fields[] = new OOUI\FieldLayout(new OOUI\CheckboxInputWidget(array('name' => 'wpMovesubpages', 'id' => 'wpMovesubpages', 'value' => '1', 'selected' => $this->moveSubpages && ($this->oldTitle->hasSubpages() || $this->moveTalk))), array('label' => new OOUI\HtmlSnippet($this->msg($this->oldTitle->hasSubpages() ? 'move-subpages' : 'move-talk-subpages')->numParams($maximumMovedPages)->params($maximumMovedPages)->parse()), 'align' => 'inline'));
     }
     # Don't allow watching if user is not logged in
     if ($user->isLoggedIn()) {
         $watchChecked = $user->isLoggedIn() && ($this->watch || $user->getBoolOption('watchmoves') || $user->isWatched($this->oldTitle));
         $fields[] = new OOUI\FieldLayout(new OOUI\CheckboxInputWidget(array('name' => 'wpWatch', 'id' => 'watch', 'value' => '1', 'selected' => $watchChecked)), array('label' => $this->msg('move-watch')->text(), 'align' => 'inline'));
     }
     if ($confirm) {
         $fields[] = new OOUI\FieldLayout(new OOUI\CheckboxInputWidget(array('name' => 'wpConfirm', 'id' => 'wpConfirm', 'value' => '1')), array('label' => $this->msg('delete_and_move_confirm')->text(), 'align' => 'inline'));
     }
     $fields[] = new OOUI\FieldLayout(new OOUI\ButtonInputWidget(array('name' => $submitVar, 'value' => $movepagebtn, 'label' => $movepagebtn, 'flags' => array('constructive', 'primary'), 'type' => 'submit')), array('align' => 'top'));
     $fieldset = new OOUI\FieldsetLayout(array('label' => $this->msg('move-page-legend')->text(), 'id' => 'mw-movepage-table', 'items' => $fields));
     $form = new OOUI\FormLayout(array('method' => 'post', 'action' => $this->getPageTitle()->getLocalURL('action=submit'), 'id' => 'movepage'));
     $form->appendContent($fieldset, new OOUI\HtmlSnippet(Html::hidden('wpOldTitle', $this->oldTitle->getPrefixedText()) . Html::hidden('wpEditToken', $user->getEditToken())));
     $out->addHTML(new OOUI\PanelLayout(array('classes' => array('movepage-wrapper'), 'expanded' => false, 'padded' => true, 'framed' => true, 'content' => $form)));
     $this->showLogFragment($this->oldTitle);
     $this->showSubpages($this->oldTitle);
 }
示例#2
0
 /**
  * Process [[ ]] wikilinks (RIL)
  * @param $s
  * @throws MWException
  * @return LinkHolderArray
  *
  * @private
  */
 function replaceInternalLinks2(&$s)
 {
     wfProfileIn(__METHOD__);
     wfProfileIn(__METHOD__ . '-setup');
     static $tc = false, $e1, $e1_img;
     # the % is needed to support urlencoded titles as well
     if (!$tc) {
         $tc = Title::legalChars() . '#%';
         # Match a link having the form [[namespace:link|alternate]]trail
         $e1 = "/^([{$tc}]+)(?:\\|(.+?))?]](.*)\$/sD";
         # Match cases where there is no "]]", which might still be images
         $e1_img = "/^([{$tc}]+)\\|(.*)\$/sD";
     }
     $holders = new LinkHolderArray($this);
     # split the entire text string on occurrences of [[
     $a = StringUtils::explode('[[', ' ' . $s);
     # get the first element (all text up to first [[), and remove the space we added
     $s = $a->current();
     $a->next();
     $line = $a->current();
     # Workaround for broken ArrayIterator::next() that returns "void"
     $s = substr($s, 1);
     $useLinkPrefixExtension = $this->getTargetLanguage()->linkPrefixExtension();
     $e2 = null;
     if ($useLinkPrefixExtension) {
         # Match the end of a line for a word that's not followed by whitespace,
         # e.g. in the case of 'The Arab al[[Razi]]', 'al' will be matched
         global $wgContLang;
         $charset = $wgContLang->linkPrefixCharset();
         $e2 = "/^((?>.*[^{$charset}]|))(.+)\$/sDu";
     }
     if (is_null($this->mTitle)) {
         wfProfileOut(__METHOD__ . '-setup');
         wfProfileOut(__METHOD__);
         throw new MWException(__METHOD__ . ": \$this->mTitle is null\n");
     }
     $nottalk = !$this->mTitle->isTalkPage();
     if ($useLinkPrefixExtension) {
         $m = array();
         if (preg_match($e2, $s, $m)) {
             $first_prefix = $m[2];
         } else {
             $first_prefix = false;
         }
     } else {
         $prefix = '';
     }
     $useSubpages = $this->areSubpagesAllowed();
     wfProfileOut(__METHOD__ . '-setup');
     # Loop for each link
     for (; $line !== false && $line !== null; $a->next(), $line = $a->current()) {
         # Check for excessive memory usage
         if ($holders->isBig()) {
             # Too big
             # Do the existence check, replace the link holders and clear the array
             $holders->replace($s);
             $holders->clear();
         }
         if ($useLinkPrefixExtension) {
             wfProfileIn(__METHOD__ . '-prefixhandling');
             if (preg_match($e2, $s, $m)) {
                 $prefix = $m[2];
                 $s = $m[1];
             } else {
                 $prefix = '';
             }
             # first link
             if ($first_prefix) {
                 $prefix = $first_prefix;
                 $first_prefix = false;
             }
             wfProfileOut(__METHOD__ . '-prefixhandling');
         }
         $might_be_img = false;
         wfProfileIn(__METHOD__ . "-e1");
         if (preg_match($e1, $line, $m)) {
             # page with normal text or alt
             $text = $m[2];
             # If we get a ] at the beginning of $m[3] that means we have a link that's something like:
             # [[Image:Foo.jpg|[http://example.com desc]]] <- having three ] in a row f***s up,
             # the real problem is with the $e1 regex
             # See bug 1300.
             #
             # Still some problems for cases where the ] is meant to be outside punctuation,
             # and no image is in sight. See bug 2095.
             #
             if ($text !== '' && substr($m[3], 0, 1) === ']' && strpos($text, '[') !== false) {
                 $text .= ']';
                 # so that replaceExternalLinks($text) works later
                 $m[3] = substr($m[3], 1);
             }
             # fix up urlencoded title texts
             if (strpos($m[1], '%') !== false) {
                 # Should anchors '#' also be rejected?
                 $m[1] = str_replace(array('<', '>'), array('&lt;', '&gt;'), rawurldecode($m[1]));
             }
             $trail = $m[3];
         } elseif (preg_match($e1_img, $line, $m)) {
             # Invalid, but might be an image with a link in its caption
             $might_be_img = true;
             $text = $m[2];
             if (strpos($m[1], '%') !== false) {
                 $m[1] = rawurldecode($m[1]);
             }
             $trail = "";
         } else {
             # Invalid form; output directly
             $s .= $prefix . '[[' . $line;
             wfProfileOut(__METHOD__ . "-e1");
             continue;
         }
         wfProfileOut(__METHOD__ . "-e1");
         wfProfileIn(__METHOD__ . "-misc");
         # Don't allow internal links to pages containing
         # PROTO: where PROTO is a valid URL protocol; these
         # should be external links.
         if (preg_match('/^(?i:' . $this->mUrlProtocols . ')/', $m[1])) {
             $s .= $prefix . '[[' . $line;
             wfProfileOut(__METHOD__ . "-misc");
             continue;
         }
         # Make subpage if necessary
         if ($useSubpages) {
             $link = $this->maybeDoSubpageLink($m[1], $text);
         } else {
             $link = $m[1];
         }
         $noforce = substr($m[1], 0, 1) !== ':';
         if (!$noforce) {
             # Strip off leading ':'
             $link = substr($link, 1);
         }
         wfProfileOut(__METHOD__ . "-misc");
         wfProfileIn(__METHOD__ . "-title");
         $nt = Title::newFromText($this->mStripState->unstripNoWiki($link));
         if ($nt === null) {
             $s .= $prefix . '[[' . $line;
             wfProfileOut(__METHOD__ . "-title");
             continue;
         }
         $ns = $nt->getNamespace();
         $iw = $nt->getInterwiki();
         wfProfileOut(__METHOD__ . "-title");
         if ($might_be_img) {
             # if this is actually an invalid link
             wfProfileIn(__METHOD__ . "-might_be_img");
             if ($ns == NS_FILE && $noforce) {
                 # but might be an image
                 $found = false;
                 while (true) {
                     # look at the next 'line' to see if we can close it there
                     $a->next();
                     $next_line = $a->current();
                     if ($next_line === false || $next_line === null) {
                         break;
                     }
                     $m = explode(']]', $next_line, 3);
                     if (count($m) == 3) {
                         # the first ]] closes the inner link, the second the image
                         $found = true;
                         $text .= "[[{$m[0]}]]{$m[1]}";
                         $trail = $m[2];
                         break;
                     } elseif (count($m) == 2) {
                         # if there's exactly one ]] that's fine, we'll keep looking
                         $text .= "[[{$m[0]}]]{$m[1]}";
                     } else {
                         # if $next_line is invalid too, we need look no further
                         $text .= '[[' . $next_line;
                         break;
                     }
                 }
                 if (!$found) {
                     # we couldn't find the end of this imageLink, so output it raw
                     # but don't ignore what might be perfectly normal links in the text we've examined
                     $holders->merge($this->replaceInternalLinks2($text));
                     $s .= "{$prefix}[[{$link}|{$text}";
                     # note: no $trail, because without an end, there *is* no trail
                     wfProfileOut(__METHOD__ . "-might_be_img");
                     continue;
                 }
             } else {
                 # it's not an image, so output it raw
                 $s .= "{$prefix}[[{$link}|{$text}";
                 # note: no $trail, because without an end, there *is* no trail
                 wfProfileOut(__METHOD__ . "-might_be_img");
                 continue;
             }
             wfProfileOut(__METHOD__ . "-might_be_img");
         }
         $wasblank = $text == '';
         if ($wasblank) {
             $text = $link;
         } else {
             # Bug 4598 madness. Handle the quotes only if they come from the alternate part
             # [[Lista d''e paise d''o munno]] -> <a href="...">Lista d''e paise d''o munno</a>
             # [[Criticism of Harry Potter|Criticism of ''Harry Potter'']]
             #    -> <a href="Criticism of Harry Potter">Criticism of <i>Harry Potter</i></a>
             $text = $this->doQuotes($text);
         }
         # Link not escaped by : , create the various objects
         if ($noforce) {
             # Interwikis
             wfProfileIn(__METHOD__ . "-interwiki");
             if ($iw && $this->mOptions->getInterwikiMagic() && $nottalk && Language::fetchLanguageName($iw, null, 'mw')) {
                 // XXX: the above check prevents links to sites with identifiers that are not language codes
                 # Bug 24502: filter duplicates
                 if (!isset($this->mLangLinkLanguages[$iw])) {
                     $this->mLangLinkLanguages[$iw] = true;
                     $this->mOutput->addLanguageLink($nt->getFullText());
                 }
                 $s = rtrim($s . $prefix);
                 $s .= trim($trail, "\n") == '' ? '' : $prefix . $trail;
                 wfProfileOut(__METHOD__ . "-interwiki");
                 continue;
             }
             wfProfileOut(__METHOD__ . "-interwiki");
             if ($ns == NS_FILE) {
                 wfProfileIn(__METHOD__ . "-image");
                 if (!wfIsBadImage($nt->getDBkey(), $this->mTitle)) {
                     if ($wasblank) {
                         # if no parameters were passed, $text
                         # becomes something like "File:Foo.png",
                         # which we don't want to pass on to the
                         # image generator
                         $text = '';
                     } else {
                         # recursively parse links inside the image caption
                         # actually, this will parse them in any other parameters, too,
                         # but it might be hard to fix that, and it doesn't matter ATM
                         $text = $this->replaceExternalLinks($text);
                         $holders->merge($this->replaceInternalLinks2($text));
                     }
                     # cloak any absolute URLs inside the image markup, so replaceExternalLinks() won't touch them
                     $s .= $prefix . $this->armorLinks($this->makeImage($nt, $text, $holders)) . $trail;
                 } else {
                     $s .= $prefix . $trail;
                 }
                 wfProfileOut(__METHOD__ . "-image");
                 continue;
             }
             if ($ns == NS_CATEGORY) {
                 wfProfileIn(__METHOD__ . "-category");
                 $s = rtrim($s . "\n");
                 # bug 87
                 if ($wasblank) {
                     $sortkey = $this->getDefaultSort();
                 } else {
                     $sortkey = $text;
                 }
                 $sortkey = Sanitizer::decodeCharReferences($sortkey);
                 $sortkey = str_replace("\n", '', $sortkey);
                 $sortkey = $this->getConverterLanguage()->convertCategoryKey($sortkey);
                 $this->mOutput->addCategory($nt->getDBkey(), $sortkey);
                 /**
                  * Strip the whitespace Category links produce, see bug 87
                  */
                 $s .= trim($prefix . $trail, "\n") == '' ? '' : $prefix . $trail;
                 wfProfileOut(__METHOD__ . "-category");
                 continue;
             }
         }
         # Self-link checking. For some languages, variants of the title are checked in
         # LinkHolderArray::doVariants() to allow batching the existence checks necessary
         # for linking to a different variant.
         if ($ns != NS_SPECIAL && $nt->equals($this->mTitle) && !$nt->hasFragment()) {
             $s .= $prefix . Linker::makeSelfLinkObj($nt, $text, '', $trail);
             continue;
         }
         # NS_MEDIA is a pseudo-namespace for linking directly to a file
         # @todo FIXME: Should do batch file existence checks, see comment below
         if ($ns == NS_MEDIA) {
             wfProfileIn(__METHOD__ . "-media");
             # Give extensions a chance to select the file revision for us
             $options = array();
             $descQuery = false;
             wfRunHooks('BeforeParserFetchFileAndTitle', array($this, $nt, &$options, &$descQuery));
             # Fetch and register the file (file title may be different via hooks)
             list($file, $nt) = $this->fetchFileAndTitle($nt, $options);
             # Cloak with NOPARSE to avoid replacement in replaceExternalLinks
             $s .= $prefix . $this->armorLinks(Linker::makeMediaLinkFile($nt, $file, $text)) . $trail;
             wfProfileOut(__METHOD__ . "-media");
             continue;
         }
         wfProfileIn(__METHOD__ . "-always_known");
         # Some titles, such as valid special pages or files in foreign repos, should
         # be shown as bluelinks even though they're not included in the page table
         #
         # @todo FIXME: isAlwaysKnown() can be expensive for file links; we should really do
         # batch file existence checks for NS_FILE and NS_MEDIA
         if ($iw == '' && $nt->isAlwaysKnown()) {
             $this->mOutput->addLink($nt);
             $s .= $this->makeKnownLinkHolder($nt, $text, array(), $trail, $prefix);
         } else {
             # Links will be added to the output link list after checking
             $s .= $holders->makeHolder($nt, $text, array(), $trail, $prefix);
         }
         wfProfileOut(__METHOD__ . "-always_known");
     }
     wfProfileOut(__METHOD__);
     return $holders;
 }
示例#3
0
 /**
  * TODO: document
  * @param Title $title
  * @return string
  */
 function getPageClasses($title)
 {
     $numeric = 'ns-' . $title->getNamespace();
     if ($title->isSpecialPage()) {
         $type = 'ns-special';
         // bug 23315: provide a class based on the canonical special page name without subpages
         list($canonicalName) = SpecialPageFactory::resolveAlias($title->getDBkey());
         if ($canonicalName) {
             $type .= ' ' . Sanitizer::escapeClass("mw-special-{$canonicalName}");
         } else {
             $type .= ' mw-invalidspecialpage';
         }
     } elseif ($title->isTalkPage()) {
         $type = 'ns-talk';
     } else {
         $type = 'ns-subject';
     }
     $name = Sanitizer::escapeClass('page-' . $title->getPrefixedText());
     return "{$numeric} {$type} {$name}";
 }
示例#4
0
 /**
  * Show an error page saying to the user that he has insufficient permissions
  * to create a new page
  *
  * @deprecated in 1.19; throw an exception directly instead
  */
 function noCreatePermission()
 {
     wfDeprecated(__METHOD__, '1.19');
     $permission = $this->mTitle->isTalkPage() ? 'createtalk' : 'createpage';
     throw new PermissionsError($permission);
 }
示例#5
0
 /**
  * @return bool
  */
 protected function showHeader()
 {
     global $wgOut, $wgUser, $wgMaxArticleSize, $wgLang;
     global $wgAllowUserCss, $wgAllowUserJs;
     if ($this->mTitle->isTalkPage()) {
         $wgOut->addWikiMsg('talkpagetext');
     }
     // Add edit notices
     $wgOut->addHTML(implode("\n", $this->mTitle->getEditNotices($this->oldid)));
     if ($this->isConflict) {
         $wgOut->wrapWikiMsg("<div class='mw-explainconflict'>\n\$1\n</div>", 'explainconflict');
         $this->edittime = $this->mArticle->getTimestamp();
     } else {
         if ($this->section != '' && !$this->isSectionEditSupported()) {
             // We use $this->section to much before this and getVal('wgSection') directly in other places
             // at this point we can't reset $this->section to '' to fallback to non-section editing.
             // Someone is welcome to try refactoring though
             $wgOut->showErrorPage('sectioneditnotsupported-title', 'sectioneditnotsupported-text');
             return false;
         }
         if ($this->section != '' && $this->section != 'new') {
             if (!$this->summary && !$this->preview && !$this->diff) {
                 $sectionTitle = self::extractSectionTitle($this->textbox1);
                 //FIXME: use Content object
                 if ($sectionTitle !== false) {
                     $this->summary = "/* {$sectionTitle} */ ";
                 }
             }
         }
         if ($this->missingComment) {
             $wgOut->wrapWikiMsg("<div id='mw-missingcommenttext'>\n\$1\n</div>", 'missingcommenttext');
         }
         if ($this->missingSummary && $this->section != 'new') {
             $wgOut->wrapWikiMsg("<div id='mw-missingsummary'>\n\$1\n</div>", 'missingsummary');
         }
         if ($this->missingSummary && $this->section == 'new') {
             $wgOut->wrapWikiMsg("<div id='mw-missingcommentheader'>\n\$1\n</div>", 'missingcommentheader');
         }
         if ($this->blankArticle) {
             $wgOut->wrapWikiMsg("<div id='mw-blankarticle'>\n\$1\n</div>", 'blankarticle');
         }
         if ($this->hookError !== '') {
             $wgOut->addWikiText($this->hookError);
         }
         if (!$this->checkUnicodeCompliantBrowser()) {
             $wgOut->addWikiMsg('nonunicodebrowser');
         }
         if ($this->section != 'new') {
             $revision = $this->mArticle->getRevisionFetched();
             if ($revision) {
                 // Let sysop know that this will make private content public if saved
                 if (!$revision->userCan(Revision::DELETED_TEXT, $wgUser)) {
                     $wgOut->wrapWikiMsg("<div class='mw-warning plainlinks'>\n\$1\n</div>\n", 'rev-deleted-text-permission');
                 } elseif ($revision->isDeleted(Revision::DELETED_TEXT)) {
                     $wgOut->wrapWikiMsg("<div class='mw-warning plainlinks'>\n\$1\n</div>\n", 'rev-deleted-text-view');
                 }
                 if (!$revision->isCurrent()) {
                     $this->mArticle->setOldSubtitle($revision->getId());
                     $wgOut->addWikiMsg('editingold');
                 }
             } elseif ($this->mTitle->exists()) {
                 // Something went wrong
                 $wgOut->wrapWikiMsg("<div class='errorbox'>\n\$1\n</div>\n", array('missing-revision', $this->oldid));
             }
         }
     }
     if (wfReadOnly()) {
         $wgOut->wrapWikiMsg("<div id=\"mw-read-only-warning\">\n\$1\n</div>", array('readonlywarning', wfReadOnlyReason()));
     } elseif ($wgUser->isAnon()) {
         if ($this->formtype != 'preview') {
             $wgOut->wrapWikiMsg("<div id='mw-anon-edit-warning'>\n\$1\n</div>", array('anoneditwarning', '{{fullurl:Special:UserLogin|returnto={{FULLPAGENAMEE}}}}', '{{fullurl:Special:UserLogin/signup|returnto={{FULLPAGENAMEE}}}}'));
         } else {
             $wgOut->wrapWikiMsg("<div id=\"mw-anon-preview-warning\">\n\$1</div>", 'anonpreviewwarning');
         }
     } else {
         if ($this->isCssJsSubpage) {
             # Check the skin exists
             if ($this->isWrongCaseCssJsPage) {
                 $wgOut->wrapWikiMsg("<div class='error' id='mw-userinvalidcssjstitle'>\n\$1\n</div>", array('userinvalidcssjstitle', $this->mTitle->getSkinFromCssJsSubpage()));
             }
             if ($this->formtype !== 'preview') {
                 if ($this->isCssSubpage && $wgAllowUserCss) {
                     $wgOut->wrapWikiMsg("<div id='mw-usercssyoucanpreview'>\n\$1\n</div>", array('usercssyoucanpreview'));
                 }
                 if ($this->isJsSubpage && $wgAllowUserJs) {
                     $wgOut->wrapWikiMsg("<div id='mw-userjsyoucanpreview'>\n\$1\n</div>", array('userjsyoucanpreview'));
                 }
             }
         }
     }
     if ($this->mTitle->isProtected('edit') && MWNamespace::getRestrictionLevels($this->mTitle->getNamespace()) !== array('')) {
         # Is the title semi-protected?
         if ($this->mTitle->isSemiProtected()) {
             $noticeMsg = 'semiprotectedpagewarning';
         } else {
             # Then it must be protected based on static groups (regular)
             $noticeMsg = 'protectedpagewarning';
         }
         LogEventsList::showLogExtract($wgOut, 'protect', $this->mTitle, '', array('lim' => 1, 'msgKey' => array($noticeMsg)));
     }
     if ($this->mTitle->isCascadeProtected()) {
         # Is this page under cascading protection from some source pages?
         list($cascadeSources, ) = $this->mTitle->getCascadeProtectionSources();
         $notice = "<div class='mw-cascadeprotectedwarning'>\n\$1\n";
         $cascadeSourcesCount = count($cascadeSources);
         if ($cascadeSourcesCount > 0) {
             # Explain, and list the titles responsible
             foreach ($cascadeSources as $page) {
                 $notice .= '* [[:' . $page->getPrefixedText() . "]]\n";
             }
         }
         $notice .= '</div>';
         $wgOut->wrapWikiMsg($notice, array('cascadeprotectedwarning', $cascadeSourcesCount));
     }
     if (!$this->mTitle->exists() && $this->mTitle->getRestrictions('create')) {
         LogEventsList::showLogExtract($wgOut, 'protect', $this->mTitle, '', array('lim' => 1, 'showIfEmpty' => false, 'msgKey' => array('titleprotectedwarning'), 'wrap' => "<div class=\"mw-titleprotectedwarning\">\n\$1</div>"));
     }
     if ($this->kblength === false) {
         $this->kblength = (int) (strlen($this->textbox1) / 1024);
     }
     if ($this->tooBig || $this->kblength > $wgMaxArticleSize) {
         $wgOut->wrapWikiMsg("<div class='error' id='mw-edit-longpageerror'>\n\$1\n</div>", array('longpageerror', $wgLang->formatNum($this->kblength), $wgLang->formatNum($wgMaxArticleSize)));
     } else {
         if (!wfMessage('longpage-hint')->isDisabled()) {
             $wgOut->wrapWikiMsg("<div id='mw-edit-longpage-hint'>\n\$1\n</div>", array('longpage-hint', $wgLang->formatSize(strlen($this->textbox1)), strlen($this->textbox1)));
         }
     }
     # Add header copyright warning
     $this->showHeaderCopyrightWarning();
     return true;
 }
示例#6
0
 /**
  * Show subpages of the page being moved. Section is not shown if both current
  * namespace does not support subpages and no talk subpages were found.
  *
  * @param Title $title Page being moved.
  */
 function showSubpages($title)
 {
     $nsHasSubpages = MWNamespace::hasSubpages($title->getNamespace());
     $subpages = $title->getSubpages();
     $count = $subpages instanceof TitleArray ? $subpages->count() : 0;
     $titleIsTalk = $title->isTalkPage();
     $subpagesTalk = $title->getTalkPage()->getSubpages();
     $countTalk = $subpagesTalk instanceof TitleArray ? $subpagesTalk->count() : 0;
     $totalCount = $count + $countTalk;
     if (!$nsHasSubpages && $countTalk == 0) {
         return;
     }
     $this->getOutput()->wrapWikiMsg('== $1 ==', ['movesubpage', $titleIsTalk ? $count : $totalCount]);
     if ($nsHasSubpages) {
         $this->showSubpagesList($subpages, $count, 'movesubpagetext', true);
     }
     if (!$titleIsTalk && $countTalk > 0) {
         $this->showSubpagesList($subpagesTalk, $countTalk, 'movesubpagetalktext');
     }
 }
示例#7
0
 protected function addTalkPageText()
 {
     global $wgOut;
     if ($this->mTitle->isTalkPage()) {
         $wgOut->addWikiMsg('talkpagetext');
     }
 }
 /**
  * This is the function that gets called for "action=edit". It
  * sets up various member variables, then passes execution to
  * another function, usually showEditForm()
  *
  * The edit form is self-submitting, so that when things like
  * preview and edit conflicts occur, we get the same form back
  * with the extra stuff added.  Only when the final submission
  * is made and all is well do we actually save and redirect to
  * the newly-edited page.
  */
 function edit()
 {
     global $wgOut, $wgRequest, $wgUser;
     // Allow extensions to modify/prevent this form or submission
     if (!wfRunHooks('AlternateEdit', array($this))) {
         return;
     }
     wfProfileIn(__METHOD__);
     wfDebug(__METHOD__ . ": enter\n");
     // This is not an article
     $wgOut->setArticleFlag(false);
     $this->importFormData($wgRequest);
     $this->firsttime = false;
     if ($this->live) {
         $this->livePreview();
         wfProfileOut(__METHOD__);
         return;
     }
     if (wfReadOnly() && $this->save) {
         // Force preview
         $this->save = false;
         $this->preview = true;
     }
     $wgOut->addModules(array('mediawiki.action.edit'));
     if ($wgUser->getOption('uselivepreview', false)) {
         $wgOut->addModules('mediawiki.legacy.preview');
     }
     // Bug #19334: textarea jumps when editing articles in IE8
     $wgOut->addStyle('common/IE80Fixes.css', 'screen', 'IE 8');
     $permErrors = $this->getEditPermissionErrors();
     if ($permErrors) {
         // Auto-block user's IP if the account was "hard" blocked
         $wgUser->spreadAnyEditBlock();
         wfDebug(__METHOD__ . ": User can't edit\n");
         $content = $this->getContent(null);
         $content = $content === '' ? null : $content;
         $this->readOnlyPage($content, true, $permErrors, 'edit');
         wfProfileOut(__METHOD__);
         return;
     } else {
         if ($this->save) {
             $this->formtype = 'save';
         } elseif ($this->preview) {
             $this->formtype = 'preview';
         } elseif ($this->diff) {
             $this->formtype = 'diff';
         } else {
             # First time through
             $this->firsttime = true;
             if ($this->previewOnOpen()) {
                 $this->formtype = 'preview';
             } else {
                 $this->formtype = 'initial';
             }
         }
     }
     // If they used redlink=1 and the page exists, redirect to the main article
     if ($wgRequest->getBool('redlink') && $this->mTitle->exists()) {
         $wgOut->redirect($this->mTitle->getFullURL());
     }
     wfProfileIn(__METHOD__ . "-business-end");
     $this->isConflict = false;
     // css / js subpages of user pages get a special treatment
     $this->isCssJsSubpage = $this->mTitle->isCssJsSubpage();
     $this->isCssSubpage = $this->mTitle->isCssSubpage();
     $this->isJsSubpage = $this->mTitle->isJsSubpage();
     $this->isWrongCaseCssJsPage = $this->isWrongCaseCssJsPage();
     $this->isNew = !$this->mTitle->exists() || $this->section == 'new';
     # Show applicable editing introductions
     if ($this->formtype == 'initial' || $this->firsttime) {
         $this->showIntro();
     }
     if ($this->mTitle->isTalkPage()) {
         $wgOut->addWikiMsg('talkpagetext');
     }
     # Optional notices on a per-namespace and per-page basis
     $editnotice_ns = 'editnotice-' . $this->mTitle->getNamespace();
     $editnotice_ns_message = wfMessage($editnotice_ns)->inContentLanguage();
     if ($editnotice_ns_message->exists()) {
         $wgOut->addWikiText($editnotice_ns_message->plain());
     }
     if (MWNamespace::hasSubpages($this->mTitle->getNamespace())) {
         $parts = explode('/', $this->mTitle->getDBkey());
         $editnotice_base = $editnotice_ns;
         while (count($parts) > 0) {
             $editnotice_base .= '-' . array_shift($parts);
             $editnotice_base_msg = wfMessage($editnotice_base)->inContentLanguage();
             if ($editnotice_base_msg->exists()) {
                 $wgOut->addWikiText($editnotice_base_msg->plain());
             }
         }
     }
     # Attempt submission here.  This will check for edit conflicts,
     # and redundantly check for locked database, blocked IPs, etc.
     # that edit() already checked just in case someone tries to sneak
     # in the back door with a hand-edited submission URL.
     if ('save' == $this->formtype) {
         if (!$this->attemptSave()) {
             wfProfileOut(__METHOD__ . "-business-end");
             wfProfileOut(__METHOD__);
             return;
         }
     }
     # First time through: get contents, set time for conflict
     # checking, etc.
     if ('initial' == $this->formtype || $this->firsttime) {
         if ($this->initialiseForm() === false) {
             $this->noSuchSectionPage();
             wfProfileOut(__METHOD__ . "-business-end");
             wfProfileOut(__METHOD__);
             return;
         }
         if (!$this->mTitle->getArticleId()) {
             wfRunHooks('EditFormPreloadText', array(&$this->textbox1, &$this->mTitle));
         } else {
             wfRunHooks('EditFormInitialText', array($this));
         }
     }
     $this->showEditForm();
     wfProfileOut(__METHOD__ . "-business-end");
     wfProfileOut(__METHOD__);
 }
 /**
  * Given a page title, returns the Open Graph representation.
  * @param Title $title
  * @return OpenGraphObject|NULL
  */
 public static function newFromTitle($title)
 {
     global $wgFbNamespace;
     if ($title instanceof Title) {
         // Talk pages redirect to subject pages
         if ($title->isTalkPage()) {
             // TODO: Parse subject page to extract <opengraph> attributes
             $title = $title->getSubjectPage();
         }
         // Use built-in type "website" for main page
         if ($title->equals(Title::newMainPage())) {
             global $wgSitename, $wgContentLanguage;
             return new OpenGraphArticleObject($title, array('og:type' => 'website', 'og:description' => $wgSitename . ' (' . $wgContentLanguage . ')'));
         }
         // File
         if ($title->getNamespace() == NS_FILE) {
             //$file = wfLocalFile( $title );
             $file = wfFindFile($title);
             if (!empty($file) && $file->exists()) {
                 return self::newFromFile($file);
             }
             return NULL;
         }
         // Blog articles are used by an extension on Wikia
         if (defined('NS_BLOG_ARTICLE') && $title->getNamespace() == NS_BLOG_ARTICLE || defined('NS_BLOG_ARTICLE_TALK') && $title->getNamespace() == NS_BLOG_ARTICLE_TALK) {
             global $wgServer, $wgUser;
             // Use a custom image for blog posts
             $image = $wgServer . '/index.php?action=ajax&rs=FacebookPushEvent::showImage&time=' . time() . '&fb_id=' . $wgUser->getId() . '&event=FBPush_OnAddBlogPost&img=blogpost.png';
             $parameters = array('og:type' => $this->translateType('blog'), 'og:image' => $image);
             return new OpenGraphArticleObject($title, $parameters);
         }
         // Don't consider NS_SPECIAL and NS_MEDIA to be articles
         if ($title->canExist()) {
             $parameters = FacebookOpenGraph::resolveTitle($title);
             // Prepend Open Graph properties with 'og:' or the app namespace
             foreach ($parameters as $name => $value) {
                 unset($parameters[$name]);
                 // Unset properties with no content
                 if (empty($value)) {
                     continue;
                 }
                 // Ignore parameters starting with fb:
                 if (substr($name, 0, 3) == 'fb:') {
                     continue;
                 }
                 // Prepent og: to built-in properties and namespace: to custom properties
                 if (in_array('og:' . $name, OpenGraphArticleObject::getBuiltinProperties())) {
                     $parameters['og:' . $name] = $value;
                 } else {
                     if (FacebookAPI::isNamespaceSetup()) {
                         $parameters[$wgFbNamespace . ':' . $name] = $value;
                     }
                 }
             }
             // Need to prepend the custom type with the namespace
             if (isset($parameters['og:type']) && FacebookAPI::isNamespaceSetup()) {
                 $parameters['og:type'] = $wgFbNamespace . ':' . $parameters['og:type'];
             }
             return new OpenGraphArticleObject($title, $parameters);
         }
     }
     return NULL;
 }
示例#10
0
 /**
  * Clears caches when article is deleted
  *
  * @param Title $title
  */
 public static function onArticleDelete($title)
 {
     // Update existence markers on article/talk tabs...
     if ($title->isTalkPage()) {
         $other = $title->getSubjectPage();
     } else {
         $other = $title->getTalkPage();
     }
     $other->invalidateCache();
     $other->purgeSquid();
     $title->touchLinks();
     $title->purgeSquid();
     // File cache
     HTMLFileCache::clearFileCache($title);
     InfoAction::invalidateCache($title);
     // Messages
     if ($title->getNamespace() == NS_MEDIAWIKI) {
         MessageCache::singleton()->replace($title->getDBkey(), false);
     }
     // Images
     if ($title->getNamespace() == NS_FILE) {
         $update = new HTMLCacheUpdate($title, 'imagelinks');
         $update->doUpdate();
     }
     // User talk pages
     if ($title->getNamespace() == NS_USER_TALK) {
         $user = User::newFromName($title->getText(), false);
         if ($user) {
             $user->setNewtalk(false);
         }
     }
     // Image redirects
     RepoGroup::singleton()->getLocalRepo()->invalidateImageRedirect($title);
 }
示例#11
0
 /**
  * Process [[ ]] wikilinks (RIL)
  * @return LinkHolderArray
  *
  * @private
  */
 function replaceInternalLinks2(&$s)
 {
     wfProfileIn(__METHOD__);
     # RTE (Rich Text Editor) - begin
     # @author: Inez Korczyński
     global $wgRTEParserEnabled;
     # RTE (Rich Text Editor) - end
     wfProfileIn(__METHOD__ . '-setup');
     static $tc = FALSE, $e1, $e1_img;
     # the % is needed to support urlencoded titles as well
     if (!$tc) {
         $tc = Title::legalChars() . '#%';
         # Match a link having the form [[namespace:link|alternate]]trail
         $e1 = "/^([{$tc}]+)(?:\\|(.+?))?]](.*)\$/sD";
         # Match cases where there is no "]]", which might still be images
         $e1_img = "/^([{$tc}]+)\\|(.*)\$/sD";
     }
     $holders = new LinkHolderArray($this);
     # split the entire text string on occurences of [[
     $a = StringUtils::explode('[[', ' ' . $s);
     # get the first element (all text up to first [[), and remove the space we added
     $s = $a->current();
     $a->next();
     $line = $a->current();
     # Workaround for broken ArrayIterator::next() that returns "void"
     $s = substr($s, 1);
     $useLinkPrefixExtension = $this->getTargetLanguage()->linkPrefixExtension();
     $e2 = null;
     if ($useLinkPrefixExtension) {
         # Match the end of a line for a word that's not followed by whitespace,
         # e.g. in the case of 'The Arab al[[Razi]]', 'al' will be matched
         $e2 = wfMsgForContent('linkprefix');
     }
     if (is_null($this->mTitle)) {
         wfProfileOut(__METHOD__ . '-setup');
         wfProfileOut(__METHOD__);
         throw new MWException(__METHOD__ . ": \$this->mTitle is null\n");
     }
     $nottalk = !$this->mTitle->isTalkPage();
     if ($useLinkPrefixExtension) {
         $m = array();
         if (preg_match($e2, $s, $m)) {
             $first_prefix = $m[2];
         } else {
             $first_prefix = false;
         }
     } else {
         $prefix = '';
     }
     if ($this->getConverterLanguage()->hasVariants()) {
         $selflink = $this->getConverterLanguage()->autoConvertToAllVariants($this->mTitle->getPrefixedText());
     } else {
         $selflink = array($this->mTitle->getPrefixedText());
     }
     $useSubpages = $this->areSubpagesAllowed();
     wfProfileOut(__METHOD__ . '-setup');
     # Loop for each link
     for (; $line !== false && $line !== null; $a->next(), $line = $a->current()) {
         # Check for excessive memory usage
         if ($holders->isBig()) {
             # Too big
             # Do the existence check, replace the link holders and clear the array
             $holders->replace($s);
             $holders->clear();
         }
         # RTE (Rich Text Editor) - begin
         # @author: Inez Korczyński
         if (!empty($wgRTEParserEnabled)) {
             $RTE_wikitextIdx = RTEMarker::getDataIdx(RTEMarker::INTERNAL_WIKITEXT, $line);
             // decode entities inside links wikimarkup (RT #38844)
             if ($pos = strpos($line, ']]')) {
                 // unmark entities inside link
                 $link = substr($line, 0, $pos);
                 $link = RTEParser::unmarkEntities($link);
                 // leave the rest of the line untouched
                 $line = $link . substr($line, $pos);
             }
         }
         # RTE - end
         if ($useLinkPrefixExtension) {
             wfProfileIn(__METHOD__ . '-prefixhandling');
             if (preg_match($e2, $s, $m)) {
                 $prefix = $m[2];
                 $s = $m[1];
             } else {
                 $prefix = '';
             }
             # first link
             if ($first_prefix) {
                 $prefix = $first_prefix;
                 $first_prefix = false;
             }
             wfProfileOut(__METHOD__ . '-prefixhandling');
         }
         $might_be_img = false;
         wfProfileIn(__METHOD__ . "-e1");
         if (preg_match($e1, $line, $m)) {
             # page with normal text or alt
             $text = $m[2];
             # If we get a ] at the beginning of $m[3] that means we have a link that's something like:
             # [[Image:Foo.jpg|[http://example.com desc]]] <- having three ] in a row f***s up,
             # the real problem is with the $e1 regex
             # See bug 1300.
             #
             # Still some problems for cases where the ] is meant to be outside punctuation,
             # and no image is in sight. See bug 2095.
             #
             if ($text !== '' && substr($m[3], 0, 1) === ']' && strpos($text, '[') !== false) {
                 $text .= ']';
                 # so that replaceExternalLinks($text) works later
                 $m[3] = substr($m[3], 1);
             }
             # fix up urlencoded title texts
             if (strpos($m[1], '%') !== false) {
                 # Should anchors '#' also be rejected?
                 $m[1] = str_replace(array('<', '>'), array('&lt;', '&gt;'), rawurldecode($m[1]));
             }
             $trail = $m[3];
         } elseif (preg_match($e1_img, $line, $m)) {
             # Invalid, but might be an image with a link in its caption
             $might_be_img = true;
             $text = $m[2];
             if (strpos($m[1], '%') !== false) {
                 $m[1] = rawurldecode($m[1]);
             }
             $trail = "";
         } else {
             # Invalid form; output directly
             $s .= $prefix . '[[' . $line;
             wfProfileOut(__METHOD__ . "-e1");
             continue;
         }
         wfProfileOut(__METHOD__ . "-e1");
         wfProfileIn(__METHOD__ . "-misc");
         # Don't allow internal links to pages containing
         # PROTO: where PROTO is a valid URL protocol; these
         # should be external links.
         if (preg_match('/^(?:' . wfUrlProtocols() . ')/', $m[1])) {
             $s .= $prefix . '[[' . $line;
             wfProfileOut(__METHOD__ . "-misc");
             continue;
         }
         # Make subpage if necessary
         if ($useSubpages) {
             $link = $this->maybeDoSubpageLink($m[1], $text);
         } else {
             $link = $m[1];
         }
         $noforce = substr($m[1], 0, 1) !== ':';
         if (!$noforce) {
             # Strip off leading ':'
             $link = substr($link, 1);
         }
         wfProfileOut(__METHOD__ . "-misc");
         wfProfileIn(__METHOD__ . "-title");
         $nt = Title::newFromText($this->mStripState->unstripNoWiki($link));
         if ($nt === null) {
             $s .= $prefix . '[[' . $line;
             wfProfileOut(__METHOD__ . "-title");
             continue;
         }
         $ns = $nt->getNamespace();
         $iw = $nt->getInterWiki();
         wfProfileOut(__METHOD__ . "-title");
         if ($might_be_img) {
             # if this is actually an invalid link
             wfProfileIn(__METHOD__ . "-might_be_img");
             if (($ns == NS_FILE || $ns == NS_VIDEO) && $noforce) {
                 # but might be an image
                 $found = false;
                 while (true) {
                     # look at the next 'line' to see if we can close it there
                     $a->next();
                     $next_line = $a->current();
                     if ($next_line === false || $next_line === null) {
                         break;
                     }
                     $m = explode(']]', $next_line, 3);
                     if (count($m) == 3) {
                         # the first ]] closes the inner link, the second the image
                         $found = true;
                         $text .= "[[{$m[0]}]]{$m[1]}";
                         $trail = $m[2];
                         break;
                     } elseif (count($m) == 2) {
                         # if there's exactly one ]] that's fine, we'll keep looking
                         $text .= "[[{$m[0]}]]{$m[1]}";
                     } else {
                         # if $next_line is invalid too, we need look no further
                         $text .= '[[' . $next_line;
                         break;
                     }
                 }
                 if (!$found) {
                     # we couldn't find the end of this imageLink, so output it raw
                     # but don't ignore what might be perfectly normal links in the text we've examined
                     $holders->merge($this->replaceInternalLinks2($text));
                     $s .= "{$prefix}[[{$link}|{$text}";
                     # note: no $trail, because without an end, there *is* no trail
                     wfProfileOut(__METHOD__ . "-might_be_img");
                     continue;
                 }
             } else {
                 # it's not an image, so output it raw
                 $s .= "{$prefix}[[{$link}|{$text}";
                 # note: no $trail, because without an end, there *is* no trail
                 wfProfileOut(__METHOD__ . "-might_be_img");
                 continue;
             }
             wfProfileOut(__METHOD__ . "-might_be_img");
         }
         $wasblank = $text == '';
         if ($wasblank) {
             $text = $link;
         } else {
             # Bug 4598 madness. Handle the quotes only if they come from the alternate part
             # [[Lista d''e paise d''o munno]] -> <a href="...">Lista d''e paise d''o munno</a>
             # [[Criticism of Harry Potter|Criticism of ''Harry Potter'']]
             #    -> <a href="Criticism of Harry Potter">Criticism of <i>Harry Potter</i></a>
             $text = $this->doQuotes($text);
         }
         # Link not escaped by : , create the various objects
         if ($noforce) {
             global $wgContLang;
             # Interwikis
             if (empty($wgRTEParserEnabled)) {
                 # wikia
                 wfProfileIn(__METHOD__ . "-interwiki");
                 if ($iw && $this->mOptions->getInterwikiMagic() && $nottalk && $wgContLang->getLanguageName($iw)) {
                     $this->mOutput->addLanguageLink($nt->getFullText());
                     $s = rtrim($s . $prefix);
                     $s .= trim($trail, "\n") == '' ? '' : $prefix . $trail;
                     wfProfileOut(__METHOD__ . "-interwiki");
                     continue;
                 }
                 wfProfileOut(__METHOD__ . "-interwiki");
             }
             # wikia
             if ($ns == NS_FILE) {
                 wfProfileIn(__METHOD__ . "-image");
                 if (!wfIsBadImage($nt->getDBkey(), $this->mTitle)) {
                     if ($wasblank) {
                         # if no parameters were passed, $text
                         # becomes something like "File:Foo.png",
                         # which we don't want to pass on to the
                         # image generator
                         $text = '';
                     } else {
                         # recursively parse links inside the image caption
                         # actually, this will parse them in any other parameters, too,
                         # but it might be hard to fix that, and it doesn't matter ATM
                         $text = $this->replaceExternalLinks($text);
                         $holders->merge($this->replaceInternalLinks2($text));
                     }
                     # RTE (Rich Text Editor) - begin
                     # @author: Inez Korczyński
                     if (!empty($wgRTEParserEnabled)) {
                         $text = RTEMarker::generate(RTEMarker::IMAGE_DATA, $RTE_wikitextIdx) . $text;
                     }
                     # RTE - end
                     # cloak any absolute URLs inside the image markup, so replaceExternalLinks() won't touch them
                     /** wikia
                     				$s .= $prefix . $this->armorLinks(
                     					$this->makeImage( $nt, $text, $holders ) ) . $trail;
                     				wikia **/
                     # cater for new placeholder-in-template namespace -  Bartek
                     # TODO: Get the hell out with this code from here this can be done in hook handler fired in makeImage function - Inez
                     if ("Template Placeholder" != $nt->getText()) {
                         $s .= $prefix . $this->armorLinks($this->makeImage($nt, $text, $holders)) . $trail;
                     } else {
                         $s .= $prefix . $this->armorLinks(ImagePlaceholder_makeDullImage($nt, $text, $holders)) . $trail;
                     }
                 } else {
                     $s .= $prefix . $trail;
                 }
                 wfProfileOut(__METHOD__ . "-image");
                 continue;
             }
             if ($ns == NS_CATEGORY) {
                 wfProfileIn(__METHOD__ . "-category");
                 # RTE (Rich Text Editor) - begin
                 # @author: Inez Korczyński
                 # Category handling
                 if (!empty($wgRTEParserEnabled)) {
                     $dataIdx = RTEData::put('placeholder', array('type' => 'category', 'wikitextIdx' => $RTE_wikitextIdx));
                     $s .= $prefix . RTEMarker::generate(RTEMarker::PLACEHOLDER, $dataIdx) . $trail;
                 } else {
                     $s = rtrim($s . "\n");
                     # bug 87
                     if ($wasblank) {
                         $sortkey = $this->getDefaultSort();
                     } else {
                         $sortkey = $text;
                     }
                     $sortkey = Sanitizer::decodeCharReferences($sortkey);
                     $sortkey = str_replace("\n", '', $sortkey);
                     $sortkey = $this->getConverterLanguage()->convertCategoryKey($sortkey);
                     $this->mOutput->addCategory($nt->getDBkey(), $sortkey);
                     /**
                      * Strip the whitespace Category links produce, see bug 87
                      * @todo We might want to use trim($tmp, "\n") here.
                      */
                     $s .= trim($prefix . $trail, "\n") == '' ? '' : $prefix . $trail;
                 }
                 wfProfileOut(__METHOD__ . "-category");
                 continue;
             }
             /* Wikia change begin - @author: Owen Davis */
             /* Support for [[Poll:...]] */
             if (defined("NS_WIKIA_POLL") && $ns == NS_WIKIA_POLL) {
                 $poll = WikiaPoll::newFromTitle($nt);
                 if ($poll instanceof WikiaPoll) {
                     # RTE (Rich Text Editor) - begin
                     # @author: Owen Davis
                     if (!empty($wgRTEParserEnabled)) {
                         $s .= $prefix . WikiaPollHooks::generateRTE($poll, $nt, $RTE_wikitextIdx) . $trail;
                     } else {
                         $s .= $prefix . WikiaPollHooks::generate($poll, $nt) . $trail;
                     }
                     # RTE - end
                     continue;
                 }
             }
             /* Wikia change end */
         }
         # RTE (Rich Text Editor) - begin
         # @author: Inez Korczyński
         # No special handling for self-linking in RTE mode
         # Self-link checking
         if (empty($wgRTEParserEnabled) && $nt->getFragment() === '' && $ns != NS_SPECIAL) {
             if (in_array($nt->getPrefixedText(), $selflink, true)) {
                 $s .= $prefix . Linker::makeSelfLinkObj($nt, $text, '', $trail);
                 continue;
             }
         }
         # RTE - end
         # NS_MEDIA is a pseudo-namespace for linking directly to a file
         # @todo FIXME: Should do batch file existence checks, see comment below
         if ($ns == NS_MEDIA) {
             # RTE (Rich Text Editor) - begin
             # @author: macbre
             # BugId:1694 - handle [[Media:xxx]] as placeholders
             if (!empty($wgRTEParserEnabled)) {
                 $dataIdx = RTEData::put('placeholder', array('type' => 'media', 'wikitextIdx' => $RTE_wikitextIdx));
                 $s .= $prefix . RTEMarker::generate(RTEMarker::PLACEHOLDER, $dataIdx) . $trail;
                 continue;
             }
             # RTE - end
             wfProfileIn(__METHOD__ . "-media");
             # Give extensions a chance to select the file revision for us
             $options = array();
             $descQuery = false;
             wfRunHooks('BeforeParserFetchFileAndTitle', array($this, $nt, &$options, &$descQuery));
             # Fetch and register the file (file title may be different via hooks)
             list($file, $nt) = $this->fetchFileAndTitle($nt, $options);
             # Cloak with NOPARSE to avoid replacement in replaceExternalLinks
             $s .= $prefix . $this->armorLinks(Linker::makeMediaLinkFile($nt, $file, $text)) . $trail;
             wfProfileOut(__METHOD__ . "-media");
             continue;
         }
         wfProfileIn(__METHOD__ . "-always_known");
         # RTE (Rich Text Editor) - begin
         # @author: Inez Korczyński
         if (!empty($wgRTEParserEnabled)) {
             $text = RTEMarker::generate(RTEMarker::INTERNAL_DATA, RTEData::put('data', array('type' => 'internal', 'wikitextIdx' => $RTE_wikitextIdx, 'text' => $text, 'link' => $link, 'wasblank' => $wasblank, 'noforce' => $noforce))) . $text;
         }
         # RTE - end
         # Some titles, such as valid special pages or files in foreign repos, should
         # be shown as bluelinks even though they're not included in the page table
         #
         # @todo FIXME: isAlwaysKnown() can be expensive for file links; we should really do
         # batch file existence checks for NS_FILE and NS_MEDIA
         if ($iw == '' && $nt->isAlwaysKnown()) {
             $this->mOutput->addLink($nt);
             $s .= $this->makeKnownLinkHolder($nt, $text, array(), $trail, $prefix);
         } else {
             # Links will be added to the output link list after checking
             $s .= $holders->makeHolder($nt, $text, array(), $trail, $prefix);
         }
         wfProfileOut(__METHOD__ . "-always_known");
     }
     wfProfileOut(__METHOD__);
     return $holders;
 }