/** * Store info in the db to enable the script to pick it up later during the day (via an automated cleaning routine) */ public function tempFileStoreInfo($filename) { global $wgExternalSharedDB, $wgCityId; wfProfileIn(__METHOD__); $title = Title::makeTitle(NS_FILE, $filename); $localRepo = RepoGroup::singleton()->getLocalRepo(); $path = LocalFile::newFromTitle($title, $localRepo)->getPath(); $dbw = wfGetDB(DB_MASTER, array(), $wgExternalSharedDB); $dbw->insert('garbage_collector', array('gc_filename' => $path, 'gc_timestamp' => $dbw->timestamp(), 'gc_wiki_id' => $wgCityId), __METHOD__); $id = $dbw->insertId(); $this->log(__METHOD__, "image stored as #{$id}"); $dbw->commit(); wfProfileOut(__METHOD__); return $id; }
/** * Store info in the db to enable the script to pick it up later during * the day (via an automated cleaning routine) * * @param string|$filename * @return int */ function tempFileStoreInfo($filename) { global $wgExternalSharedDB, $wgCityId; $path = LocalFile::newFromTitle(Title::makeTitle(NS_FILE, $filename), RepoGroup::singleton()->getLocalRepo())->getPath(); $dbw = wfGetDB(DB_MASTER, array(), $wgExternalSharedDB); $dbw->insert('garbage_collector', array('gc_filename' => $path, 'gc_timestamp' => $dbw->timestamp(), 'gc_wiki_id' => $wgCityId), __METHOD__); $dbw->commit(); return $dbw->insertId(); }
/** * Update search index when an article is moved. * @param Title $oTitle Old title of the moved article. * @param Title $oNewtitle New title of the moved article. * @param User $oUser User that moved the article. * @param int $iOldID ID of the page that has been moved. * @param int $iNewID ID of the newly created redirect. * @return bool allow other hooked methods to be executed. Always true. */ public function onTitleMoveComplete(&$oTitle, &$oNewtitle, &$oUser, $iOldID, $iNewID) { try { // Moving article BuildIndexMainControl::getInstance()->updateIndexWikiByTitleObject($oNewtitle); // Check if redirect is created; 0 is no redirect if ($iNewID !== 0) { BuildIndexMainControl::getInstance()->updateIndexWikiByTitleObject($oTitle); } // Moving file if namespace of title is the file namespace if ($oTitle->getNamespace() == NS_FILE) { $oOldFile = LocalFile::newFromTitle($oTitle, RepoGroup::singleton()->getLocalRepo()); $oNewFile = RepoGroup::singleton()->findFile($oNewtitle); BuildIndexMainControl::getInstance()->deleteIndexFile($oOldFile->getPath(), 'repo'); BuildIndexMainControl::getInstance()->updateIndexFile($oNewFile); } } catch (BsException $e) { wfDebugLog('ExtendedSearch', 'onTitleMoveComplete: ' . $e->getMessage()); } return true; }
/** * @param LocalFile $file file to check * @return int RESULT_* flag * @see BAC-731 */ private function processMissingFile(File $file) { global $wgUploadDirectory, $wgCityId; try { $exists = $this->repo->fileExists($file->getPath()); } catch (Exception $ex) { $exists = true; $this->error(sprintf("%s caught: %s", get_class($ex), $ex->getMessage())); } // file is fine, continue... if ($exists) { return self::RESULT_EXISTS; } $restored = false; $this->output(sprintf("'%s' doesn't exist (%s)\n", $file->getTitle(), $file->getUrlRel())); // let's assume that given file was moved from A // let's get all possible A's and try to find images for them $candidates = $this->getCandidates($file); if (empty($candidates) && !empty($this->otherLocation)) { # check other location - maybe this file is there :) $candidates = $this->checkOtherLocation($file); } if (!empty($candidates)) { $this->output(sprintf(" %d candidate(s) found...\n", count($candidates))); foreach ($candidates as $candidate) { $srcFile = LocalFile::newFromTitle($candidate, $this->repo); $srcPath = $wgUploadDirectory . '/' . $srcFile->getUrlRel(); // check on FS storage $foundOnFS = file_exists($srcPath); $this->output(sprintf(" '%s' -> <%s> [%s]\n", $srcFile->getName(), $srcPath, $foundOnFS ? 'found' : 'not found')); // check the next candidate (or if --dry-run) if (!$foundOnFS || $this->isDryRun) { continue; } // upload found image to Swift $swift = \Wikia\SwiftStorage::newFromWiki($wgCityId); $metadata = ['Sha1Base36' => $file->getSha1()]; $status = $swift->store($srcPath, $file->getUrlRel(), $metadata, $file->getMimeType()); if ($status->isOK()) { self::log('restored', $file->getName()); $restored = true; break; } } $this->output("\n"); } // remove an image if it can't be restored if (!$restored && !$this->isDryRun) { $file->delete(self::REASON); $this->output(sprintf(" Removed '%s'!\n", $file->getName())); self::log('removed', $file->getName()); } return $restored ? self::RESULT_RESTORED : self::RESULT_NOT_RESTORED; }
private function getMediaType($ns) { global $wgEnableVideoToolExt; wfProfileIn(__METHOD__); $result = 0; $oTitle = $this->mTitle; if (in_array($ns, $this->mediaNS)) { $mediaType = MEDIATYPE_UNKNOWN; $oLocalFile = LocalFile::newFromTitle($oTitle, RepoGroup::singleton()->getLocalRepo()); if ($oLocalFile instanceof LocalFile) { $mediaType = $oLocalFile->getMediaType(); if (empty($mediaType)) { $mediaType = MEDIATYPE_UNKNOWN; } } switch ($mediaType) { case MEDIATYPE_BITMAP: $result = 1; break; case MEDIATYPE_DRAWING: $result = 2; break; case MEDIATYPE_AUDIO: $result = 3; break; case MEDIATYPE_VIDEO: $result = 4; break; case MEDIATYPE_MULTIMEDIA: $result = 5; break; case MEDIATYPE_OFFICE: $result = 6; break; case MEDIATYPE_TEXT: $result = 7; break; case MEDIATYPE_EXECUTABLE: $result = 8; break; case MEDIATYPE_ARCHIVE: $result = 9; break; default: $result = 1; break; } } wfProfileOut(__METHOD__); return $result; }
private function internalLinkHelper($matches) { // Here we can handle every possibility of links: // category-links, image-links, Page-links... Whatever $matches[1] = trim($matches[1]); $link_tmp = explode("|", $matches[1], 2); $link_int = $link_tmp[0]; $link_text = isset($link_tmp[1]) ? $link_tmp[1] : $link_tmp[0]; //%% unset($link_tmp); $title = Title::newFromText($link_int); if (!is_a($title, 'Title')) { // no title object, so error out! return $matches[1]; } if (true == $title->isExternal()) { // Interwiki-Link $link_url = $title->escapeFullURL(); // This one contains some HTML code which is bad // Get the first occurrence of ", and remove everything else $remove_from = strpos('"', $link_url); if ($remove_from > 1) { $link_url = substr(0, $remove_from, $link_url); } $command = $link_text; wfRunHooks('w2lInterwikiLinks', array(&$this, &$link_url, &$link_text, &$command)); return $command; } switch ($title->getNamespace()) { case NS_MEDIA: // this is just a link to the mediawiki-page return $link_text; break; case NS_IMAGE: $link = $title; $parts = explode("|", $matches[1]); $imagename = array_shift($parts); $case_imagename = $imagename; // still need to remove the Namespace: $tmp_name = explode(':', $imagename, 2); $imagename = $tmp_name[1]; $imgwidth = "10cm"; foreach ($parts as $part) { if (preg_match("/\\d+px/", $part)) { continue; } if (preg_match("/(\\d+cm)/", $part, $widthmatch)) { $imgwidth = $widthmatch[1]; continue; } if (preg_match("/thumb|thumbnail|frame/", $part)) { continue; } if (preg_match("/left|right|center|none/", $part)) { continue; } $caption = trim($part); } $title = Title::makeTitleSafe(NS_IMAGE, $imagename); $this->repo = RepoGroup::singleton()->getLocalRepo(); $file = LocalFile::newFromTitle($title, $this->repo); $file->loadFromFile(); if ($file && $file->exists()) { $imagepath = $file->getPath(); $imagepath = str_replace('\\', '/', $imagepath); } else { // does not exist!!! $case_imagename = str_replace('_', ' ', $case_imagename); return $case_imagename; } //%%$title = $file->getTitle()->getText(); $graphic_package = 'graphicx'; $graphic_command = "\\begin{center} \\resizebox{" . $imgwidth . "}{!}{\\includegraphics{{$imagepath}}}\\\\ \\textit{{$caption}}nd{center}\n"; wfRunHooks('w2lImage', array(&$this, &$file, &$graphic_package, &$graphic_command, &$imagepath, &$imagename, &$imgwith, &$caption)); $this->addPackageDependency($graphic_package); $masked_command = $this->getMark($graphic_package); $this->mask($masked_command, $graphic_command); return $masked_command; break; case NS_CATEGORY: // Namespace is a category, but a plain link to a cat-page is also matched here... if ($link_int[0] != ':') { wfRunHooks('w2lAddCategory', array(&$this, &$link_int)); return ''; } // else: Fall through // else: Fall through default: $link_url = $title->getFullUrl(); $link_page = $title->getDBKey(); $command = $link_text; wfRunHooks('w2lInternalLinks', array(&$this, &$command, &$link_text, &$link_page, &$link_url)); return $command; break; } return $link_text; }