Mediawiki/Erweiterung/Description: Unterschied zwischen den Versionen
< Mediawiki | Erweiterung
Michi (Diskussion | Beiträge) (Die Seite wurde neu angelegt: == Weblinks == * [http://www.mediawiki.org/wiki/Extension:Description Description] {{cat|Mediawiki}}) |
Michi (Diskussion | Beiträge) Keine Bearbeitungszusammenfassung |
||
Zeile 1: | Zeile 1: | ||
== Installation == | |||
1. Herunterladen der aktuellen Software unter http://www.mediawiki.org/wiki/Special:ExtensionDistributor/Description | |||
Anlegen des Verzeichnisses "extensions/IconLink". | |||
# <b>mkdir extensions/Description</b> | |||
# <b>chown wiki:wiki extensions/Description</b> | |||
2. Anlegen der Datei "extensions/FaviconLink.php" und Einfügen des folgenden PHP-Codes: IconLink 0.1 (2008-03-11). | |||
# <b>vi extensions/Description/Description.php</b> | |||
{| class=wiki width=100% | |||
| | |||
<source lang=php enclose=div> | |||
<?php | |||
/** | |||
* Description.php -- Adds meaningful description <meta> tag to MW pages | |||
* Copyright 2008 Vinismo, Inc. (http://vinismo.com/) | |||
* | |||
* This program is free software; you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation; either version 2 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with this program; if not, write to the Free Software | |||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |||
* | |||
* @author Evan Prodromou <evan@vinismo.com> | |||
* @addtogroup Extensions | |||
*/ | |||
if (!defined('MEDIAWIKI')) { | |||
exit( 1 ); | |||
} | |||
define('DESCRIPTION_VERSION', '0.1'); | |||
$wgExtensionFunctions[] = 'DescriptionSetup'; | |||
$wgExtensionCredits['other'][] = array('name' => 'Description', | |||
'version' => DESCRIPTION_VERSION, | |||
'author' => 'Evan Prodromou', | |||
'url' => 'http://www.mediawiki.org/wiki/Extension:Description', | |||
'description' => 'Adds a description meta-tag to MW pages'); | |||
function DescriptionSetup() { | |||
global $wgHooks; | |||
$wgHooks['ArticleViewHeader'][] = 'DescriptionArticleViewHeader'; | |||
} | |||
function DescriptionArticleViewHeader(&$article, &$outputDone = null, &$pcache = null) { | |||
global $wgOut; | |||
$desc = DescriptionFromArticle($article); | |||
if (!is_null($desc)) { | |||
$wgOut->addMeta('description', htmlspecialchars($desc)); | |||
} | |||
return TRUE; | |||
} | |||
function DescriptionFromArticle(&$article) { | |||
if (defined('MWRDF_VERSION')) { | |||
$desc = DescriptionFromRDF($article); | |||
} | |||
if (is_null($desc) || strlen($desc) == 0) { | |||
$desc = DescriptionFromText($article); | |||
} | |||
return $desc; | |||
} | |||
function DescriptionFromRDF(&$article) { | |||
$nt = $article->getTitle(); | |||
$uri = $nt->getFullUrl(); | |||
$model = MwRdfGetModel($article); | |||
$results = $model->rdqlQuery("SELECT ?description " . | |||
"WHERE (<$uri> dc:description ?description) " . "USING dc FOR http://purl.org/dc/elements/1.1/", FALSE); | |||
$desc = ''; | |||
foreach ($results as $row) { | |||
$rowval = preg_replace("/^\"(.*?)\"$/", '\1', $row['?description']); | |||
$desc .= (($desc) ? ' ' : '') . $rowval; | |||
} | |||
return $desc; | |||
} | |||
function DescriptionFromText(&$article) { | |||
global $wgParser, $wgContLang; | |||
# Expand all templates | |||
$text = $article->getContent(true); | |||
$text = $wgParser->preprocess($text, $article->mTitle, new ParserOptions()); | |||
# Find first non-ws, non-empty, non-image, non-table content | |||
$imageLabel = $wgContLang->getNsText(NS_IMAGE); | |||
$paragraphs = explode("\n", $text); | |||
$desc = ''; | |||
foreach ($paragraphs as $paragraph) { | |||
if (preg_match("/^\s*(=|__|\[\[[Ii]mage:|\[\[$imageLabel:|\{\||\|#|\*)/", $paragraph)) { | |||
continue; | |||
} else if (preg_match("/^\s*$/", $paragraph)) { | |||
continue; | |||
} else { | |||
$desc = DescriptionStripParagraph($paragraph); | |||
break; | |||
} | |||
} | |||
return $desc; | |||
} | |||
function DescriptionStripParagraph($para) { | |||
$para = preg_replace("/'''''(.*?)'''''/", '\1', $para); | |||
$para = preg_replace("/'''(.*?)'''/", '\1', $para); | |||
$para = preg_replace("/''(.*?)''/", '\1', $para); | |||
$para = preg_replace("@<(.*?)>(.*?)</\1>@", '\2', $para); | |||
$para = preg_replace("/\[\[([^\]]*?)\|([^\]]*?)\]\]/", '\2', $para); | |||
$para = preg_replace("/\[\[([^\]]*?)\]\]/", '\1', $para); | |||
$para = preg_replace("/\[(\S*)\s+(.*?)\]/", '\2', $para); | |||
$para = preg_replace("/\[(\S*)\s*\]/", '\1', $para); | |||
return $para; | |||
} | |||
?> | |||
</source> | |||
|} | |||
4. Anpassung der Rechte. | |||
# <b>chown wiki:wiki extensions/Description/Description/.php</b> | |||
5. Einfügen der folgenden Zeile in die Datei "LocalSettings.php". | |||
## Extension: IconLink | |||
require_once("$IP/extensions/Description/Description.php"); | |||
== Weblinks == | == Weblinks == | ||
Version vom 3. März 2009, 19:12 Uhr
Installation
1. Herunterladen der aktuellen Software unter http://www.mediawiki.org/wiki/Special:ExtensionDistributor/Description
Anlegen des Verzeichnisses "extensions/IconLink".
# mkdir extensions/Description # chown wiki:wiki extensions/Description
2. Anlegen der Datei "extensions/FaviconLink.php" und Einfügen des folgenden PHP-Codes: IconLink 0.1 (2008-03-11).
# vi extensions/Description/Description.php
<?php
/**
* Description.php -- Adds meaningful description <meta> tag to MW pages
* Copyright 2008 Vinismo, Inc. (http://vinismo.com/)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* @author Evan Prodromou <evan@vinismo.com>
* @addtogroup Extensions
*/
if (!defined('MEDIAWIKI')) {
exit( 1 );
}
define('DESCRIPTION_VERSION', '0.1');
$wgExtensionFunctions[] = 'DescriptionSetup';
$wgExtensionCredits['other'][] = array('name' => 'Description',
'version' => DESCRIPTION_VERSION,
'author' => 'Evan Prodromou',
'url' => 'http://www.mediawiki.org/wiki/Extension:Description',
'description' => 'Adds a description meta-tag to MW pages');
function DescriptionSetup() {
global $wgHooks;
$wgHooks['ArticleViewHeader'][] = 'DescriptionArticleViewHeader';
}
function DescriptionArticleViewHeader(&$article, &$outputDone = null, &$pcache = null) {
global $wgOut;
$desc = DescriptionFromArticle($article);
if (!is_null($desc)) {
$wgOut->addMeta('description', htmlspecialchars($desc));
}
return TRUE;
}
function DescriptionFromArticle(&$article) {
if (defined('MWRDF_VERSION')) {
$desc = DescriptionFromRDF($article);
}
if (is_null($desc) || strlen($desc) == 0) {
$desc = DescriptionFromText($article);
}
return $desc;
}
function DescriptionFromRDF(&$article) {
$nt = $article->getTitle();
$uri = $nt->getFullUrl();
$model = MwRdfGetModel($article);
$results = $model->rdqlQuery("SELECT ?description " .
"WHERE (<$uri> dc:description ?description) " . "USING dc FOR http://purl.org/dc/elements/1.1/", FALSE);
$desc = '';
foreach ($results as $row) {
$rowval = preg_replace("/^\"(.*?)\"$/", '\1', $row['?description']);
$desc .= (($desc) ? ' ' : '') . $rowval;
}
return $desc;
}
function DescriptionFromText(&$article) {
global $wgParser, $wgContLang;
# Expand all templates
$text = $article->getContent(true);
$text = $wgParser->preprocess($text, $article->mTitle, new ParserOptions());
# Find first non-ws, non-empty, non-image, non-table content
$imageLabel = $wgContLang->getNsText(NS_IMAGE);
$paragraphs = explode("\n", $text);
$desc = '';
foreach ($paragraphs as $paragraph) {
if (preg_match("/^\s*(=|__|\[\[[Ii]mage:|\[\[$imageLabel:|\{\||\|#|\*)/", $paragraph)) {
continue;
} else if (preg_match("/^\s*$/", $paragraph)) {
continue;
} else {
$desc = DescriptionStripParagraph($paragraph);
break;
}
}
return $desc;
}
function DescriptionStripParagraph($para) {
$para = preg_replace("/'''''(.*?)'''''/", '\1', $para);
$para = preg_replace("/'''(.*?)'''/", '\1', $para);
$para = preg_replace("/''(.*?)''/", '\1', $para);
$para = preg_replace("@<(.*?)>(.*?)</\1>@", '\2', $para);
$para = preg_replace("/\[\[([^\]]*?)\|([^\]]*?)\]\]/", '\2', $para);
$para = preg_replace("/\[\[([^\]]*?)\]\]/", '\1', $para);
$para = preg_replace("/\[(\S*)\s+(.*?)\]/", '\2', $para);
$para = preg_replace("/\[(\S*)\s*\]/", '\1', $para);
return $para;
}
?>
|
4. Anpassung der Rechte.
# chown wiki:wiki extensions/Description/Description/.php
5. Einfügen der folgenden Zeile in die Datei "LocalSettings.php".
## Extension: IconLink require_once("$IP/extensions/Description/Description.php");