/**
  * Handle the 'unapprovefile' action, defined for ApprovedRevs -
  * unset the previously-approved revision, log the change, and show
  * a message to the user.
  */
 public static function unsetFileAsApproved($action, $article)
 {
     // return "true" if the call failed (meaning, pass on handling
     // of the hook to others), and "false" otherwise
     if ($action != 'unapprovefile') {
         return true;
     }
     $title = $article->getTitle();
     if (!ApprovedRevs::userCanApprove($title)) {
         return true;
     }
     ApprovedRevs::unsetApprovedFileInDB($title);
     // the message depends on whether the page should display
     // a blank right now or not
     global $egApprovedRevsBlankIfUnapproved;
     if ($egApprovedRevsBlankIfUnapproved) {
         $successMsg = wfMessage('approvedrevs-unapprovesuccess2')->text();
     } else {
         $successMsg = wfMessage('approvedrevs-unapprovesuccess')->text();
     }
     global $wgOut;
     $wgOut->addHTML("\t\t" . Xml::element('div', array('class' => 'successbox'), $successMsg) . "\n");
     $wgOut->addHTML("\t\t" . Xml::element('p', array('style' => 'clear: both')) . "\n");
     // show the revision, instead of the history page
     $article->doPurge();
     $article->view();
     return false;
 }
Beispiel #2
0
 /**
  * Display a message to the user if (a) "blank if unapproved" is set,
  * (b) the page is approvable, (c) the user has 'viewlinktolatest'
  * permission, and (d) either the page has no approved revision, or
  * the user is looking at a revision that's not the latest - the
  * displayed message depends on which of those cases it is.
  * @TODO - this should probably get split up into two methods.
  *
  * @since 0.5.6
  *
  * @param Article &$article
  * @param boolean $outputDone
  * @param boolean $useParserCache
  *
  * @return true
  */
 public static function setArticleHeader(Article &$article, &$outputDone, &$useParserCache)
 {
     global $wgOut, $wgRequest, $egApprovedRevsBlankIfUnapproved;
     // For now, we only set the header if "blank if unapproved"
     // is set.
     if (!$egApprovedRevsBlankIfUnapproved) {
         return true;
     }
     $title = $article->getTitle();
     if (!ApprovedRevs::pageIsApprovable($title)) {
         return true;
     }
     // If the user isn't supposed to see these kinds of
     // messages, exit.
     if (!$title->userCan('viewlinktolatest')) {
         return false;
     }
     // If there's an approved revision for this page, and the
     // user is looking at it - either by simply going to the page,
     // or by looking at the revision that happens to be approved -
     // don't display anything.
     $approvedRevID = ApprovedRevs::getApprovedRevID($title);
     if (!empty($approvedRevID) && (!$wgRequest->getCheck('oldid') || $wgRequest->getInt('oldid') == $approvedRevID)) {
         return true;
     }
     // Disable caching, so that if it's a specific ID being shown
     // that happens to be the latest, it doesn't show a blank page.
     $useParserCache = false;
     $wgOut->addHTML('<span style="margin-left: 10.75px">');
     // If the user is looking at a specific revision, show an
     // "approve this revision" message - otherwise, it means
     // there's no approved revision (we would have exited out if
     // there were), so show a message explaining why the page is
     // blank, with a link to the latest revision.
     if ($wgRequest->getCheck('oldid')) {
         if (ApprovedRevs::userCanApprove($title)) {
             // @TODO - why is this message being shown
             // at all? Aren't the "approve this revision"
             // links in the history page always good
             // enough?
             $wgOut->addHTML(Xml::tags('span', array('id' => 'contentSub2'), Xml::element('a', array('href' => $title->getLocalUrl(array('action' => 'approve', 'oldid' => $wgRequest->getInt('oldid')))), wfMessage('approvedrevs-approvethisrev')->text())));
         }
     } else {
         $wgOut->appendSubtitle(htmlspecialchars(wfMessage('approvedrevs-blankpageshown')->text()) . '&#160;' . Xml::element('a', array('href' => $title->getLocalUrl(array('oldid' => $article->getRevIdFetched()))), wfMessage('approvedrevs-viewlatestrev')->text()));
     }
     $wgOut->addHTML('</span>');
     return true;
 }
 /**
  * Display a message
  *
  * @since 0.5.6
  *
  * @param Article &$article
  * @param boolean $outputDone
  * @param boolean $useParserCache
  *
  * @return true
  */
 public static function setArticleHeader(Article &$article, &$outputDone, &$useParserCache)
 {
     global $wgOut, $wgRequest, $egApprovedRevsBlankIfUnapproved;
     // For now, we only set the header if "blank if unapproved"
     // is set.
     if (!$egApprovedRevsBlankIfUnapproved) {
         return true;
     }
     $title = $article->getTitle();
     if (!ApprovedRevs::pageIsApprovable($title)) {
         return true;
     }
     if (!ApprovedRevs::userCanApprove($title)) {
         return true;
     }
     $approvedRevID = ApprovedRevs::getApprovedRevID($title);
     if (!empty($approvedRevID) && !($wgRequest->getCheck('oldid') && $wgRequest->getInt('oldid') == $approvedRevID)) {
         return true;
     }
     // Disable caching, so that if it's a specific ID being shown
     // that happens to be the latest, it doesn't show a blank page.
     $useParserCache = false;
     $wgOut->addHTML('<span style="margin-left: 10.75px">');
     if ($wgRequest->getCheck('oldid')) {
         $wgOut->addHTML(Xml::tags('span', array('id' => 'contentSub2'), Xml::element('a', array('href' => $title->getLocalUrl(array('action' => 'approve', 'oldid' => $wgRequest->getInt('oldid')))), wfMsg('approvedrevs-approvethisrev'))));
     } else {
         $wgOut->appendSubtitle(htmlspecialchars(wfMsg('approvedrevs-blankpageshown')) . '&#160;' . Xml::element('a', array('href' => $title->getLocalUrl(array('oldid' => $article->getRevIdFetched()))), wfMsg('approvedrevs-viewlatestrev')));
     }
     $wgOut->addHTML('</span>');
     return true;
 }
 function formatResult($skin, $result)
 {
     $title = Title::makeTitle(NS_FILE, $result->title);
     if (!self::$repo) {
         self::$repo = RepoGroup::singleton();
     }
     $pageLink = Linker::link($title);
     #
     #	Unapproved Files and undesignated Files
     #
     if ($this->mMode == 'unapproved' || $this->mMode == 'undesignated') {
         global $egApprovedRevsShowApproveLatest;
         $nsApproved = ApprovedRevs::titleInNamespacePermissions($title);
         $cats = ApprovedRevs::getTitleApprovableCategories($title);
         $catsApproved = ApprovedRevs::titleInCategoryPermissions($title);
         $pgApproved = ApprovedRevs::titleInPagePermissions($title);
         $magicApproved = ApprovedRevs::pageHasMagicWord($title);
         if ($this->mMode == 'undesignated' && ($nsApproved || $catsApproved || $pgApproved || $magicApproved)) {
             // if showing undesignated pages only, don't show pages that have real approvability
             return '';
         }
         if ($egApprovedRevsShowApproveLatest && ApprovedRevs::userCanApprove($title)) {
             $approveLink = ' (' . Xml::element('a', array('href' => $title->getLocalUrl(array('action' => 'approvefile', 'ts' => $result->latest_ts, 'sha1' => $result->latest_sha1))), wfMessage('approvedrevs-approve')->text()) . ')';
         } else {
             $approveLink = '';
         }
         return "{$pageLink}{$approveLink}";
         #
         # Not Latest Files:
         # [[My File.jpg]] (revision 2ba82h7f approved; revision 2ba82h7f latest)
     } elseif ($this->mMode == 'notlatestfiles') {
         $approved_file = self::$repo->findFileFromKey($result->approved_sha1, array('time' => $result->approved_ts));
         $latest_file = self::$repo->findFileFromKey($result->latest_sha1, array('time' => $result->latest_ts));
         $approvedLink = Xml::element('a', array('href' => $approved_file->getUrl()), wfMessage('approvedrevs-approvedfile')->text());
         $latestLink = Xml::element('a', array('href' => $latest_file->getUrl()), wfMessage('approvedrevs-latestfile')->text());
         return "{$pageLink} ({$approvedLink} | {$latestLink})";
         #
         #	All Files with an approved revision
         #
     } else {
         // main mode (pages with an approved revision)
         global $wgUser, $wgOut, $wgLang;
         $additionalInfo = Xml::element('span', array('class' => $result->approved_sha1 == $result->latest_sha1 && $result->approved_ts == $result->latest_ts ? 'approvedRevIsLatest' : 'approvedRevNotLatest'), wfMessage('approvedrevs-revisionnumber', substr($result->approved_sha1, 0, 8))->parse());
         // Get data on the most recent approval from the
         // 'approval' log, and display it if it's there.
         $sk = $wgUser->getSkin();
         $loglist = new LogEventsList($sk, $wgOut);
         $pager = new LogPager($loglist, 'approval', '', $title);
         $pager->mLimit = 1;
         $pager->doQuery();
         $result = $pager->getResult();
         $row = $result->fetchObject();
         if (!empty($row)) {
             $timestamp = $wgLang->timeanddate(wfTimestamp(TS_MW, $row->log_timestamp), true);
             $date = $wgLang->date(wfTimestamp(TS_MW, $row->log_timestamp), true);
             $time = $wgLang->time(wfTimestamp(TS_MW, $row->log_timestamp), true);
             $userLink = $sk->userLink($row->log_user, $row->user_name);
             $additionalInfo .= ', ' . wfMessage('approvedrevs-approvedby', $userLink, $timestamp, $row->user_name, $date, $time)->text();
         }
         return "{$pageLink} ({$additionalInfo})";
     }
 }
 function formatResult($skin, $result)
 {
     $title = Title::newFromId($result->id);
     // FIXME: not sure this is required with v1.0+, need to verify
     if (!ApprovedRevs::pageIsApprovable($title)) {
         return false;
     }
     $pageLink = Linker::link($title);
     if ($this->mMode == 'unapproved' || $this->mMode == 'undesignated') {
         global $egApprovedRevsShowApproveLatest;
         $line = $pageLink;
         if ($egApprovedRevsShowApproveLatest && ApprovedRevs::userCanApprove($title)) {
             $line .= ' (' . Xml::element('a', array('href' => $title->getLocalUrl(array('action' => 'approve', 'oldid' => $result->latest_id))), wfMessage('approvedrevs-approvelatest')->text()) . ')';
         }
         return $line;
     } elseif ($this->mMode == 'notlatest') {
         $diffLink = Xml::element('a', array('href' => $title->getLocalUrl(array('diff' => $result->latest_id, 'oldid' => $result->rev_id))), wfMessage('approvedrevs-difffromlatest')->text());
         return "{$pageLink} ({$diffLink})";
     } else {
         // main mode (pages with an approved revision)
         global $wgUser, $wgOut, $wgLang;
         $additionalInfo = Xml::element('span', array('class' => $result->rev_id == $result->latest_id ? 'approvedRevIsLatest' : 'approvedRevNotLatest'), wfMessage('approvedrevs-revisionnumber', $result->rev_id)->text());
         // Get data on the most recent approval from the
         // 'approval' log, and display it if it's there.
         $loglist = new LogEventsList($wgOut->getSkin(), $wgOut);
         $pager = new LogPager($loglist, 'approval', '', $title->getText());
         $pager->mLimit = 1;
         $pager->doQuery();
         $row = $pager->mResult->fetchObject();
         if (!empty($row)) {
             $timestamp = $wgLang->timeanddate(wfTimestamp(TS_MW, $row->log_timestamp), true);
             $date = $wgLang->date(wfTimestamp(TS_MW, $row->log_timestamp), true);
             $time = $wgLang->time(wfTimestamp(TS_MW, $row->log_timestamp), true);
             $userLink = Linker::userLink($row->log_user, $row->user_name);
             $additionalInfo .= ', ' . wfMessage('approvedrevs-approvedby', $userLink, $timestamp, $row->user_name, $date, $time)->text();
         }
         return "{$pageLink} ({$additionalInfo})";
     }
 }