Exemple #1
0
 public function execute()
 {
     global $wgTitle;
     $dbr = wfGetDB(DB_SLAVE);
     $pages = $dbr->select('page', array('page_id', 'page_latest'));
     while ($page = $pages->fetchObject()) {
         $title = Title::newFromID($page->page_id);
         // some extensions, like Semantic Forms, need $wgTitle
         // set as well
         $wgTitle = $title;
         if (ApprovedRevs::pageIsApprovable($title) && !ApprovedRevs::hasApprovedRevision($title)) {
             ApprovedRevs::setApprovedRevID($title, $page->page_latest, true);
             $this->output(wfTimestamp(TS_DB) . ' Approved the last revision of page "' . $title->getFullText() . '".');
         }
     }
     $this->output("\n Finished setting all current revisions to approved. \n");
 }
 /**
  * Hook to insert things into article headers.
  * 
  * @since 0.5.6
  * 
  * @param Article &$article
  * @param boolean $outputDone
  * @param boolean $useParserCache
  * 
  * @return true
  */
 public static function onArticleViewHeader(Article &$article, &$outputDone, &$useParserCache)
 {
     global $wgOut, $wgRequest, $egApprovedRevsBlankIfUnapproved;
     if (ApprovedRevs::pageIsApprovable($article->getTitle()) && $article->getTitle()->userCan('approverevisions')) {
         $approvedId = ApprovedRevs::getApprovedRevID($article->getTitle());
         if ($egApprovedRevsBlankIfUnapproved && (empty($approvedId) || $wgRequest->getCheck('oldid') && $wgRequest->getInt('oldid') != $approvedId)) {
             $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' => $article->getTitle()->getLocalUrl(array('action' => 'approve', 'oldid' => $wgRequest->getInt('oldid')))), wfMsg('approvedrevs-approvethisrev'))));
             } else {
                 $wgOut->appendSubtitle(htmlspecialchars(wfMsg('approvedrevs-blankpageshown')) . '&#160;' . Xml::element('a', array('href' => $article->getTitle()->getLocalUrl(array('oldid' => $article->getRevIdFetched()))), wfMsg('approvedrevs-viewlatestrev')));
             }
             $wgOut->addHTML('</span>');
         }
     }
     return true;
 }
 /**
  * If this page is approvable, but has no approved revision, display
  * a header message stating that, if the setting to display this
  * message is activated.
  */
 public static function displayNotApprovedHeader(Article &$article, &$outputDone, &$useParserCache)
 {
     global $egApprovedRevsShowNotApprovedMessage;
     if (!$egApprovedRevsShowNotApprovedMessage) {
         return true;
     }
     $title = $article->getTitle();
     if (!ApprovedRevs::pageIsApprovable($title)) {
         return true;
     }
     if (!ApprovedRevs::hasApprovedRevision($title)) {
         $text = wfMessage('approvedrevs-noapprovedrevision')->text();
         global $wgOut;
         if ($wgOut->getSubtitle() != '') {
             $wgOut->addSubtitle('<br />' . $text);
         } else {
             $wgOut->setSubtitle($text);
         }
     }
     return true;
 }
 /**
  * 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::newFromId($result->id);
     if (!ApprovedRevs::pageIsApprovable($title)) {
         return false;
     }
     $pageLink = Linker::link($title);
     if ($this->mMode == 'unapproved') {
         global $egApprovedRevsShowApproveLatest;
         $line = $pageLink;
         if ($egApprovedRevsShowApproveLatest && $title->userCan('approverevisions')) {
             $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})";
     }
 }