本文整理汇总了PHP中wfLocalFile函数的典型用法代码示例。如果您正苦于以下问题:PHP wfLocalFile函数的具体用法?PHP wfLocalFile怎么用?PHP wfLocalFile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wfLocalFile函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onPowerDelete
/**
* @static
* @param string $action
* @param Article $article
* @return bool
* @throws UserBlockedError
* @throws PermissionsError
*/
static function onPowerDelete($action, $article)
{
global $wgOut, $wgUser, $wgRequest;
if ($action !== 'powerdelete') {
return true;
}
if (!$wgUser->isAllowed('delete') || !$wgUser->isAllowed('powerdelete')) {
throw new PermissionsError('powerdelete');
}
if ($wgUser->isBlocked()) {
throw new UserBlockedError($wgUser->mBlock);
}
if (wfReadOnly()) {
$wgOut->readOnlyPage();
return false;
}
$reason = $wgRequest->getText('reason');
$title = $article->getTitle();
$file = $title->getNamespace() == NS_IMAGE ? wfLocalFile($title) : false;
if ($file) {
$oldimage = null;
FileDeleteForm::doDelete($title, $file, $oldimage, $reason, false);
} else {
$article->doDelete($reason);
}
// this is stupid, but otherwise, WikiPage::doUpdateRestrictions complains about passing by reference
$false = false;
$article->doUpdateRestrictions(array('create' => 'sysop'), array('create' => 'infinity'), $false, $reason, $wgUser);
return false;
}
示例2: run
/**
* Run a thumbnail job on a given PDF file.
* @return bool true
*/
public function run() {
if ( !isset( $this->params['page'] ) ) {
wfDebugLog('thumbnails', 'A page for thumbnails job of ' . $this->title->getText() . ' was not specified! That should never happen!');
return true; // no page set? that should never happen
}
$file = wfLocalFile( $this->title ); // we just want a local file
if ( !$file ) {
return true; // Just silently fail, perhaps the file was already deleted, don't bother
}
switch ($this->params['jobtype']) {
case self::BIG_THUMB:
global $wgImageLimits;
// Ignore user preferences, do default thumbnails
// everything here shamelessy copied and reused from includes/ImagePage.php
$sizeSel = User::getDefaultOption( 'imagesize' );
// The user offset might still be incorrect, specially if
// $wgImageLimits got changed (see bug #8858).
if ( !isset( $wgImageLimits[$sizeSel] ) ) {
// Default to the first offset in $wgImageLimits
$sizeSel = 0;
}
$max = $wgImageLimits[$sizeSel];
$maxWidth = $max[0];
$maxHeight = $max[1];
$width_orig = $file->getWidth( $this->params['page'] );
$width = $width_orig;
$height_orig = $file->getHeight( $this->params['page'] );
$height = $height_orig;
if ( $width > $maxWidth || $height > $maxHeight ) {
# Calculate the thumbnail size.
# First case, the limiting factor is the width, not the height.
if ( $width / $height >= $maxWidth / $maxHeight ) {
$height = round( $height * $maxWidth / $width );
$width = $maxWidth;
# Note that $height <= $maxHeight now.
} else {
$newwidth = floor( $width * $maxHeight / $height );
$height = round( $height * $newwidth / $width );
$width = $newwidth;
# Note that $height <= $maxHeight now, but might not be identical
# because of rounding.
}
$transformParams = array( 'page' => $this->params['page'], 'width' => $width );
$file->transform( $transformParams );
}
break;
case self::SMALL_THUMB:
global $wgUser;
$sk = $wgUser->getSkin();
$sk->makeThumbLinkObj( $this->title, $file, '', '', 'none', array( 'page' => $this->params['page'] ) );
break;
}
return true;
}
示例3: setUp
protected function setUp()
{
parent::setUp();
$this->setMwGlobals(array('wgEnableUploads' => true, 'wgAllowCopyUploads' => true));
if (wfLocalFile('UploadFromUrlTest.png')->exists()) {
$this->deleteFile('UploadFromUrlTest.png');
}
}
示例4: build
public function build()
{
$this->file = wfLocalFile($this->title);
if ($this->file && $this->file->exists()) {
$this->fileText();
}
return $this->doc;
}
示例5: doDBUpdates
public function doDBUpdates()
{
$method = $this->getOption('method', 'normal');
$file = $this->getOption('file');
$t = -microtime(true);
$dbw = wfGetDB(DB_MASTER);
if ($file) {
$res = $dbw->select('image', array('img_name'), array('img_name' => $file), __METHOD__);
if (!$res) {
$this->error("No such file: {$file}", true);
return false;
}
$this->output("Populating img_sha1 field for specified files\n");
} else {
$res = $dbw->select('image', array('img_name'), array('img_sha1' => ''), __METHOD__);
$this->output("Populating img_sha1 field\n");
}
$imageTable = $dbw->tableName('image');
if ($method == 'pipe') {
// @todo FIXME: Kill this and replace with a second unbuffered DB connection.
global $wgDBuser, $wgDBserver, $wgDBpassword, $wgDBname;
$cmd = 'mysql -u' . wfEscapeShellArg($wgDBuser) . ' -h' . wfEscapeShellArg($wgDBserver) . ' -p' . wfEscapeShellArg($wgDBpassword, $wgDBname);
$this->output("Using pipe method\n");
$pipe = popen($cmd, 'w');
}
$numRows = $res->numRows();
$i = 0;
foreach ($res as $row) {
if ($i % $this->mBatchSize == 0) {
$this->output(sprintf("Done %d of %d, %5.3f%% \r", $i, $numRows, $i / $numRows * 100));
wfWaitForSlaves();
}
$file = wfLocalFile($row->img_name);
if (!$file) {
continue;
}
$sha1 = $file->getRepo()->getFileSha1($file->getPath());
if (strval($sha1) !== '') {
$sql = "UPDATE {$imageTable} SET img_sha1=" . $dbw->addQuotes($sha1) . " WHERE img_name=" . $dbw->addQuotes($row->img_name);
if ($method == 'pipe') {
fwrite($pipe, "{$sql};\n");
} else {
$dbw->query($sql, __METHOD__);
}
}
$i++;
}
if ($method == 'pipe') {
fflush($pipe);
pclose($pipe);
}
$t += microtime(true);
$this->output(sprintf("\nDone %d files in %.1f seconds\n", $numRows, $t));
return !$file;
// we only updated *some* files, don't log
}
示例6: setUp
public function setUp()
{
global $wgEnableUploads, $wgAllowCopyUploads;
parent::setUp();
$wgEnableUploads = true;
$wgAllowCopyUploads = true;
wfSetupSession();
if (wfLocalFile('UploadFromUrlTest.png')->exists()) {
$this->deleteFile('UploadFromUrlTest.png');
}
}
示例7: execute
public function execute()
{
$method = $this->getOption('method', 'normal');
$file = $this->getOption('file');
$t = -microtime(true);
$dbw = wfGetDB(DB_MASTER);
if ($file) {
$res = $dbw->selectRow('image', array('img_name'), array('img_name' => $dbw->addQuotes($file)), __METHOD__);
if (!$res) {
$this->error("No such file: {$file}", true);
return;
}
} else {
$res = $dbw->select('image', array('img_name'), array('img_sha1' => ''), __METHOD__);
}
$imageTable = $dbw->tableName('image');
$oldimageTable = $dbw->tableName('oldimage');
$batch = array();
if ($method == 'pipe') {
// @fixme kill this and replace with a second unbuffered DB connection.
global $wgDBuser, $wgDBserver, $wgDBpassword, $wgDBname;
$cmd = 'mysql -u' . wfEscapeShellArg($wgDBuser) . ' -h' . wfEscapeShellArg($wgDBserver) . ' -p' . wfEscapeShellArg($wgDBpassword, $wgDBname);
$this->output("Using pipe method\n");
$pipe = popen($cmd, 'w');
}
$numRows = $res->numRows();
$i = 0;
foreach ($res as $row) {
if ($i % 100 == 0) {
$this->output(sprintf("Done %d of %d, %5.3f%% \r", $i, $numRows, $i / $numRows * 100));
wfWaitForSlaves(5);
}
$file = wfLocalFile($row->img_name);
if (!$file) {
continue;
}
$sha1 = File::sha1Base36($file->getPath());
if (strval($sha1) !== '') {
$sql = "UPDATE {$imageTable} SET img_sha1=" . $dbw->addQuotes($sha1) . " WHERE img_name=" . $dbw->addQuotes($row->img_name);
if ($method == 'pipe') {
fwrite($pipe, "{$sql};\n");
} else {
$dbw->query($sql, __METHOD__);
}
}
$i++;
}
if ($method == 'pipe') {
fflush($pipe);
pclose($pipe);
}
$t += microtime(true);
$this->output(sprintf("\nDone %d files in %.1f seconds\n", $numRows, $t));
}
示例8: execute
/**
* Output the information for the external editor
*/
public function execute()
{
global $wgContLang, $wgScript, $wgScriptPath, $wgCanonicalServer;
$this->getOutput()->disable();
$response = $this->getRequest()->response();
$response->header('Content-type: application/x-external-editor; charset=utf-8');
$response->header('Cache-control: no-cache');
$special = $wgContLang->getNsText(NS_SPECIAL);
# $type can be "Edit text", "Edit file" or "Diff text" at the moment
# See the protocol specifications at [[m:Help:External editors/Tech]] for
# details.
if (count($this->urls)) {
$urls = $this->urls;
$type = "Diff text";
} elseif ($this->getRequest()->getVal('mode') == 'file') {
$type = "Edit file";
$image = wfLocalFile($this->getTitle());
if ($image) {
$urls = array('File' => array('Extension' => $image->getExtension(), 'URL' => $image->getCanonicalURL()));
} else {
$urls = array();
}
} else {
$type = "Edit text";
# *.wiki file extension is used by some editors for syntax
# highlighting, so we follow that convention
$urls = array('File' => array('Extension' => 'wiki', 'URL' => $this->getTitle()->getCanonicalURL(array('action' => 'edit', 'internaledit' => 'true'))));
}
$files = '';
foreach ($urls as $key => $vars) {
$files .= "\n[{$key}]\n";
foreach ($vars as $varname => $varval) {
$files .= "{$varname}={$varval}\n";
}
}
$url = $this->getTitle()->getFullURL($this->getRequest()->appendQueryValue('internaledit', 1, true));
$control = <<<CONTROL
; You're seeing this file because you're using Mediawiki's External Editor feature.
; This is probably because you selected use external editor in your preferences.
; To edit normally, either disable that preference or go to the URL:
; {$url}
; See http://www.mediawiki.org/wiki/Manual:External_editors for details.
[Process]
Type={$type}
Engine=MediaWiki
Script={$wgCanonicalServer}{$wgScript}
Server={$wgCanonicalServer}
Path={$wgScriptPath}
Special namespace={$special}
{$files}
CONTROL;
echo $control;
}
示例9: __construct
function __construct($title, $time = false)
{
parent::__construct($title);
$this->img = wfFindFile($this->mTitle, $time);
if (!$this->img) {
$this->img = wfLocalFile($this->mTitle);
$this->current = $this->img;
} else {
$this->current = $time ? wfLocalFile($this->mTitle) : $this->img;
}
$this->repo = $this->img->repo;
}
示例10: imageUrl
/**
* Return the URL of an image, provided its name.
*
* Backwards-compatibility for extensions.
* Note that fromSharedDirectory will only use the shared path for files
* that actually exist there now, and will return local paths otherwise.
*
* @param string $name Name of the image, without the leading "Image:"
* @param boolean $fromSharedDirectory Should this be in $wgSharedUploadPath?
* @return string URL of $name image
* @deprecated
*/
static function imageUrl($name, $fromSharedDirectory = false)
{
wfDeprecated(__METHOD__);
$image = null;
if ($fromSharedDirectory) {
$image = wfFindFile($name);
}
if (!$image) {
$image = wfLocalFile($name);
}
return $image->getUrl();
}
示例11: axMultiEditImageUpload
function axMultiEditImageUpload()
{
global $wgRequest;
$res = array();
$postfix = $wgRequest->getVal('num');
$infix = '';
if ($wgRequest->getVal('infix') != '') {
$infix = $wgRequest->getVal('infix');
}
// do the real upload
$uploadform = new CreatePageImageUploadForm($wgRequest);
$uploadform->mTempPath = $wgRequest->getFileTempName('wp' . $infix . 'UploadFile' . $postfix);
$uploadform->mFileSize = $wgRequest->getFileSize('wp' . $infix . 'UploadFile' . $postfix);
$uploadform->mSrcName = $wgRequest->getFileName('wp' . $infix . 'UploadFile' . $postfix);
$uploadform->CurlError = $wgRequest->getUploadError('wp' . $infix . 'UploadFile' . $postfix);
$uploadform->mLastTimestamp = $wgRequest->getText('wp' . $infix . 'LastTimestamp' . $postfix);
$par_name = $wgRequest->getText('wp' . $infix . 'ParName' . $postfix);
$file_ext = explode('.', $uploadform->mSrcName);
$file_ext = @$file_ext[1];
$uploadform->mParameterExt = $file_ext;
if ($infix == '') {
$uploadform->mDesiredDestName = $wgRequest->getText('Createtitle') . ' ' . trim($par_name);
} else {
$uploadform->mDesiredDestName = $wgRequest->getText('Createtitle');
}
$uploadform->mSessionKey = false;
$uploadform->mStashed = false;
$uploadform->mRemoveTempFile = false;
// some of the values are fixed, we have no need to add them to the form itself
$uploadform->mIgnoreWarning = 1;
$uploadform->mUploadDescription = wfMsg('createpage-uploaded-from');
$uploadform->mWatchthis = 1;
$uploadedfile = $uploadform->execute();
if ($uploadedfile['error'] == 0) {
$imageobj = wfLocalFile($uploadedfile['timestamp']);
$imageurl = $imageobj->createThumb(60);
$res = array('error' => 0, 'msg' => $uploadedfile['msg'], 'url' => $imageurl, 'timestamp' => $uploadedfile['timestamp'], 'num' => $postfix);
} else {
if ($uploadedfile['once']) {
#if ( !$error_once ) {
$res = array('error' => 1, 'msg' => $uploadedfile['msg'], 'num' => $postfix);
#}
$error_once = true;
} else {
$res = array('error' => 1, 'msg' => $uploadedfile['msg'], 'num' => $postfix);
}
}
$text = json_encode($res);
$ar = new AjaxResponse($text);
$ar->setContentType('text/html; charset=utf-8');
return $ar;
}
示例12: loadFile
/**
* @return bool
*/
protected function loadFile() {
if ( $this->mFileLoaded ) {
return true;
}
$this->mFileLoaded = true;
$this->mFile = wfFindFile( $this->mTitle );
if ( !$this->mFile ) {
$this->mFile = wfLocalFile( $this->mTitle ); // always a File
}
$this->mRepo = $this->mFile->getRepo();
return true;
}
示例13: upload
function upload( $title, $path ) {
echo "$title seems not to be present in the wiki. Trying to upload from $path.\n";
$image = wfLocalFile( $title );
$archive = $image->publish( $path );
$image->recordUpload( $archive->value, "Test file used for PagedTiffHandler unit test", "No license" );
if( !$archive->isGood() )
{
echo "Something went wrong. Please manually upload $path\n";
return false;
} else {
echo "Upload was successful.\n";
return $image;
}
}
示例14: doRecreate
private function doRecreate($all) {
global $wgExIndexMIMETypes, $wgExIndexOnHTTP;
$dbw = wfGetDB( DB_MASTER );
$tbl_pag = $dbw->tableName( 'page' );
$tbl_idx = $dbw->tableName( 'searchindex' );
$searchWhere = $all ? '' : ' AND NOT EXISTS (SELECT null FROM '.$tbl_idx.' WHERE si_page=p.page_id AND si_url IS NOT null)';
$result = $dbw->query('SELECT p.page_id FROM '.$tbl_pag.' p WHERE p.page_namespace = '.NS_FILE.$searchWhere );
$this->output( $result->numRows()." file(s) found\n" );
$syncIdx = false;
$countDone = 0;
$countSkipped = 0;
while (($row = $result->fetchObject()) !== false) {
$titleObj = Title::newFromID($row->page_id);
$file = wfLocalFile($titleObj->getText());
if (in_array( $file->getMimeType(), $wgExIndexMIMETypes )) {
$url = $wgExIndexOnHTTP ? preg_replace( '/^https:/i', 'http:', $file->getFullUrl() ) : $file->getFullUrl();
$dbw->update('searchindex',
array( 'si_url' => $url ),
array( 'si_page' => $row->page_id ),
'SearchIndexUpdate:update' );
$syncIdx = true;
} else {
$countSkipped++;
}
$countDone++;
}
if ( $syncIdx ) {
$this->output( "Syncing index... " );
$index = $dbw->getProperty('mTablePrefix')."si_url_idx";
$dbw->query( "CALL ctx_ddl.sync_index('$index')" );
$this->output( "Done\n" );
}
$this->output("Finished ($countDone processed" );
if ( $countSkipped > 0 ) {
$this->output(", $countSkipped skipped " );
}
$this->output(")\n" );
}
示例15: edit
function edit()
{
global $wgOut, $wgScript, $wgScriptPath, $wgServer, $wgLang;
$wgOut->disable();
$name = $this->mTitle->getText();
$pos = strrpos($name, ".") + 1;
header("Content-type: application/x-external-editor; charset=" . $this->mCharset);
header("Cache-control: no-cache");
# $type can be "Edit text", "Edit file" or "Diff text" at the moment
# See the protocol specifications at [[m:Help:External editors/Tech]] for
# details.
if (!isset($this->mMode)) {
$type = "Edit text";
$url = $this->mTitle->getFullURL("action=edit&internaledit=true");
# *.wiki file extension is used by some editors for syntax
# highlighting, so we follow that convention
$extension = "wiki";
} elseif ($this->mMode == "file") {
$type = "Edit file";
$image = wfLocalFile($this->mTitle);
$url = $image->getFullURL();
$extension = substr($name, $pos);
}
$special = $wgLang->getNsText(NS_SPECIAL);
$control = <<<CONTROL
; You're seeing this file because you're using Mediawiki's External Editor
; feature. This is probably because you selected use external editor
; in your preferences. To edit normally, either disable that preference
; or go to the URL {$url} .
; See http://www.mediawiki.org/wiki/Manual:External_editors for details.
[Process]
Type={$type}
Engine=MediaWiki
Script={$wgServer}{$wgScript}
Server={$wgServer}
Path={$wgScriptPath}
Special namespace={$special}
[File]
Extension={$extension}
URL={$url}
CONTROL;
echo $control;
}