User:Woytecr/area/Extensions FAQ pl

From MediaWiki.org

< User:Woytecr(Redirected from Extensions FAQ/pl)
Jump to: navigation, search

Contents

[edit] Jak mogą włączyć rozszerzenie?

Skopiuj pobrany plik wtyczki do folderu extensions/ i dodaj polecenie require_once( "extensions/FILENAME" ); do pliku LocalSettings.php, gdzie FILENAME jest nazwą pliku Twojego rozszerzenia, na przykład Extension.php.

Zobacz również Manual:Extensions#Installing an extension

[edit] Jak napisać swoje własne rozszerzenie?

Zobacz Manual:Extensions#Writing Extensions.

[edit] How do I disable caching for pages using my extension?

The extension purgePage can also be used to perform the steps listed below, it works for MediaWiki 1.3 - 1.5.

For MediaWiki 1.3, include the following code in your extension:

 global $wgOut;
 $wgOut->enableClientCache(false);

For MediaWiki 1.4, use this (won't necessarily work in all cases):

 global $wgTitle;
 $dbw =& wfGetDB( DB_MASTER );
 $dbw->update( 'cur', array( 'cur_touched' => $dbw->timestamp( time() + 120 ) ), 
     array( 
         'cur_namespace' => $wgTitle->getNamespace(), 
         'cur_title' => $wgTitle->getDBkey() 
     ), 'nameOfYourExtension' 
 );

Note: The above doesn't work in all cases. Using the same logic but with different code the following lines work much better.

 $ts = mktime();
 $now = gmdate("YmdHis", $ts + 120);
 $ns = $wgTitle->getNamespace();
 $ti = wfStrencode($wgTitle->getDBkey());
 $sql = "UPDATE cur SET cur_touched='$now' WHERE cur_namespace=$ns AND cur_title='$ti'";
 wfQuery($sql, DB_WRITE, "");

For MediaWiki 1.4 the following also works (possibly better than the above method):

 global $wgTitle;
 wfPurgeSquidServers(array($wgTitle->getInternalURL()));
 $wgTitle->invalidateCache();

In MediaWiki 1.5beta5, a more reliable interface was introduced. Your parser hook function may take a parser object as a third parameter, by reference. Use the following code:

 function wfSomeHookFunction( $text, $params, &$parser ) {
     $parser->disableCache();
     ...
 }

Note: on MediaWiki version 1.5.8 any of the above didn't work. You can see the following code functioning properly here. I had to use the following code in the second function of the extension (not the "setHook" function):

 global $wgTitle;
 	$dbw =& wfGetDB( DB_MASTER );
 	$dbw->update( 'page', array( 'page_touched' => $dbw->timestamp( time() + 120 ) ), 
     	array( 
        	'page_namespace' => $wgTitle->getNamespace(), 
        	'page_title' => $wgTitle->getDBkey() 
    	), 'name of your Extension as defined in $wgExtensionFunctions[] =' 
 	);
  }

WARNING: In version 1.6 and many early versions of 1.7, it is impossible for extensions to prevent pages from being cached when edits are submitted. This is not expected behavior, see bugzilla:5683. There are a number of ways to work around this issue:

  • Install the DisableCache hack. This is the most elegant solution, but has not been thoroughly tested.
  • Run action=purge after submitting edits. This is the safest choice, but may not be feasible in large wikis.
  • Disable caching site-wide. This will sharply increase the amount of work that your server will have to perform. To disable all caching, put the following code in LocalSettings.php:
# Client-side caching:
 
/** Allow client-side caching of pages */
$wgCachePages       = false;
 
/**
 * Set this to current time to invalidate all prior cached pages. Affects both
 * client- and server-side caching.
 * You can get the current date on your server by using the command:
 *   date +%Y%m%d%H%M%S
 */
$wgCacheEpoch = 'date +%Y%m%d%H%M%S';

[edit] Recent versions

In MediaWiki 1.7.0 and upwards, the following should be sufficient:

$parser->disableCache();

where $parser is the reference to the parent parser that is passed as a third parameter to parser hook extensions.

[edit] How do I render wikitext in my extension?

[edit] Special pages

When rendering output that will not be subject to parser cache, such as on a special page

global $wgOut;
$wgOut->parse( $text );

where $text is the wikitext to be parsed.

[edit] Parser hooks

See Manual:Tag extensions#How do I render wikitext in my extension?

[edit] How do I enable searching in my extension's output (dynamic content)?

You can't. Dynamic content can not be included in a static index.

[edit] How can I avoid modification of my extension's HTML output?

See Manual:Tag extensions#How can I avoid modification of my extension's HTML output?

[edit] How can I pass XML-style parameters in my extension tag?

See Manual:Tag extensions#How can I pass XML-style parameters in my extension tag?

[edit] Extensions and Templates

See Manual:Tag extensions#Extensions and Templates

[edit] "NaodW..." or "UNIQ..."

In previous version of MediaWiki, another problem with templates and extensions was the appearance of "NaodW..." or "UNIQ..." strings in the template output. MediaWiki 1.5(.1) has problems with some PHP versions which causes that output. You should upgrade to MediaWiki 1.5.2 or later.

[edit] How can I determine in my extension, if an article is protected or not?

Use the Title class and the isProtected( ) method, e.g.

 function extensionFunction() {
    # Assume $title is the title object
    if( $title->isProtected( 'edit' ) ) {
       # Protected from editing, do things
    } else {
       # Not protected from editing
    }
 }

[edit] What permissions do I apply to the extensions folder?

All the scripts in the /wiki structure need to be readable and executable by the user that PHP runs as. All perms are usually 755 and owner/group being a different user. The LocalSettings.php file is created by the script on setup and so will be an example to set the rest by.

[edit] How do I get my extension to show up on Special:Version?

See Manual:Extensions#Credits

Personal tools