Hoo man has submitted this change and it was merged.

Change subject: Check that $title is defined and is a Title object
......................................................................


Check that $title is defined and is a Title object

During testing the context does not always contain a valid
Title object. In those cases AbuseFilter will fail hard.
This changeset makes the filter survive some of those
failures.

Change-Id: I0b2247432619ddf15cc17ed41b4b7a6a11e910e0
---
M AbuseFilter.class.php
M AbuseFilter.hooks.php
2 files changed, 31 insertions(+), 29 deletions(-)

Approvals:
  Hoo man: Verified; Looks good to me, approved



diff --git a/AbuseFilter.class.php b/AbuseFilter.class.php
index cb4daa8..ba17032 100644
--- a/AbuseFilter.class.php
+++ b/AbuseFilter.class.php
@@ -1920,7 +1920,7 @@
                $vars = new AbuseFilterVariableHolder;
 
                // NOTE: $page may end up remaining null, e.g. if $title points 
to a special page.
-               if ( !$page && $title->canExist() && $title->exists() ) {
+               if ( !$page && $title instanceof Title && $title->canExist() && 
$title->exists() ) {
                        $page = WikiPage::factory( $title );
                }
 
@@ -1938,42 +1938,44 @@
                        array( 'diff-var' => 'edit_diff', 'line-prefix' => '-' 
) );
 
                // Links
-               $vars->setLazyLoadVar( 'all_links', 'links-from-wikitext',
-                       array(
-                               'namespace' => $title->getNamespace(),
-                               'title' => $title->getText(),
-                               'text-var' => 'new_wikitext',
-                               'article' => $page
-                       ) );
-               $vars->setLazyLoadVar( 'old_links', 
'links-from-wikitext-or-database',
-                       array(
-                               'namespace' => $title->getNamespace(),
-                               'title' => $title->getText(),
-                               'text-var' => 'old_wikitext'
-                       ) );
                $vars->setLazyLoadVar( 'added_links', 'link-diff-added',
                        array( 'oldlink-var' => 'old_links', 'newlink-var' => 
'all_links' ) );
                $vars->setLazyLoadVar( 'removed_links', 'link-diff-removed',
                        array( 'oldlink-var' => 'old_links', 'newlink-var' => 
'all_links' ) );
-
-               $vars->setLazyLoadVar( 'new_html', 'parse-wikitext',
-                       array(
-                               'namespace' => $title->getNamespace(),
-                               'title' => $title->getText(),
-                               'wikitext-var' => 'new_wikitext',
-                               'article' => $page
-                       ) );
                $vars->setLazyLoadVar( 'new_text', 'strip-html',
                        array( 'html-var' => 'new_html' ) );
-               $vars->setLazyLoadVar( 'old_html', 'parse-wikitext-nonedit',
-                       array(
-                               'namespace' => $title->getNamespace(),
-                               'title' => $title->getText(),
-                               'wikitext-var' => 'old_wikitext'
-                       ) );
                $vars->setLazyLoadVar( 'old_text', 'strip-html',
                        array( 'html-var' => 'old_html' ) );
 
+               if ( $title instanceof Title ) {
+                       $vars->setLazyLoadVar( 'all_links', 
'links-from-wikitext',
+                               array(
+                                       'namespace' => $title->getNamespace(),
+                                       'title' => $title->getText(),
+                                       'text-var' => 'new_wikitext',
+                                       'article' => $page
+                               ) );
+                       $vars->setLazyLoadVar( 'old_links', 
'links-from-wikitext-or-database',
+                               array(
+                                       'namespace' => $title->getNamespace(),
+                                       'title' => $title->getText(),
+                                       'text-var' => 'old_wikitext'
+                               ) );
+                       $vars->setLazyLoadVar( 'new_html', 'parse-wikitext',
+                               array(
+                                       'namespace' => $title->getNamespace(),
+                                       'title' => $title->getText(),
+                                       'wikitext-var' => 'new_wikitext',
+                                       'article' => $page
+                               ) );
+                       $vars->setLazyLoadVar( 'old_html', 
'parse-wikitext-nonedit',
+                               array(
+                                       'namespace' => $title->getNamespace(),
+                                       'title' => $title->getText(),
+                                       'wikitext-var' => 'old_wikitext'
+                               ) );
+               }
+
                return $vars;
        }
 
diff --git a/AbuseFilter.hooks.php b/AbuseFilter.hooks.php
index 47bcf9c..a6edf6b 100644
--- a/AbuseFilter.hooks.php
+++ b/AbuseFilter.hooks.php
@@ -83,7 +83,7 @@
                $oldcontent = null;
 
                $title = $context->getTitle();
-               if ( $title->canExist() && $title->exists() ) {
+               if ( ( $title instanceof Title ) && $title->canExist() && 
$title->exists() ) {
                        // Make sure we load the latest text saved in database 
(bug 31656)
                        $page = $context->getWikiPage();
                        $revision = $page->getRevision();

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I0b2247432619ddf15cc17ed41b4b7a6a11e910e0
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/AbuseFilter
Gerrit-Branch: master
Gerrit-Owner: John Erling Blad <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Hoo man <[email protected]>

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

Reply via email to