当前位置: 首页>>代码示例>>PHP>>正文


PHP LocalFile::newFromTitle方法代码示例

本文整理汇总了PHP中LocalFile::newFromTitle方法的典型用法代码示例。如果您正苦于以下问题:PHP LocalFile::newFromTitle方法的具体用法?PHP LocalFile::newFromTitle怎么用?PHP LocalFile::newFromTitle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在LocalFile的用法示例。


在下文中一共展示了LocalFile::newFromTitle方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: tempFileStoreInfo

 /**
  * 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;
 }
开发者ID:schwarer2006,项目名称:wikia,代码行数:18,代码来源:WikiaTempFilesUpload.class.php

示例2: tempFileStoreInfo

 /**
  * 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();
 }
开发者ID:Tjorriemorrie,项目名称:app,代码行数:16,代码来源:WikiaMiniUpload_body.php

示例3: onTitleMoveComplete

 /**
  * 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;
 }
开发者ID:hfroese,项目名称:mediawiki-extensions-BlueSpiceExtensions,代码行数:30,代码来源:ExtendedSearch.class.php

示例4: processMissingFile

 /**
  * @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;
 }
开发者ID:Tjorriemorrie,项目名称:app,代码行数:59,代码来源:fixBrokenImages.php

示例5: getMediaType

 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;
 }
开发者ID:schwarer2006,项目名称:wikia,代码行数:51,代码来源:WikiaApiQueryEventsData.php

示例6: internalLinkHelper

 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;
 }
开发者ID:mediawiki-extensions,项目名称:wiki2latex,代码行数:97,代码来源:w2lParser.php


注:本文中的LocalFile::newFromTitle方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。