Extension:Lockdown/hiding pages

From MediaWiki.org

Jump to: navigation, search

This page contains patches to mediawiki that will hide pages that are not readable from several listings. These patches have been provided by User:WIKImaniac ([1]).

Contents

[edit] security flaws & bugfixes

Following instructions have to be read like this:

+        add this line
         don't change this line
         … /* indicates that some lines have been left out here */
-        remove this line

[edit] Special:Search

patch
file SpecialSearch.php
function showMatches
description avoids content of protected pages appearing in search results
author(s) WIKImaniac
date 2008-02-04
MediaWiki version 1.10.0
while( $result = $matches->next() ) {
+              if ( ( $result->getTitle() != NULL ) && ( $result->getTitle()->userCanRead() ) ) {
                        $out .= $this->showHit( $result, $terms );
+                     }
                }

[edit] Special:Allpages, …

patch
file Lockdown.php
description avoids names of protected namespaces appearing in combo boxes
author(s) Adrian Mikula
/* Checks whether the given namespace is visible to the user who is logged in.
*  @author Adrian Mikula
*  @return Boolean
*/

function namespaceIsVisible($ns)
{
        global $wgNamespacePermissionLockdown, $wgUser;

        $groups = @$wgNamespacePermissionLockdown[$ns]['read'];
        if (!$groups) $groups = @$wgNamespacePermissionLockdown['*']['read'];
        if (!$groups) $groups = @$wgNamespacePermissionLockdown[$ns]['*'];
        if (!$groups) return true;

        $ugroups = $wgUser->getEffectiveGroups();
        $match = array_intersect($ugroups, $groups);
        if ($match) return true;
        return false;
}

/* Removes hidden namespaces from an array of namespaces.
*  @author Adrian Mikula
*  @return array
*/

function filterHiddenNamespaces($namespaces)
{
        foreach ( $namespaces as $ns => $name )
        {
                if (!namespaceIsVisible($ns))
                {
                        unset($namespaces[$ns]);
                }
        }
        return $namespaces;
}
patch
file Language\Language.php
function getNamespaces
description avoids names of protected namespaces appearing in combo boxes
author(s) Adrian Mikula
function getNamespaces() {
                $this->load();
-                return $this->namespaceNames;
+                return filterHiddenNamespaces($this->namespaceNames);
        }

[edit] Special:Recentchanges

patch
file includes\SpecialRecentchanges.php
function wfSpecialRecentchanges
description avoids changes and edit summary of protected pages appearing in recent changes
author(s) WIKImaniac
date 2008-02-04
MediaWiki version 1.10.0
# Namespace filtering
        $hidem .= is_null( $namespace ) ?  '' : ' AND rc_namespace' . ($invert ? '!=' : '=') . $namespace;

+       global $wgExtraNamespaces;

+       foreach ( $wgExtraNamespaces as $num => $title ) {
+              if (!namespaceIsVisible($num)) {
+                     $hidem .= ' AND rc_namespace!='.$num;
+              }
+       }

[edit] Special:Wantedpages

patch
file includes\SpecialWantedpages.php
function formatResult
description avoids entries of protected pages appearing in wanted changes
author(s) WIKImaniac
date 2008-02-04
MediaWiki version 1.10.0
function formatResult( $skin, $result ) {
+              global $wgLang;
+              if ( namespaceIsVisible( $result->namespace ) ) {
                        $title = Title::makeTitleSafe( $result->namespace, $result->title );
                        …
+              }
        }

[edit] Special:Logs

patch
file includes\SpecialLog.php
function logLine
description avoids entries of protected pages appearing in the logs
author(s) WIKImaniac
date 2008-02-04
MediaWiki version 1.10.0
function logLine( $s ) {
                global $wgLang, $wgUser;;       
+              if ( namespaceIsVisible( $s->log_namespace ) ) {
                        $skin = $wgUser->getSkin();
                        …
+              }
        }

[edit] Categories

patch
file includes\CategoryPage.php
function addPage
description avoids entries of protected pages appearing in categories
author(s) WIKImaniac
date 2008-02-04
MediaWiki version 1.10.0
function addPage( $title, $sortkey, $pageLength ) {
                global $wgContLang;
+              if ( namespaceIsVisible( $title->getNamespace() ) ) {
                        $this->articles[] = $this->getSkin()->makeSizeLinkObj(
                                $pageLength, $title, $wgContLang->convert( $title->getPrefixedText() )
                        );
                        $this->articles_start_char[] = $wgContLang->convert( $wgContLang->firstChar( $sortkey ) );
+              }
        }

[edit] Special:Prefixindex

patch
file includes\SpecialPrefixindex.php
function showChunk
description avoids entries of protected pages appearing in prefixindex
author(s) WIKImaniac
date 2008-02-04
MediaWiki version 1.10.0
$out = '<table style="background: inherit;" border="0" width="100%">';

                while( ($n < $this->maxPerPage) && ($s = $dbr->fetchObject( $res )) ) {
+                     if ( namespaceIsVisible( $s->page_namespace ) ) {
                                $t = Title::makeTitle( $s->page_namespace, $s->page_title );
                                if( $t ) {
                                        $link = ($s->page_is_redirect ? '<div class="allpagesredirect">' : '' ) .
                                                $sk->makeKnownLinkObj( $t, htmlspecialchars( $t->getText() ), false, false ) .
                                                ($s->page_is_redirect ? '</div>' : '' );
                                } else {
                                        $link = '[[' . htmlspecialchars( $s->page_title ) . ']]';
                                }
                                if( $n % 3 == 0 ) {
                                        $out .= '<tr>';
                                }
                                $out .= "<td>$link</td>";
                                $n++;
                                if( $n % 3 == 0 ) {
                                        $out .= '</tr>';
                                }
+                     }
                }

[edit] Special:Mostlinked

patch
file includes\SpecialMostlinked.php
function formatResult
description avoids entries of protected pages appearing in most linked pages
author(s) WIKImaniac
date 2008-02-04
MediaWiki version 1.10.0
function formatResult( $skin, $result ) {
                global $wgLang;

+                if ( namespaceIsVisible( $result->namespace ) ) {
                        $title = Title::makeTitleSafe( $result->namespace, $result->title );
                        $link = $skin->makeLinkObj( $title );
                        $wlh = $this->makeWlhLink( $title,
                                wfMsgExt( 'nlinks', array( 'parsemag', 'escape'),
                                        $wgLang->formatNum( $result->value ) ), $skin );
                        return wfSpecialList( $link, $wlh );
+                }
        }
}

[edit] Special:Listredirects

patch
file includes\SpecialListredirects.php
function formatResult
description avoids entries of protected pages appearing in list of redirects
author(s) WIKImaniac
date 2008-02-04
MediaWiki version 1.10.0
function formatResult( $skin, $result ) {
                global $wgContLang;

+              if ( namespaceIsVisible( $result->namespace ) ) {

                        # Make a link to the redirect itself
                        $rd_title = Title::makeTitle( $result->namespace, $result->title );
                        …
+              }
        }

[edit] Special:Linksearch

patch
file extensions\LinkSearch\LinkSearch_body.php
function formatResult
description avoids entries of protected pages appearing in Special:Linksearch – if you are using Extension:LinkSearch
author(s) WIKImaniac
date 2008-02-04
MediaWiki version 1.10.0
function formatResult( $skin, $result ) {
+              if ( namespaceIsVisible( $result->namespace ) ) {
                        $title = Title::makeTitle( $result->namespace, $result->title );
                        $url = $result->url;
                        $pageLink = $skin->makeKnownLinkObj( $title );
                        $urlLink = $skin->makeExternalLink( $url, $url );

                        return wfMsgHtml( 'linksearch-line', $urlLink, $pageLink );
+              }
        }
Personal tools