/** * The ImageBeforeProduce HTML hook, used here to provide datetime * negotiation for embedded images. * * @param Skin $skin Skin object for this page * @param Title $title Title object for this image * @param File $file File object for this image * @param array $frameParams frame parameters * @param array $handlerParams handler parameters * @param string $time not really used by hook * @param string $res used to replace HTML for image rendering * * @return boolean indicating whether caller should use $res instead of * default HTML for image rendering */ public function onImageBeforeProduceHTML(&$skin, &$title, &$file, &$frameParams, &$handlerParams, &$time, &$res) { global $wgMementoTimeNegotiationForThumbnails; if ($wgMementoTimeNegotiationForThumbnails === true) { if ($this->oldIDSet === true) { $history = $file->getHistory(1, $this->articleDatetime); $file = $history[0]; } } return true; }
function doQuery() { if ($this->mQueryDone) { return; } $this->mImg = $this->mImagePage->getFile(); // ensure loading if (!$this->mImg->exists()) { return; } $queryLimit = $this->mLimit + 1; // limit plus extra row if ($this->mIsBackwards) { // Fetch the file history $this->mHist = $this->mImg->getHistory($queryLimit, null, $this->mOffset, false); // The current rev may not meet the offset/limit $numRows = count($this->mHist); if ($numRows <= $this->mLimit && $this->mImg->getTimestamp() > $this->mOffset) { $this->mHist = array_merge(array($this->mImg), $this->mHist); } } else { // The current rev may not meet the offset if (!$this->mOffset || $this->mImg->getTimestamp() < $this->mOffset) { $this->mHist[] = $this->mImg; } // Old image versions (fetch extra row for nav links) $oiLimit = count($this->mHist) ? $this->mLimit : $this->mLimit + 1; // Fetch the file history $this->mHist = array_merge($this->mHist, $this->mImg->getHistory($oiLimit, $this->mOffset, null, false)); } $numRows = count($this->mHist); // Total number of query results if ($numRows) { # Index value of top item in the list $firstIndex = $this->mIsBackwards ? $this->mHist[$numRows - 1]->getTimestamp() : $this->mHist[0]->getTimestamp(); # Discard the extra result row if there is one if ($numRows > $this->mLimit && $numRows > 1) { if ($this->mIsBackwards) { # Index value of item past the index $this->mPastTheEndIndex = $this->mHist[0]->getTimestamp(); # Index value of bottom item in the list $lastIndex = $this->mHist[1]->getTimestamp(); # Display range $this->mRange = array(1, $numRows - 1); } else { # Index value of item past the index $this->mPastTheEndIndex = $this->mHist[$numRows - 1]->getTimestamp(); # Index value of bottom item in the list $lastIndex = $this->mHist[$numRows - 2]->getTimestamp(); # Display range $this->mRange = array(0, $numRows - 2); } } else { # Setting indexes to an empty string means that they will be # omitted if they would otherwise appear in URLs. It just so # happens that this is the right thing to do in the standard # UI, in all the relevant cases. $this->mPastTheEndIndex = ''; # Index value of bottom item in the list $lastIndex = $this->mIsBackwards ? $this->mHist[0]->getTimestamp() : $this->mHist[$numRows - 1]->getTimestamp(); # Display range $this->mRange = array(0, $numRows - 1); } } else { $firstIndex = ''; $lastIndex = ''; $this->mPastTheEndIndex = ''; } if ($this->mIsBackwards) { $this->mIsFirst = $numRows < $queryLimit; $this->mIsLast = $this->mOffset == ''; $this->mLastShown = $firstIndex; $this->mFirstShown = $lastIndex; } else { $this->mIsFirst = $this->mOffset == ''; $this->mIsLast = $numRows < $queryLimit; $this->mLastShown = $lastIndex; $this->mFirstShown = $firstIndex; } $this->mQueryDone = true; }
/** * If a file is deleted, check if the sha1 (and timestamp?) exist in the * approved_revs_files table, and delete that row accordingly. A deleted * version of a file should not be the approved version! **/ public static function onFileDeleteComplete(File $file, $oldimage, $article, $user, $reason) { $dbr = wfGetDB(DB_SLAVE); // check if this file has an approved revision $approvedFile = $dbr->selectRow('approved_revs_files', array('approved_timestamp', 'approved_sha1'), array('file_title' => $file->getTitle()->getDBkey())); // If an approved revision exists, loop through all files in history. // Since this hook happens AFTER deletion (there is no hook before deletion), check to see // if the sha1 of the approved revision is NOT in the history. If it is not in the history, // then it has no business being in the approved_revs_files table, and should be deleted. if ($approvedFile) { $revs = array(); $approvedExists = false; $hist = $file->getHistory(); foreach ($hist as $OldLocalFile) { // need to check both sha1 and timestamp, since reverted files can have the same // sha1, but different timestamps if ($OldLocalFile->getTimestamp() == $approvedFile->approved_timestamp && $OldLocalFile->getSha1() == $approvedFile->approved_sha1) { $approvedExists = true; } } if (!$approvedExists) { ApprovedRevs::unsetApprovedFileInDB($file->getTitle()); } } return true; }