Skip to content

Commit

Permalink
* normalize()d page titles now correctly use the localized namespace …
Browse files Browse the repository at this point in the history
…title. Fixes issue 68.

* Fix incorrect normalization of pages with namespace != 0
* Moved a bunch of tests that don't require admin access
  • Loading branch information
MER-C committed Mar 23, 2015
1 parent 2f0aa88 commit f0c7926
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
15 changes: 11 additions & 4 deletions src/org/wikipedia/Wiki.java
Expand Up @@ -6992,20 +6992,27 @@ public String normalize(String s) throws IOException
s = s.substring(1);
if (s.isEmpty())
return s;

int ns = namespace(s);
// localize namespace names
if (ns != MAIN_NAMESPACE)
{
int colon = s.indexOf(":");
s = namespaceIdentifier(ns) + s.substring(colon);
}
char[] temp = s.toCharArray();
if (wgCapitalLinks)
{
// convert first character in the actual title to upper case
int ns = namespace(s);
if (ns == MAIN_NAMESPACE)
temp[0] = Character.toUpperCase(temp[0]);
else
{
// don't forget the extra colon
int index = namespaceIdentifier(ns).length();
temp[index] = Character.toUpperCase(temp[index]);
int index = namespaceIdentifier(ns).length() + 1; // + 1 for colon
temp[index] = Character.toUpperCase(temp[index]);
}
}

for (int i = 0; i < temp.length; i++)
{
switch (temp[i])
Expand Down
14 changes: 2 additions & 12 deletions test/org/wikipedia/AdminUnitTest.java
Expand Up @@ -6,7 +6,7 @@
import static org.junit.Assert.*;

/**
* Unit tests for Wiki.java
* Unit tests for Wiki.java requiring administrator access.
* @author MER-C
*/

Expand All @@ -25,17 +25,7 @@ public static void setUpClass()
enWiki.setMaxLag(-1);
}

@Test
public void getRevision() throws Exception
{
// revdel
// https://en.wikipedia.org/w/index.php?title=Imran_Khan_%28singer%29&oldid=596714684
Wiki.Revision rev = enWiki.getRevision(596714684L);
assertTrue("getRevision: user revdeled", rev.isUserDeleted());
assertTrue("getRevision: summary revdeled", rev.isSummaryDeleted());
assertTrue("getRevision: content revdeled", rev.isContentDeleted());
}


/**
* See https://test.wikipedia.org/wiki/User:MER-C/UnitTests/Delete
* @throws Exception if something goes wrong
Expand Down
5 changes: 5 additions & 0 deletions test/org/wikipedia/WikiUnitTest.java
Expand Up @@ -217,6 +217,7 @@ public void normalize() throws Exception
assertEquals("normalize", "File:Blah.jpg", enWiki.normalize("File:Blah.jpg"));
assertEquals("normalize", "File:Blah.jpg", enWiki.normalize("File:blah.jpg"));
assertEquals("normalize", "Category:Wikipedia:blah", enWiki.normalize("Category:Wikipedia:blah"));
assertEquals("normalize", "Hilfe Diskussion:Glossar", deWiki.normalize("Help talk:Glossar"));
}

@Test
Expand Down Expand Up @@ -246,6 +247,10 @@ public void getRevision() throws Exception
rev = enWiki.getRevision(596714684L);
assertNull("getRevision: summary revdeled", rev.getSummary());
assertNull("getRevision: user revdeled", rev.getUser());
assertTrue("getRevision: user revdeled", rev.isUserDeleted());
assertTrue("getRevision: summary revdeled", rev.isSummaryDeleted());
// NOT IMPLEMENTED:
// assertTrue("getRevision: content revdeled", rev.isContentDeleted());
}

@Test
Expand Down

0 comments on commit f0c7926

Please sign in to comment.