/** * static method used in hook * * * @access public * @static * * @param UploadForm $uploadForm -- uploadForm object */ public static function uploadComplete($uploadForm) { if (!$uploadForm->getLocalFile() instanceof LocalFile) { return true; } $title = $uploadForm->getLocalFile()->getTitle(); if (!$title instanceof Title) { return true; } wfProfileIn(__METHOD__); $mTitle = $title->getText(); $relPath = $uploadForm->getLocalFile()->getRel(); $fullPath = $uploadForm->getLocalFile()->getPath(); $aHistory = $uploadForm->getLocalFile()->getHistory(1); $oldPath = false; if (isset($aHistory) && isset($aHistory[0])) { $oOldLocalFile = $aHistory[0]; if (isset($oOldLocalFile) && $oOldLocalFile instanceof OldLocalFile) { $oldPath = $oOldLocalFile->getArchiveName(); } } if (!empty($oldPath)) { $oldPath = sprintf("%s/%s", $uploadForm->getLocalFile()->getArchivePath(), $oldPath); } /** * write log to database */ self::log($title, $fullPath, $relPath, $oldPath, "u"); wfProfileOut(__METHOD__); return true; }
/** * @since 1.1 * * @param UploadForm $image * * @return true */ public function onUploadComplete(UploadForm $image) { global $wgServerName, $wgScriptPath, $wgServer, $wgVersion; $urlServer = 'http://' . $wgServerName . $wgScriptPath; // $classe = get_class($image); if (compareMWVersion($wgVersion, '1.16.0') == -1) { $localfile = $image->mLocalFile; } else { $localfile = $image->getLocalFile(); } $path = utils::prepareString($localfile->mime, $localfile->size, $wgServer . urldecode($localfile->url)); if (!file_exists($path)) { $dbr = wfGetDB(DB_SLAVE); $lastRevision = Revision::loadFromTitle($dbr, $localfile->getTitle()); if ($lastRevision->getPrevious() == null) { $rev_id = 0; } else { $rev_id = $lastRevision->getPrevious()->getId(); } $revID = $lastRevision->getId(); $model = DSMWRevisionManager::loadModel($rev_id); $patch = new DSMWPatch(false, true, null, $urlServer, $rev_id, null, null, null, $localfile->mime, $localfile->size, urldecode($localfile->url), null); $patch->storePage($localfile->getTitle(), $revID); // stores the patch in a wikipage DSMWRevisionManager::storeModel($revID, $sessionId = session_id(), $model, $blobCB = 0); } return true; }