Welterkj has uploaded a new change for review.
https://gerrit.wikimedia.org/r/169316
Change subject: Add category pages and tags.
......................................................................
Add category pages and tags.
This change adds a category for all pages generated by the
GraphViz extension. There is one "root" category for GraphViz
and a subcategory for each renderer (dot, neato, fdp, sfdp,
circo, twopi and mscgen). This makes it easy to find graph
images created by the extension.
Change-Id: I942f703614165d7cadcf501b1312139e265bf5f0
---
M GraphRenderParms.php
M GraphViz_body.php
M RELEASE-NOTES.md
M i18n/en.json
M i18n/qqq.json
5 files changed, 131 insertions(+), 17 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/GraphViz
refs/changes/16/169316/1
diff --git a/GraphRenderParms.php b/GraphRenderParms.php
index a0d4c8f..f6d21ce 100644
--- a/GraphRenderParms.php
+++ b/GraphRenderParms.php
@@ -159,12 +159,16 @@
return $this->getGraphName( $userSpecific ) . '.src';
}
+ public function getImageBaseName( $userSpecific ) {
+ return $this->getGraphName( $userSpecific ) . '_' .
$this->getRenderer();
+ }
+
public function getImageFileName( $userSpecific ) {
- return $this->getGraphName( $userSpecific ) . '.' .
$this->imageType;
+ return $this->getImageBaseName( $userSpecific ) . '.' .
$this->imageType;
}
public function getMapFileName( $userSpecific ) {
- return $this->getGraphName( $userSpecific ) . '.map';
+ return $this->getImageBaseName( $userSpecific ) . '.map';
}
public function getSourcePath( $userSpecific ) {
diff --git a/GraphViz_body.php b/GraphViz_body.php
index 95634c4..c051374 100644
--- a/GraphViz_body.php
+++ b/GraphViz_body.php
@@ -104,7 +104,7 @@
*
* @var string IMAGE_DUMMY
*/
- const IMAGE_DUMMY = "File_graph_GraphVizExtensionDummy";
+ const IMAGE_DUMMY = "File_graph_GraphVizExtensionDummy_dot";
/**
* Used as an array key in GraphViz::$graphTypes and other arrays.
@@ -121,6 +121,27 @@
* @var integer MSCGEN
*/
const MSCGEN = 1;
+
+ /**
+ * The name of the root category containing pages created by this
extension.
+ *
+ * @var integer ROOT_CATEGORY
+ */
+ const ROOT_CATEGORY = "GraphViz";
+
+ /**
+ * Subcategories of pages created by this extension.
+ * @var array $subCategories
+ */
+ private static $subCategories = array(
+ 'mscgen',
+ 'dot',
+ 'neato',
+ 'fdp',
+ 'sfdp',
+ 'circo',
+ 'twopi'
+ );
/**
* A list of dot attributes that are forbidden.
@@ -260,6 +281,50 @@
}
/**
+ * Create a category page for GraphViz::ROOT_CATEGORY and subcategory
pages for GraphViz::$subCategories.
+ * @author Keith Welter
+ */
+ public static function createCategoryPages() {
+ $rootCategoryName = self::ROOT_CATEGORY;
+ $rootCategoryDesc = wfMessage( 'graphviz-category-desc',
"[[:Category:$rootCategoryName]]" )->text();
+ self::createCategoryPage( $rootCategoryName, $rootCategoryDesc,
"" );
+
+ foreach( self::$subCategories as $subCategory ) {
+ $subCategoryName = $rootCategoryName . ' ' .
$subCategory;
+ $subCategoryDesc = wfMessage(
'graphviz-subcategory-desc', "[[:Category:$subCategoryName]]", $subCategory
)->text();
+ $subCategoryDesc .= "[[Category:$rootCategoryName]]";
+ self::createCategoryPage( $subCategoryName,
$subCategoryDesc, "" );
+ }
+ }
+
+ public static function getCategoryTags( $renderer ) {
+ $rootCategoryName = self::ROOT_CATEGORY;
+ return
"[[Category:$rootCategoryName]][[Category:$rootCategoryName $renderer]]";
+ }
+
+ /**
+ * Create a category page with the given name if it does not already
exist.
+ * @param[in] string $name is the name to use for the new category page.
+ * @param[in] string $pageText is the page text to supply.
+ * @param[in] string $comment is the comment to supply for the edit.
+ * @author Keith Welter
+ */
+ public static function createCategoryPage( $name, $pageText, $comment )
{
+ $title = Title::newFromText( "Category:" . $name );
+
+ if ( !$title->exists() ) {
+ $wikiPage = new WikiPage( $title );
+ $flags = EDIT_NEW;
+ $status = self::doEditContent( $wikiPage, $title,
$pageText, $comment, $flags, null );
+ if ( $status->isOK() ) {
+ wfDebug( __METHOD__ . ": created category
'$name'\n" );
+ } else {
+ wfDebug( __METHOD__ . ": create failed for
category '$name'\n" );
+ }
+ }
+ }
+
+ /**
* Create a dummy file page with a trivial graph image of the given
image type.
* New graph images of the same type may be uploaded on top of this
dummy without
* triggering any parser code. This makes it possible to do graph
image file
@@ -293,6 +358,8 @@
* @return true
*/
public static function onParserInit( Parser &$parser ) {
+ self::createCategoryPages();
+
self::initDummyFilePages( $parser );
foreach ( self::$graphTypes as $graphType ) {
@@ -380,6 +447,44 @@
}
/**
+ * Convenience function for creating or editing page text.
+ *
+ * @param[in] WikiPage $wikiPage is the wiki page to create or edit.
+ * @param[in] string $title is the title of the wiki page to create or
edit.
+ * @param[in] string $pageText is the page text to supply.
+ * @param[in] string $comment is the comment to supply for the edit.
+ * @param[in] integer $flags see the WikiPage::doEditContent flags
documentation
+ * @param[in] User $user is the user on behalf of whom the edit is
recorded.
+ *
+ * @return Status.
+ *
+ * @author Keith Welter
+ */
+ public static function doEditContent( $wikiPage, $title, $pageText,
$comment, $flags, $user ) {
+ $status = Status::newGood();
+
+ $oldVersion = version_compare( $GLOBALS['wgVersion'], '1.21',
'<' );
+ if ( $oldVersion ) {
+ // Do stuff for MediaWiki 1.20 and older
+ $status = $wikiPage->doEdit( $pageText, $comment,
$flags, false, $user );
+ } else {
+ // Do stuff for MediaWiki 1.21 and newer
+ $content = ContentHandler::makeContent( $pageText,
$title );
+ $status = $wikiPage->doEditContent( $content, $comment,
$flags, false, $user );
+ }
+
+ return $status;
+ }
+
+ public static function getRendererFromImageFileName( $imageFileName ) {
+ $renderer = strrev( $imageFileName );
+ $renderer = substr( $renderer, 0, strpos( $renderer, '_' ) );
+ $renderer = strrev( $renderer );
+ wfDebug( __METHOD__ . ": imageFileName: $imageFileName
renderer: $renderer\n" );
+ return $renderer;
+ }
+
+ /**
* Upload a list of graph images for a wiki page with the given title
text.
*
* @param[in] string $titleText is the title text of the wiki page.
@@ -400,7 +505,8 @@
foreach ( $imageFilePaths as $imageFilePath ) {
wfDebug( __METHOD__ . ": uploading $imageFilePath\n" );
$imageFileName = basename( $imageFilePath );
- $pageText = self::getMapHowToText( $imageFileName );
+ $renderer = self::getRendererFromImageFileName(
pathinfo ( $imageFilePath, PATHINFO_FILENAME ) );
+ $pageText = self::getMapHowToText( $imageFileName ) .
self::getCategoryTags( $renderer );
$imageTitle = Title::newFromText( $imageFileName,
NS_FILE );
if ( !$imageTitle->exists() ) {
@@ -421,17 +527,10 @@
// The upload for this title has already
occured in GraphViz::render
// but the page text and comment have not been
updated yet so do it now.
unlink( $imageFilePath );
- $wikiPage = new WikiFilePage( $imageTitle );
- $oldVersion = version_compare(
$GLOBALS['wgVersion'], '1.21', '<' );
- if ( $oldVersion ) {
- // Do stuff for MediaWiki 1.20 and older
- $status = $wikiPage->doEdit( $pageText,
$comment, EDIT_UPDATE | EDIT_SUPPRESS_RC, false, $user );
- } else {
- // Do stuff for MediaWiki 1.21 and newer
- $content = ContentHandler::makeContent(
$pageText, $imageTitle );
- $status = $wikiPage->doEditContent(
$content, $comment, EDIT_UPDATE | EDIT_SUPPRESS_RC, false, $user );
- }
+ $wikiPage = new WikiFilePage( $imageTitle );
+ $flags = EDIT_UPDATE | EDIT_SUPPRESS_RC;
+ self::doEditContent( $wikiPage, $imageTitle,
$pageText, $comment, $flags, $user );
wfDebug( __METHOD__ . ": updated file page for
$imageFilePath\n" );
// Go ahead and count this as an upload since
it has been done.
@@ -1027,8 +1126,8 @@
}
// prepare to upload
- $pageText = "";
- $comment = "";
+ $pageText = self::getCategoryTags( $renderer );
+ $comment = wfMessage( 'graphviz-upload-comment',
$titleText )->text();
$watch = false;
$removeTempFile = true;
@@ -1246,9 +1345,15 @@
$graphParms->deleteFiles( $isPreview );
if ( $deleteUploads ) {
- $imageFile = UploadLocalFile::getUploadedFile(
$graphParms->getImageFileName( $isPreview ) );
+ $imageFileName = $graphParms->getImageFileName(
$isPreview );
+ $imageFile = UploadLocalFile::getUploadedFile(
$imageFileName );
if ( $imageFile ) {
$imageFile->delete( wfMessage(
'graphviz-delete-reason' )->text() );
+
+ $imageTitle = Title::newFromText(
$imageFileName, NS_FILE );
+ if ( $imageTitle->exists() ) {
+ self::deleteFilePage( $imageTitle );
+ }
}
}
}
diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md
index bb9e0df..91cb0b3 100644
--- a/RELEASE-NOTES.md
+++ b/RELEASE-NOTES.md
@@ -2,6 +2,7 @@
## GraphViz 1.5.x ## (not released yet)
* Add tag arguments preparse="dynamic" and preparse="static".
+* Add categories for pages created by this extension.
## GraphViz 1.4.1 ## (2014-10-21)
* Fix for [bug 72325](https://bugzilla.wikimedia.org/show_bug.cgi?id=72325).
diff --git a/i18n/en.json b/i18n/en.json
index 696eb91..64aa805 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -24,5 +24,7 @@
"graphviz-uploaderror": "Graph image upload failed for file: $1",
"graphviz-upload-comment": "generated by the GraphViz
[[Special:Version#Installed_extensions|extension]] from the [[$1]] page",
"graphviz-unrecognized-preparse-value": "The preparse value \"$1\" is
unrecognized.",
+ "graphviz-category-desc": "$1 contains pages created by the GraphViz
extension.",
+ "graphviz-subcategory-desc": "$1 contains pages created using the $2
command.",
"graphviz-map-desc": "= ImageMap =\nWhen including this image in a wiki
page, use the following mark-up to enable links:\n
<nowiki>\n<imagemap>\nFile:$1\n$2</imagemap>\n</nowiki>\nSee
[https://www.mediawiki.org/wiki/Extension:ImageMap ImageMap] for more
information."
}
diff --git a/i18n/qqq.json b/i18n/qqq.json
index a0dea67..9416f21 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -24,5 +24,7 @@
"graphviz-uploaderror": "Used as error message.",
"graphviz-upload-comment": "Comment supplied for an image uploaded by
the extension. Parameters:\n* $1 - article title",
"graphviz-unrecognized-preparse-value": "Used as error message.
Parameters:\n* $1 - attribute name",
+ "graphviz-category-desc": "GraphViz category page text. Parameters:\n* $1
- GraphViz category tag",
+ "graphviz-subcategory-desc": "GraphViz subcategory page text.
Parameters:\n* $1 - GraphViz subcategory tag\n* $2 - graph render command
associated with subcategory",
"graphviz-map-desc": "Do not translate the tags <code><nowiki></code>,
<code><imagemap></code>, <code></imagemap></code> or <code></nowiki></code>.
Parameters:\n* $1 - image file name\n* $2 - image map shape, coordinates and
URL (0 or more lines)"
}
--
To view, visit https://gerrit.wikimedia.org/r/169316
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I942f703614165d7cadcf501b1312139e265bf5f0
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/GraphViz
Gerrit-Branch: master
Gerrit-Owner: Welterkj <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits