/**
  * Render the header of a diff page including:
  * Name with url to page
  * Bytes added/removed
  * Day and time of edit
  * Edit Comment
  */
 function showHeader()
 {
     $title = $this->targetTitle;
     if ($this->prevRev) {
         $bytesChanged = $this->rev->getSize() - $this->prevRev->getSize();
     } else {
         $bytesChanged = $this->rev->getSize();
     }
     if ($bytesChanged > 0) {
         $changeMsg = 'mobile-frontend-diffview-bytesadded';
         $sizeClass = MobileUI::iconClass('bytesadded', 'before', 'icon-12px meta mw-mf-bytesadded');
     } elseif ($bytesChanged === 0) {
         $changeMsg = 'mobile-frontend-diffview-bytesnochange';
         $sizeClass = MobileUI::iconClass('bytesneutral', 'before', 'icon-12px meta mw-mf-bytesneutral');
     } else {
         $changeMsg = 'mobile-frontend-diffview-bytesremoved';
         $sizeClass = MobileUI::iconClass('bytesremoved', 'before', 'icon-12px meta mw-mf-bytesremoved');
         $bytesChanged = abs($bytesChanged);
     }
     if ($this->rev->isMinor()) {
         $minor = ChangesList::flag('minor');
     } else {
         $minor = '';
     }
     if ($this->rev->getComment() !== '') {
         $comment = Linker::formatComment($this->rev->getComment(), $title);
     } else {
         $comment = $this->msg('mobile-frontend-changeslist-nocomment')->escaped();
     }
     $ts = new MWTimestamp($this->rev->getTimestamp());
     $this->getOutput()->addHtml(Html::openElement('div', array('id' => 'mw-mf-diff-info', 'class' => 'page-summary')) . Html::openElement('h2', array()) . Html::element('a', array('href' => $title->getLocalURL()), $title->getPrefixedText()) . Html::closeElement('h2') . $this->msg('mobile-frontend-diffview-comma')->rawParams(Html::element('span', array('class' => $sizeClass), $this->msg($changeMsg)->numParams($bytesChanged)->text()), Html::element('span', array('class' => 'mw-mf-diff-date meta'), $ts->getHumanTimestamp()))->text() . Html::closeElement('div') . $minor . Html::rawElement('div', array('id' => 'mw-mf-diff-comment'), $comment));
 }
Esempio n. 2
0
	/**
	 * @param $audience Integer: one of:
	 *      Revision::FOR_PUBLIC       to be displayed to all users
	 *      Revision::FOR_THIS_USER    to be displayed to the given user
	 *      Revision::RAW              get the text regardless of permissions
	 * @param $user User object to check for, only if FOR_THIS_USER is passed
	 *              to the $audience parameter
	 * @return string Comment stored for the last article revision
	 */
	public function getComment( $audience = Revision::FOR_PUBLIC, User $user = null ) {
		$this->loadLastEdit();
		if ( $this->mLastRevision ) {
			return $this->mLastRevision->getComment( $audience, $user );
		} else {
			return '';
		}
	}
Esempio n. 3
0
 /**
  * Wrap and format the given revision's comment block, if the current
  * user is allowed to view it.
  *
  * @param $rev Revision object
  * @param $local Boolean: whether section links should refer to local page
  * @param $isPublic Boolean: show only if all users can see it
  * @return String: HTML fragment
  */
 static function revComment(Revision $rev, $local = false, $isPublic = false)
 {
     if ($rev->getRawComment() == "") {
         return "";
     }
     if ($rev->isDeleted(Revision::DELETED_COMMENT) && $isPublic) {
         $block = " <span class=\"comment\">" . wfMsgHtml('rev-deleted-comment') . "</span>";
     } elseif ($rev->userCan(Revision::DELETED_COMMENT)) {
         $block = self::commentBlock($rev->getComment(Revision::FOR_THIS_USER), $rev->getTitle(), $local);
     } else {
         $block = " <span class=\"comment\">" . wfMsgHtml('rev-deleted-comment') . "</span>";
     }
     if ($rev->isDeleted(Revision::DELETED_COMMENT)) {
         return " <span class=\"history-deleted\">{$block}</span>";
     }
     return $block;
 }
 /**
  * Render the contribution of the pagerevision (time, bytes added/deleted, pagename comment)
  * @param Revision $rev
  */
 protected function showContributionsRow(Revision $rev)
 {
     $user = $this->getUser();
     $userId = $rev->getUser(Revision::FOR_THIS_USER, $user);
     if ($userId === 0) {
         $username = IP::prettifyIP($rev->getUserText(Revision::RAW));
         $isAnon = true;
     } else {
         $username = $rev->getUserText(Revision::FOR_THIS_USER, $user);
         $isAnon = false;
     }
     // FIXME: Style differently user comment when this is the case
     if ($rev->userCan(Revision::DELETED_COMMENT, $user)) {
         $comment = $rev->getComment(Revision::FOR_THIS_USER, $user);
         $comment = $this->formatComment($comment, $this->title);
     } else {
         $comment = $this->msg('rev-deleted-comment')->plain();
     }
     $ts = $rev->getTimestamp();
     $this->renderListHeaderWhereNeeded($this->getLanguage()->userDate($ts, $this->getUser()));
     $ts = new MWTimestamp($ts);
     if ($rev->userCan(Revision::DELETED_TEXT, $user)) {
         $diffLink = SpecialPage::getTitleFor('MobileDiff', $rev->getId())->getLocalUrl();
     } else {
         $diffLink = false;
     }
     // FIXME: Style differently user comment when this is the case
     if (!$rev->userCan(Revision::DELETED_USER, $user)) {
         $username = $this->msg('rev-deleted-user')->plain();
     }
     $bytes = null;
     if (isset($this->prevLengths[$rev->getParentId()])) {
         $bytes = $rev->getSize() - $this->prevLengths[$rev->getParentId()];
     }
     $isMinor = $rev->isMinor();
     $this->renderFeedItemHtml($ts, $diffLink, $username, $comment, $rev->getTitle(), $isAnon, $bytes, $isMinor);
 }
 /**
  * @param Revision $revision
  * @return string
  */
 protected function feedItemDesc($revision)
 {
     if ($revision) {
         $msg = wfMessage('colon-separator')->inContentLanguage()->text();
         $content = $revision->getContent();
         if ($content instanceof TextContent) {
             // only textual content has a "source view".
             $html = nl2br(htmlspecialchars($content->getNativeData()));
         } else {
             //XXX: we could get an HTML representation of the content via getParserOutput, but that may
             //     contain JS magic and generally may not be suitable for inclusion in a feed.
             //     Perhaps Content should have a getDescriptiveHtml method and/or a getSourceText method.
             //Compare also FeedUtils::formatDiffRow.
             $html = '';
         }
         return '<p>' . htmlspecialchars($revision->getUserText()) . $msg . htmlspecialchars(FeedItem::stripComment($revision->getComment())) . "</p>\n<hr />\n<div>" . $html . "</div>";
     }
     return '';
 }
 /**
  * Generate a FeedItem object from a given revision table row
  * Borrows Recent Changes' feed generation functions for formatting;
  * includes a diff to the previous revision (if any).
  *
  * @param stdClass|array $row Database row
  * @return FeedItem
  */
 function feedItem($row)
 {
     $rev = new Revision($row);
     $rev->setTitle($this->getTitle());
     $text = FeedUtils::formatDiffRow($this->getTitle(), $this->getTitle()->getPreviousRevisionID($rev->getId()), $rev->getId(), $rev->getTimestamp(), $rev->getComment());
     if ($rev->getComment() == '') {
         global $wgContLang;
         $title = $this->msg('history-feed-item-nocomment', $rev->getUserText(), $wgContLang->timeanddate($rev->getTimestamp()), $wgContLang->date($rev->getTimestamp()), $wgContLang->time($rev->getTimestamp()))->inContentLanguage()->text();
     } else {
         $title = $rev->getUserText() . $this->msg('colon-separator')->inContentLanguage()->text() . FeedItem::stripComment($rev->getComment());
     }
     return new FeedItem($title, $text, $this->getTitle()->getFullURL('diff=' . $rev->getId() . '&oldid=prev'), $rev->getTimestamp(), $rev->getUserText(), $this->getTitle()->getTalkPage()->getFullURL());
 }
 /**
  * Show a row in history, including:
  * time of edit
  * changed bytes
  * name of editor
  * comment of edit
  * @param Revision $rev Revision id of the row wants to show
  * @param Revision|null $prev Revision id of previous Revision to display the difference
  */
 protected function showRow(Revision $rev, $prev)
 {
     $user = $this->getUser();
     $userId = $rev->getUser(Revision::FOR_THIS_USER, $user);
     if ($userId === 0) {
         $username = IP::prettifyIP($rev->getUserText(Revision::RAW));
         $isAnon = true;
     } else {
         $username = $rev->getUserText(Revision::FOR_THIS_USER, $user);
         $isAnon = false;
     }
     // FIXME: Style differently user comment when this is the case
     if ($rev->userCan(Revision::DELETED_COMMENT, $user)) {
         $comment = $rev->getComment(Revision::FOR_THIS_USER, $user);
         $comment = $this->formatComment($comment, $this->title);
     } else {
         $comment = $this->msg('rev-deleted-comment')->plain();
     }
     $ts = $rev->getTimestamp();
     $this->renderListHeaderWhereNeeded($this->getLanguage()->userDate($ts, $this->getUser()));
     $ts = new MWTimestamp($ts);
     $canSeeText = $rev->userCan(Revision::DELETED_TEXT, $user);
     if ($canSeeText && $prev && $prev->userCan(Revision::DELETED_TEXT, $user)) {
         $diffLink = SpecialPage::getTitleFor('MobileDiff', $rev->getId())->getLocalUrl();
     } elseif ($canSeeText && $rev->getTitle() !== null) {
         $diffLink = $rev->getTitle()->getLocalUrl(array('oldid' => $rev->getId()));
     } else {
         $diffLink = false;
     }
     // FIXME: Style differently user comment when this is the case
     if (!$rev->userCan(Revision::DELETED_USER, $user)) {
         $username = $this->msg('rev-deleted-user')->plain();
     }
     // When the page is named there is no need to print it in output
     if ($this->title) {
         $title = null;
     } else {
         $title = $rev->getTitle();
     }
     $bytes = $rev->getSize();
     if ($prev) {
         $bytes -= $prev->getSize();
     }
     $isMinor = $rev->isMinor();
     $this->renderFeedItemHtml($ts, $diffLink, $username, $comment, $title, $isAnon, $bytes, $isMinor);
 }
 /**
  * Extract information from the Revision
  *
  * @param Revision $revision
  * @param object $row Should have a field 'ts_tags' if $this->fld_tags is set
  * @return array
  */
 protected function extractRevisionInfo(Revision $revision, $row)
 {
     $title = $revision->getTitle();
     $user = $this->getUser();
     $vals = array();
     $anyHidden = false;
     if ($this->fld_ids) {
         $vals['revid'] = intval($revision->getId());
         if (!is_null($revision->getParentId())) {
             $vals['parentid'] = intval($revision->getParentId());
         }
     }
     if ($this->fld_flags) {
         $vals['minor'] = $revision->isMinor();
     }
     if ($this->fld_user || $this->fld_userid) {
         if ($revision->isDeleted(Revision::DELETED_USER)) {
             $vals['userhidden'] = true;
             $anyHidden = true;
         }
         if ($revision->userCan(Revision::DELETED_USER, $user)) {
             if ($this->fld_user) {
                 $vals['user'] = $revision->getUserText(Revision::RAW);
             }
             $userid = $revision->getUser(Revision::RAW);
             if (!$userid) {
                 $vals['anon'] = true;
             }
             if ($this->fld_userid) {
                 $vals['userid'] = $userid;
             }
         }
     }
     if ($this->fld_timestamp) {
         $vals['timestamp'] = wfTimestamp(TS_ISO_8601, $revision->getTimestamp());
     }
     if ($this->fld_size) {
         if (!is_null($revision->getSize())) {
             $vals['size'] = intval($revision->getSize());
         } else {
             $vals['size'] = 0;
         }
     }
     if ($this->fld_sha1) {
         if ($revision->isDeleted(Revision::DELETED_TEXT)) {
             $vals['sha1hidden'] = true;
             $anyHidden = true;
         }
         if ($revision->userCan(Revision::DELETED_TEXT, $user)) {
             if ($revision->getSha1() != '') {
                 $vals['sha1'] = wfBaseConvert($revision->getSha1(), 36, 16, 40);
             } else {
                 $vals['sha1'] = '';
             }
         }
     }
     if ($this->fld_contentmodel) {
         $vals['contentmodel'] = $revision->getContentModel();
     }
     if ($this->fld_comment || $this->fld_parsedcomment) {
         if ($revision->isDeleted(Revision::DELETED_COMMENT)) {
             $vals['commenthidden'] = true;
             $anyHidden = true;
         }
         if ($revision->userCan(Revision::DELETED_COMMENT, $user)) {
             $comment = $revision->getComment(Revision::RAW);
             if ($this->fld_comment) {
                 $vals['comment'] = $comment;
             }
             if ($this->fld_parsedcomment) {
                 $vals['parsedcomment'] = Linker::formatComment($comment, $title);
             }
         }
     }
     if ($this->fld_tags) {
         if ($row->ts_tags) {
             $tags = explode(',', $row->ts_tags);
             ApiResult::setIndexedTagName($tags, 'tag');
             $vals['tags'] = $tags;
         } else {
             $vals['tags'] = array();
         }
     }
     $content = null;
     global $wgParser;
     if ($this->fetchContent) {
         $content = $revision->getContent(Revision::FOR_THIS_USER, $this->getUser());
         // Expand templates after getting section content because
         // template-added sections don't count and Parser::preprocess()
         // will have less input
         if ($content && $this->section !== false) {
             $content = $content->getSection($this->section, false);
             if (!$content) {
                 $this->dieUsage("There is no section {$this->section} in r" . $revision->getId(), 'nosuchsection');
             }
         }
         if ($revision->isDeleted(Revision::DELETED_TEXT)) {
             $vals['texthidden'] = true;
             $anyHidden = true;
         } elseif (!$content) {
             $vals['textmissing'] = true;
         }
     }
     if ($this->fld_content && $content) {
         $text = null;
         if ($this->generateXML) {
             if ($content->getModel() === CONTENT_MODEL_WIKITEXT) {
                 $t = $content->getNativeData();
                 # note: don't set $text
                 $wgParser->startExternalParse($title, ParserOptions::newFromContext($this->getContext()), Parser::OT_PREPROCESS);
                 $dom = $wgParser->preprocessToDom($t);
                 if (is_callable(array($dom, 'saveXML'))) {
                     $xml = $dom->saveXML();
                 } else {
                     $xml = $dom->__toString();
                 }
                 $vals['parsetree'] = $xml;
             } else {
                 $vals['badcontentformatforparsetree'] = true;
                 $this->setWarning("Conversion to XML is supported for wikitext only, " . $title->getPrefixedDBkey() . " uses content model " . $content->getModel());
             }
         }
         if ($this->expandTemplates && !$this->parseContent) {
             #XXX: implement template expansion for all content types in ContentHandler?
             if ($content->getModel() === CONTENT_MODEL_WIKITEXT) {
                 $text = $content->getNativeData();
                 $text = $wgParser->preprocess($text, $title, ParserOptions::newFromContext($this->getContext()));
             } else {
                 $this->setWarning("Template expansion is supported for wikitext only, " . $title->getPrefixedDBkey() . " uses content model " . $content->getModel());
                 $vals['badcontentformat'] = true;
                 $text = false;
             }
         }
         if ($this->parseContent) {
             $po = $content->getParserOutput($title, $revision->getId(), ParserOptions::newFromContext($this->getContext()));
             $text = $po->getText();
         }
         if ($text === null) {
             $format = $this->contentFormat ? $this->contentFormat : $content->getDefaultFormat();
             $model = $content->getModel();
             if (!$content->isSupportedFormat($format)) {
                 $name = $title->getPrefixedDBkey();
                 $this->setWarning("The requested format {$this->contentFormat} is not " . "supported for content model {$model} used by {$name}");
                 $vals['badcontentformat'] = true;
                 $text = false;
             } else {
                 $text = $content->serialize($format);
                 // always include format and model.
                 // Format is needed to deserialize, model is needed to interpret.
                 $vals['contentformat'] = $format;
                 $vals['contentmodel'] = $model;
             }
         }
         if ($text !== false) {
             ApiResult::setContentValue($vals, 'content', $text);
         }
     }
     if ($content && (!is_null($this->diffto) || !is_null($this->difftotext))) {
         static $n = 0;
         // Number of uncached diffs we've had
         if ($n < $this->getConfig()->get('APIMaxUncachedDiffs')) {
             $vals['diff'] = array();
             $context = new DerivativeContext($this->getContext());
             $context->setTitle($title);
             $handler = $revision->getContentHandler();
             if (!is_null($this->difftotext)) {
                 $model = $title->getContentModel();
                 if ($this->contentFormat && !ContentHandler::getForModelID($model)->isSupportedFormat($this->contentFormat)) {
                     $name = $title->getPrefixedDBkey();
                     $this->setWarning("The requested format {$this->contentFormat} is not " . "supported for content model {$model} used by {$name}");
                     $vals['diff']['badcontentformat'] = true;
                     $engine = null;
                 } else {
                     $difftocontent = ContentHandler::makeContent($this->difftotext, $title, $model, $this->contentFormat);
                     $engine = $handler->createDifferenceEngine($context);
                     $engine->setContent($content, $difftocontent);
                 }
             } else {
                 $engine = $handler->createDifferenceEngine($context, $revision->getID(), $this->diffto);
                 $vals['diff']['from'] = $engine->getOldid();
                 $vals['diff']['to'] = $engine->getNewid();
             }
             if ($engine) {
                 $difftext = $engine->getDiffBody();
                 ApiResult::setContentValue($vals['diff'], 'body', $difftext);
                 if (!$engine->wasCacheHit()) {
                     $n++;
                 }
             }
         } else {
             $vals['diff']['notcached'] = true;
         }
     }
     if ($anyHidden && $revision->isDeleted(Revision::DELETED_RESTRICTED)) {
         $vals['suppressed'] = true;
     }
     return $vals;
 }
Esempio n. 9
0
 private function extractRowInfo($row)
 {
     $revision = new Revision($row);
     $title = $revision->getTitle();
     $vals = array();
     if ($this->fld_ids) {
         $vals['revid'] = intval($revision->getId());
         // $vals['oldid'] = intval( $row->rev_text_id ); // todo: should this be exposed?
         if (!is_null($revision->getParentId())) {
             $vals['parentid'] = intval($revision->getParentId());
         }
     }
     if ($this->fld_flags && $revision->isMinor()) {
         $vals['minor'] = '';
     }
     if ($this->fld_user || $this->fld_userid) {
         if ($revision->isDeleted(Revision::DELETED_USER)) {
             $vals['userhidden'] = '';
         } else {
             if ($this->fld_user) {
                 $vals['user'] = $revision->getUserText();
             }
             $userid = $revision->getUser();
             if (!$userid) {
                 $vals['anon'] = '';
             }
             if ($this->fld_userid) {
                 $vals['userid'] = $userid;
             }
         }
     }
     if ($this->fld_timestamp) {
         $vals['timestamp'] = wfTimestamp(TS_ISO_8601, $revision->getTimestamp());
     }
     if ($this->fld_size) {
         if (!is_null($revision->getSize())) {
             $vals['size'] = intval($revision->getSize());
         } else {
             $vals['size'] = 0;
         }
     }
     if ($this->fld_sha1) {
         if ($revision->getSha1() != '') {
             $vals['sha1'] = wfBaseConvert($revision->getSha1(), 36, 16, 40);
         } else {
             $vals['sha1'] = '';
         }
     }
     if ($this->fld_comment || $this->fld_parsedcomment) {
         if ($revision->isDeleted(Revision::DELETED_COMMENT)) {
             $vals['commenthidden'] = '';
         } else {
             $comment = $revision->getComment();
             if ($this->fld_comment) {
                 $vals['comment'] = $comment;
             }
             if ($this->fld_parsedcomment) {
                 $vals['parsedcomment'] = Linker::formatComment($comment, $title);
             }
         }
     }
     if ($this->fld_tags) {
         if ($row->ts_tags) {
             $tags = explode(',', $row->ts_tags);
             $this->getResult()->setIndexedTagName($tags, 'tag');
             $vals['tags'] = $tags;
         } else {
             $vals['tags'] = array();
         }
     }
     if (!is_null($this->token)) {
         $tokenFunctions = $this->getTokenFunctions();
         foreach ($this->token as $t) {
             $val = call_user_func($tokenFunctions[$t], $title->getArticleID(), $title, $revision);
             if ($val === false) {
                 $this->setWarning("Action '{$t}' is not allowed for the current user");
             } else {
                 $vals[$t . 'token'] = $val;
             }
         }
     }
     $text = null;
     global $wgParser;
     if ($this->fld_content || !is_null($this->difftotext)) {
         $text = $revision->getText();
         // Expand templates after getting section content because
         // template-added sections don't count and Parser::preprocess()
         // will have less input
         if ($this->section !== false) {
             $text = $wgParser->getSection($text, $this->section, false);
             if ($text === false) {
                 $this->dieUsage("There is no section {$this->section} in r" . $revision->getId(), 'nosuchsection');
             }
         }
     }
     if ($this->fld_content && !$revision->isDeleted(Revision::DELETED_TEXT)) {
         if ($this->generateXML) {
             $wgParser->startExternalParse($title, ParserOptions::newFromContext($this->getContext()), OT_PREPROCESS);
             $dom = $wgParser->preprocessToDom($text);
             if (is_callable(array($dom, 'saveXML'))) {
                 $xml = $dom->saveXML();
             } else {
                 $xml = $dom->__toString();
             }
             $vals['parsetree'] = $xml;
         }
         if ($this->expandTemplates && !$this->parseContent) {
             $text = $wgParser->preprocess($text, $title, ParserOptions::newFromContext($this->getContext()));
         }
         if ($this->parseContent) {
             $text = $wgParser->parse($text, $title, ParserOptions::newFromContext($this->getContext()))->getText();
         }
         ApiResult::setContent($vals, $text);
     } elseif ($this->fld_content) {
         $vals['texthidden'] = '';
     }
     if (!is_null($this->diffto) || !is_null($this->difftotext)) {
         global $wgAPIMaxUncachedDiffs;
         static $n = 0;
         // Number of uncached diffs we've had
         if ($n < $wgAPIMaxUncachedDiffs) {
             $vals['diff'] = array();
             $context = new DerivativeContext($this->getContext());
             $context->setTitle($title);
             if (!is_null($this->difftotext)) {
                 $engine = new DifferenceEngine($context);
                 $engine->setText($text, $this->difftotext);
             } else {
                 $engine = new DifferenceEngine($context, $revision->getID(), $this->diffto);
                 $vals['diff']['from'] = $engine->getOldid();
                 $vals['diff']['to'] = $engine->getNewid();
             }
             $difftext = $engine->getDiffBody();
             ApiResult::setContent($vals['diff'], $difftext);
             if (!$engine->wasCacheHit()) {
                 $n++;
             }
         } else {
             $vals['diff']['notcached'] = '';
         }
     }
     return $vals;
 }
Esempio n. 10
0
 /**
  * Generate a FeedItem object from a given revision table row
  * Borrows Recent Changes' feed generation functions for formatting;
  * includes a diff to the previous revision (if any).
  *
  * @param $row
  * @return FeedItem
  */
 function feedItem($row)
 {
     $rev = new Revision($row);
     $rev->setTitle($this->mTitle);
     $text = rcFormatDiffRow($this->mTitle, $this->mTitle->getPreviousRevisionID($rev->getId()), $rev->getId(), $rev->getTimestamp(), $rev->getComment());
     if ($rev->getComment() == '') {
         global $wgContLang;
         $title = wfMsgForContent('history-feed-item-nocomment', $rev->getUserText(), $wgContLang->timeanddate($rev->getTimestamp()));
     } else {
         $title = $rev->getUserText() . ": " . $this->stripComment($rev->getComment());
     }
     return new FeedItem($title, $text, $this->mTitle->getFullUrl('diff=' . $rev->getId() . '&oldid=prev'), $rev->getTimestamp(), $rev->getUserText(), $this->mTitle->getTalkPage()->getFullUrl());
 }
Esempio n. 11
0
 /**
  * Perform article updates on a special page creation.
  *
  * @param Revision $rev
  *
  * @fixme This is a shitty interface function. Kill it and replace the
  * other shitty functions like editUpdates and such so it's not needed
  * anymore.
  */
 function createUpdates($rev)
 {
     $this->mGoodAdjustment = $this->isCountable($rev->getText());
     $this->mTotalAdjustment = 1;
     $this->editUpdates($rev->getText(), $rev->getComment(), $rev->isMinor(), wfTimestamp(), $rev->getId(), true);
 }
Esempio n. 12
0
 /**
  * @brief Adjusting Special:Contributions
  *
  * @param ContribsPager $contribsPager
  * @param String $ret string passed to wgOutput
  * @param Object $row Std Object with values from database table
  *
  * @return true
  */
 public function onContributionsLineEnding(&$contribsPager, &$ret, $row)
 {
     wfProfileIn(__METHOD__);
     $app = F::app();
     if (isset($row->page_namespace) && in_array(MWNamespace::getSubject($row->page_namespace), $app->wg->WallNS)) {
         $topmarktext = '';
         $rev = new Revision($row);
         $page = $rev->getTitle();
         $page->resetArticleId($row->rev_page);
         $skin = $app->wg->User->getSkin();
         $wfMsgOptsBase = $this->getMessageOptions(null, $row, true);
         $isThread = $wfMsgOptsBase['isThread'];
         $isNew = $wfMsgOptsBase['isNew'];
         $wfMsgOptsBase['createdAt'] = Xml::element('a', array('href' => $wfMsgOptsBase['articleUrl']), $app->wg->Lang->timeanddate($app->wf->Timestamp(TS_MW, $row->rev_timestamp), true));
         if ($isNew) {
             $wfMsgOptsBase['DiffLink'] = $app->wf->Msg('diff');
         } else {
             $query = array('diff' => 'prev', 'oldid' => $row->rev_id);
             $wfMsgOptsBase['DiffLink'] = Xml::element('a', array('href' => $rev->getTitle()->getLocalUrl($query)), $app->wf->Msg('diff'));
         }
         $wallMessage = F::build('WallMessage', array($page));
         $historyLink = $wallMessage->getMessagePageUrl(true) . '?action=history';
         $wfMsgOptsBase['historyLink'] = Xml::element('a', array('href' => $historyLink), $app->wf->Msg('hist'));
         // Don't show useless link to people who cannot hide revisions
         $canHide = $app->wg->User->isAllowed('deleterevision');
         if ($canHide || $rev->getVisibility() && $app->wg->User->isAllowed('deletedhistory')) {
             if (!$rev->userCan(Revision::DELETED_RESTRICTED)) {
                 $del = $skin->revDeleteLinkDisabled($canHide);
                 // revision was hidden from sysops
             } else {
                 $query = array('type' => 'revision', 'target' => $page->getPrefixedDbkey(), 'ids' => $rev->getId());
                 $del = $skin->revDeleteLink($query, $rev->isDeleted(Revision::DELETED_RESTRICTED), $canHide);
             }
             $del .= ' ';
         } else {
             $del = '';
         }
         $ret = $del;
         if (wfRunHooks('WallContributionsLine', array(MWNamespace::getSubject($row->page_namespace), $wallMessage, $wfMsgOptsBase, &$ret))) {
             $wfMsgOpts = array($wfMsgOptsBase['articleUrl'], $wfMsgOptsBase['articleTitleTxt'], $wfMsgOptsBase['wallPageUrl'], $wfMsgOptsBase['wallPageName'], $wfMsgOptsBase['createdAt'], $wfMsgOptsBase['DiffLink'], $wfMsgOptsBase['historyLink']);
             if ($isThread && $isNew) {
                 $wfMsgOpts[7] = Xml::element('strong', array(), wfMsg('newpageletter') . ' ');
             } else {
                 $wfMsgOpts[7] = '';
             }
             $ret .= $app->wf->Msg('wall-contributions-wall-line', $wfMsgOpts);
         }
         if (!$isNew) {
             $summary = $rev->getComment();
             if (empty($summary)) {
                 $msg = $app->wf->MsgForContent($this->getMessagePrefix($row->page_namespace) . '-edit');
             } else {
                 $msg = $app->wf->MsgForContent('wall-recentchanges-summary', $summary);
             }
             $ret .= ' ' . Xml::openElement('span', array('class' => 'comment')) . $msg . Xml::closeElement('span');
         }
     }
     wfProfileOut(__METHOD__);
     return true;
 }
 /**
  * Update the revision's recentchanges record if fields have been hidden
  * @param Revision $rev
  * @param int $bitfield new rev_deleted bitfield value
  */
 function updateRecentChanges($rev, $bitfield)
 {
     $this->db->update('recentchanges', array('rc_user' => $bitfield & Revision::DELETED_USER ? 0 : $rev->getUser(), 'rc_user_text' => $bitfield & Revision::DELETED_USER ? wfMsg('rev-deleted-user') : $rev->getUserText(), 'rc_comment' => $bitfield & Revision::DELETED_COMMENT ? wfMsg('rev-deleted-comment') : $rev->getComment()), array('rc_this_oldid' => $rev->getId()), 'RevisionDeleter::updateRecentChanges');
 }
 private function extractRowInfo($row)
 {
     $revision = new Revision($row);
     $title = $revision->getTitle();
     $vals = array();
     if ($this->fld_ids) {
         $vals['revid'] = intval($revision->getId());
         // $vals['oldid'] = intval( $row->rev_text_id ); // todo: should this be exposed?
         if (!is_null($revision->getParentId())) {
             $vals['parentid'] = intval($revision->getParentId());
         }
     }
     if ($this->fld_flags && $revision->isMinor()) {
         $vals['minor'] = '';
     }
     if ($this->fld_user || $this->fld_userid) {
         if ($revision->isDeleted(Revision::DELETED_USER)) {
             $vals['userhidden'] = '';
         } else {
             if ($this->fld_user) {
                 $vals['user'] = $revision->getUserText();
             }
             $userid = $revision->getUser();
             if (!$userid) {
                 $vals['anon'] = '';
             }
             if ($this->fld_userid) {
                 $vals['userid'] = $userid;
             }
         }
     }
     if ($this->fld_timestamp) {
         $vals['timestamp'] = wfTimestamp(TS_ISO_8601, $revision->getTimestamp());
     }
     if ($this->fld_size) {
         if (!is_null($revision->getSize())) {
             $vals['size'] = intval($revision->getSize());
         } else {
             $vals['size'] = 0;
         }
     }
     if ($this->fld_sha1) {
         if ($revision->getSha1() != '') {
             $vals['sha1'] = wfBaseConvert($revision->getSha1(), 36, 16, 40);
         } else {
             $vals['sha1'] = '';
         }
     }
     if ($this->fld_contentmodel) {
         $vals['contentmodel'] = $revision->getContentModel();
     }
     if ($this->fld_comment || $this->fld_parsedcomment) {
         if ($revision->isDeleted(Revision::DELETED_COMMENT)) {
             $vals['commenthidden'] = '';
         } else {
             $comment = $revision->getComment();
             if ($this->fld_comment) {
                 $vals['comment'] = $comment;
             }
             if ($this->fld_parsedcomment) {
                 $vals['parsedcomment'] = Linker::formatComment($comment, $title);
             }
         }
     }
     if ($this->fld_tags) {
         if ($row->ts_tags) {
             $tags = explode(',', $row->ts_tags);
             $this->getResult()->setIndexedTagName($tags, 'tag');
             $vals['tags'] = $tags;
         } else {
             $vals['tags'] = array();
         }
     }
     if (!is_null($this->token)) {
         $tokenFunctions = $this->getTokenFunctions();
         foreach ($this->token as $t) {
             $val = call_user_func($tokenFunctions[$t], $title->getArticleID(), $title, $revision);
             if ($val === false) {
                 $this->setWarning("Action '{$t}' is not allowed for the current user");
             } else {
                 $vals[$t . 'token'] = $val;
             }
         }
     }
     $content = null;
     global $wgParser;
     if ($this->fld_content || !is_null($this->difftotext)) {
         $content = $revision->getContent();
         // Expand templates after getting section content because
         // template-added sections don't count and Parser::preprocess()
         // will have less input
         if ($this->section !== false) {
             $content = $content->getSection($this->section, false);
             if (!$content) {
                 $this->dieUsage("There is no section {$this->section} in r" . $revision->getId(), 'nosuchsection');
             }
         }
     }
     if ($this->fld_content && !$revision->isDeleted(Revision::DELETED_TEXT)) {
         $text = null;
         if ($this->generateXML) {
             if ($content->getModel() === CONTENT_MODEL_WIKITEXT) {
                 $t = $content->getNativeData();
                 # note: don't set $text
                 $wgParser->startExternalParse($title, ParserOptions::newFromContext($this->getContext()), OT_PREPROCESS);
                 $dom = $wgParser->preprocessToDom($t);
                 if (is_callable(array($dom, 'saveXML'))) {
                     $xml = $dom->saveXML();
                 } else {
                     $xml = $dom->__toString();
                 }
                 $vals['parsetree'] = $xml;
             } else {
                 $this->setWarning("Conversion to XML is supported for wikitext only, " . $title->getPrefixedDBkey() . " uses content model " . $content->getModel() . ")");
             }
         }
         if ($this->expandTemplates && !$this->parseContent) {
             #XXX: implement template expansion for all content types in ContentHandler?
             if ($content->getModel() === CONTENT_MODEL_WIKITEXT) {
                 $text = $content->getNativeData();
                 $text = $wgParser->preprocess($text, $title, ParserOptions::newFromContext($this->getContext()));
             } else {
                 $this->setWarning("Template expansion is supported for wikitext only, " . $title->getPrefixedDBkey() . " uses content model " . $content->getModel() . ")");
                 $text = false;
             }
         }
         if ($this->parseContent) {
             $po = $content->getParserOutput($title, $revision->getId(), ParserOptions::newFromContext($this->getContext()));
             $text = $po->getText();
         }
         if ($text === null) {
             $format = $this->contentFormat ? $this->contentFormat : $content->getDefaultFormat();
             if (!$content->isSupportedFormat($format)) {
                 $model = $content->getModel();
                 $name = $title->getPrefixedDBkey();
                 $this->dieUsage("The requested format {$this->contentFormat} is not supported " . "for content model {$model} used by {$name}", 'badformat');
             }
             $text = $content->serialize($format);
             $vals['contentformat'] = $format;
         }
         if ($text !== false) {
             ApiResult::setContent($vals, $text);
         }
     } elseif ($this->fld_content) {
         $vals['texthidden'] = '';
     }
     if (!is_null($this->diffto) || !is_null($this->difftotext)) {
         global $wgAPIMaxUncachedDiffs;
         static $n = 0;
         // Number of uncached diffs we've had
         if ($n < $wgAPIMaxUncachedDiffs) {
             $vals['diff'] = array();
             $context = new DerivativeContext($this->getContext());
             $context->setTitle($title);
             $handler = $revision->getContentHandler();
             if (!is_null($this->difftotext)) {
                 $model = $title->getContentModel();
                 if ($this->contentFormat && !ContentHandler::getForModelID($model)->isSupportedFormat($this->contentFormat)) {
                     $name = $title->getPrefixedDBkey();
                     $this->dieUsage("The requested format {$this->contentFormat} is not supported for " . "content model {$model} used by {$name}", 'badformat');
                 }
                 $difftocontent = ContentHandler::makeContent($this->difftotext, $title, $model, $this->contentFormat);
                 $engine = $handler->createDifferenceEngine($context);
                 $engine->setContent($content, $difftocontent);
             } else {
                 $engine = $handler->createDifferenceEngine($context, $revision->getID(), $this->diffto);
                 $vals['diff']['from'] = $engine->getOldid();
                 $vals['diff']['to'] = $engine->getNewid();
             }
             $difftext = $engine->getDiffBody();
             ApiResult::setContent($vals['diff'], $difftext);
             if (!$engine->wasCacheHit()) {
                 $n++;
             }
         } else {
             $vals['diff']['notcached'] = '';
         }
     }
     return $vals;
 }