Samwilson has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/322631

Change subject: Fix hooks, DB usage, etc.
......................................................................

Fix hooks, DB usage, etc.

Move all documentation to mediawiki.org, remove redundant unit test
hook, fix the pre-edit-form display hook (removing evil global),
properly output messages, and fix LIKE database clauses.

Change-Id: I4f4ce9ca012eaf29fd8103983ac1a0fa85f55e27
---
M README.md
M extension.json
M src/Hooks.php
M src/Person.php
4 files changed, 19 insertions(+), 114 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Genealogy 
refs/changes/31/322631/1

diff --git a/README.md b/README.md
index 56cfd9e..75ac6c3 100644
--- a/README.md
+++ b/README.md
@@ -2,81 +2,3 @@
 =============================
 
 All details: https://mediawiki.org/wiki/Extension:Genealogy
-
-
-## Usage summary
-
-This extension creates one parser function: `{{#genealogy: … }}`.
-Its first first parameter is unnamed (i.e. doesn't have an equals sign) but 
all others are.
-
-The following parameters are supported, two for defining data and four for 
reporting data:
-
-2. Define and output a link to a parent:<br />
-   `{{#genealogy:parent | Page Name Here }}`
-3. Define a partner (no output produced; use `partners` to list):<br />
-   `{{#genealogy:partner | Page Name Here |start date=Y-m-d |end date=Y-m-d }}`
-4. List all siblings:<br />
-   `{{#genealogy:siblings}}`
-5. List all partners:<br />
-   `{{#genealogy:partners}}`
-6. List all children:<br />
-   `{{#genealogy:children}}`
-7. Display a tree (a connected graph):<br />
-   `{{#genealogy:tree|ancestors=List|descendants=List}}`<br />
-   where each `List` is a newline-separated list of page titles.
-
-
-## Templates
-
-**Example:**
-For an example template that makes use of these parser functions, see 
`person_template.wikitext`.
-
-**Preload:**
-When this extension creates a link to a page that doesn't yet exist,
-the text of `[[Template:Person/preload]]` is preloaded.
-The location of this preload text can be customised
-by modifying the `genealogy-person-preload` system message.
-
-**Person list-item:**
-Three types of lists of people can be generated: `siblings`, `partners`, and 
`children`.
-The default behaviour is a simple bulleted list,
-but this can be overridden by a template, `Template:Person/list-item`
-(the template name is specified by the `genealogy-person-list-item` system 
message).
-For example, to get a comma-separated one-line list of people, the following 
template code could be used:
-
-```
-{{{link}}}{{#ifeq:{{{index}}}|{{{count}}}|.|,}}
-```
-
-There are four parameters that are available for use in the list-item template:
-* `link` — A wikitext link.
-* `title` — The page title.
-* `index` — The index of this list-item in the full list, starting from 1. 
-* `count` — The total number of items in the full list.
-
-
-## Installation
-
-1. Clone the *Genealogy* and *GraphViz* extensions into your extensions 
directory:
-   ```
-   $ cd extensions
-   $ git clone 
https://gerrit.wikimedia.org/r/p/mediawiki/extensions/GraphViz.git
-   $ git clone 
https://gerrit.wikimedia.org/r/p/mediawiki/extensions/ImageMap.git
-   $ git clone 
https://gerrit.wikimedia.org/r/p/mediawiki/extensions/Genealogy.git
-   ```
-2. Enable them in your `LocalSettings.php` file:
-   ```
-   require_once "$IP/extensions/GraphViz/GraphViz.php";
-   require_once "$IP/extensions/ImageMap/ImageMap.php";
-   wfLoadExtension( 'Genealogy' );
-   ```
-
-
-## Development
-
-The *Genealogy* extension is developed by Sam Wilson and released under version
-3 of the GPL (see `LICENSE.txt` for details).
-
-You can see this extension in use on [ArchivesWiki](https://archives.org.au).
-
-Please report all bugs via Phabricator: http://phabricator.wikimedia.org/
diff --git a/extension.json b/extension.json
index 7bda702..ca2ebb1 100644
--- a/extension.json
+++ b/extension.json
@@ -20,8 +20,7 @@
        },
        "Hooks": {
                "ParserFirstCallInit": 
"MediaWiki\\Extensions\\Genealogy\\Hooks::onParserFirstCallInit",
-               "UnitTestsList": 
"MediaWiki\\Extensions\\Genealogy\\Hooks::onUnitTestsList",
-               "EditPageBeforeEditToolbar": 
"MediaWiki\\Extensions\\Genealogy\\Hooks::onEditPageBeforeEditToolbar"
+               "EditPage::showEditForm:initial": 
"MediaWiki\\Extensions\\Genealogy\\Hooks::onEditPageShowEditFormInitial"
        },
        "manifest_version": 1
 }
diff --git a/src/Hooks.php b/src/Hooks.php
index 73d6dc9..bb5fc72 100644
--- a/src/Hooks.php
+++ b/src/Hooks.php
@@ -3,14 +3,10 @@
 namespace MediaWiki\Extensions\Genealogy;
 
 use EditPage;
-use GraphRenderParms;
-use GraphViz;
-use Linker;
-use MediaWiki\Linker\LinkRendererFactory;
+use MediaWiki\MediaWikiServices;
+use OutputPage;
 use Parser;
 use Title;
-use WikiPage;
-use Xml;
 
 class Hooks {
 
@@ -25,36 +21,24 @@
        }
 
        /**
-        * Hooked to UnitTestsList.
-        * @param String[] $files
-        * @return boolean
-        */
-       public static function onUnitTestsList( &$files ) {
-               $files = array_merge( $files, glob( __DIR__ . 
'/tests/phpunit/*Test.php' ) );
-               return true;
-
-       }
-
-       /**
-        * This method is called by the EditPageBeforeEditToolbar hook and adds 
a list of the current
-        * page's Genealogy partners that *aren't* a result of a 
{{#genealogy:partner|…}} call in the
-        * current page.
-        * @param string $toolbarHtml The existing toolbar HTMl.
+        * This method is called by the EditPage::showEditForm:initial hook and 
adds a list of the
+        * current page's Genealogy partners that *are not* a result of a 
{{#genealogy:partner|…}} call
+        * in the current page.
+        * @param EditPage $editPage The current page that's being edited.
+        * @param OutputPage $output The output.
         * @return void
         */
-       public static function onEditPageBeforeEditToolbar( &$toolbarHtml ) {
-               global $wgTitle;
-               $person = new Person( $wgTitle );
+       public static function onEditPageShowEditFormInitial( EditPage 
&$editPage, OutputPage &$output  ) {
+               $person = new Person( $editPage->getTitle() );
                $peopleList = [];
+               $renderer = MediaWikiServices::getInstance()->getLinkRenderer();
                foreach ( $person->getPartners( true ) as $partner ) {
-                       $peopleList[] = '<a 
href="'.$partner->getTitle()->getLinkURL().'">'
-                               .$partner->getTitle()->getText()
-                               ."</a>";
+                       $peopleList[] = $renderer->makeKnownLink( 
$partner->getTitle() );
                }
                if ( count( $peopleList ) > 0 ) {
                        $msg = wfMessage( 'genealogy-existing-partners', count( 
$peopleList ) );
                        $successBox = '<p class="successbox">' . $msg. join( ', 
', $peopleList ) . '</p>';
-                       $toolbarHtml = $successBox . $toolbarHtml;
+                       $output->addHTML( $successBox );
                }
        }
 
diff --git a/src/Person.php b/src/Person.php
index 767241a..8dfbb51 100644
--- a/src/Person.php
+++ b/src/Person.php
@@ -91,9 +91,9 @@
                if ( !empty( $birthYear ) && !empty( $deathYear ) ) {
                        $dateString = "($birthYear&ndash;$deathYear)";
                } elseif ( !empty( $birthYear ) && empty( $deathYear ) ) {
-                       $dateString = "(".wfMessage( 'genealogy-born' 
)."&nbsp;$birthYear)";
+                       $dateString = "(".wfMessage( 'genealogy-born' 
)->text()."&nbsp;$birthYear)";
                } elseif ( empty( $birthYear ) && !empty( $deathYear ) ) {
-                       $dateString = "(".wfMessage( 'genealogy-died' 
)."&nbsp;$deathYear)";
+                       $dateString = "(".wfMessage( 'genealogy-died' 
)->text()."&nbsp;$deathYear)";
                }
                $date = ( $this->hasDates() ) ? " $dateString" : "";
                if ( $this->getTitle()->exists() ) {
@@ -101,7 +101,7 @@
                } else {
                        $query = [
                                'action' => 'edit',
-                               'preload' => wfMessage( 
'genealogy-person-preload' ),
+                               'preload' => wfMessage( 
'genealogy-person-preload' )->text(),
                        ];
                        $url = $this->getTitle()->getFullURL( $query );
                        return '[' . $url . ' ' . 
$this->getTitle()->getFullText() . ']';
@@ -222,7 +222,7 @@
 
                $where = [
                        'pp_value' => $this->getTitles(),
-                       "pp_propname LIKE 'genealogy $type %'",
+                       'pp_propname' . $dbr->buildLike( 'genealogy ', $type.' 
', $dbr->anyString() ),
                        'pp_page = page_id',
                ];
                $results = $dbr->select( $tables, $columns, $where, __METHOD__, 
[], [ 'page'=>[] ] );
@@ -260,8 +260,8 @@
                                'page_props', // table to use
                                'pp_value', // Field to select
                        [ // where conditions
-                       'pp_page' => $articleIds,
-                       "pp_propname LIKE 'genealogy $type %'"
+                               'pp_page' => $articleIds,
+                               'pp_propname' . $dbr->buildLike( 'genealogy ', 
$type.' ', $dbr->anyString() ),
                        ],
                        __METHOD__,
                        [ 'ORDER BY' => 'pp_value' ]

-- 
To view, visit https://gerrit.wikimedia.org/r/322631
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I4f4ce9ca012eaf29fd8103983ac1a0fa85f55e27
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Genealogy
Gerrit-Branch: master
Gerrit-Owner: Samwilson <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to